File: WebInspectorUIProxy.h

package info (click to toggle)
webkit2gtk 2.42.2-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 362,452 kB
  • sloc: cpp: 2,881,971; javascript: 282,447; ansic: 134,088; python: 43,789; ruby: 18,308; perl: 15,872; asm: 14,389; xml: 4,395; yacc: 2,350; sh: 2,074; java: 1,734; lex: 1,323; makefile: 288; pascal: 60
file content (353 lines) | stat: -rw-r--r-- 12,102 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
 * Copyright (C) 2010-2021 Apple Inc. All rights reserved.
 * Portions Copyright (c) 2011 Motorola Mobility, Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

#pragma once

#include "APIObject.h"
#include "Connection.h"
#include "DebuggableInfoData.h"
#include "MessageReceiver.h"
#include "WebInspectorUtilities.h"
#include "WebPageProxyIdentifier.h"
#include <JavaScriptCore/InspectorFrontendChannel.h>
#include <WebCore/Color.h>
#include <WebCore/FloatRect.h>
#include <WebCore/InspectorClient.h>
#include <WebCore/InspectorFrontendClient.h>
#include <wtf/Forward.h>
#include <wtf/RefPtr.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>

#if PLATFORM(MAC)
#include "WKGeometry.h"
#include <WebCore/IntRect.h>
#include <wtf/HashMap.h>
#include <wtf/RetainPtr.h>
#include <wtf/RunLoop.h>

OBJC_CLASS NSString;
OBJC_CLASS NSURL;
OBJC_CLASS NSView;
OBJC_CLASS NSWindow;
OBJC_CLASS WKWebInspectorUIProxyObjCAdapter;
OBJC_CLASS WKInspectorViewController;
#elif PLATFORM(WIN)
#include "WebView.h"
#elif PLATFORM(GTK)
#include <wtf/glib/GWeakPtr.h>
#endif

namespace WebCore {
class CertificateInfo;
}

namespace API {
class InspectorClient;
}

