2016-10-17 20:14:44 +02:00
|
|
|
// Copyright 2013 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.
|
2013-11-08 17:06:06 +01:00
|
|
|
|
|
|
|
#include "libcef/browser/devtools_frontend.h"
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include "libcef/browser/devtools_manager_delegate.h"
|
|
|
|
#include "libcef/browser/net/devtools_scheme_handler.h"
|
2013-11-08 17:06:06 +01:00
|
|
|
|
2014-09-04 19:53:40 +02:00
|
|
|
#include "base/json/json_reader.h"
|
2014-12-13 21:18:31 +01:00
|
|
|
#include "base/json/json_writer.h"
|
2016-06-21 00:59:23 +02:00
|
|
|
#include "base/json/string_escape.h"
|
2016-10-17 20:14:44 +02:00
|
|
|
#include "base/macros.h"
|
2014-09-04 19:53:40 +02:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2015-03-04 02:00:13 +01:00
|
|
|
#include "base/strings/stringprintf.h"
|
2013-12-17 23:04:35 +01:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2015-03-04 02:00:13 +01:00
|
|
|
#include "base/values.h"
|
2016-10-17 20:14:44 +02:00
|
|
|
#include "content/public/browser/browser_context.h"
|
2015-03-04 02:00:13 +01:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2013-12-17 23:04:35 +01:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "content/public/browser/storage_partition.h"
|
2013-11-08 17:06:06 +01:00
|
|
|
#include "content/public/browser/web_contents.h"
|
|
|
|
#include "content/public/common/content_client.h"
|
2016-10-17 20:14:44 +02:00
|
|
|
#include "content/public/common/url_constants.h"
|
2015-11-10 21:18:16 +01:00
|
|
|
#include "ipc/ipc_channel.h"
|
2015-03-04 02:00:13 +01:00
|
|
|
#include "net/base/io_buffer.h"
|
|
|
|
#include "net/base/net_errors.h"
|
|
|
|
#include "net/http/http_response_headers.h"
|
|
|
|
#include "net/url_request/url_fetcher.h"
|
|
|
|
#include "net/url_request/url_fetcher_response_writer.h"
|
2013-11-08 17:06:06 +01:00
|
|
|
|
2015-01-09 18:22:10 +01:00
|
|
|
namespace {
|
|
|
|
|
2015-03-04 02:00:13 +01:00
|
|
|
|
|
|
|
// ResponseWriter -------------------------------------------------------------
|
|
|
|
|
|
|
|
class ResponseWriter : public net::URLFetcherResponseWriter {
|
|
|
|
public:
|
2016-10-17 20:14:44 +02:00
|
|
|
ResponseWriter(base::WeakPtr<CefDevToolsFrontend> shell_devtools_,
|
2015-03-04 02:00:13 +01:00
|
|
|
int stream_id);
|
|
|
|
~ResponseWriter() override;
|
|
|
|
|
|
|
|
// URLFetcherResponseWriter overrides:
|
|
|
|
int Initialize(const net::CompletionCallback& callback) override;
|
|
|
|
int Write(net::IOBuffer* buffer,
|
|
|
|
int num_bytes,
|
|
|
|
const net::CompletionCallback& callback) override;
|
2016-11-10 22:13:41 +01:00
|
|
|
int Finish(int net_error, const net::CompletionCallback& callback) override;
|
2015-03-04 02:00:13 +01:00
|
|
|
|
|
|
|
private:
|
2016-10-17 20:14:44 +02:00
|
|
|
base::WeakPtr<CefDevToolsFrontend> shell_devtools_;
|
2015-03-04 02:00:13 +01:00
|
|
|
int stream_id_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ResponseWriter);
|
|
|
|
};
|
|
|
|
|
|
|
|
ResponseWriter::ResponseWriter(
|
2016-10-17 20:14:44 +02:00
|
|
|
base::WeakPtr<CefDevToolsFrontend> shell_devtools,
|
2015-03-04 02:00:13 +01:00
|
|
|
int stream_id)
|
2016-10-17 20:14:44 +02:00
|
|
|
: shell_devtools_(shell_devtools),
|
2015-03-04 02:00:13 +01:00
|
|
|
stream_id_(stream_id) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ResponseWriter::~ResponseWriter() {
|
|
|
|
}
|
|
|
|
|
|
|
|
int ResponseWriter::Initialize(const net::CompletionCallback& callback) {
|
|
|
|
return net::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ResponseWriter::Write(net::IOBuffer* buffer,
|
|
|
|
int num_bytes,
|
|
|
|
const net::CompletionCallback& callback) {
|
2016-03-16 03:55:59 +01:00
|
|
|
std::string chunk = std::string(buffer->data(), num_bytes);
|
|
|
|
if (!base::IsStringUTF8(chunk))
|
|
|
|
return num_bytes;
|
|
|
|
|
2015-03-04 02:00:13 +01:00
|
|
|
base::FundamentalValue* id = new base::FundamentalValue(stream_id_);
|
2016-03-16 03:55:59 +01:00
|
|
|
base::StringValue* chunkValue = new base::StringValue(chunk);
|
2015-03-04 02:00:13 +01:00
|
|
|
|
|
|
|
content::BrowserThread::PostTask(
|
|
|
|
content::BrowserThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefDevToolsFrontend::CallClientFunction,
|
2016-10-17 20:14:44 +02:00
|
|
|
shell_devtools_, "DevToolsAPI.streamWrite",
|
2016-03-16 03:55:59 +01:00
|
|
|
base::Owned(id), base::Owned(chunkValue), nullptr));
|
2015-03-04 02:00:13 +01:00
|
|
|
return num_bytes;
|
|
|
|
}
|
|
|
|
|
2016-11-10 22:13:41 +01:00
|
|
|
int ResponseWriter::Finish(int net_error,
|
|
|
|
const net::CompletionCallback& callback) {
|
2015-03-04 02:00:13 +01:00
|
|
|
return net::OK;
|
|
|
|
}
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
static std::string GetFrontendURL() {
|
|
|
|
return base::StringPrintf("%s://%s/inspector.html",
|
|
|
|
content::kChromeDevToolsScheme, scheme::kChromeDevToolsHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-01-09 18:22:10 +01:00
|
|
|
// This constant should be in sync with
|
|
|
|
// the constant at devtools_ui_bindings.cc.
|
|
|
|
const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4;
|
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
// static
|
|
|
|
CefDevToolsFrontend* CefDevToolsFrontend::Show(
|
|
|
|
CefRefPtr<CefBrowserHostImpl> inspected_browser,
|
|
|
|
const CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient> client,
|
2014-10-11 02:12:01 +02:00
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
const CefPoint& inspect_element_at) {
|
2014-04-15 21:02:30 +02:00
|
|
|
CefBrowserSettings new_settings = settings;
|
|
|
|
if (CefColorGetA(new_settings.background_color) == 0) {
|
|
|
|
// Use white as the default background color for DevTools instead of the
|
|
|
|
// CefSettings.background_color value.
|
|
|
|
new_settings.background_color = SK_ColorWHITE;
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
CefBrowserHostImpl::CreateParams create_params;
|
|
|
|
if (!inspected_browser->IsViewsHosted())
|
|
|
|
create_params.window_info.reset(new CefWindowInfo(windowInfo));
|
|
|
|
create_params.client = client;
|
|
|
|
create_params.settings = new_settings;
|
|
|
|
create_params.devtools_opener = inspected_browser;
|
|
|
|
create_params.request_context = inspected_browser->GetRequestContext();
|
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
CefRefPtr<CefBrowserHostImpl> frontend_browser =
|
2016-01-19 21:09:01 +01:00
|
|
|
CefBrowserHostImpl::Create(create_params);
|
2013-11-08 17:06:06 +01:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
content::WebContents* inspected_contents = inspected_browser->web_contents();
|
2014-10-11 02:12:01 +02:00
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
// CefDevToolsFrontend will delete itself when the frontend WebContents is
|
|
|
|
// destroyed.
|
|
|
|
CefDevToolsFrontend* devtools_frontend = new CefDevToolsFrontend(
|
|
|
|
static_cast<CefBrowserHostImpl*>(frontend_browser.get()),
|
2016-06-10 18:43:53 +02:00
|
|
|
inspected_contents, inspect_element_at);
|
2013-11-08 17:06:06 +01:00
|
|
|
|
|
|
|
// Need to load the URL after creating the DevTools objects.
|
2016-10-17 20:14:44 +02:00
|
|
|
frontend_browser->GetMainFrame()->LoadURL(GetFrontendURL());
|
2013-11-08 17:06:06 +01:00
|
|
|
|
|
|
|
return devtools_frontend;
|
|
|
|
}
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
void CefDevToolsFrontend::Activate() {
|
|
|
|
frontend_browser_->ActivateContents(web_contents());
|
|
|
|
}
|
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
void CefDevToolsFrontend::Focus() {
|
2016-06-10 18:43:53 +02:00
|
|
|
frontend_browser_->SetFocus(true);
|
2013-11-08 17:06:06 +01:00
|
|
|
}
|
|
|
|
|
2015-03-04 02:00:13 +01:00
|
|
|
void CefDevToolsFrontend::InspectElementAt(int x, int y) {
|
2016-06-10 18:43:53 +02:00
|
|
|
if (inspect_element_at_.x != x || inspect_element_at_.y != y)
|
|
|
|
inspect_element_at_.Set(x, y);
|
2015-03-04 02:00:13 +01:00
|
|
|
if (agent_host_)
|
2016-07-21 23:21:32 +02:00
|
|
|
agent_host_->InspectElement(this, x, y);
|
2015-03-04 02:00:13 +01:00
|
|
|
}
|
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
void CefDevToolsFrontend::Close() {
|
2016-10-17 20:14:44 +02:00
|
|
|
content::BrowserThread::PostTask(
|
|
|
|
content::BrowserThread::UI, FROM_HERE,
|
2014-11-20 17:43:12 +01:00
|
|
|
base::Bind(&CefBrowserHostImpl::CloseBrowser, frontend_browser_.get(),
|
|
|
|
true));
|
2013-11-08 17:06:06 +01:00
|
|
|
}
|
|
|
|
|
2015-03-04 02:00:13 +01:00
|
|
|
void CefDevToolsFrontend::DisconnectFromTarget() {
|
|
|
|
if (!agent_host_)
|
|
|
|
return;
|
2016-06-21 00:59:23 +02:00
|
|
|
agent_host_->DetachClient(this);
|
2015-03-04 02:00:13 +01:00
|
|
|
agent_host_ = NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
CefDevToolsFrontend::CefDevToolsFrontend(
|
|
|
|
CefRefPtr<CefBrowserHostImpl> frontend_browser,
|
2016-06-10 18:43:53 +02:00
|
|
|
content::WebContents* inspected_contents,
|
|
|
|
const CefPoint& inspect_element_at)
|
2016-10-17 20:14:44 +02:00
|
|
|
: content::WebContentsObserver(frontend_browser->web_contents()),
|
2013-11-08 17:06:06 +01:00
|
|
|
frontend_browser_(frontend_browser),
|
2015-03-19 23:06:16 +01:00
|
|
|
inspected_contents_(inspected_contents),
|
2016-06-10 18:43:53 +02:00
|
|
|
inspect_element_at_(inspect_element_at),
|
2015-03-04 02:00:13 +01:00
|
|
|
weak_factory_(this) {
|
2013-11-08 17:06:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefDevToolsFrontend::~CefDevToolsFrontend() {
|
2015-03-04 02:00:13 +01:00
|
|
|
for (const auto& pair : pending_requests_)
|
|
|
|
delete pair.first;
|
2013-11-08 17:06:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefDevToolsFrontend::RenderViewCreated(
|
|
|
|
content::RenderViewHost* render_view_host) {
|
2014-09-04 19:53:40 +02:00
|
|
|
if (!frontend_host_) {
|
2015-11-10 21:18:16 +01:00
|
|
|
frontend_host_.reset(content::DevToolsFrontendHost::Create(
|
|
|
|
web_contents()->GetMainFrame(),
|
|
|
|
base::Bind(&CefDevToolsFrontend::HandleMessageFromDevToolsFrontend,
|
|
|
|
base::Unretained(this))));
|
2014-09-04 19:53:40 +02:00
|
|
|
}
|
2013-11-08 17:06:06 +01:00
|
|
|
}
|
|
|
|
|
2015-03-19 23:06:16 +01:00
|
|
|
void CefDevToolsFrontend::DocumentAvailableInMainFrame() {
|
2015-07-31 22:54:54 +02:00
|
|
|
// Don't call AttachClient multiple times for the same DevToolsAgentHost.
|
|
|
|
// Otherwise it will call AgentHostClosed which closes the DevTools window.
|
|
|
|
// This may happen in cases where the DevTools content fails to load.
|
|
|
|
scoped_refptr<content::DevToolsAgentHost> agent_host =
|
2015-03-19 23:06:16 +01:00
|
|
|
content::DevToolsAgentHost::GetOrCreateFor(inspected_contents_);
|
2015-07-31 22:54:54 +02:00
|
|
|
if (agent_host != agent_host_) {
|
|
|
|
agent_host_ = agent_host;
|
|
|
|
agent_host_->AttachClient(this);
|
2016-10-17 20:14:44 +02:00
|
|
|
if (inspect_element_at_.IsEmpty()) {
|
|
|
|
agent_host_->InspectElement(
|
|
|
|
this, inspect_element_at_.x, inspect_element_at_.y);
|
|
|
|
}
|
2015-07-31 22:54:54 +02:00
|
|
|
}
|
2015-03-04 02:00:13 +01:00
|
|
|
}
|
|
|
|
|
2014-05-29 19:15:34 +02:00
|
|
|
void CefDevToolsFrontend::WebContentsDestroyed() {
|
2015-03-04 02:00:13 +01:00
|
|
|
if (agent_host_)
|
2016-06-21 00:59:23 +02:00
|
|
|
agent_host_->DetachClient(this);
|
2013-11-08 17:06:06 +01:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
void CefDevToolsFrontend::SetPreferences(const std::string& json) {
|
|
|
|
preferences_.Clear();
|
|
|
|
if (json.empty())
|
|
|
|
return;
|
|
|
|
base::DictionaryValue* dict = nullptr;
|
|
|
|
std::unique_ptr<base::Value> parsed = base::JSONReader::Read(json);
|
|
|
|
if (!parsed || !parsed->GetAsDictionary(&dict))
|
|
|
|
return;
|
|
|
|
for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
|
|
|
|
if (!it.value().IsType(base::Value::TYPE_STRING))
|
|
|
|
continue;
|
|
|
|
preferences_.SetWithoutPathExpansion(it.key(), it.value().CreateDeepCopy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-04 19:53:40 +02:00
|
|
|
void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
|
|
|
|
const std::string& message) {
|
2015-03-04 02:00:13 +01:00
|
|
|
if (!agent_host_)
|
|
|
|
return;
|
2014-09-04 19:53:40 +02:00
|
|
|
std::string method;
|
|
|
|
base::ListValue* params = NULL;
|
|
|
|
base::DictionaryValue* dict = NULL;
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<base::Value> parsed_message = base::JSONReader::Read(message);
|
2014-09-04 19:53:40 +02:00
|
|
|
if (!parsed_message ||
|
|
|
|
!parsed_message->GetAsDictionary(&dict) ||
|
2014-12-13 21:18:31 +01:00
|
|
|
!dict->GetString("method", &method)) {
|
2014-09-04 19:53:40 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-03-04 02:00:13 +01:00
|
|
|
int request_id = 0;
|
|
|
|
dict->GetInteger("id", &request_id);
|
2014-12-13 21:18:31 +01:00
|
|
|
dict->GetList("params", ¶ms);
|
2014-09-04 19:53:40 +02:00
|
|
|
|
2015-11-10 21:18:16 +01:00
|
|
|
if (method == "dispatchProtocolMessage" && params && params->GetSize() == 1) {
|
2016-06-21 00:59:23 +02:00
|
|
|
if (!agent_host_ || !agent_host_->IsAttached())
|
|
|
|
return;
|
2015-11-10 21:18:16 +01:00
|
|
|
std::string protocol_message;
|
|
|
|
if (!params->GetString(0, &protocol_message))
|
|
|
|
return;
|
2016-06-21 00:59:23 +02:00
|
|
|
agent_host_->DispatchProtocolMessage(this, protocol_message);
|
2014-12-13 21:18:31 +01:00
|
|
|
} else if (method == "loadCompleted") {
|
2015-08-14 16:41:08 +02:00
|
|
|
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
|
2014-12-13 21:18:31 +01:00
|
|
|
base::ASCIIToUTF16("DevToolsAPI.setUseSoftMenu(true);"));
|
2015-03-04 02:00:13 +01:00
|
|
|
} else if (method == "loadNetworkResource" && params->GetSize() == 3) {
|
|
|
|
// TODO(pfeldman): handle some of the embedder messages in content.
|
|
|
|
std::string url;
|
|
|
|
std::string headers;
|
|
|
|
int stream_id;
|
|
|
|
if (!params->GetString(0, &url) ||
|
|
|
|
!params->GetString(1, &headers) ||
|
|
|
|
!params->GetInteger(2, &stream_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GURL gurl(url);
|
|
|
|
if (!gurl.is_valid()) {
|
|
|
|
base::DictionaryValue response;
|
|
|
|
response.SetInteger("statusCode", 404);
|
|
|
|
SendMessageAck(request_id, &response);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
net::URLFetcher* fetcher =
|
2015-06-06 00:06:48 +02:00
|
|
|
net::URLFetcher::Create(gurl, net::URLFetcher::GET, this).release();
|
2015-03-04 02:00:13 +01:00
|
|
|
pending_requests_[fetcher] = request_id;
|
2016-05-25 01:35:43 +02:00
|
|
|
fetcher->SetRequestContext(
|
|
|
|
content::BrowserContext::GetDefaultStoragePartition(
|
|
|
|
web_contents()->GetBrowserContext())->
|
|
|
|
GetURLRequestContext());
|
2015-03-04 02:00:13 +01:00
|
|
|
fetcher->SetExtraRequestHeaders(headers);
|
2016-10-17 20:14:44 +02:00
|
|
|
fetcher->SaveResponseWithWriter(
|
|
|
|
std::unique_ptr<net::URLFetcherResponseWriter>(
|
|
|
|
new ResponseWriter(weak_factory_.GetWeakPtr(), stream_id)));
|
2015-03-04 02:00:13 +01:00
|
|
|
fetcher->Start();
|
|
|
|
return;
|
2015-04-23 12:03:42 +02:00
|
|
|
} else if (method == "getPreferences") {
|
|
|
|
SendMessageAck(request_id, &preferences_);
|
|
|
|
return;
|
|
|
|
} else if (method == "setPreference") {
|
|
|
|
std::string name;
|
|
|
|
std::string value;
|
|
|
|
if (!params->GetString(0, &name) ||
|
|
|
|
!params->GetString(1, &value)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
preferences_.SetStringWithoutPathExpansion(name, value);
|
|
|
|
} else if (method == "removePreference") {
|
|
|
|
std::string name;
|
|
|
|
if (!params->GetString(0, &name))
|
|
|
|
return;
|
|
|
|
preferences_.RemoveWithoutPathExpansion(name, nullptr);
|
2015-10-09 17:23:12 +02:00
|
|
|
} else if (method == "requestFileSystems") {
|
|
|
|
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
|
|
|
|
base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([]);"));
|
2014-12-13 21:18:31 +01:00
|
|
|
} else {
|
2014-09-04 19:53:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-04 02:00:13 +01:00
|
|
|
if (request_id)
|
|
|
|
SendMessageAck(request_id, nullptr);
|
2014-09-04 19:53:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefDevToolsFrontend::DispatchProtocolMessage(
|
2016-10-17 20:14:44 +02:00
|
|
|
content::DevToolsAgentHost* agent_host, const std::string& message) {
|
|
|
|
|
2015-01-09 18:22:10 +01:00
|
|
|
if (message.length() < kMaxMessageChunkSize) {
|
2016-06-21 00:59:23 +02:00
|
|
|
std::string param;
|
|
|
|
base::EscapeJSONString(message, true, ¶m);
|
|
|
|
std::string code = "DevToolsAPI.dispatchMessage(" + param + ");";
|
|
|
|
base::string16 javascript = base::UTF8ToUTF16(code);
|
2015-08-14 16:41:08 +02:00
|
|
|
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript);
|
2015-01-09 18:22:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
size_t total_size = message.length();
|
2015-01-09 18:22:10 +01:00
|
|
|
for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) {
|
|
|
|
std::string param;
|
2016-06-21 00:59:23 +02:00
|
|
|
base::EscapeJSONString(message.substr(pos, kMaxMessageChunkSize), true,
|
|
|
|
¶m);
|
|
|
|
std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + "," +
|
|
|
|
std::to_string(pos ? 0 : total_size) + ");";
|
2015-01-09 18:22:10 +01:00
|
|
|
base::string16 javascript = base::UTF8ToUTF16(code);
|
2015-08-14 16:41:08 +02:00
|
|
|
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript);
|
2015-01-09 18:22:10 +01:00
|
|
|
}
|
2014-09-04 19:53:40 +02:00
|
|
|
}
|
|
|
|
|
2015-03-04 02:00:13 +01:00
|
|
|
void CefDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) {
|
|
|
|
// TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc.
|
|
|
|
// We should handle some of the commands including this one in content.
|
|
|
|
DCHECK(source);
|
|
|
|
PendingRequestsMap::iterator it = pending_requests_.find(source);
|
|
|
|
DCHECK(it != pending_requests_.end());
|
|
|
|
|
|
|
|
base::DictionaryValue response;
|
|
|
|
base::DictionaryValue* headers = new base::DictionaryValue();
|
|
|
|
net::HttpResponseHeaders* rh = source->GetResponseHeaders();
|
|
|
|
response.SetInteger("statusCode", rh ? rh->response_code() : 200);
|
|
|
|
response.Set("headers", headers);
|
|
|
|
|
2016-02-05 01:49:19 +01:00
|
|
|
size_t iterator = 0;
|
2015-03-04 02:00:13 +01:00
|
|
|
std::string name;
|
|
|
|
std::string value;
|
|
|
|
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value))
|
|
|
|
headers->SetString(name, value);
|
|
|
|
|
|
|
|
SendMessageAck(it->second, &response);
|
|
|
|
pending_requests_.erase(it);
|
|
|
|
delete source;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefDevToolsFrontend::CallClientFunction(
|
|
|
|
const std::string& function_name,
|
|
|
|
const base::Value* arg1,
|
|
|
|
const base::Value* arg2,
|
|
|
|
const base::Value* arg3) {
|
|
|
|
std::string javascript = function_name + "(";
|
|
|
|
if (arg1) {
|
|
|
|
std::string json;
|
2015-06-06 00:06:48 +02:00
|
|
|
base::JSONWriter::Write(*arg1, &json);
|
2015-03-04 02:00:13 +01:00
|
|
|
javascript.append(json);
|
|
|
|
if (arg2) {
|
2015-06-06 00:06:48 +02:00
|
|
|
base::JSONWriter::Write(*arg2, &json);
|
2015-03-04 02:00:13 +01:00
|
|
|
javascript.append(", ").append(json);
|
|
|
|
if (arg3) {
|
2015-06-06 00:06:48 +02:00
|
|
|
base::JSONWriter::Write(*arg3, &json);
|
2015-03-04 02:00:13 +01:00
|
|
|
javascript.append(", ").append(json);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
javascript.append(");");
|
2015-08-14 16:41:08 +02:00
|
|
|
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
|
2015-03-04 02:00:13 +01:00
|
|
|
base::UTF8ToUTF16(javascript));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefDevToolsFrontend::SendMessageAck(int request_id,
|
2016-10-17 20:14:44 +02:00
|
|
|
const base::Value* arg) {
|
2015-03-04 02:00:13 +01:00
|
|
|
base::FundamentalValue id_value(request_id);
|
|
|
|
CallClientFunction("DevToolsAPI.embedderMessageAck",
|
|
|
|
&id_value, arg, nullptr);
|
|
|
|
}
|
|
|
|
|
2014-09-04 19:53:40 +02:00
|
|
|
void CefDevToolsFrontend::AgentHostClosed(
|
2016-10-17 20:14:44 +02:00
|
|
|
content::DevToolsAgentHost* agent_host, bool replaced) {
|
2014-11-19 18:56:37 +01:00
|
|
|
DCHECK(agent_host == agent_host_.get());
|
2013-11-08 17:06:06 +01:00
|
|
|
Close();
|
|
|
|
}
|