| 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 "RemoteWebInspectorUI.h" |
| 28 | |
| 29 | #include "RemoteWebInspectorProxyMessages.h" |
| 30 | #include "RemoteWebInspectorUIMessages.h" |
| 31 | #include "WebCoreArgumentCoders.h" |
| 32 | #include "WebPage.h" |
| 33 | #include "WebProcess.h" |
| 34 | #include <WebCore/CertificateInfo.h> |
| 35 | #include <WebCore/Chrome.h> |
| 36 | #include <WebCore/DOMWrapperWorld.h> |
| 37 | #include <WebCore/FloatRect.h> |
| 38 | #include <WebCore/InspectorController.h> |
| 39 | |
| 40 | namespace WebKit { |
| 41 | using namespace WebCore; |
| 42 | |
| 43 | Ref<RemoteWebInspectorUI> RemoteWebInspectorUI::create(WebPage& page) |
| 44 | { |
| 45 | return adoptRef(*new RemoteWebInspectorUI(page)); |
| 46 | } |
| 47 | |
| 48 | RemoteWebInspectorUI::RemoteWebInspectorUI(WebPage& page) |
| 49 | : m_page(page) |
| 50 | , m_frontendAPIDispatcher(page) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | void RemoteWebInspectorUI::initialize(const String& debuggableType, const String& backendCommandsURL) |
| 55 | { |
| 56 | m_debuggableType = debuggableType; |
| 57 | m_backendCommandsURL = backendCommandsURL; |
| 58 | |
| 59 | m_page.corePage()->inspectorController().setInspectorFrontendClient(this); |
| 60 | |
| 61 | m_frontendAPIDispatcher.reset(); |
| 62 | m_frontendAPIDispatcher.dispatchCommand("setDockingUnavailable"_s , true); |
| 63 | } |
| 64 | |
| 65 | void RemoteWebInspectorUI::didSave(const String& url) |
| 66 | { |
| 67 | m_frontendAPIDispatcher.dispatchCommand("savedURL"_s , url); |
| 68 | } |
| 69 | |
| 70 | void RemoteWebInspectorUI::didAppend(const String& url) |
| 71 | { |
| 72 | m_frontendAPIDispatcher.dispatchCommand("appendedToURL"_s , url); |
| 73 | } |
| 74 | |
| 75 | void RemoteWebInspectorUI::sendMessageToFrontend(const String& message) |
| 76 | { |
| 77 | m_frontendAPIDispatcher.dispatchMessageAsync(message); |
| 78 | } |
| 79 | |
| 80 | void RemoteWebInspectorUI::sendMessageToBackend(const String& message) |
| 81 | { |
| 82 | WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::SendMessageToBackend(message), m_page.pageID()); |
| 83 | } |
| 84 | |
| 85 | void RemoteWebInspectorUI::windowObjectCleared() |
| 86 | { |
| 87 | if (m_frontendHost) |
| 88 | m_frontendHost->disconnectClient(); |
| 89 | |
| 90 | m_frontendHost = InspectorFrontendHost::create(this, m_page.corePage()); |
| 91 | m_frontendHost->addSelfToGlobalObjectInWorld(mainThreadNormalWorld()); |
| 92 | } |
| 93 | |
| 94 | void RemoteWebInspectorUI::frontendLoaded() |
| 95 | { |
| 96 | m_frontendAPIDispatcher.frontendLoaded(); |
| 97 | |
| 98 | m_frontendAPIDispatcher.dispatchCommand("setIsVisible"_s , true); |
| 99 | |
| 100 | bringToFront(); |
| 101 | } |
| 102 | |
| 103 | void RemoteWebInspectorUI::changeSheetRect(const FloatRect& rect) |
| 104 | { |
| 105 | WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::SetSheetRect(rect), m_page.pageID()); |
| 106 | } |
| 107 | |
| 108 | void RemoteWebInspectorUI::startWindowDrag() |
| 109 | { |
| 110 | WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::StartWindowDrag(), m_page.pageID()); |
| 111 | } |
| 112 | |
| 113 | void RemoteWebInspectorUI::moveWindowBy(float x, float y) |
| 114 | { |
| 115 | FloatRect frameRect = m_page.corePage()->chrome().windowRect(); |
| 116 | frameRect.move(x, y); |
| 117 | m_page.corePage()->chrome().setWindowRect(frameRect); |
| 118 | } |
| 119 | |
| 120 | WebCore::UserInterfaceLayoutDirection RemoteWebInspectorUI::userInterfaceLayoutDirection() const |
| 121 | { |
| 122 | return m_page.corePage()->userInterfaceLayoutDirection(); |
| 123 | } |
| 124 | |
| 125 | void RemoteWebInspectorUI::bringToFront() |
| 126 | { |
| 127 | WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::BringToFront(), m_page.pageID()); |
| 128 | } |
| 129 | |
| 130 | void RemoteWebInspectorUI::closeWindow() |
| 131 | { |
| 132 | m_page.corePage()->inspectorController().setInspectorFrontendClient(nullptr); |
| 133 | |
| 134 | WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::FrontendDidClose(), m_page.pageID()); |
| 135 | } |
| 136 | |
| 137 | void RemoteWebInspectorUI::reopen() |
| 138 | { |
| 139 | WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::Reopen(), m_page.pageID()); |
| 140 | } |
| 141 | |
| 142 | void RemoteWebInspectorUI::openInNewTab(const String& url) |
| 143 | { |
| 144 | WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::OpenInNewTab(url), m_page.pageID()); |
| 145 | } |
| 146 | |
| 147 | void RemoteWebInspectorUI::save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs) |
| 148 | { |
| 149 | WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::Save(filename, content, base64Encoded, forceSaveAs), m_page.pageID()); |
| 150 | } |
| 151 | |
| 152 | void RemoteWebInspectorUI::append(const String& filename, const String& content) |
| 153 | { |
| 154 | WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::Append(filename, content), m_page.pageID()); |
| 155 | } |
| 156 | |
| 157 | void RemoteWebInspectorUI::inspectedURLChanged(const String& urlString) |
| 158 | { |
| 159 | // Do nothing. The remote side can know if the main resource changed. |
| 160 | } |
| 161 | |
| 162 | void RemoteWebInspectorUI::showCertificate(const CertificateInfo& certificateInfo) |
| 163 | { |
| 164 | WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorProxy::ShowCertificate(certificateInfo), m_page.pageID()); |
| 165 | } |
| 166 | |
| 167 | } // namespace WebKit |
| 168 | |