2011-01-25 19:37:27 +01:00
|
|
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsFrontend.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
2011-01-25 19:37:27 +01:00
|
|
|
|
|
|
|
#undef LOG
|
|
|
|
#include "browser_devtools_agent.h"
|
|
|
|
#include "browser_devtools_callargs.h"
|
|
|
|
#include "browser_devtools_client.h"
|
|
|
|
#include "browser_impl.h"
|
2011-11-17 19:52:16 +01:00
|
|
|
#include "cef_context.h"
|
2011-01-25 19:37:27 +01:00
|
|
|
|
2011-10-12 21:09:15 +02:00
|
|
|
#include "base/bind.h"
|
2011-01-25 19:37:27 +01:00
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
|
|
|
|
using WebKit::WebDevToolsAgent;
|
|
|
|
using WebKit::WebDevToolsFrontend;
|
|
|
|
using WebKit::WebDevToolsMessageData;
|
|
|
|
using WebKit::WebString;
|
|
|
|
using WebKit::WebView;
|
|
|
|
|
|
|
|
BrowserDevToolsClient::BrowserDevToolsClient(CefBrowserImpl* browser,
|
|
|
|
BrowserDevToolsAgent *agent)
|
2011-10-12 21:09:15 +02:00
|
|
|
: ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
|
2011-01-25 19:37:27 +01:00
|
|
|
browser_(browser),
|
|
|
|
dev_tools_agent_(agent),
|
2011-01-29 02:42:59 +01:00
|
|
|
web_view_(browser->UIT_GetWebView()) {
|
2011-01-25 19:37:27 +01:00
|
|
|
web_tools_frontend_.reset(WebDevToolsFrontend::create(web_view_, this,
|
2011-11-17 19:52:16 +01:00
|
|
|
WebString::fromUTF8(_Context->locale())));
|
2011-01-25 19:37:27 +01:00
|
|
|
dev_tools_agent_->attach(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserDevToolsClient::~BrowserDevToolsClient() {
|
|
|
|
// It is a chance that page will be destroyed at detach step of
|
|
|
|
// dev_tools_agent_ and we should clean pending requests a bit earlier.
|
2011-10-12 21:09:15 +02:00
|
|
|
weak_factory_.InvalidateWeakPtrs();
|
2011-01-25 19:37:27 +01:00
|
|
|
if (dev_tools_agent_)
|
|
|
|
dev_tools_agent_->detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDevToolsClient::sendMessageToBackend(
|
|
|
|
const WebString& data) {
|
|
|
|
if (dev_tools_agent_)
|
|
|
|
dev_tools_agent_->AsyncCall(BrowserDevToolsCallArgs(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDevToolsClient::activateWindow() {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDevToolsClient::closeWindow() {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDevToolsClient::dockWindow() {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDevToolsClient::undockWindow() {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDevToolsClient::AsyncCall(const BrowserDevToolsCallArgs &args) {
|
2011-10-12 21:09:15 +02:00
|
|
|
MessageLoop::current()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
base::Bind(&BrowserDevToolsClient::Call, weak_factory_.GetWeakPtr(),
|
|
|
|
args));
|
2011-01-25 19:37:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDevToolsClient::Call(const BrowserDevToolsCallArgs &args) {
|
|
|
|
web_tools_frontend_->dispatchOnInspectorFrontend(args.data_);
|
|
|
|
if (BrowserDevToolsCallArgs::calls_count() == 1)
|
|
|
|
all_messages_processed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDevToolsClient::all_messages_processed() {
|
|
|
|
web_view_->mainFrame()->executeScript(WebKit::WebScriptSource(
|
|
|
|
WebString::fromUTF8("if (window.WebInspector && "
|
|
|
|
"WebInspector.queuesAreEmpty) WebInspector.queuesAreEmpty();")));
|
|
|
|
}
|