mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-16 20:20:51 +01:00
Remove the old (non-functional) about:tracing implementation. A new implementation is required due to Chromium changes (issue #1146).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1533 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
3d218e4442
commit
4e58096051
6
cef.gyp
6
cef.gyp
@ -556,7 +556,6 @@
|
||||
'type': 'none',
|
||||
'dependencies': [
|
||||
'<(DEPTH)/content/browser/devtools/devtools_resources.gyp:devtools_resources',
|
||||
'<(DEPTH)/content/browser/tracing/tracing_resources.gyp:tracing_resources',
|
||||
'<(DEPTH)/content/content_resources.gyp:content_resources',
|
||||
'<(DEPTH)/net/net.gyp:net_resources',
|
||||
'<(DEPTH)/ui/resources/ui_resources.gyp:ui_resources',
|
||||
@ -573,7 +572,6 @@
|
||||
'action_name': 'repack_cef_pack',
|
||||
'variables': {
|
||||
'pak_inputs': [
|
||||
'<(SHARED_INTERMEDIATE_DIR)/content/browser/tracing/tracing_resources.pak',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/content/content_resources.pak',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources_100_percent.pak',
|
||||
@ -596,7 +594,6 @@
|
||||
'action_name': 'make_pack_resources_header',
|
||||
'variables': {
|
||||
'header_inputs': [
|
||||
'<(SHARED_INTERMEDIATE_DIR)/content/browser/tracing/grit/tracing_resources.h',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/content/grit/content_resources.h',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/net/grit/net_resources.h',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/grit/ui_resources.h',
|
||||
@ -660,7 +657,6 @@
|
||||
# CEF grit resource includes
|
||||
'<(DEPTH)/cef/libcef/resources/grit_stub',
|
||||
'<(grit_out_dir)',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/content/browser/tracing',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_strings',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/webkit',
|
||||
],
|
||||
@ -863,8 +859,6 @@
|
||||
'libcef/common/values_impl.h',
|
||||
'libcef/renderer/browser_impl.cc',
|
||||
'libcef/renderer/browser_impl.h',
|
||||
'libcef/renderer/chrome_bindings.cc',
|
||||
'libcef/renderer/chrome_bindings.h',
|
||||
'libcef/renderer/content_renderer_client.cc',
|
||||
'libcef/renderer/content_renderer_client.h',
|
||||
'libcef/renderer/dom_document_impl.cc',
|
||||
|
@ -2120,8 +2120,6 @@ void CefBrowserHostImpl::OnRequest(const Cef_Request_Params& params) {
|
||||
message.get());
|
||||
message->Detach(NULL);
|
||||
}
|
||||
} else if (params.name == scheme::kChromeProcessMessage) {
|
||||
scheme::OnChromeProcessMessage(this, params.arguments);
|
||||
} else {
|
||||
// Invalid request.
|
||||
NOTREACHED();
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "include/cef_trace.h"
|
||||
#include "include/cef_version.h"
|
||||
#include "include/cef_web_plugin.h"
|
||||
#include "libcef/browser/context.h"
|
||||
@ -16,7 +15,6 @@
|
||||
#include "libcef/browser/internal_scheme_handler.h"
|
||||
#include "libcef/browser/scheme_impl.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/browser/trace_subscriber.h"
|
||||
#include "libcef/common/content_client.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
@ -31,7 +29,6 @@
|
||||
#include "content/browser/net/view_blob_internals_job_factory.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "grit/cef_resources.h"
|
||||
#include "grit/tracing_resources.h"
|
||||
#include "ipc/ipc_channel.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
#include "v8/include/v8.h"
|
||||
@ -40,20 +37,17 @@
|
||||
namespace scheme {
|
||||
|
||||
const char kChromeURL[] = "chrome://";
|
||||
const char kChromeProcessMessage[] = "chrome.send";
|
||||
|
||||
namespace {
|
||||
|
||||
const char kChromeCreditsDomain[] = "credits";
|
||||
const char kChromeLicenseDomain[] = "license";
|
||||
const char kChromeTracingDomain[] = "tracing";
|
||||
const char kChromeVersionDomain[] = "version";
|
||||
|
||||
enum ChromeDomain {
|
||||
CHROME_UNKNOWN = 0,
|
||||
CHROME_CREDITS,
|
||||
CHROME_LICENSE,
|
||||
CHROME_TRACING,
|
||||
CHROME_VERSION,
|
||||
};
|
||||
|
||||
@ -64,7 +58,6 @@ ChromeDomain GetChromeDomain(const std::string& domain_name) {
|
||||
} domains[] = {
|
||||
{ kChromeCreditsDomain, CHROME_CREDITS },
|
||||
{ kChromeLicenseDomain, CHROME_LICENSE },
|
||||
{ kChromeTracingDomain, CHROME_TRACING },
|
||||
{ kChromeVersionDomain, CHROME_VERSION },
|
||||
};
|
||||
|
||||
@ -205,9 +198,6 @@ class Delegate : public InternalHandlerDelegate {
|
||||
case CHROME_LICENSE:
|
||||
handled = OnLicense(action);
|
||||
break;
|
||||
case CHROME_TRACING:
|
||||
handled = OnTracing(path, action);
|
||||
break;
|
||||
case CHROME_VERSION:
|
||||
handled = OnVersion(action);
|
||||
break;
|
||||
@ -256,16 +246,6 @@ class Delegate : public InternalHandlerDelegate {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnTracing(const std::string& path, Action* action) {
|
||||
if (path == "tracing.js") {
|
||||
action->resource_id = IDR_TRACING_JS;
|
||||
} else {
|
||||
action->mime_type = "text/html";
|
||||
action->resource_id = IDR_TRACING_HTML;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnVersion(Action* action) {
|
||||
base::StringPiece piece = CefContentClient::Get()->GetDataResource(
|
||||
IDR_CEF_VERSION_HTML, ui::SCALE_FACTOR_NONE);
|
||||
@ -344,301 +324,6 @@ void DidFinishChromeVersionLoad(CefRefPtr<CefFrame> frame) {
|
||||
CefVisitWebPluginInfo(new Visitor(frame));
|
||||
}
|
||||
|
||||
// Test that the tracing browser window hasn't closed or navigated elsewhere.
|
||||
bool IsTraceFrameValid(CefRefPtr<CefFrameHostImpl> frame) {
|
||||
if (!frame->IsValid())
|
||||
return false;
|
||||
|
||||
std::string tracing_url(kChromeURL);
|
||||
tracing_url += kChromeTracingDomain;
|
||||
|
||||
std::string url = frame->GetURL();
|
||||
if (url.find(tracing_url.c_str()) != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LoadTraceFile(CefRefPtr<CefFrameHostImpl> frame,
|
||||
const base::FilePath& path) {
|
||||
CEF_REQUIRE_FILET();
|
||||
|
||||
if (!IsTraceFrameValid(frame))
|
||||
return;
|
||||
|
||||
std::string file_contents;
|
||||
if (!base::ReadFileToString(path, &file_contents)) {
|
||||
frame->SendJavaScript(
|
||||
"tracingController.onLoadTraceFileCanceled();", std::string(), 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to escape the file contents, because it will go into a javascript
|
||||
// quoted string in LoadTraceFileSuccess. We need to escape control characters
|
||||
// (to have well-formed javascript statements), as well as \ and ' (the only
|
||||
// special characters in a ''-quoted string). Do the escaping on this thread,
|
||||
// it may take a little while for big files and we don't want to block the UI
|
||||
// during that time. Also do the UTF-16 conversion here.
|
||||
// Note: we're using UTF-16 because we'll need to cut the string into slices
|
||||
// to give to Javascript, and it's easier to cut than UTF-8 (since JS strings
|
||||
// are arrays of 16-bit values, UCS-2 really, whereas we can't cut inside of a
|
||||
// multibyte UTF-8 codepoint).
|
||||
size_t size = file_contents.size();
|
||||
std::string escaped_contents;
|
||||
escaped_contents.reserve(size);
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
char c = file_contents[i];
|
||||
if (c < ' ') {
|
||||
escaped_contents += base::StringPrintf("\\u%04x", c);
|
||||
continue;
|
||||
}
|
||||
if (c == '\\' || c == '\'')
|
||||
escaped_contents.push_back('\\');
|
||||
escaped_contents.push_back(c);
|
||||
}
|
||||
file_contents.clear();
|
||||
|
||||
const string16& contents16 = UTF8ToUTF16(escaped_contents);
|
||||
|
||||
// We need to pass contents to tracingController.onLoadTraceFileComplete, but
|
||||
// that may be arbitrarily big, and IPC messages are limited in size. So we
|
||||
// need to cut it into pieces and rebuild the string in Javascript.
|
||||
// IPC::Channel::kMaximumMessageSize is in bytes, and we need to account for
|
||||
// overhead.
|
||||
static const size_t kMaxSize = IPC::Channel::kMaximumMessageSize / 2 - 128;
|
||||
const string16& first_prefix = ASCIIToUTF16("window.traceData = '");
|
||||
const string16& prefix = ASCIIToUTF16("window.traceData += '");
|
||||
const string16& suffix = ASCIIToUTF16("';");
|
||||
|
||||
for (size_t i = 0; i < contents16.size(); i += kMaxSize) {
|
||||
string16 javascript = i == 0 ? first_prefix : prefix;
|
||||
javascript += contents16.substr(i, kMaxSize) + suffix;
|
||||
frame->SendJavaScript(UTF16ToUTF8(javascript), std::string(), 0);
|
||||
}
|
||||
|
||||
frame->SendJavaScript(
|
||||
"tracingController.onLoadTraceFileComplete(window.traceData);"
|
||||
"delete window.traceData;",
|
||||
std::string(), 0);
|
||||
}
|
||||
|
||||
void SaveTraceFile(CefRefPtr<CefFrameHostImpl> frame,
|
||||
const base::FilePath& path,
|
||||
scoped_ptr<std::string> contents) {
|
||||
CEF_REQUIRE_FILET();
|
||||
|
||||
if (!IsTraceFrameValid(frame))
|
||||
return;
|
||||
|
||||
if (file_util::WriteFile(path, contents->c_str(), contents->size())) {
|
||||
frame->SendJavaScript(
|
||||
"tracingController.onSaveTraceFileComplete();",
|
||||
std::string(), 0);
|
||||
} else {
|
||||
frame->SendJavaScript(
|
||||
"tracingController.onSaveTraceFileCanceled();",
|
||||
std::string(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void OnKnownCategoriesCollected(
|
||||
CefRefPtr<CefFrameHostImpl> frame,
|
||||
const std::set<std::string>& known_categories) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
if (!IsTraceFrameValid(frame))
|
||||
return;
|
||||
|
||||
std::string categories;
|
||||
for (std::set<std::string>::iterator iter = known_categories.begin();
|
||||
iter != known_categories.end();
|
||||
++iter) {
|
||||
if (categories.length() > 0)
|
||||
categories += ",";
|
||||
categories += "\"" + *iter + "\"";
|
||||
}
|
||||
|
||||
frame->SendJavaScript(
|
||||
"tracingController.onKnownCategoriesCollected([" + categories + "]);",
|
||||
std::string(), 0);
|
||||
}
|
||||
|
||||
void OnChromeTracingProcessMessage(CefRefPtr<CefBrowser> browser,
|
||||
const std::string& action,
|
||||
const base::ListValue* arguments) {
|
||||
CefRefPtr<CefFrameHostImpl> frame =
|
||||
static_cast<CefFrameHostImpl*>(browser->GetMainFrame().get());
|
||||
|
||||
if (action == "tracingControllerInitialized") {
|
||||
// Send the client info to the tracingController.
|
||||
} else if (action == "beginTracing") {
|
||||
if (!arguments || arguments->GetSize() != 3) {
|
||||
NOTREACHED() << "Invalid arguments to " << action.c_str();
|
||||
return;
|
||||
}
|
||||
|
||||
class Client : public CefTraceClient {
|
||||
public:
|
||||
explicit Client(CefRefPtr<CefFrameHostImpl> frame)
|
||||
: frame_(frame),
|
||||
ended_(false) {
|
||||
}
|
||||
|
||||
virtual void OnTraceDataCollected(const char* fragment,
|
||||
size_t fragment_size) OVERRIDE {
|
||||
std::string javascript("window.traceData += '");
|
||||
|
||||
std::string escaped_data;
|
||||
ReplaceChars(std::string(fragment, fragment_size),
|
||||
"\\", "\\\\", &escaped_data);
|
||||
javascript += escaped_data;
|
||||
|
||||
// Intentionally append a , to the traceData. This technically causes all
|
||||
// traceData that we pass back to JS to end with a comma, but that is
|
||||
// actually something the JS side strips away anyway.
|
||||
javascript += ",';";
|
||||
|
||||
Execute(javascript);
|
||||
}
|
||||
|
||||
virtual void OnTraceBufferPercentFullReply(float percent_full) OVERRIDE {
|
||||
Execute(base::StringPrintf(
|
||||
"tracingController.onRequestBufferPercentFullComplete(%f);",
|
||||
percent_full));
|
||||
}
|
||||
|
||||
virtual void OnEndTracingComplete() OVERRIDE {
|
||||
ended_ = true;
|
||||
Execute("tracingController.onEndTracingComplete(window.traceData);"
|
||||
"delete window.traceData;");
|
||||
}
|
||||
|
||||
private:
|
||||
void Execute(const std::string& code) {
|
||||
if (!IsTraceFrameValid(frame_) && !ended_) {
|
||||
ended_ = true;
|
||||
CefEndTracingAsync();
|
||||
return;
|
||||
}
|
||||
frame_->SendJavaScript(code, std::string(), 0);
|
||||
}
|
||||
|
||||
CefRefPtr<CefFrameHostImpl> frame_;
|
||||
bool ended_;
|
||||
IMPLEMENT_REFCOUNTING(Callback);
|
||||
};
|
||||
|
||||
std::string categories;
|
||||
arguments->GetString(1, &categories);
|
||||
|
||||
CefRefPtr<CefTraceClient> client = new Client(frame);
|
||||
|
||||
// Tracing may already be running, in which case the previous client will
|
||||
// continue handling it.
|
||||
CefBeginTracing(client, categories);
|
||||
} else if (action == "endTracingAsync") {
|
||||
// This is really us beginning to end tracing, rather than tracing being
|
||||
// truly over. When this function yields, we expect to get some number of
|
||||
// OnTraceDataCollected callbacks, which will append data to
|
||||
// window.traceData. To set up for this, set window.traceData to the empty
|
||||
// string.
|
||||
frame->SendJavaScript("window.traceData = '';", std::string(), 0);
|
||||
|
||||
if (!CefEndTracingAsync()) {
|
||||
// We weren't really tracing to begin with.
|
||||
frame->SendJavaScript(
|
||||
"tracingController.onEndTracingComplete(window.traceData);"
|
||||
"delete window.traceData;",
|
||||
std::string(), 0);
|
||||
}
|
||||
} else if (action == "beginRequestBufferPercentFull") {
|
||||
CefGetTraceBufferPercentFullAsync();
|
||||
} else if (action == "loadTraceFile") {
|
||||
class Callback : public CefRunFileDialogCallback {
|
||||
public:
|
||||
explicit Callback(CefRefPtr<CefFrameHostImpl> frame)
|
||||
: frame_(frame) {
|
||||
}
|
||||
|
||||
virtual void OnFileDialogDismissed(
|
||||
CefRefPtr<CefBrowserHost> browser_host,
|
||||
const std::vector<CefString>& file_paths) OVERRIDE {
|
||||
if (!IsTraceFrameValid(frame_))
|
||||
return;
|
||||
|
||||
if (!file_paths.empty()) {
|
||||
CEF_POST_TASK(CEF_FILET,
|
||||
base::Bind(LoadTraceFile, frame_,
|
||||
base::FilePath(file_paths.front())));
|
||||
} else {
|
||||
frame_->SendJavaScript(
|
||||
"tracingController.onLoadTraceFileCanceled();",
|
||||
std::string(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
CefRefPtr<CefFrameHostImpl> frame_;
|
||||
IMPLEMENT_REFCOUNTING(Callback);
|
||||
};
|
||||
|
||||
browser->GetHost()->RunFileDialog(FILE_DIALOG_OPEN, CefString(),
|
||||
CefString(), std::vector<CefString>(), new Callback(frame));
|
||||
} else if (action == "saveTraceFile") {
|
||||
if (!arguments || arguments->GetSize() != 1) {
|
||||
NOTREACHED() << "Invalid arguments to " << action.c_str();
|
||||
return;
|
||||
}
|
||||
|
||||
class Callback : public CefRunFileDialogCallback {
|
||||
public:
|
||||
Callback(CefRefPtr<CefFrameHostImpl> frame,
|
||||
scoped_ptr<std::string> contents)
|
||||
: frame_(frame),
|
||||
contents_(contents.Pass()) {
|
||||
}
|
||||
|
||||
virtual void OnFileDialogDismissed(
|
||||
CefRefPtr<CefBrowserHost> browser_host,
|
||||
const std::vector<CefString>& file_paths) OVERRIDE {
|
||||
if (!IsTraceFrameValid(frame_))
|
||||
return;
|
||||
|
||||
if (!file_paths.empty()) {
|
||||
CEF_POST_TASK(CEF_FILET,
|
||||
base::Bind(SaveTraceFile, frame_,
|
||||
base::FilePath(file_paths.front()),
|
||||
base::Passed(contents_.Pass())));
|
||||
} else {
|
||||
frame_->SendJavaScript(
|
||||
"tracingController.onSaveTraceFileCanceled();",
|
||||
std::string(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
CefRefPtr<CefFrameHostImpl> frame_;
|
||||
scoped_ptr<std::string> contents_;
|
||||
IMPLEMENT_REFCOUNTING(Callback);
|
||||
};
|
||||
|
||||
std::string contents_str;
|
||||
arguments->GetString(0, &contents_str);
|
||||
|
||||
scoped_ptr<std::string> contents(new std::string());
|
||||
contents_str.swap(*contents);
|
||||
|
||||
browser->GetHost()->RunFileDialog(FILE_DIALOG_SAVE, CefString(),
|
||||
CefString(), std::vector<CefString>(),
|
||||
new Callback(frame, contents.Pass()));
|
||||
} else if (action == "getKnownCategories") {
|
||||
CefContext::Get()->GetTraceSubscriber()->GetKnownCategoriesAsync(
|
||||
base::Bind(OnKnownCategoriesCollected, frame));
|
||||
} else {
|
||||
NOTREACHED() << "Unknown trace action: " << action.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
// Wrapper for a ChromeProtocolHandler instance from
|
||||
// content/browser/webui/url_data_manager_backend.cc.
|
||||
class ChromeProtocolHandlerWrapper :
|
||||
@ -707,28 +392,6 @@ void DidFinishChromeLoad(CefRefPtr<CefFrame> frame,
|
||||
}
|
||||
}
|
||||
|
||||
void OnChromeProcessMessage(CefRefPtr<CefBrowser> browser,
|
||||
const base::ListValue& arguments) {
|
||||
std::string action;
|
||||
const base::ListValue* args = NULL;
|
||||
|
||||
size_t size = arguments.GetSize();
|
||||
if (size > 0) {
|
||||
arguments.GetString(0, &action);
|
||||
if (size > 1)
|
||||
arguments.GetList(1, &args);
|
||||
}
|
||||
|
||||
GURL url = GURL(browser->GetMainFrame()->GetURL().ToString());
|
||||
ChromeDomain domain = GetChromeDomain(url.host());
|
||||
switch (domain) {
|
||||
case CHROME_TRACING:
|
||||
OnChromeTracingProcessMessage(browser, action, args);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
||||
WrapChromeProtocolHandler(
|
||||
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
||||
|
@ -27,7 +27,6 @@ class BrowserContext;
|
||||
namespace scheme {
|
||||
|
||||
extern const char kChromeURL[];
|
||||
extern const char kChromeProcessMessage[];
|
||||
|
||||
// Register the chrome scheme handler.
|
||||
void RegisterChromeHandler();
|
||||
@ -40,10 +39,6 @@ bool WillHandleBrowserAboutURL(GURL* url,
|
||||
void DidFinishChromeLoad(CefRefPtr<CefFrame> frame,
|
||||
const GURL& validated_url);
|
||||
|
||||
// Used to execute messages from render process bindings.
|
||||
void OnChromeProcessMessage(CefRefPtr<CefBrowser> browser,
|
||||
const base::ListValue& arguments);
|
||||
|
||||
// Create a new ProtocolHandler that will filter the URLs passed to the default
|
||||
// "chrome" protocol handler and forward the rest to CEF's handler.
|
||||
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
||||
|
@ -1,119 +0,0 @@
|
||||
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "libcef/renderer/chrome_bindings.h"
|
||||
#include "libcef/renderer/browser_impl.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/values.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
|
||||
namespace scheme {
|
||||
|
||||
namespace {
|
||||
|
||||
void SetList(CefRefPtr<CefV8Value> source, base::ListValue* target);
|
||||
|
||||
// Transfer a V8 value to a List index.
|
||||
void SetListValue(base::ListValue* list, int index,
|
||||
CefRefPtr<CefV8Value> value) {
|
||||
if (value->IsArray()) {
|
||||
base::ListValue* new_list = new base::ListValue();
|
||||
SetList(value, new_list);
|
||||
list->Set(index, new_list);
|
||||
} else if (value->IsString()) {
|
||||
list->Set(index,
|
||||
base::Value::CreateStringValue(value->GetStringValue().ToString()));
|
||||
} else if (value->IsBool()) {
|
||||
list->Set(index, base::Value::CreateBooleanValue(value->GetBoolValue()));
|
||||
} else if (value->IsInt()) {
|
||||
list->Set(index, base::Value::CreateIntegerValue(value->GetIntValue()));
|
||||
} else if (value->IsDouble()) {
|
||||
list->Set(index, base::Value::CreateDoubleValue(value->GetDoubleValue()));
|
||||
}
|
||||
}
|
||||
|
||||
// Transfer a V8 array to a List.
|
||||
void SetList(CefRefPtr<CefV8Value> source, base::ListValue* target) {
|
||||
DCHECK(source->IsArray());
|
||||
|
||||
int arg_length = source->GetArrayLength();
|
||||
if (arg_length == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < arg_length; ++i)
|
||||
SetListValue(target, i, source->GetValue(i));
|
||||
}
|
||||
|
||||
class V8Handler : public CefV8Handler {
|
||||
public:
|
||||
V8Handler() {}
|
||||
|
||||
virtual bool Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) OVERRIDE {
|
||||
std::string nameStr = name;
|
||||
if (nameStr == "send") {
|
||||
if (arguments.size() > 0 && arguments.size() <= 2 &&
|
||||
arguments[0]->IsString()) {
|
||||
base::ListValue args;
|
||||
SetListValue(&args, 0, arguments[0]);
|
||||
if (arguments.size() > 1)
|
||||
SetListValue(&args, 1, arguments[1]);
|
||||
|
||||
CefRefPtr<CefBrowserImpl> browser = static_cast<CefBrowserImpl*>(
|
||||
CefV8Context::GetCurrentContext()->GetBrowser().get());
|
||||
browser->SendProcessMessage(PID_BROWSER, kChromeProcessMessage, &args,
|
||||
false);
|
||||
|
||||
retval = CefV8Value::CreateBool(true);
|
||||
} else {
|
||||
exception = "Invalid number of arguments or argument format";
|
||||
}
|
||||
return true;
|
||||
} else if (nameStr == "bind") {
|
||||
// Return the "send" object.
|
||||
DCHECK(object->GetFunctionName() == "send");
|
||||
retval = object;
|
||||
return true;
|
||||
}
|
||||
|
||||
NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
IMPLEMENT_REFCOUNTING(V8Handler);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
void OnContextCreated(CefRefPtr<CefBrowserImpl> browser,
|
||||
CefRefPtr<CefFrameImpl> frame,
|
||||
CefRefPtr<CefV8Context> context) {
|
||||
GURL url = GURL(frame->GetURL().ToString());
|
||||
if (url.scheme() != chrome::kChromeUIScheme)
|
||||
return;
|
||||
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
|
||||
CefRefPtr<CefV8Handler> handler = new V8Handler();
|
||||
|
||||
// Add "chrome".
|
||||
CefRefPtr<CefV8Value> chrome = CefV8Value::CreateObject(NULL);
|
||||
global->SetValue("chrome", chrome, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
// Add "chrome.send".
|
||||
CefRefPtr<CefV8Value> send = CefV8Value::CreateFunction("send", handler);
|
||||
chrome->SetValue("send", send, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
// Add "chrome.send.bind".
|
||||
CefRefPtr<CefV8Value> bind = CefV8Value::CreateFunction("bind", handler);
|
||||
send->SetValue("bind", bind, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
} // namespace scheme
|
@ -1,23 +0,0 @@
|
||||
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_RENDERER_CHROME_BINDINGS_H_
|
||||
#define CEF_LIBCEF_RENDERER_CHROME_BINDINGS_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_v8.h"
|
||||
#include "libcef/renderer/browser_impl.h"
|
||||
#include "libcef/renderer/frame_impl.h"
|
||||
|
||||
namespace scheme {
|
||||
|
||||
extern const char kChromeProcessMessage[];
|
||||
|
||||
void OnContextCreated(CefRefPtr<CefBrowserImpl> browser,
|
||||
CefRefPtr<CefFrameImpl> frame,
|
||||
CefRefPtr<CefV8Context> context);
|
||||
|
||||
} // namespace scheme
|
||||
|
||||
#endif // CEF_LIBCEF_RENDERER_CHROME_BINDINGS_H_
|
@ -23,7 +23,6 @@ MSVC_POP_WARNING();
|
||||
#include "libcef/common/request_impl.h"
|
||||
#include "libcef/common/values_impl.h"
|
||||
#include "libcef/renderer/browser_impl.h"
|
||||
#include "libcef/renderer/chrome_bindings.h"
|
||||
#include "libcef/renderer/render_message_filter.h"
|
||||
#include "libcef/renderer/render_process_observer.h"
|
||||
#include "libcef/renderer/thread_util.h"
|
||||
@ -610,8 +609,6 @@ void CefContentRendererClient::DidCreateScriptContext(
|
||||
|
||||
CefRefPtr<CefV8Context> contextPtr(new CefV8ContextImpl(context));
|
||||
|
||||
scheme::OnContextCreated(browserPtr, framePtr, contextPtr);
|
||||
|
||||
// Notify the render process handler.
|
||||
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
||||
if (application.get()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user