#include "config.h"
#include "core/inspector/InspectorFrontendHost.h"
-#include "bindings/v8/ScriptFunctionCall.h"
-#include "bindings/v8/ScriptState.h"
+#include "bindings/core/v8/ScriptFunctionCall.h"
+#include "bindings/core/v8/ScriptState.h"
#include "core/clipboard/Pasteboard.h"
+#include "core/dom/ExecutionContext.h"
+#include "core/events/Event.h"
+#include "core/events/EventTarget.h"
#include "core/fetch/ResourceFetcher.h"
+#include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
#include "core/html/parser/TextResourceDecoder.h"
#include "core/inspector/InspectorController.h"
#include "platform/network/ResourceRequest.h"
#include "platform/network/ResourceResponse.h"
-namespace WebCore {
+namespace blink {
class FrontendMenuProvider FINAL : public ContextMenuProvider {
public:
- static PassRefPtr<FrontendMenuProvider> create(InspectorFrontendHost* frontendHost, ScriptObject frontendApiObject, const Vector<ContextMenuItem>& items)
+ static PassRefPtr<FrontendMenuProvider> create(InspectorFrontendHost* frontendHost, ScriptValue frontendApiObject, const Vector<ContextMenuItem>& items)
{
return adoptRef(new FrontendMenuProvider(frontendHost, frontendApiObject, items));
}
void disconnect()
{
- m_frontendApiObject = ScriptObject();
+ m_frontendApiObject = ScriptValue();
m_frontendHost = 0;
}
private:
- FrontendMenuProvider(InspectorFrontendHost* frontendHost, ScriptObject frontendApiObject, const Vector<ContextMenuItem>& items)
+ FrontendMenuProvider(InspectorFrontendHost* frontendHost, ScriptValue frontendApiObject, const Vector<ContextMenuItem>& items)
: m_frontendHost(frontendHost)
, m_frontendApiObject(frontendApiObject)
, m_items(items)
m_frontendHost->m_menuProvider = 0;
}
m_items.clear();
+ m_frontendHost = 0;
}
InspectorFrontendHost* m_frontendHost;
- ScriptObject m_frontendApiObject;
+ ScriptValue m_frontendApiObject;
Vector<ContextMenuItem> m_items;
};
, m_frontendPage(frontendPage)
, m_menuProvider(0)
{
- ScriptWrappable::init(this);
}
InspectorFrontendHost::~InspectorFrontendHost()
ASSERT(!m_client);
}
+void InspectorFrontendHost::trace(Visitor* visitor)
+{
+ visitor->trace(m_frontendPage);
+}
+
void InspectorFrontendHost::disconnectClient()
{
m_client = 0;
if (m_menuProvider)
m_menuProvider->disconnect();
- m_frontendPage = 0;
+ m_frontendPage = nullptr;
}
void InspectorFrontendHost::setZoomFactor(float zoom)
{
- m_frontendPage->mainFrame()->setPageAndTextZoomFactors(zoom, 1);
+ if (!m_frontendPage)
+ return;
+ if (LocalFrame* frame = m_frontendPage->deprecatedLocalMainFrame())
+ frame->setPageAndTextZoomFactors(zoom, 1);
}
float InspectorFrontendHost::zoomFactor()
{
- return m_frontendPage->mainFrame()->pageZoomFactor();
-}
-
-void InspectorFrontendHost::inspectedURLChanged(const String& newURL)
-{
- if (m_client)
- m_client->inspectedURLChanged(newURL);
+ if (!m_frontendPage)
+ return 1;
+ if (LocalFrame* frame = m_frontendPage->deprecatedLocalMainFrame())
+ return frame->pageZoomFactor();
+ return 1;
}
void InspectorFrontendHost::setInjectedScriptForOrigin(const String& origin, const String& script)
{
+ if (!m_frontendPage)
+ return;
m_frontendPage->inspectorController().setInjectedScriptForOrigin(origin, script);
}
static String escapeUnicodeNonCharacters(const String& str)
{
+ const UChar nonChar = 0xD800;
+
+ unsigned i = 0;
+ while (i < str.length() && str[i] < nonChar)
+ ++i;
+ if (i == str.length())
+ return str;
+
StringBuilder dst;
- for (unsigned i = 0; i < str.length(); ++i) {
+ dst.append(str, 0, i);
+ for (; i < str.length(); ++i) {
UChar c = str[i];
- if (c >= 0xD800) {
+ if (c >= nonChar) {
unsigned symbol = static_cast<unsigned>(c);
String symbolCode = String::format("\\u%04X", symbol);
dst.append(symbolCode);
} else {
dst.append(c);
}
-
}
return dst.toString();
}
m_client->sendMessageToEmbedder(escapeUnicodeNonCharacters(message));
}
+void InspectorFrontendHost::showContextMenu(Page* page, float x, float y, const Vector<ContextMenuItem>& items)
+{
+ ASSERT(m_frontendPage);
+ ScriptState* frontendScriptState = ScriptState::forMainWorld(m_frontendPage->deprecatedLocalMainFrame());
+ ScriptValue frontendApiObject = frontendScriptState->getFromGlobalObject("InspectorFrontendAPI");
+ ASSERT(frontendApiObject.isObject());
+
+ RefPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider::create(this, frontendApiObject, items);
+ m_menuProvider = menuProvider.get();
+ float zoom = page->deprecatedLocalMainFrame()->pageZoomFactor();
+ page->inspectorController().showContextMenu(x * zoom, y * zoom, menuProvider);
+}
+
void InspectorFrontendHost::showContextMenu(Event* event, const Vector<ContextMenuItem>& items)
{
if (!event)
return;
ASSERT(m_frontendPage);
- ScriptState* frontendScriptState = mainWorldScriptState(m_frontendPage->mainFrame());
- ScriptObject frontendApiObject;
- if (!ScriptGlobalObject::get(frontendScriptState, "InspectorFrontendAPI", frontendApiObject)) {
- ASSERT_NOT_REACHED();
- return;
+ ScriptState* frontendScriptState = ScriptState::forMainWorld(m_frontendPage->deprecatedLocalMainFrame());
+ ScriptValue frontendApiObject = frontendScriptState->getFromGlobalObject("InspectorFrontendAPI");
+ ASSERT(frontendApiObject.isObject());
+
+ Page* targetPage = m_frontendPage;
+ if (event->target() && event->target()->executionContext() && event->target()->executionContext()->executingWindow()) {
+ LocalDOMWindow* window = event->target()->executionContext()->executingWindow();
+ if (window->document() && window->document()->page())
+ targetPage = window->document()->page();
}
+
RefPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider::create(this, frontendApiObject, items);
- m_frontendPage->contextMenuController().showContextMenu(event, menuProvider);
+ targetPage->contextMenuController().showContextMenu(event, menuProvider);
m_menuProvider = menuProvider.get();
}
return m_client && m_client->isUnderTest();
}
-} // namespace WebCore
+bool InspectorFrontendHost::isHostedMode()
+{
+ return false;
+}
+
+} // namespace blink