namespace WebKit {

class WebFrameProxy;
class WebInspectorUIProxyClient;
class WebPageProxy;
class WebPreferences;
#if ENABLE(INSPECTOR_EXTENSIONS)
class WebInspectorUIExtensionControllerProxy;
#endif

enum class AttachmentSide {
    Bottom,
    Right,
    Left,
};

class WebInspectorUIProxy
    : public API::ObjectImpl<API::Object::Type::Inspector>
    , public IPC::MessageReceiver
    , public Inspector::FrontendChannel
#if PLATFORM(WIN)
    , public WebCore::WindowMessageListener
#endif
{
public:
    static Ref<WebInspectorUIProxy> create(WebPageProxy& inspectedPage)
    {
        return adoptRef(*new WebInspectorUIProxy(inspectedPage));
    }

    explicit WebInspectorUIProxy(WebPageProxy&);
    virtual ~WebInspectorUIProxy();

    void invalidate();

    API::InspectorClient& inspectorClient() { return *m_inspectorClient; }
    void setInspectorClient(std::unique_ptr<API::InspectorClient>&&);

    // Public APIs
    WebPageProxy* inspectedPage() const { return m_inspectedPage; }
    WebPageProxy* inspectorPage() const { return m_inspectorPage; }

#if ENABLE(INSPECTOR_EXTENSIONS)
    WebInspectorUIExtensionControllerProxy* extensionController() const { return m_extensionController.get(); }
#endif

    bool isConnected() const { return !!m_inspectorPage; }
    bool isVisible() const { return m_isVisible; }
    bool isFront();

    void connect();

    void show();
    void hide();
    void close();
    void closeForCrash();
    void reopen();
    void resetState();

    void reset();
    void updateForNewPageProcess(WebPageProxy&);

#if PLATFORM(MAC)
    enum class InspectionTargetType { Local, Remote };
    static RetainPtr<NSWindow> createFrontendWindow(NSRect savedWindowFrame, InspectionTargetType, WebPageProxy* inspectedPage = nullptr);
    static void showSavePanel(NSWindow *, NSURL *, Vector<WebCore::InspectorFrontendClient::SaveData>&&, bool forceSaveAs, CompletionHandler<void(NSURL *)>&&);

    void didBecomeActive();

    void updateInspectorWindowTitle() const;
    void inspectedViewFrameDidChange(CGFloat = 0);
    void windowFrameDidChange();
    void windowFullScreenDidChange();

    void closeFrontendPage();
    void closeFrontendAfterInactivityTimerFired();

    void attachmentViewDidChange(NSView *oldView, NSView *newView);
    void attachmentWillMoveFromWindow(NSWindow *oldWindow);
    void attachmentDidMoveToWindow(NSWindow *newWindow);

    const WebCore::FloatRect& sheetRect() const { return m_sheetRect; }
#endif

#if PLATFORM(WIN)
    static void showSavePanelForSingleFile(HWND, Vector<WebCore::InspectorFrontendClient::SaveData>&&);
#endif

#if PLATFORM(GTK)
    GtkWidget* inspectorView() const { return m_inspectorView.get(); };
    void setClient(std::unique_ptr<WebInspectorUIProxyClient>&&);
#endif

    void showConsole();
    void showResources();
    void showMainResourceForFrame(WebFrameProxy*);
    void openURLExternally(const String& url);
    void revealFileExternally(const String& path);

    AttachmentSide attachmentSide() const { return m_attachmentSide; }
    bool isAttached() const { return m_isAttached; }
    void attachRight();
    void attachLeft();
    void attachBottom();
    void attach(AttachmentSide = AttachmentSide::Bottom);
    void detach();

    void setAttachedWindowHeight(unsigned);
    void setAttachedWindowWidth(unsigned);

    void setSheetRect(const WebCore::FloatRect&);

    void startWindowDrag();

    bool isProfilingPage() const { return m_isProfilingPage; }
    void togglePageProfiling();

    bool isElementSelectionActive() const { return m_elementSelectionActive; }
    void toggleElementSelection();

    bool isUnderTest() const { return m_underTest; }

    void setDiagnosticLoggingAvailable(bool);

    // Provided by platform WebInspectorUIProxy implementations.
    static String inspectorPageURL();
    static String inspectorTestPageURL();
    static bool isMainOrTestInspectorPage(const URL&);
    static DebuggableInfoData infoForLocalDebuggable();

    static const unsigned minimumWindowWidth;
    static const unsigned minimumWindowHeight;

    static const unsigned initialWindowWidth;
    static const unsigned initialWindowHeight;

    // Testing methods.
    void evaluateInFrontendForTesting(const String&);

private:
    void createFrontendPage();
    void closeFrontendPageAndWindow();

    // IPC::MessageReceiver
    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;

    // Inspector::FrontendChannel
    void sendMessageToFrontend(const String& message) override;
    ConnectionType connectionType() const override { return ConnectionType::Local; }

    WebPageProxy* platformCreateFrontendPage();
    void platformCreateFrontendWindow();
    void platformCloseFrontendPageAndWindow();

    void platformDidCloseForCrash();
    void platformInvalidate();
    void platformResetState();
    void platformBringToFront();
    void platformBringInspectedPageToFront();
    void platformHide();
    bool platformIsFront();
    void platformAttachAvailabilityChanged(bool);
    void platformSetForcedAppearance(WebCore::InspectorFrontendClient::Appearance);
    void platformOpenURLExternally(const String&);
    void platformInspectedURLChanged(const String&);
    void platformShowCertificate(const WebCore::CertificateInfo&);
    void platformAttach();
    void platformDetach();
    void platformSetAttachedWindowHeight(unsigned);
    void platformSetAttachedWindowWidth(unsigned);
    void platformSetSheetRect(const WebCore::FloatRect&);
    void platformStartWindowDrag();
    void platformRevealFileExternally(const String&);
    void platformSave(Vector<WebCore::InspectorFrontendClient::SaveData>&&, bool forceSaveAs);
    void platformLoad(const String& path, CompletionHandler<void(const String&)>&&);
    void platformPickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&&);

#if PLATFORM(MAC)
    bool platformCanAttach(bool webProcessCanAttach);
#else
    bool platformCanAttach(bool webProcessCanAttach) { return webProcessCanAttach; }
#endif

