1/*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#pragma once
33
34#include "InspectorFrontendClient.h"
35#include <wtf/Forward.h>
36#include <wtf/Noncopyable.h>
37#include <wtf/text/WTFString.h>
38
39namespace WebCore {
40
41class FloatRect;
42class Frame;
43class InspectorController;
44class InspectorBackendDispatchTask;
45class InspectorFrontendHost;
46class Page;
47
48class InspectorFrontendClientLocal : public InspectorFrontendClient {
49 WTF_MAKE_NONCOPYABLE(InspectorFrontendClientLocal);
50 WTF_MAKE_FAST_ALLOCATED;
51public:
52 class WEBCORE_EXPORT Settings {
53 public:
54 Settings() = default;
55 virtual ~Settings() = default;
56 virtual String getProperty(const String& name);
57 virtual void setProperty(const String& name, const String& value);
58 };
59
60 WEBCORE_EXPORT InspectorFrontendClientLocal(InspectorController* inspectedPageController, Page* frontendPage, std::unique_ptr<Settings>);
61 WEBCORE_EXPORT virtual ~InspectorFrontendClientLocal();
62
63 WEBCORE_EXPORT void windowObjectCleared() final;
64 WEBCORE_EXPORT void frontendLoaded() override;
65
66 void startWindowDrag() override { }
67 WEBCORE_EXPORT void moveWindowBy(float x, float y) final;
68
69 WEBCORE_EXPORT UserInterfaceLayoutDirection userInterfaceLayoutDirection() const final;
70
71 WEBCORE_EXPORT void requestSetDockSide(DockSide) final;
72 WEBCORE_EXPORT void changeAttachedWindowHeight(unsigned) final;
73 WEBCORE_EXPORT void changeAttachedWindowWidth(unsigned) final;
74 WEBCORE_EXPORT void changeSheetRect(const FloatRect&) final;
75 WEBCORE_EXPORT void openInNewTab(const String& url) final;
76 bool canSave() override { return false; }
77 void save(const String&, const String&, bool, bool) override { }
78 void append(const String&, const String&) override { }
79
80 virtual void attachWindow(DockSide) = 0;
81 virtual void detachWindow() = 0;
82
83 WEBCORE_EXPORT void sendMessageToBackend(const String& message) final;
84
85 WEBCORE_EXPORT bool isUnderTest() final;
86 bool isRemote() const final { return false; }
87 WEBCORE_EXPORT unsigned inspectionLevel() const final;
88
89 WEBCORE_EXPORT bool canAttachWindow();
90 WEBCORE_EXPORT void setDockingUnavailable(bool);
91
92 WEBCORE_EXPORT static unsigned constrainedAttachedWindowHeight(unsigned preferredHeight, unsigned totalWindowHeight);
93 WEBCORE_EXPORT static unsigned constrainedAttachedWindowWidth(unsigned preferredWidth, unsigned totalWindowWidth);
94
95 // Direct Frontend API
96 WEBCORE_EXPORT bool isDebuggingEnabled();
97 WEBCORE_EXPORT void setDebuggingEnabled(bool);
98
99 WEBCORE_EXPORT bool isTimelineProfilingEnabled();
100 WEBCORE_EXPORT void setTimelineProfilingEnabled(bool);
101
102 WEBCORE_EXPORT bool isProfilingJavaScript();
103 WEBCORE_EXPORT void startProfilingJavaScript();
104 WEBCORE_EXPORT void stopProfilingJavaScript();
105
106 WEBCORE_EXPORT void showConsole();
107
108 WEBCORE_EXPORT void showMainResourceForFrame(Frame*);
109
110 WEBCORE_EXPORT void showResources();
111
112 WEBCORE_EXPORT void setAttachedWindow(DockSide);
113
114 WEBCORE_EXPORT Page* inspectedPage() const;
115 Page* frontendPage() const { return m_frontendPage; }
116protected:
117 virtual void setAttachedWindowHeight(unsigned) = 0;
118 virtual void setAttachedWindowWidth(unsigned) = 0;
119 WEBCORE_EXPORT void restoreAttachedWindowHeight();
120
121 virtual void setSheetRect(const WebCore::FloatRect&) = 0;
122
123private:
124 bool evaluateAsBoolean(const String& expression);
125 void evaluateOnLoad(const String& expression);
126
127 friend class FrontendMenuProvider;
128 InspectorController* m_inspectedPageController { nullptr };
129 Page* m_frontendPage { nullptr };
130 // TODO(yurys): this ref shouldn't be needed.
131 RefPtr<InspectorFrontendHost> m_frontendHost;
132 std::unique_ptr<InspectorFrontendClientLocal::Settings> m_settings;
133 bool m_frontendLoaded { false };
134 DockSide m_dockSide;
135 Vector<String> m_evaluateOnLoad;
136 Ref<InspectorBackendDispatchTask> m_dispatchTask;
137};
138
139} // namespace WebCore
140