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 354 355 356 357 358 359 360 361 362 363 364
|
/*
* Copyright (C) 2016-2021 Apple 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.
*/
#include "config.h"
#include "RemoteWebInspectorUI.h"
#include "RemoteWebInspectorUIMessages.h"
#include "RemoteWebInspectorUIProxyMessages.h"
#include "WebCoreArgumentCoders.h"
#include "WebInspectorUI.h"
#include "WebPage.h"
#include "WebProcess.h"
#include <WebCore/CertificateInfo.h>
#include <WebCore/Chrome.h>
#include <WebCore/DOMWrapperWorld.h>
#include <WebCore/FloatRect.h>
#include <WebCore/InspectorController.h>
#include <WebCore/Page.h>
#include <WebCore/Settings.h>
#if ENABLE(INSPECTOR_EXTENSIONS)
#include "WebInspectorUIExtensionController.h"
#endif
#if !PLATFORM(MAC) && !PLATFORM(GTK) && !PLATFORM(WIN)
#include <WebCore/NotImplemented.h>
#endif
namespace WebKit {
using namespace WebCore;
Ref<RemoteWebInspectorUI> RemoteWebInspectorUI::create(WebPage& page)
{
return adoptRef(*new RemoteWebInspectorUI(page));
}
RemoteWebInspectorUI::RemoteWebInspectorUI(WebPage& page)
: m_page(page)
, m_frontendAPIDispatcher(InspectorFrontendAPIDispatcher::create(*page.corePage()))
{
WebInspectorUI::enableFrontendFeatures(page);
}
RemoteWebInspectorUI::~RemoteWebInspectorUI() = default;
void RemoteWebInspectorUI::initialize(DebuggableInfoData&& debuggableInfo, const String& backendCommandsURL)
{
#if ENABLE(INSPECTOR_EXTENSIONS)
m_extensionController = makeUnique<WebInspectorUIExtensionController>(*this, m_page.identifier());
#endif
m_debuggableInfo = WTFMove(debuggableInfo);
m_backendCommandsURL = backendCommandsURL;
m_page.corePage()->inspectorController().setInspectorFrontendClient(this);
m_frontendAPIDispatcher->reset();
m_frontendAPIDispatcher->dispatchCommandWithResultAsync("setDockingUnavailable"_s, { JSON::Value::create(true) });
}
void RemoteWebInspectorUI::updateFindString(const String& findString)
{
m_frontendAPIDispatcher->dispatchCommandWithResultAsync("updateFindString"_s, { JSON::Value::create(findString) });
}
void RemoteWebInspectorUI::sendMessageToFrontend(const String& message)
{
m_frontendAPIDispatcher->dispatchMessageAsync(message);
}
void RemoteWebInspectorUI::sendMessageToBackend(const String& message)
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::SendMessageToBackend(message), m_page.identifier());
}
void RemoteWebInspectorUI::windowObjectCleared()
{
if (m_frontendHost)
m_frontendHost->disconnectClient();
m_frontendHost = InspectorFrontendHost::create(this, m_page.corePage());
m_frontendHost->addSelfToGlobalObjectInWorld(mainThreadNormalWorld());
}
void RemoteWebInspectorUI::frontendLoaded()
{
m_frontendAPIDispatcher->frontendLoaded();
m_frontendAPIDispatcher->dispatchCommandWithResultAsync("setIsVisible"_s, { JSON::Value::create(true) });
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::FrontendLoaded(), m_page.identifier());
bringToFront();
}
void RemoteWebInspectorUI::pagePaused()
{
m_frontendAPIDispatcher->suspend();
}
void RemoteWebInspectorUI::pageUnpaused()
{
m_frontendAPIDispatcher->unsuspend();
}
void RemoteWebInspectorUI::changeSheetRect(const FloatRect& rect)
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::SetSheetRect(rect), m_page.identifier());
}
void RemoteWebInspectorUI::setForcedAppearance(WebCore::InspectorFrontendClient::Appearance appearance)
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::SetForcedAppearance(appearance), m_page.identifier());
}
void RemoteWebInspectorUI::startWindowDrag()
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::StartWindowDrag(), m_page.identifier());
}
void RemoteWebInspectorUI::moveWindowBy(float x, float y)
{
FloatRect frameRect = m_page.corePage()->chrome().windowRect();
frameRect.move(x, y);
m_page.corePage()->chrome().setWindowRect(frameRect);
}
WebCore::UserInterfaceLayoutDirection RemoteWebInspectorUI::userInterfaceLayoutDirection() const
{
return m_page.corePage()->userInterfaceLayoutDirection();
}
bool RemoteWebInspectorUI::supportsDockSide(DockSide dockSide)
{
switch (dockSide) {
case DockSide::Undocked:
return true;
case DockSide::Right:
case DockSide::Left:
case DockSide::Bottom:
return false;
}
ASSERT_NOT_REACHED();
return false;
}
void RemoteWebInspectorUI::bringToFront()
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::BringToFront(), m_page.identifier());
}
void RemoteWebInspectorUI::closeWindow()
{
m_page.corePage()->inspectorController().setInspectorFrontendClient(nullptr);
#if ENABLE(INSPECTOR_EXTENSIONS)
m_extensionController = nullptr;
#endif
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::FrontendDidClose(), m_page.identifier());
}
void RemoteWebInspectorUI::reopen()
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::Reopen(), m_page.identifier());
}
void RemoteWebInspectorUI::resetState()
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::ResetState(), m_page.identifier());
}
void RemoteWebInspectorUI::showConsole()
{
m_frontendAPIDispatcher->dispatchCommandWithResultAsync("showConsole"_s);
}
void RemoteWebInspectorUI::showResources()
{
m_frontendAPIDispatcher->dispatchCommandWithResultAsync("showResources"_s);
}
void RemoteWebInspectorUI::openURLExternally(const String& url)
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::OpenURLExternally(url), m_page.identifier());
}
void RemoteWebInspectorUI::revealFileExternally(const String& path)
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::RevealFileExternally(path), m_page.identifier());
}
void RemoteWebInspectorUI::save(Vector<WebCore::InspectorFrontendClient::SaveData>&& saveDatas, bool forceSaveAs)
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::Save(WTFMove(saveDatas), forceSaveAs), m_page.identifier());
}
void RemoteWebInspectorUI::load(const String& path, CompletionHandler<void(const String&)>&& completionHandler)
{
WebProcess::singleton().parentProcessConnection()->sendWithAsyncReply(Messages::RemoteWebInspectorUIProxy::Load(path), WTFMove(completionHandler), m_page.identifier());
}
void RemoteWebInspectorUI::pickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler)
{
WebProcess::singleton().parentProcessConnection()->sendWithAsyncReply(Messages::RemoteWebInspectorUIProxy::PickColorFromScreen(), WTFMove(completionHandler), m_page.identifier());
}
void RemoteWebInspectorUI::inspectedURLChanged(const String& urlString)
{
// Do nothing. The remote side can know if the main resource changed.
}
void RemoteWebInspectorUI::showCertificate(const CertificateInfo& certificateInfo)
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::ShowCertificate(certificateInfo), m_page.identifier());
}
void RemoteWebInspectorUI::setInspectorPageDeveloperExtrasEnabled(bool enabled)
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::SetInspectorPageDeveloperExtrasEnabled(enabled), m_page.identifier());
}
Inspector::DebuggableType RemoteWebInspectorUI::debuggableType() const
{
return m_debuggableInfo.debuggableType;
}
String RemoteWebInspectorUI::targetPlatformName() const
{
return m_debuggableInfo.targetPlatformName;
}
String RemoteWebInspectorUI::targetBuildVersion() const
{
return m_debuggableInfo.targetBuildVersion;
}
String RemoteWebInspectorUI::targetProductVersion() const
{
return m_debuggableInfo.targetProductVersion;
}
bool RemoteWebInspectorUI::targetIsSimulator() const
{
return m_debuggableInfo.targetIsSimulator;
}
#if ENABLE(INSPECTOR_TELEMETRY)
bool RemoteWebInspectorUI::supportsDiagnosticLogging()
{
return m_page.corePage()->settings().diagnosticLoggingEnabled();
}
void RemoteWebInspectorUI::logDiagnosticEvent(const String& eventName, const DiagnosticLoggingClient::ValueDictionary& dictionary)
{
m_page.corePage()->diagnosticLoggingClient().logDiagnosticMessageWithValueDictionary(eventName, "Remote Web Inspector Frontend Diagnostics"_s, dictionary, ShouldSample::No);
}
void RemoteWebInspectorUI::setDiagnosticLoggingAvailable(bool available)
{
// Inspector's diagnostic logging client should never be used unless the page setting is also enabled.
ASSERT(!available || supportsDiagnosticLogging());
m_diagnosticLoggingAvailable = available;
m_frontendAPIDispatcher->dispatchCommandWithResultAsync("setDiagnosticLoggingAvailable"_s, { JSON::Value::create(m_diagnosticLoggingAvailable) });
}
#endif // ENABLE(INSPECTOR_TELEMETRY)
#if ENABLE(INSPECTOR_EXTENSIONS)
bool RemoteWebInspectorUI::supportsWebExtensions()
{
return true;
}
void RemoteWebInspectorUI::didShowExtensionTab(const Inspector::ExtensionID& extensionID, const Inspector::ExtensionTabID& extensionTabID, const WebCore::FrameIdentifier& frameID)
{
if (!m_extensionController)
return;
m_extensionController->didShowExtensionTab(extensionID, extensionTabID, frameID);
}
void RemoteWebInspectorUI::didHideExtensionTab(const Inspector::ExtensionID& extensionID, const Inspector::ExtensionTabID& extensionTabID)
{
if (!m_extensionController)
return;
m_extensionController->didHideExtensionTab(extensionID, extensionTabID);
}
void RemoteWebInspectorUI::didNavigateExtensionTab(const Inspector::ExtensionID& extensionID, const Inspector::ExtensionTabID& extensionTabID, const URL& newURL)
{
if (!m_extensionController)
return;
m_extensionController->didNavigateExtensionTab(extensionID, extensionTabID, newURL);
}
void RemoteWebInspectorUI::inspectedPageDidNavigate(const URL& newURL)
{
if (!m_extensionController)
return;
m_extensionController->inspectedPageDidNavigate(newURL);
}
#endif // ENABLE(INSPECTOR_EXTENSIONS)
WebCore::Page* RemoteWebInspectorUI::frontendPage()
{
return m_page.corePage();
}
#if !PLATFORM(MAC) && !PLATFORM(GTK) && !PLATFORM(WIN)
bool RemoteWebInspectorUI::canSave(InspectorFrontendClient::SaveMode)
{
notImplemented();
return false;
}
bool RemoteWebInspectorUI::canLoad()
{
notImplemented();
return false;
}
bool RemoteWebInspectorUI::canPickColorFromScreen()
{
notImplemented();
return false;
}
String RemoteWebInspectorUI::localizedStringsURL() const
{
notImplemented();
return emptyString();
}
#endif // !PLATFORM(MAC) && !PLATFORM(GTK) && !PLATFORM(WIN)
} // namespace WebKit
|