    // Called by WebInspectorUIProxy messages
    void openLocalInspectorFrontend(bool canAttach, bool underTest);
    void setFrontendConnection(IPC::Connection::Handle&&);

    void sendMessageToBackend(const String&);
    void frontendLoaded();
    void didClose();
    void bringToFront();
    void bringInspectedPageToFront();
    void attachAvailabilityChanged(bool);
    void setForcedAppearance(WebCore::InspectorFrontendClient::Appearance);
    void inspectedURLChanged(const String&);
    void showCertificate(const WebCore::CertificateInfo&);
    void setInspectorPageDeveloperExtrasEnabled(bool);
    void elementSelectionChanged(bool);
    void timelineRecordingChanged(bool);

    void setDeveloperPreferenceOverride(WebCore::InspectorClient::DeveloperPreference, std::optional<bool>);
#if ENABLE(INSPECTOR_NETWORK_THROTTLING)
    void setEmulatedConditions(std::optional<int64_t>&& bytesPerSecondLimit);
#endif

    void save(Vector<WebCore::InspectorFrontendClient::SaveData>&&, bool forceSaveAs);
    void load(const String& path, CompletionHandler<void(const String&)>&&);
    void pickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&&);

    bool canAttach() const { return m_canAttach; }
    bool shouldOpenAttached();

    void open();

    unsigned inspectionLevel() const;

    WebPreferences& inspectorPagePreferences() const;

#if PLATFORM(MAC)
    void applyForcedAppearance();
#endif

#if PLATFORM(GTK) || PLATFORM(WPE)
    void updateInspectorWindowTitle() const;
#endif

#if PLATFORM(WIN)
    static LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);
    bool registerWindowClass();
    void windowReceivedMessage(HWND, UINT, WPARAM, LPARAM) override;
#endif

    WebPageProxy* m_inspectedPage { nullptr };
    WebPageProxy* m_inspectorPage { nullptr };
    std::unique_ptr<API::InspectorClient> m_inspectorClient;
    WebPageProxyIdentifier m_inspectedPageIdentifier;

#if ENABLE(INSPECTOR_EXTENSIONS)
    RefPtr<WebInspectorUIExtensionControllerProxy> m_extensionController;
#endif
    
    bool m_underTest { false };
    bool m_isVisible { false };
    bool m_isAttached { false };
    bool m_canAttach { false };
    bool m_isProfilingPage { false };
    bool m_showMessageSent { false };
    bool m_ignoreFirstBringToFront { false };
    bool m_elementSelectionActive { false };
    bool m_ignoreElementSelectionChange { false };
    bool m_isActiveFrontend { false };
    bool m_isOpening { false };
    bool m_closing { false };

    AttachmentSide m_attachmentSide {AttachmentSide::Bottom};

#if PLATFORM(MAC)
    RetainPtr<WKInspectorViewController> m_inspectorViewController;
    RetainPtr<NSWindow> m_inspectorWindow;
    RetainPtr<WKWebInspectorUIProxyObjCAdapter> m_objCAdapter;
    HashMap<String, RetainPtr<NSURL>> m_suggestedToActualURLMap;
    RunLoop::Timer m_closeFrontendAfterInactivityTimer;
    String m_urlString;
    WebCore::FloatRect m_sheetRect;
    WebCore::InspectorFrontendClient::Appearance m_frontendAppearance { WebCore::InspectorFrontendClient::Appearance::System };
    bool m_isObservingContentLayoutRect { false };
#elif PLATFORM(GTK)
    std::unique_ptr<WebInspectorUIProxyClient> m_client;
    GWeakPtr<GtkWidget> m_inspectorView;
    GWeakPtr<GtkWidget> m_inspectorWindow;
    GtkWidget* m_headerBar { nullptr };
    String m_inspectedURLString;
#elif PLATFORM(WIN)
    HWND m_inspectedViewWindow { nullptr };
    HWND m_inspectedViewParentWindow { nullptr };
    HWND m_inspectorViewWindow { nullptr };
    HWND m_inspectorDetachWindow { nullptr };
    RefPtr<WebView> m_inspectorView;
#endif
};

} // namespace WebKit