summaryrefslogtreecommitdiff
path: root/Source/WebCore/inspector/InspectorFrontendHost.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/inspector/InspectorFrontendHost.cpp')
-rw-r--r--Source/WebCore/inspector/InspectorFrontendHost.cpp182
1 files changed, 116 insertions, 66 deletions
diff --git a/Source/WebCore/inspector/InspectorFrontendHost.cpp b/Source/WebCore/inspector/InspectorFrontendHost.cpp
index 06057bf3d..564f14ec1 100644
--- a/Source/WebCore/inspector/InspectorFrontendHost.cpp
+++ b/Source/WebCore/inspector/InspectorFrontendHost.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
* Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
*
* Redistribution and use in source and binary forms, with or without
@@ -11,7 +11,7 @@
* 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.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -28,30 +28,25 @@
*/
#include "config.h"
-
-#if ENABLE(INSPECTOR)
-
#include "InspectorFrontendHost.h"
#include "ContextMenu.h"
-#include "ContextMenuItem.h"
#include "ContextMenuController.h"
+#include "ContextMenuItem.h"
#include "ContextMenuProvider.h"
#include "DOMWrapperWorld.h"
-#include "Element.h"
+#include "Document.h"
+#include "Editor.h"
#include "Event.h"
-#include "FrameLoader.h"
+#include "FocusController.h"
#include "HitTestResult.h"
-#include "HTMLFrameOwnerElement.h"
#include "InspectorFrontendClient.h"
#include "JSMainThreadExecState.h"
#include "MainFrame.h"
#include "MouseEvent.h"
+#include "Node.h"
#include "Page.h"
#include "Pasteboard.h"
-#include "ResourceError.h"
-#include "ResourceRequest.h"
-#include "ResourceResponse.h"
#include "ScriptGlobalObject.h"
#include "ScriptState.h"
#include "Sound.h"
@@ -66,14 +61,14 @@ namespace WebCore {
#if ENABLE(CONTEXT_MENUS)
class FrontendMenuProvider : public ContextMenuProvider {
public:
- static PassRefPtr<FrontendMenuProvider> create(InspectorFrontendHost* frontendHost, Deprecated::ScriptObject frontendApiObject, const Vector<ContextMenuItem>& items)
+ static Ref<FrontendMenuProvider> create(InspectorFrontendHost* frontendHost, Deprecated::ScriptObject frontendApiObject, const Vector<ContextMenuItem>& items)
{
- return adoptRef(new FrontendMenuProvider(frontendHost, frontendApiObject, items));
+ return adoptRef(*new FrontendMenuProvider(frontendHost, frontendApiObject, items));
}
void disconnect()
{
- m_frontendApiObject = Deprecated::ScriptObject();
+ m_frontendApiObject = { };
m_frontendHost = nullptr;
}
@@ -90,17 +85,17 @@ private:
contextMenuCleared();
}
- virtual void populateContextMenu(ContextMenu* menu) override
+ void populateContextMenu(ContextMenu* menu) override
{
- for (size_t i = 0; i < m_items.size(); ++i)
- menu->appendItem(m_items[i]);
+ for (auto& item : m_items)
+ menu->appendItem(item);
}
- virtual void contextMenuItemSelected(ContextMenuItem* item) override
+ void contextMenuItemSelected(ContextMenuAction action, const String&) override
{
if (m_frontendHost) {
- UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
- int itemNumber = item->action() - ContextMenuItemBaseCustomTag;
+ UserGestureIndicator gestureIndicator(ProcessingUserGesture);
+ int itemNumber = action - ContextMenuItemBaseCustomTag;
Deprecated::ScriptFunctionCall function(m_frontendApiObject, "contextMenuItemSelected", WebCore::functionCallHandlerFromAnyThread);
function.appendArgument(itemNumber);
@@ -108,7 +103,7 @@ private:
}
}
- virtual void contextMenuCleared() override
+ void contextMenuCleared() override
{
if (m_frontendHost) {
Deprecated::ScriptFunctionCall function(m_frontendApiObject, "contextMenuCleared", WebCore::functionCallHandlerFromAnyThread);
@@ -160,11 +155,13 @@ void InspectorFrontendHost::requestSetDockSide(const String& side)
if (!m_client)
return;
if (side == "undocked")
- m_client->requestSetDockSide(InspectorFrontendClient::UNDOCKED);
+ m_client->requestSetDockSide(InspectorFrontendClient::DockSide::Undocked);
else if (side == "right")
- m_client->requestSetDockSide(InspectorFrontendClient::DOCKED_TO_RIGHT);
+ m_client->requestSetDockSide(InspectorFrontendClient::DockSide::Right);
+ else if (side == "left")
+ m_client->requestSetDockSide(InspectorFrontendClient::DockSide::Left);
else if (side == "bottom")
- m_client->requestSetDockSide(InspectorFrontendClient::DOCKED_TO_BOTTOM);
+ m_client->requestSetDockSide(InspectorFrontendClient::DockSide::Bottom);
}
void InspectorFrontendHost::closeWindow()
@@ -181,15 +178,32 @@ void InspectorFrontendHost::bringToFront()
m_client->bringToFront();
}
+void InspectorFrontendHost::inspectedURLChanged(const String& newURL)
+{
+ if (m_client)
+ m_client->inspectedURLChanged(newURL);
+}
+
void InspectorFrontendHost::setZoomFactor(float zoom)
{
- m_frontendPage->mainFrame().setPageAndTextZoomFactors(zoom, 1);
+ if (m_frontendPage)
+ m_frontendPage->mainFrame().setPageAndTextZoomFactors(zoom, 1);
}
-void InspectorFrontendHost::inspectedURLChanged(const String& newURL)
+float InspectorFrontendHost::zoomFactor()
{
- if (m_client)
- m_client->inspectedURLChanged(newURL);
+ if (m_frontendPage)
+ return m_frontendPage->mainFrame().pageZoomFactor();
+
+ return 1.0;
+}
+
+String InspectorFrontendHost::userInterfaceLayoutDirection()
+{
+ if (m_client && m_client->userInterfaceLayoutDirection() == UserInterfaceLayoutDirection::RTL)
+ return ASCIILiteral("rtl");
+
+ return ASCIILiteral("ltr");
}
void InspectorFrontendHost::setAttachedWindowHeight(unsigned height)
@@ -204,10 +218,10 @@ void InspectorFrontendHost::setAttachedWindowWidth(unsigned width)
m_client->changeAttachedWindowWidth(width);
}
-void InspectorFrontendHost::setToolbarHeight(unsigned height)
+void InspectorFrontendHost::startWindowDrag()
{
if (m_client)
- m_client->setToolbarHeight(height);
+ m_client->startWindowDrag();
}
void InspectorFrontendHost::moveWindowBy(float x, float y) const
@@ -218,12 +232,50 @@ void InspectorFrontendHost::moveWindowBy(float x, float y) const
String InspectorFrontendHost::localizedStringsURL()
{
- return m_client ? m_client->localizedStringsURL() : "";
+ return m_client ? m_client->localizedStringsURL() : String();
+}
+
+String InspectorFrontendHost::backendCommandsURL()
+{
+ return m_client ? m_client->backendCommandsURL() : String();
}
String InspectorFrontendHost::debuggableType()
{
- return ASCIILiteral("web");
+ return m_client ? m_client->debuggableType() : String();
+}
+
+unsigned InspectorFrontendHost::inspectionLevel()
+{
+ return m_client ? m_client->inspectionLevel() : 1;
+}
+
+String InspectorFrontendHost::platform()
+{
+#if PLATFORM(MAC) || PLATFORM(IOS)
+ return ASCIILiteral("mac");
+#elif OS(WINDOWS)
+ return ASCIILiteral("windows");
+#elif OS(LINUX)
+ return ASCIILiteral("linux");
+#elif OS(FREEBSD)
+ return ASCIILiteral("freebsd");
+#elif OS(OPENBSD)
+ return ASCIILiteral("openbsd");
+#elif OS(SOLARIS)
+ return ASCIILiteral("solaris");
+#else
+ return ASCIILiteral("unknown");
+#endif
+}
+
+String InspectorFrontendHost::port()
+{
+#if PLATFORM(GTK)
+ return ASCIILiteral("gtk");
+#else
+ return ASCIILiteral("unknown");
+#endif
}
void InspectorFrontendHost::copyText(const String& text)
@@ -231,8 +283,22 @@ void InspectorFrontendHost::copyText(const String& text)
Pasteboard::createForCopyAndPaste()->writePlainText(text, Pasteboard::CannotSmartReplace);
}
+void InspectorFrontendHost::killText(const String& text, bool shouldPrependToKillRing, bool shouldStartNewSequence)
+{
+ if (!m_frontendPage)
+ return;
+
+ Editor& editor = m_frontendPage->focusController().focusedOrMainFrame().editor();
+ editor.setStartNewKillRingSequence(shouldStartNewSequence);
+ Editor::KillRingInsertionMode insertionMode = shouldPrependToKillRing ? Editor::KillRingInsertionMode::PrependText : Editor::KillRingInsertionMode::AppendText;
+ editor.addTextToKillRing(text, insertionMode);
+}
+
void InspectorFrontendHost::openInNewTab(const String& url)
{
+ if (WebCore::protocolIsJavaScript(url))
+ return;
+
if (m_client)
m_client->openInNewTab(url);
}
@@ -267,72 +333,56 @@ void InspectorFrontendHost::sendMessageToBackend(const String& message)
}
#if ENABLE(CONTEXT_MENUS)
+
void InspectorFrontendHost::showContextMenu(Event* event, const Vector<ContextMenuItem>& items)
{
if (!event)
return;
ASSERT(m_frontendPage);
- JSC::ExecState* frontendExecState = execStateFromPage(debuggerWorld(), m_frontendPage);
- Deprecated::ScriptObject frontendApiObject;
- if (!ScriptGlobalObject::get(frontendExecState, "InspectorFrontendAPI", frontendApiObject)) {
+ auto& state = *execStateFromPage(debuggerWorld(), m_frontendPage);
+ JSC::JSObject* frontendApiObject;
+ if (!ScriptGlobalObject::get(state, "InspectorFrontendAPI", frontendApiObject)) {
ASSERT_NOT_REACHED();
return;
}
- RefPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider::create(this, frontendApiObject, items);
- m_frontendPage->contextMenuController().showContextMenu(event, menuProvider);
- m_menuProvider = menuProvider.get();
+ auto menuProvider = FrontendMenuProvider::create(this, { &state, frontendApiObject }, items);
+ m_menuProvider = menuProvider.ptr();
+ m_frontendPage->contextMenuController().showContextMenu(*event, menuProvider);
}
+
#endif
void InspectorFrontendHost::dispatchEventAsContextMenuEvent(Event* event)
{
#if ENABLE(CONTEXT_MENUS) && USE(ACCESSIBILITY_CONTEXT_MENUS)
- if (!event || !event->isMouseEvent())
+ if (!is<MouseEvent>(event))
return;
Frame* frame = event->target()->toNode()->document().frame();
- MouseEvent* mouseEvent = toMouseEvent(event);
- IntPoint mousePoint = IntPoint(mouseEvent->clientX(), mouseEvent->clientY());
+ MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
+ IntPoint mousePoint = IntPoint(mouseEvent.clientX(), mouseEvent.clientY());
- m_frontendPage->contextMenuController().showContextMenuAt(frame, mousePoint);
+ m_frontendPage->contextMenuController().showContextMenuAt(*frame, mousePoint);
#else
UNUSED_PARAM(event);
#endif
}
-String InspectorFrontendHost::loadResourceSynchronously(const String& url)
-{
- ResourceRequest request(url);
- request.setHTTPMethod("GET");
-
- Vector<char> data;
- ResourceError error;
- ResourceResponse response;
- m_frontendPage->mainFrame().loader().loadResourceSynchronously(request, DoNotAllowStoredCredentials, DoNotAskClientForCrossOriginCredentials, error, response, data);
- return String::fromUTF8(data.data(), data.size());
-}
-
bool InspectorFrontendHost::isUnderTest()
{
return m_client && m_client->isUnderTest();
}
-void InspectorFrontendHost::beep()
-{
- systemBeep();
-}
-
-bool InspectorFrontendHost::canSaveAs()
+void InspectorFrontendHost::unbufferedLog(const String& message)
{
- return false;
+ // This is used only for debugging inspector tests.
+ WTFLogAlways("%s", message.utf8().data());
}
-bool InspectorFrontendHost::canInspectWorkers()
+void InspectorFrontendHost::beep()
{
- return false;
+ systemBeep();
}
} // namespace WebCore
-
-#endif // ENABLE(INSPECTOR)