diff options
Diffstat (limited to 'Source/WebCore/inspector/InspectorFrontendClientLocal.cpp')
-rw-r--r-- | Source/WebCore/inspector/InspectorFrontendClientLocal.cpp | 139 |
1 files changed, 85 insertions, 54 deletions
diff --git a/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp b/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp index 4e85bc532..76670246a 100644 --- a/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp +++ b/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Google Inc. All rights reserved. + * Copyright (C) 2015 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 @@ -29,9 +30,6 @@ */ #include "config.h" - -#if ENABLE(INSPECTOR) - #include "InspectorFrontendClientLocal.h" #include "Chrome.h" @@ -44,7 +42,6 @@ #include "InspectorController.h" #include "InspectorFrontendHost.h" #include "InspectorPageAgent.h" -#include "InspectorWebBackendDispatchers.h" #include "MainFrame.h" #include "Page.h" #include "ScriptController.h" @@ -54,10 +51,9 @@ #include "Timer.h" #include "UserGestureIndicator.h" #include "WindowFeatures.h" -#include <bindings/ScriptValue.h> +#include <inspector/InspectorBackendDispatchers.h> #include <wtf/Deque.h> #include <wtf/text/CString.h> -#include <wtf/text/WTFString.h> using namespace Inspector; @@ -67,20 +63,21 @@ static const char* inspectorAttachedHeightSetting = "inspectorAttachedHeight"; static const unsigned defaultAttachedHeight = 300; static const float minimumAttachedHeight = 250.0f; static const float maximumAttachedHeightRatio = 0.75f; -static const float minimumAttachedWidth = 750.0f; +static const float minimumAttachedWidth = 500.0f; static const float minimumAttachedInspectedWidth = 320.0f; -class InspectorBackendDispatchTask { +class InspectorBackendDispatchTask : public RefCounted<InspectorBackendDispatchTask> { WTF_MAKE_FAST_ALLOCATED; public: - InspectorBackendDispatchTask(InspectorController* inspectorController) - : m_inspectorController(inspectorController) - , m_timer(this, &InspectorBackendDispatchTask::timerFired) + static Ref<InspectorBackendDispatchTask> create(InspectorController* inspectedPageController) { + return adoptRef(*new InspectorBackendDispatchTask(inspectedPageController)); } void dispatch(const String& message) { + ASSERT_ARG(message, !message.isEmpty()); + m_messages.append(message); if (!m_timer.isActive()) m_timer.startOneShot(0); @@ -90,20 +87,34 @@ public: { m_messages.clear(); m_timer.stop(); + m_inspectedPageController = nullptr; } - void timerFired(Timer<InspectorBackendDispatchTask>&) + void timerFired() { - if (!m_messages.isEmpty()) { - // Dispatch can lead to the timer destruction -> schedule the next shot first. + ASSERT(m_inspectedPageController); + + // Dispatching a message can possibly close the frontend and destroy + // the owning frontend client, so keep a protector reference here. + Ref<InspectorBackendDispatchTask> protectedThis(*this); + + if (!m_messages.isEmpty()) + m_inspectedPageController->dispatchMessageFromFrontend(m_messages.takeFirst()); + + if (!m_messages.isEmpty() && m_inspectedPageController) m_timer.startOneShot(0); - m_inspectorController->dispatchMessageFromFrontend(m_messages.takeFirst()); - } } private: - InspectorController* m_inspectorController; - Timer<InspectorBackendDispatchTask> m_timer; + InspectorBackendDispatchTask(InspectorController* inspectedPageController) + : m_inspectedPageController(inspectedPageController) + , m_timer(*this, &InspectorBackendDispatchTask::timerFired) + { + ASSERT_ARG(inspectedPageController, inspectedPageController); + } + + InspectorController* m_inspectedPageController { nullptr }; + Timer m_timer; Deque<String> m_messages; }; @@ -116,23 +127,23 @@ void InspectorFrontendClientLocal::Settings::setProperty(const String&, const St { } -InspectorFrontendClientLocal::InspectorFrontendClientLocal(InspectorController* inspectorController, Page* frontendPage, PassOwnPtr<Settings> settings) - : m_inspectorController(inspectorController) +InspectorFrontendClientLocal::InspectorFrontendClientLocal(InspectorController* inspectedPageController, Page* frontendPage, std::unique_ptr<Settings> settings) + : m_inspectedPageController(inspectedPageController) , m_frontendPage(frontendPage) - , m_settings(settings) - , m_frontendLoaded(false) - , m_dockSide(UNDOCKED) + , m_settings(WTFMove(settings)) + , m_dockSide(DockSide::Undocked) + , m_dispatchTask(InspectorBackendDispatchTask::create(inspectedPageController)) { m_frontendPage->settings().setAllowFileAccessFromFileURLs(true); - m_dispatchTask = adoptPtr(new InspectorBackendDispatchTask(inspectorController)); } InspectorFrontendClientLocal::~InspectorFrontendClientLocal() { if (m_frontendHost) m_frontendHost->disconnectClient(); - m_frontendPage = 0; - m_inspectorController = 0; + m_frontendPage = nullptr; + m_inspectedPageController = nullptr; + m_dispatchTask->reset(); } void InspectorFrontendClientLocal::windowObjectCleared() @@ -140,28 +151,32 @@ void InspectorFrontendClientLocal::windowObjectCleared() if (m_frontendHost) m_frontendHost->disconnectClient(); - JSC::ExecState* frontendExecState = execStateFromPage(debuggerWorld(), m_frontendPage); m_frontendHost = InspectorFrontendHost::create(this, m_frontendPage); - ScriptGlobalObject::set(frontendExecState, "InspectorFrontendHost", m_frontendHost.get()); + ScriptGlobalObject::set(*execStateFromPage(debuggerWorld(), m_frontendPage), "InspectorFrontendHost", *m_frontendHost); } void InspectorFrontendClientLocal::frontendLoaded() { // Call setDockingUnavailable before bringToFront. If we display the inspector window via bringToFront first it causes // the call to canAttachWindow to return the wrong result on Windows. - // Calling bringToFront first causes the visibleHeight of the inspected page to always return 0 immediately after. + // Calling bringToFront first causes the visibleHeight of the inspected page to always return 0 immediately after. // Thus if we call canAttachWindow first we can avoid this problem. This change does not cause any regressions on Mac. setDockingUnavailable(!canAttachWindow()); bringToFront(); m_frontendLoaded = true; - for (Vector<String>::iterator it = m_evaluateOnLoad.begin(); it != m_evaluateOnLoad.end(); ++it) - evaluateOnLoad(*it); + for (auto& evaluate : m_evaluateOnLoad) + evaluateOnLoad(evaluate); m_evaluateOnLoad.clear(); } +UserInterfaceLayoutDirection InspectorFrontendClientLocal::userInterfaceLayoutDirection() const +{ + return m_frontendPage->userInterfaceLayoutDirection(); +} + void InspectorFrontendClientLocal::requestSetDockSide(DockSide dockSide) { - if (dockSide == UNDOCKED) { + if (dockSide == DockSide::Undocked) { detachWindow(); setAttachedWindow(dockSide); } else if (canAttachWindow()) { @@ -173,17 +188,17 @@ void InspectorFrontendClientLocal::requestSetDockSide(DockSide dockSide) bool InspectorFrontendClientLocal::canAttachWindow() { // Don't allow attaching to another inspector -- two inspectors in one window is too much! - bool isInspectorPage = m_inspectorController->hasInspectorFrontendClient(); + bool isInspectorPage = m_inspectedPageController->inspectionLevel() > 0; if (isInspectorPage) return false; // If we are already attached, allow attaching again to allow switching sides. - if (m_dockSide != UNDOCKED) + if (m_dockSide != DockSide::Undocked) return true; // Don't allow the attach if the window would be too small to accommodate the minimum inspector size. - unsigned inspectedPageHeight = m_inspectorController->inspectedPage().mainFrame().view()->visibleHeight(); - unsigned inspectedPageWidth = m_inspectorController->inspectedPage().mainFrame().view()->visibleWidth(); + unsigned inspectedPageHeight = m_inspectedPageController->inspectedPage().mainFrame().view()->visibleHeight(); + unsigned inspectedPageWidth = m_inspectedPageController->inspectedPage().mainFrame().view()->visibleWidth(); unsigned maximumAttachedHeight = inspectedPageHeight * maximumAttachedHeightRatio; return minimumAttachedHeight <= maximumAttachedHeight && minimumAttachedWidth <= inspectedPageWidth; } @@ -195,7 +210,7 @@ void InspectorFrontendClientLocal::setDockingUnavailable(bool unavailable) void InspectorFrontendClientLocal::changeAttachedWindowHeight(unsigned height) { - unsigned totalHeight = m_frontendPage->mainFrame().view()->visibleHeight() + m_inspectorController->inspectedPage().mainFrame().view()->visibleHeight(); + unsigned totalHeight = m_frontendPage->mainFrame().view()->visibleHeight() + m_inspectedPageController->inspectedPage().mainFrame().view()->visibleHeight(); unsigned attachedHeight = constrainedAttachedWindowHeight(height, totalHeight); m_settings->setProperty(inspectorAttachedHeightSetting, String::number(attachedHeight)); setAttachedWindowHeight(attachedHeight); @@ -203,20 +218,20 @@ void InspectorFrontendClientLocal::changeAttachedWindowHeight(unsigned height) void InspectorFrontendClientLocal::changeAttachedWindowWidth(unsigned width) { - unsigned totalWidth = m_frontendPage->mainFrame().view()->visibleWidth() + m_inspectorController->inspectedPage().mainFrame().view()->visibleWidth(); + unsigned totalWidth = m_frontendPage->mainFrame().view()->visibleWidth() + m_inspectedPageController->inspectedPage().mainFrame().view()->visibleWidth(); unsigned attachedWidth = constrainedAttachedWindowWidth(width, totalWidth); setAttachedWindowWidth(attachedWidth); } void InspectorFrontendClientLocal::openInNewTab(const String& url) { - UserGestureIndicator indicator(DefinitelyProcessingUserGesture); - Frame& mainFrame = m_inspectorController->inspectedPage().mainFrame(); - FrameLoadRequest request(mainFrame.document()->securityOrigin(), ResourceRequest(), "_blank"); + UserGestureIndicator indicator(ProcessingUserGesture); + Frame& mainFrame = m_inspectedPageController->inspectedPage().mainFrame(); + FrameLoadRequest request(mainFrame.document()->securityOrigin(), ResourceRequest(), "_blank", LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Allow, ReplaceDocumentIfJavaScriptURL, ShouldOpenExternalURLsPolicy::ShouldNotAllow); bool created; WindowFeatures windowFeatures; - RefPtr<Frame> frame = WebCore::createWindow(&mainFrame, &mainFrame, request, windowFeatures, created); + RefPtr<Frame> frame = WebCore::createWindow(mainFrame, mainFrame, request, windowFeatures, created); if (!frame) return; @@ -224,7 +239,9 @@ void InspectorFrontendClientLocal::openInNewTab(const String& url) frame->page()->setOpenedByDOM(); // FIXME: Why does one use mainFrame and the other frame? - frame->loader().changeLocation(mainFrame.document()->securityOrigin(), frame->document()->completeURL(url), "", false, false); + ResourceRequest resourceRequest(frame->document()->completeURL(url)); + FrameLoadRequest frameRequest(mainFrame.document()->securityOrigin(), resourceRequest, "_self", LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Allow, ReplaceDocumentIfJavaScriptURL, ShouldOpenExternalURLsPolicy::ShouldNotAllow); + frame->loader().changeLocation(frameRequest); } void InspectorFrontendClientLocal::moveWindowBy(float x, float y) @@ -238,13 +255,16 @@ void InspectorFrontendClientLocal::setAttachedWindow(DockSide dockSide) { const char* side = "undocked"; switch (dockSide) { - case UNDOCKED: + case DockSide::Undocked: side = "undocked"; break; - case DOCKED_TO_RIGHT: + case DockSide::Right: side = "right"; break; - case DOCKED_TO_BOTTOM: + case DockSide::Left: + side = "left"; + break; + case DockSide::Bottom: side = "bottom"; break; } @@ -256,7 +276,7 @@ void InspectorFrontendClientLocal::setAttachedWindow(DockSide dockSide) void InspectorFrontendClientLocal::restoreAttachedWindowHeight() { - unsigned inspectedPageHeight = m_inspectorController->inspectedPage().mainFrame().view()->visibleHeight(); + unsigned inspectedPageHeight = m_inspectedPageController->inspectedPage().mainFrame().view()->visibleHeight(); String value = m_settings->getProperty(inspectorAttachedHeightSetting); unsigned preferredHeight = value.isEmpty() ? defaultAttachedHeight : value.toUInt(); @@ -319,7 +339,7 @@ void InspectorFrontendClientLocal::showResources() void InspectorFrontendClientLocal::showMainResourceForFrame(Frame* frame) { - String frameId = m_inspectorController->pageAgent()->frameId(frame); + String frameId = m_inspectedPageController->pageAgent()->frameId(frame); evaluateOnLoad(String::format("[\"showMainResourceForFrame\", \"%s\"]", frameId.ascii().data())); } @@ -340,23 +360,34 @@ void InspectorFrontendClientLocal::sendMessageToBackend(const String& message) bool InspectorFrontendClientLocal::isUnderTest() { - return m_inspectorController->isUnderTest(); + return m_inspectedPageController->isUnderTest(); +} + +unsigned InspectorFrontendClientLocal::inspectionLevel() const +{ + return m_inspectedPageController->inspectionLevel() + 1; } bool InspectorFrontendClientLocal::evaluateAsBoolean(const String& expression) { - Deprecated::ScriptValue value = m_frontendPage->mainFrame().script().executeScript(expression); - return value.toString(mainWorldExecState(&m_frontendPage->mainFrame())) == "true"; + auto& state = *mainWorldExecState(&m_frontendPage->mainFrame()); + return m_frontendPage->mainFrame().script().executeScript(expression).toWTFString(&state) == "true"; } void InspectorFrontendClientLocal::evaluateOnLoad(const String& expression) { if (m_frontendLoaded) - m_frontendPage->mainFrame().script().executeScript("InspectorFrontendAPI.dispatch(" + expression + ")"); + m_frontendPage->mainFrame().script().executeScript("if (InspectorFrontendAPI) InspectorFrontendAPI.dispatch(" + expression + ")"); else m_evaluateOnLoad.append(expression); } -} // namespace WebCore +Page* InspectorFrontendClientLocal::inspectedPage() const +{ + if (!m_inspectedPageController) + return nullptr; -#endif + return &m_inspectedPageController->inspectedPage(); +} + +} // namespace WebCore |