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 | |
52 | class RemoteWebInspectorProxyClient { |
53 | public: |
54 | virtual ~RemoteWebInspectorProxyClient() { } |
55 | virtual void sendMessageToBackend(const String& message) = 0; |
56 | virtual void closeFromFrontend() = 0; |
57 | }; |
58 | |
59 | class RemoteWebInspectorProxy : public RefCounted<RemoteWebInspectorProxy>, public IPC::MessageReceiver { |
60 | public: |
61 | static Ref<RemoteWebInspectorProxy> create() |
62 | { |
63 | return adoptRef(*new RemoteWebInspectorProxy()); |
64 | } |
65 | |
66 | ~RemoteWebInspectorProxy(); |
67 | |
68 | void setClient(RemoteWebInspectorProxyClient* client) { m_client = client; } |
69 | |
70 | bool isUnderTest() const { return false; } |
71 | |
72 | void invalidate(); |
73 | |
74 | void load(const String& debuggableType, const String& backendCommandsURL); |
75 | void closeFromBackend(); |
76 | void show(); |
77 | |
78 | void sendMessageToFrontend(const String& message); |
79 | |
80 | #if PLATFORM(MAC) |
81 | NSWindow *window() const { return m_window.get(); } |
82 | WKWebView *webView() const; |
83 | |
84 | const WebCore::FloatRect& sheetRect() const { return m_sheetRect; } |
85 | #endif |
86 | |
87 | #if PLATFORM(GTK) |
88 | void updateWindowTitle(const CString&); |
89 | #endif |
90 | |
91 | void closeFromCrash(); |
92 | |
93 | private: |
94 | RemoteWebInspectorProxy(); |
95 | |
96 | // IPC::MessageReceiver |
97 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
98 | |
99 | // RemoteWebInspectorProxy messages. |
100 | void frontendDidClose(); |
101 | void reopen(); |
102 | void bringToFront(); |
103 | void save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs); |
104 | void append(const String& filename, const String& content); |
105 | void setSheetRect(const WebCore::FloatRect&); |
106 | void startWindowDrag(); |
107 | void openInNewTab(const String& url); |
108 | void showCertificate(const WebCore::CertificateInfo&); |
109 | void sendMessageToBackend(const String& message); |
110 | |
111 | void createFrontendPageAndWindow(); |
112 | void closeFrontendPageAndWindow(); |
113 | |
114 | // Platform implementations. |
115 | WebPageProxy* platformCreateFrontendPageAndWindow(); |
116 | void platformCloseFrontendPageAndWindow(); |
117 | void platformBringToFront(); |
118 | void platformSave(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs); |
119 | void platformAppend(const String& filename, const String& content); |
120 | void platformSetSheetRect(const WebCore::FloatRect&); |
121 | void platformStartWindowDrag(); |
122 | void platformOpenInNewTab(const String& url); |
123 | void platformShowCertificate(const WebCore::CertificateInfo&); |
124 | |
125 | RemoteWebInspectorProxyClient* m_client { nullptr }; |
126 | WebPageProxy* m_inspectorPage { nullptr }; |
127 | |
128 | String m_debuggableType; |
129 | String m_backendCommandsURL; |
130 | |
131 | #if PLATFORM(MAC) |
132 | RetainPtr<WKInspectorViewController> m_inspectorView; |
133 | RetainPtr<NSWindow> m_window; |
134 | RetainPtr<WKRemoteWebInspectorProxyObjCAdapter> m_objCAdapter; |
135 | HashMap<String, RetainPtr<NSURL>> m_suggestedToActualURLMap; |
136 | WebCore::FloatRect m_sheetRect; |
137 | #endif |
138 | #if PLATFORM(GTK) |
139 | GtkWidget* m_webView { nullptr }; |
140 | GtkWidget* m_window { nullptr }; |
141 | #endif |
142 | }; |
143 | |
144 | } // namespace WebKit |
145 | |