This source file includes following definitions.
- m_client
- windowObjectCleared
- inspectedURLChanged
- sendMessageToBackend
- sendMessageToEmbedder
- isUnderTest
#include "config.h"
#include "InspectorFrontendClientImpl.h"
#include "V8InspectorFrontendHost.h"
#include "WebDevToolsFrontendClient.h"
#include "WebDevToolsFrontendImpl.h"
#include "bindings/v8/ScriptController.h"
#include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
#include "core/inspector/InspectorFrontendHost.h"
#include "core/page/Page.h"
#include "public/platform/WebFloatPoint.h"
#include "public/platform/WebString.h"
#include "wtf/text/WTFString.h"
using namespace WebCore;
namespace blink {
InspectorFrontendClientImpl::InspectorFrontendClientImpl(Page* frontendPage, WebDevToolsFrontendClient* client, WebDevToolsFrontendImpl* frontend)
: m_frontendPage(frontendPage)
, m_client(client)
{
}
InspectorFrontendClientImpl::~InspectorFrontendClientImpl()
{
if (m_frontendHost)
m_frontendHost->disconnectClient();
m_client = 0;
}
void InspectorFrontendClientImpl::windowObjectCleared()
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handleScope(isolate);
v8::Handle<v8::Context> frameContext = m_frontendPage->mainFrame() ? toV8Context(isolate, m_frontendPage->mainFrame(), DOMWrapperWorld::mainWorld()) : v8::Local<v8::Context>();
v8::Context::Scope contextScope(frameContext);
if (m_frontendHost)
m_frontendHost->disconnectClient();
m_frontendHost = InspectorFrontendHost::create(this, m_frontendPage);
v8::Handle<v8::Value> frontendHostObj = toV8(m_frontendHost.get(), v8::Handle<v8::Object>(), frameContext->GetIsolate());
v8::Handle<v8::Object> global = frameContext->Global();
global->Set(v8::String::NewFromUtf8(isolate, "InspectorFrontendHost"), frontendHostObj);
ScriptController* scriptController = m_frontendPage->mainFrame() ? &m_frontendPage->mainFrame()->script() : 0;
if (scriptController) {
String installAdditionalAPI =
""
"(function(host, methodEntries) {"
" host._lastCallId = 0;"
" host._callbacks = [];"
" host.embedderMessageAck = function(id, error)"
" {"
" var callback = host._callbacks[id];"
" delete host._callbacks[id];"
" if (callback)"
" callback(error);"
" };"
" function dispatch(methodName, argumentCount)"
" {"
" var callId = ++host._lastCallId;"
" var argsArray = Array.prototype.slice.call(arguments, 2);"
" var callback = argsArray[argsArray.length - 1];"
" if (typeof callback === \"function\") {"
" argsArray.pop();"
" host._callbacks[callId] = callback;"
" }"
" var message = { \"id\": callId, \"method\": methodName };"
" argsArray = argsArray.slice(0, argumentCount);"
" if (argsArray.length)"
" message.params = argsArray;"
" host.sendMessageToEmbedder(JSON.stringify(message));"
" };"
" methodEntries.forEach(function(methodEntry) { host[methodEntry[0]] = dispatch.bind(null, methodEntry[0], methodEntry[1]); });"
"})(InspectorFrontendHost,"
" [['addFileSystem', 0],"
" ['append', 2],"
" ['bringToFront', 0],"
" ['closeWindow', 0],"
" ['indexPath', 2],"
" ['inspectElementCompleted', 0],"
" ['moveWindowBy', 2],"
" ['openInNewTab', 1],"
" ['removeFileSystem', 1],"
" ['requestFileSystems', 0],"
" ['resetZoom', 0],"
" ['save', 3],"
" ['searchInPath', 3],"
" ['setContentsResizingStrategy', 2],"
" ['setIsDocked', 1],"
" ['stopIndexing', 1],"
" ['zoomIn', 0],"
" ['zoomOut', 0]]);"
""
""
"InspectorFrontendHost.requestSetDockSide = function(dockSide)"
"{"
" InspectorFrontendHost.setIsDocked(dockSide !== \"undocked\");"
"};"
"InspectorFrontendHost.supportsFileSystems = function() { return true; };"
""
""
"InspectorFrontendHost.canInspectWorkers = function() { return true; };"
"InspectorFrontendHost.canSaveAs = function() { return true; };"
"InspectorFrontendHost.canSave = function() { return true; };"
"InspectorFrontendHost.loaded = function() {};"
"InspectorFrontendHost.hiddenPanels = function() { return ""; };"
"InspectorFrontendHost.localizedStringsURL = function() { return ""; };"
"InspectorFrontendHost.close = function(url) { };";
scriptController->executeScriptInMainWorld(installAdditionalAPI, ScriptController::ExecuteScriptWhenScriptsDisabled);
}
}
void InspectorFrontendClientImpl::inspectedURLChanged(const String& url)
{
m_frontendPage->mainFrame()->document()->setTitle("Developer Tools - " + url);
}
void InspectorFrontendClientImpl::sendMessageToBackend(const String& message)
{
m_client->sendMessageToBackend(message);
}
void InspectorFrontendClientImpl::sendMessageToEmbedder(const String& message)
{
m_client->sendMessageToEmbedder(message);
}
bool InspectorFrontendClientImpl::isUnderTest()
{
return m_client->isUnderTest();
}
}