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 | #include "config.h" |
27 | #include "RemoteWebInspectorProxy.h" |
28 | |
29 | #include "APINavigation.h" |
30 | #include "RemoteWebInspectorProxyMessages.h" |
31 | #include "RemoteWebInspectorUIMessages.h" |
32 | #include "WebInspectorProxy.h" |
33 | #include "WebPageGroup.h" |
34 | #include "WebPageProxy.h" |
35 | #include <WebCore/CertificateInfo.h> |
36 | #include <WebCore/NotImplemented.h> |
37 | |
38 | namespace WebKit { |
39 | using namespace WebCore; |
40 | |
41 | RemoteWebInspectorProxy::RemoteWebInspectorProxy() |
42 | { |
43 | } |
44 | |
45 | RemoteWebInspectorProxy::~RemoteWebInspectorProxy() |
46 | { |
47 | ASSERT(!m_inspectorPage); |
48 | } |
49 | |
50 | void RemoteWebInspectorProxy::invalidate() |
51 | { |
52 | closeFrontendPageAndWindow(); |
53 | } |
54 | |
55 | void RemoteWebInspectorProxy::load(const String& debuggableType, const String& backendCommandsURL) |
56 | { |
57 | createFrontendPageAndWindow(); |
58 | |
59 | m_debuggableType = debuggableType; |
60 | m_backendCommandsURL = backendCommandsURL; |
61 | |
62 | m_inspectorPage->process().send(Messages::RemoteWebInspectorUI::Initialize(debuggableType, backendCommandsURL), m_inspectorPage->pageID()); |
63 | m_inspectorPage->loadRequest(URL(URL(), WebInspectorProxy::inspectorPageURL())); |
64 | } |
65 | |
66 | void RemoteWebInspectorProxy::closeFromBackend() |
67 | { |
68 | closeFrontendPageAndWindow(); |
69 | } |
70 | |
71 | void RemoteWebInspectorProxy::closeFromCrash() |
72 | { |
73 | // Behave as if the frontend just closed, so clients are informed the frontend is gone. |
74 | frontendDidClose(); |
75 | } |
76 | |
77 | void RemoteWebInspectorProxy::show() |
78 | { |
79 | bringToFront(); |
80 | } |
81 | |
82 | void RemoteWebInspectorProxy::sendMessageToFrontend(const String& message) |
83 | { |
84 | m_inspectorPage->process().send(Messages::RemoteWebInspectorUI::SendMessageToFrontend(message), m_inspectorPage->pageID()); |
85 | } |
86 | |
87 | void RemoteWebInspectorProxy::frontendDidClose() |
88 | { |
89 | Ref<RemoteWebInspectorProxy> protect(*this); |
90 | |
91 | if (m_client) |
92 | m_client->closeFromFrontend(); |
93 | |
94 | closeFrontendPageAndWindow(); |
95 | } |
96 | |
97 | void RemoteWebInspectorProxy::reopen() |
98 | { |
99 | ASSERT(!m_debuggableType.isEmpty()); |
100 | |
101 | closeFrontendPageAndWindow(); |
102 | load(m_debuggableType, m_backendCommandsURL); |
103 | } |
104 | |
105 | void RemoteWebInspectorProxy::bringToFront() |
106 | { |
107 | platformBringToFront(); |
108 | } |
109 | |
110 | void RemoteWebInspectorProxy::save(const String& suggestedURL, const String& content, bool base64Encoded, bool forceSaveDialog) |
111 | { |
112 | platformSave(suggestedURL, content, base64Encoded, forceSaveDialog); |
113 | } |
114 | |
115 | void RemoteWebInspectorProxy::append(const String& suggestedURL, const String& content) |
116 | { |
117 | platformAppend(suggestedURL, content); |
118 | } |
119 | |
120 | void RemoteWebInspectorProxy::setSheetRect(const FloatRect& rect) |
121 | { |
122 | platformSetSheetRect(rect); |
123 | } |
124 | |
125 | void RemoteWebInspectorProxy::startWindowDrag() |
126 | { |
127 | platformStartWindowDrag(); |
128 | } |
129 | |
130 | void RemoteWebInspectorProxy::openInNewTab(const String& url) |
131 | { |
132 | platformOpenInNewTab(url); |
133 | } |
134 | |
135 | void RemoteWebInspectorProxy::showCertificate(const CertificateInfo& certificateInfo) |
136 | { |
137 | platformShowCertificate(certificateInfo); |
138 | } |
139 | |
140 | void RemoteWebInspectorProxy::sendMessageToBackend(const String& message) |
141 | { |
142 | if (m_client) |
143 | m_client->sendMessageToBackend(message); |
144 | } |
145 | |
146 | void RemoteWebInspectorProxy::createFrontendPageAndWindow() |
147 | { |
148 | if (m_inspectorPage) |
149 | return; |
150 | |
151 | m_inspectorPage = platformCreateFrontendPageAndWindow(); |
152 | |
153 | trackInspectorPage(m_inspectorPage, nullptr); |
154 | |
155 | m_inspectorPage->process().addMessageReceiver(Messages::RemoteWebInspectorProxy::messageReceiverName(), m_inspectorPage->pageID(), *this); |
156 | m_inspectorPage->process().assumeReadAccessToBaseURL(*m_inspectorPage, WebInspectorProxy::inspectorBaseURL()); |
157 | } |
158 | |
159 | void RemoteWebInspectorProxy::closeFrontendPageAndWindow() |
160 | { |
161 | if (!m_inspectorPage) |
162 | return; |
163 | |
164 | m_inspectorPage->process().removeMessageReceiver(Messages::RemoteWebInspectorProxy::messageReceiverName(), m_inspectorPage->pageID()); |
165 | |
166 | untrackInspectorPage(m_inspectorPage); |
167 | |
168 | m_inspectorPage = nullptr; |
169 | |
170 | platformCloseFrontendPageAndWindow(); |
171 | } |
172 | |
173 | #if (!ENABLE(REMOTE_INSPECTOR) && !PLATFORM(MAC)) || PLATFORM(WPE) |
174 | WebPageProxy* RemoteWebInspectorProxy::platformCreateFrontendPageAndWindow() |
175 | { |
176 | notImplemented(); |
177 | return nullptr; |
178 | } |
179 | |
180 | void RemoteWebInspectorProxy::platformBringToFront() { } |
181 | void RemoteWebInspectorProxy::platformSave(const String&, const String&, bool, bool) { } |
182 | void RemoteWebInspectorProxy::platformAppend(const String&, const String&) { } |
183 | void RemoteWebInspectorProxy::platformSetSheetRect(const FloatRect&) { } |
184 | void RemoteWebInspectorProxy::platformStartWindowDrag() { } |
185 | void RemoteWebInspectorProxy::platformOpenInNewTab(const String&) { } |
186 | void RemoteWebInspectorProxy::platformShowCertificate(const CertificateInfo&) { } |
187 | void RemoteWebInspectorProxy::platformCloseFrontendPageAndWindow() { } |
188 | #endif |
189 | |
190 | } // namespace WebKit |
191 | |