1 | /* |
2 | * Copyright (C) 2016 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "APIObject.h" |
29 | #include "MessageReceiver.h" |
30 | #include <WebCore/FloatRect.h> |
31 | #include <wtf/Forward.h> |
32 | #include <wtf/HashMap.h> |
33 | #include <wtf/RetainPtr.h> |
34 | #include <wtf/text/WTFString.h> |
35 | |
36 | #if PLATFORM(MAC) |
37 | OBJC_CLASS NSURL; |
38 | OBJC_CLASS NSWindow; |
39 | OBJC_CLASS WKInspectorViewController; |
40 | OBJC_CLASS WKRemoteWebInspectorProxyObjCAdapter; |
41 | OBJC_CLASS WKWebView; |
42 | #endif |
43 | |
44 | namespace WebCore { |
45 | class CertificateInfo; |
46 | } |
47 | |
48 | namespace WebKit { |
49 | |
50 | class WebPageProxy; |
51 | class WebView; |
52 | |
53 | class RemoteWebInspectorProxyClient { |
54 | public: |
55 | virtual ~RemoteWebInspectorProxyClient() { } |
56 | virtual void sendMessageToBackend(const String& message) = 0; |
57 | virtual void closeFromFrontend() = 0; |
58 | }; |
59 | |
60 | class RemoteWebInspectorProxy : public RefCounted<RemoteWebInspectorProxy>, public IPC::MessageReceiver { |
61 | public: |
62 | static Ref<RemoteWebInspectorProxy> create() |
63 | { |
64 | return adoptRef(*new RemoteWebInspectorProxy()); |
65 | } |
66 | |
67 | ~RemoteWebInspectorProxy(); |
68 | |
69 | void setClient(RemoteWebInspectorProxyClient* client) { m_client = client; } |
70 | |
71 | bool isUnderTest() const { return false; } |
72 | |
73 | void invalidate(); |
74 | |
75 | void load(const String& debuggableType, const String& backendCommandsURL); |
76 | void closeFromBackend(); |
77 | void show(); |
78 | |
79 | void sendMessageToFrontend(const String& message); |
80 | |
81 | #if PLATFORM(MAC) |
82 | NSWindow *window() const { return m_window.get(); } |
83 | WKWebView *webView() const; |
84 | |
85 | const WebCore::FloatRect& sheetRect() const { return m_sheetRect; } |
86 | #endif |
87 | |
88 | #if PLATFORM(GTK) |
89 | void updateWindowTitle(const CString&); |
90 | #endif |
91 | |
92 | #if PLATFORM(WIN_CAIRO) |
93 | LRESULT sizeChange(); |
94 | LRESULT onClose(); |
95 | |
96 | static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); |
97 | #endif |
98 | |
99 | void closeFromCrash(); |
100 | |
101 | private: |
102 | RemoteWebInspectorProxy(); |
103 | |
104 | // IPC::MessageReceiver |
105 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
106 | |
107 | // RemoteWebInspectorProxy messages. |
108 | void frontendDidClose(); |
109 | void reopen(); |
110 | void bringToFront(); |
111 | void save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs); |
112 | void append(const String& filename, const String& content); |
113 | void setSheetRect(const WebCore::FloatRect&); |
114 | void startWindowDrag(); |
115 | void openInNewTab(const String& url); |
116 | void showCertificate(const WebCore::CertificateInfo&); |
117 | void sendMessageToBackend(const String& message); |
118 | |
119 | void createFrontendPageAndWindow(); |
120 | void closeFrontendPageAndWindow(); |
121 | |
122 | // Platform implementations. |
123 | WebPageProxy* platformCreateFrontendPageAndWindow(); |
124 | void platformCloseFrontendPageAndWindow(); |
125 | void platformBringToFront(); |
126 | void platformSave(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs); |
127 | void platformAppend(const String& filename, const String& content); |
128 | void platformSetSheetRect(const WebCore::FloatRect&); |
129 | void platformStartWindowDrag(); |
130 | void platformOpenInNewTab(const String& url); |
131 | void platformShowCertificate(const WebCore::CertificateInfo&); |
132 | |
133 | RemoteWebInspectorProxyClient* m_client { nullptr }; |
134 | WebPageProxy* m_inspectorPage { nullptr }; |
135 | |
136 | String m_debuggableType; |
137 | String m_backendCommandsURL; |
138 | |
139 | #if PLATFORM(MAC) |
140 | RetainPtr<WKInspectorViewController> m_inspectorView; |
141 | RetainPtr<NSWindow> m_window; |
142 | RetainPtr<WKRemoteWebInspectorProxyObjCAdapter> m_objCAdapter; |
143 | HashMap<String, RetainPtr<NSURL>> m_suggestedToActualURLMap; |
144 | WebCore::FloatRect m_sheetRect; |
145 | #endif |
146 | #if PLATFORM(GTK) |
147 | GtkWidget* m_webView { nullptr }; |
148 | GtkWidget* m_window { nullptr }; |
149 | #endif |
150 | #if PLATFORM(WIN_CAIRO) |
151 | HWND m_frontendHandle; |
152 | RefPtr<WebView> m_webView; |
153 | #endif |
154 | }; |
155 | |
156 | } // namespace WebKit |
157 | |