2013-01-03 18:24:24 +01:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
2012-04-03 03:34:16 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2012-09-04 17:18:04 +02:00
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
|
2013-05-07 23:48:34 +02:00
|
|
|
#include "config.h"
|
2012-09-04 17:18:04 +02:00
|
|
|
MSVC_PUSH_WARNING_LEVEL(0);
|
2013-10-17 01:09:07 +02:00
|
|
|
#include "bindings/v8/V8Binding.h"
|
2013-05-07 23:48:34 +02:00
|
|
|
#include "bindings/v8/V8RecursionScope.h"
|
2012-09-04 17:18:04 +02:00
|
|
|
MSVC_POP_WARNING();
|
2013-07-25 00:40:07 +02:00
|
|
|
#undef ceil
|
2014-04-04 18:50:38 +02:00
|
|
|
#undef FROM_HERE
|
2012-09-04 17:18:04 +02:00
|
|
|
#undef LOG
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/content_renderer_client.h"
|
|
|
|
|
2013-02-02 01:21:59 +01:00
|
|
|
#include "libcef/browser/context.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/common/cef_messages.h"
|
2012-12-31 11:41:15 +01:00
|
|
|
#include "libcef/common/cef_switches.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/common/content_client.h"
|
2013-11-21 21:59:28 +01:00
|
|
|
#include "libcef/common/request_impl.h"
|
2012-11-20 21:08:36 +01:00
|
|
|
#include "libcef/common/values_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/browser_impl.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
#include "libcef/renderer/render_frame_observer.h"
|
2012-11-02 19:16:28 +01:00
|
|
|
#include "libcef/renderer/render_message_filter.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/render_process_observer.h"
|
|
|
|
#include "libcef/renderer/thread_util.h"
|
|
|
|
#include "libcef/renderer/v8_impl.h"
|
2013-10-16 02:25:38 +02:00
|
|
|
#include "libcef/renderer/webkit_glue.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-12-31 11:41:15 +01:00
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/path_service.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2013-04-04 20:10:17 +02:00
|
|
|
#include "chrome/renderer/loadtimes_extension_bindings.h"
|
2013-10-23 21:30:47 +02:00
|
|
|
#include "chrome/renderer/printing/print_web_view_helper.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "content/child/child_thread.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
#include "content/child/worker_task_runner.h"
|
2013-12-17 23:04:35 +01:00
|
|
|
#include "content/common/frame_messages.h"
|
2013-02-02 01:21:59 +01:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "content/public/browser/render_process_host.h"
|
2013-06-24 18:40:40 +02:00
|
|
|
#include "content/public/common/content_constants.h"
|
2014-01-14 18:37:02 +01:00
|
|
|
#include "content/public/common/content_paths.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/renderer/render_thread.h"
|
|
|
|
#include "content/public/renderer/render_view.h"
|
2013-12-17 23:04:35 +01:00
|
|
|
#include "content/renderer/render_frame_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "ipc/ipc_sync_channel.h"
|
2012-12-31 11:41:15 +01:00
|
|
|
#include "media/base/media.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "third_party/WebKit/public/platform/WebPrerenderingSupport.h"
|
|
|
|
#include "third_party/WebKit/public/platform/WebString.h"
|
|
|
|
#include "third_party/WebKit/public/platform/WebURL.h"
|
|
|
|
#include "third_party/WebKit/public/platform/WebWorkerRunLoop.h"
|
2013-06-24 18:40:40 +02:00
|
|
|
#include "third_party/WebKit/public/web/WebDocument.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "third_party/WebKit/public/web/WebFrame.h"
|
2014-02-19 17:27:54 +01:00
|
|
|
#include "third_party/WebKit/public/web/WebKit.h"
|
2013-06-24 18:40:40 +02:00
|
|
|
#include "third_party/WebKit/public/web/WebPluginParams.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "third_party/WebKit/public/web/WebPrerendererClient.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebView.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebWorkerInfo.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "v8/include/v8.h"
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2012-05-29 19:18:33 +02:00
|
|
|
namespace {
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
// Stub implementation of blink::WebPrerenderingSupport.
|
|
|
|
class CefPrerenderingSupport : public blink::WebPrerenderingSupport {
|
2012-05-29 19:18:33 +02:00
|
|
|
public:
|
|
|
|
virtual ~CefPrerenderingSupport() {}
|
|
|
|
|
|
|
|
private:
|
2013-11-08 22:28:56 +01:00
|
|
|
virtual void add(const blink::WebPrerender& prerender) OVERRIDE {}
|
|
|
|
virtual void cancel(const blink::WebPrerender& prerender) OVERRIDE {}
|
|
|
|
virtual void abandon(const blink::WebPrerender& prerender) OVERRIDE {}
|
2012-05-29 19:18:33 +02:00
|
|
|
};
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
// Stub implementation of blink::WebPrerendererClient.
|
2012-05-29 19:18:33 +02:00
|
|
|
class CefPrerendererClient : public content::RenderViewObserver,
|
2013-11-08 22:28:56 +01:00
|
|
|
public blink::WebPrerendererClient {
|
2012-05-29 19:18:33 +02:00
|
|
|
public:
|
|
|
|
explicit CefPrerendererClient(content::RenderView* render_view)
|
|
|
|
: content::RenderViewObserver(render_view) {
|
|
|
|
DCHECK(render_view);
|
|
|
|
render_view->GetWebView()->setPrerendererClient(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~CefPrerendererClient() {}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
virtual void willAddPrerender(blink::WebPrerender* prerender) OVERRIDE {}
|
2012-05-29 19:18:33 +02:00
|
|
|
};
|
|
|
|
|
2013-01-03 18:24:24 +01:00
|
|
|
// Implementation of SequencedTaskRunner for WebWorker threads.
|
|
|
|
class CefWebWorkerTaskRunner : public base::SequencedTaskRunner,
|
2014-04-04 18:50:38 +02:00
|
|
|
public content::WorkerTaskRunner::Observer {
|
2013-01-03 18:24:24 +01:00
|
|
|
public:
|
2014-04-04 18:50:38 +02:00
|
|
|
CefWebWorkerTaskRunner(content::WorkerTaskRunner* runner,
|
2013-01-03 18:24:24 +01:00
|
|
|
int worker_id)
|
|
|
|
: runner_(runner),
|
|
|
|
worker_id_(worker_id) {
|
|
|
|
DCHECK(runner_);
|
|
|
|
DCHECK_GT(worker_id_, 0);
|
|
|
|
DCHECK(RunsTasksOnCurrentThread());
|
|
|
|
|
|
|
|
// Adds an observer for the current thread.
|
|
|
|
runner_->AddStopObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// SequencedTaskRunner methods:
|
|
|
|
virtual bool PostNonNestableDelayedTask(
|
|
|
|
const tracked_objects::Location& from_here,
|
|
|
|
const base::Closure& task,
|
|
|
|
base::TimeDelta delay) OVERRIDE {
|
|
|
|
return PostDelayedTask(from_here, task, delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TaskRunner methods:
|
|
|
|
virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
|
|
|
|
const base::Closure& task,
|
|
|
|
base::TimeDelta delay) OVERRIDE {
|
|
|
|
if (delay != base::TimeDelta())
|
2013-02-09 23:38:24 +01:00
|
|
|
LOG(WARNING) << "Delayed tasks are not supported on WebWorker threads";
|
2013-01-03 18:24:24 +01:00
|
|
|
runner_->PostTask(worker_id_, task);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool RunsTasksOnCurrentThread() const OVERRIDE {
|
|
|
|
return (runner_->CurrentWorkerId() == worker_id_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// WorkerTaskRunner::Observer methods:
|
|
|
|
virtual void OnWorkerRunLoopStopped() OVERRIDE {
|
|
|
|
CefContentRendererClient::Get()->RemoveWorkerTaskRunner(worker_id_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-04-04 18:50:38 +02:00
|
|
|
content::WorkerTaskRunner* runner_;
|
2013-01-03 18:24:24 +01:00
|
|
|
int worker_id_;
|
|
|
|
};
|
|
|
|
|
2012-05-29 19:18:33 +02:00
|
|
|
} // namespace
|
|
|
|
|
2012-11-02 19:16:28 +01:00
|
|
|
CefContentRendererClient::CefContentRendererClient()
|
2013-06-05 01:37:26 +02:00
|
|
|
: devtools_agent_count_(0),
|
2013-02-02 01:21:59 +01:00
|
|
|
uncaught_exception_stack_size_(0),
|
|
|
|
single_process_cleanup_complete_(false) {
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefContentRendererClient::~CefContentRendererClient() {
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefContentRendererClient* CefContentRendererClient::Get() {
|
|
|
|
return static_cast<CefContentRendererClient*>(
|
2013-04-16 00:16:01 +02:00
|
|
|
CefContentClient::Get()->renderer());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserImpl> CefContentRendererClient::GetBrowserForView(
|
|
|
|
content::RenderView* view) {
|
|
|
|
CEF_REQUIRE_RT_RETURN(NULL);
|
|
|
|
|
|
|
|
BrowserMap::const_iterator it = browsers_.find(view);
|
|
|
|
if (it != browsers_.end())
|
|
|
|
return it->second;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserImpl> CefContentRendererClient::GetBrowserForMainFrame(
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebFrame* frame) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_REQUIRE_RT_RETURN(NULL);
|
|
|
|
|
|
|
|
BrowserMap::const_iterator it = browsers_.begin();
|
|
|
|
for (; it != browsers_.end(); ++it) {
|
|
|
|
content::RenderView* render_view = it->second->render_view();
|
|
|
|
if (render_view && render_view->GetWebView() &&
|
|
|
|
render_view->GetWebView()->mainFrame() == frame) {
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefContentRendererClient::OnBrowserDestroyed(CefBrowserImpl* browser) {
|
|
|
|
BrowserMap::iterator it = browsers_.begin();
|
|
|
|
for (; it != browsers_.end(); ++it) {
|
|
|
|
if (it->second.get() == browser) {
|
|
|
|
browsers_.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No browser was found in the map.
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
|
2012-12-31 11:41:15 +01:00
|
|
|
void CefContentRendererClient::WebKitInitialized() {
|
2013-03-08 01:41:26 +01:00
|
|
|
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
|
|
|
|
2014-05-29 19:15:34 +02:00
|
|
|
// Create global objects associated with the default Isolate.
|
|
|
|
CefV8IsolateCreated();
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebRuntimeFeatures::enableMediaPlayer(
|
2012-12-31 11:41:15 +01:00
|
|
|
media::IsMediaLibraryInitialized());
|
|
|
|
|
|
|
|
// TODO(cef): Enable these once the implementation supports it.
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebRuntimeFeatures::enableNotifications(false);
|
2012-12-31 11:41:15 +01:00
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebRuntimeFeatures::enableMediaStream(
|
2013-03-08 01:52:57 +01:00
|
|
|
command_line.HasSwitch(switches::kEnableMediaStream));
|
2013-03-08 01:41:26 +01:00
|
|
|
|
2013-06-05 01:37:26 +02:00
|
|
|
const CefContentClient::SchemeInfoList* schemes =
|
|
|
|
CefContentClient::Get()->GetCustomSchemes();
|
|
|
|
if (!schemes->empty()) {
|
2012-12-31 11:41:15 +01:00
|
|
|
// Register the custom schemes.
|
2013-06-05 01:37:26 +02:00
|
|
|
CefContentClient::SchemeInfoList::const_iterator it = schemes->begin();
|
|
|
|
for (; it != schemes->end(); ++it) {
|
|
|
|
const CefContentClient::SchemeInfo& info = *it;
|
2013-11-08 22:28:56 +01:00
|
|
|
const blink::WebString& scheme =
|
|
|
|
blink::WebString::fromUTF8(info.scheme_name);
|
2013-04-18 19:58:23 +02:00
|
|
|
if (info.is_standard) {
|
|
|
|
// Standard schemes must also be registered as CORS enabled to support
|
|
|
|
// CORS-restricted requests (for example, XMLHttpRequest redirects).
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebSecurityPolicy::registerURLSchemeAsCORSEnabled(scheme);
|
2012-12-31 11:41:15 +01:00
|
|
|
}
|
2013-04-18 19:58:23 +02:00
|
|
|
if (info.is_local)
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebSecurityPolicy::registerURLSchemeAsLocal(scheme);
|
2013-04-18 19:58:23 +02:00
|
|
|
if (info.is_display_isolated)
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(scheme);
|
2012-12-31 11:41:15 +01:00
|
|
|
}
|
|
|
|
}
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2012-12-31 11:41:15 +01:00
|
|
|
if (!cross_origin_whitelist_entries_.empty()) {
|
|
|
|
// Add the cross-origin white list entries.
|
|
|
|
for (size_t i = 0; i < cross_origin_whitelist_entries_.size(); ++i) {
|
|
|
|
const Cef_CrossOriginWhiteListEntry_Params& entry =
|
|
|
|
cross_origin_whitelist_entries_[i];
|
|
|
|
GURL gurl = GURL(entry.source_origin);
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebSecurityPolicy::addOriginAccessWhitelistEntry(
|
2012-12-31 11:41:15 +01:00
|
|
|
gurl,
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebString::fromUTF8(entry.target_protocol),
|
|
|
|
blink::WebString::fromUTF8(entry.target_domain),
|
2012-12-31 11:41:15 +01:00
|
|
|
entry.allow_target_subdomains);
|
2012-04-24 20:01:48 +02:00
|
|
|
}
|
2012-12-31 11:41:15 +01:00
|
|
|
cross_origin_whitelist_entries_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The number of stack trace frames to capture for uncaught exceptions.
|
|
|
|
if (command_line.HasSwitch(switches::kUncaughtExceptionStackSize)) {
|
|
|
|
int uncaught_exception_stack_size = 0;
|
|
|
|
base::StringToInt(
|
|
|
|
command_line.GetSwitchValueASCII(switches::kUncaughtExceptionStackSize),
|
|
|
|
&uncaught_exception_stack_size);
|
|
|
|
|
|
|
|
if (uncaught_exception_stack_size > 0) {
|
2013-01-03 18:24:24 +01:00
|
|
|
uncaught_exception_stack_size_ = uncaught_exception_stack_size;
|
|
|
|
CefV8SetUncaughtExceptionStackSize(uncaught_exception_stack_size_);
|
2012-04-24 20:01:48 +02:00
|
|
|
}
|
|
|
|
}
|
2012-12-31 11:41:15 +01:00
|
|
|
|
|
|
|
// Notify the render process handler.
|
|
|
|
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
|
|
|
if (application.get()) {
|
|
|
|
CefRefPtr<CefRenderProcessHandler> handler =
|
|
|
|
application->GetRenderProcessHandler();
|
|
|
|
if (handler.get())
|
|
|
|
handler->OnWebKitInitialized();
|
|
|
|
}
|
2012-04-24 20:01:48 +02:00
|
|
|
}
|
|
|
|
|
2013-01-03 18:24:24 +01:00
|
|
|
void CefContentRendererClient::OnRenderProcessShutdown() {
|
|
|
|
// Destroy global objects associated with the default Isolate.
|
|
|
|
CefV8IsolateDestroyed();
|
|
|
|
}
|
|
|
|
|
2012-11-02 19:16:28 +01:00
|
|
|
void CefContentRendererClient::DevToolsAgentAttached() {
|
|
|
|
CEF_REQUIRE_RT();
|
|
|
|
++devtools_agent_count_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefContentRendererClient::DevToolsAgentDetached() {
|
|
|
|
CEF_REQUIRE_RT();
|
|
|
|
--devtools_agent_count_;
|
|
|
|
if (devtools_agent_count_ == 0 && uncaught_exception_stack_size_ > 0) {
|
|
|
|
// When the last DevToolsAgent is detached the stack size is set to 0.
|
|
|
|
// Restore the user-specified stack size here.
|
2013-01-03 18:24:24 +01:00
|
|
|
CefV8SetUncaughtExceptionStackSize(uncaught_exception_stack_size_);
|
|
|
|
|
|
|
|
// And do the same for any WebWorker threads.
|
|
|
|
WorkerTaskRunnerMap map_copy;
|
|
|
|
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(worker_task_runner_lock_);
|
|
|
|
map_copy = worker_task_runner_map_;
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkerTaskRunnerMap::const_iterator it = map_copy.begin();
|
|
|
|
for (; it != map_copy.end(); ++it) {
|
|
|
|
it->second->PostTask(FROM_HERE,
|
|
|
|
base::Bind(CefV8SetUncaughtExceptionStackSize,
|
|
|
|
uncaught_exception_stack_size_));
|
|
|
|
}
|
2012-11-02 19:16:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 18:24:24 +01:00
|
|
|
scoped_refptr<base::SequencedTaskRunner>
|
|
|
|
CefContentRendererClient::GetCurrentTaskRunner() {
|
|
|
|
// Check if currently on the render thread.
|
|
|
|
if (CEF_CURRENTLY_ON_RT())
|
|
|
|
return render_task_runner_;
|
|
|
|
|
|
|
|
// Check if a WebWorker exists for the current thread.
|
2014-04-04 18:50:38 +02:00
|
|
|
content::WorkerTaskRunner* worker_runner =
|
|
|
|
content::WorkerTaskRunner::Instance();
|
2013-01-03 18:24:24 +01:00
|
|
|
int worker_id = worker_runner->CurrentWorkerId();
|
|
|
|
if (worker_id > 0) {
|
|
|
|
base::AutoLock lock_scope(worker_task_runner_lock_);
|
|
|
|
WorkerTaskRunnerMap::const_iterator it =
|
|
|
|
worker_task_runner_map_.find(worker_id);
|
|
|
|
if (it != worker_task_runner_map_.end())
|
|
|
|
return it->second;
|
|
|
|
|
|
|
|
scoped_refptr<base::SequencedTaskRunner> task_runner =
|
|
|
|
new CefWebWorkerTaskRunner(worker_runner, worker_id);
|
|
|
|
worker_task_runner_map_[worker_id] = task_runner;
|
|
|
|
return task_runner;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<base::SequencedTaskRunner>
|
|
|
|
CefContentRendererClient::GetWorkerTaskRunner(int worker_id) {
|
|
|
|
base::AutoLock lock_scope(worker_task_runner_lock_);
|
|
|
|
WorkerTaskRunnerMap::const_iterator it =
|
|
|
|
worker_task_runner_map_.find(worker_id);
|
|
|
|
if (it != worker_task_runner_map_.end())
|
|
|
|
return it->second;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefContentRendererClient::RemoveWorkerTaskRunner(int worker_id) {
|
|
|
|
base::AutoLock lock_scope(worker_task_runner_lock_);
|
|
|
|
WorkerTaskRunnerMap::iterator it = worker_task_runner_map_.find(worker_id);
|
|
|
|
if (it != worker_task_runner_map_.end())
|
|
|
|
worker_task_runner_map_.erase(it);
|
2012-11-02 19:16:28 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 01:21:59 +01:00
|
|
|
void CefContentRendererClient::RunSingleProcessCleanup() {
|
|
|
|
DCHECK(content::RenderProcessHost::run_renderer_in_process());
|
|
|
|
|
|
|
|
// Make sure the render thread was actually started.
|
|
|
|
if (!render_task_runner_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
|
|
|
RunSingleProcessCleanupOnUIThread();
|
|
|
|
} else {
|
|
|
|
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefContentRendererClient::RunSingleProcessCleanupOnUIThread,
|
|
|
|
base::Unretained(this)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for the render thread cleanup to complete. Spin instead of using
|
|
|
|
// base::WaitableEvent because calling Wait() is not allowed on the UI
|
|
|
|
// thread.
|
|
|
|
bool complete = false;
|
|
|
|
do {
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(single_process_cleanup_lock_);
|
|
|
|
complete = single_process_cleanup_complete_;
|
|
|
|
}
|
|
|
|
if (!complete)
|
|
|
|
base::PlatformThread::YieldCurrentThread();
|
|
|
|
} while (!complete);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefContentRendererClient::RenderThreadStarted() {
|
2013-01-03 18:24:24 +01:00
|
|
|
render_task_runner_ = base::MessageLoopProxy::current();
|
2012-04-03 03:34:16 +02:00
|
|
|
observer_.reset(new CefRenderProcessObserver());
|
|
|
|
|
|
|
|
content::RenderThread* thread = content::RenderThread::Get();
|
|
|
|
thread->AddObserver(observer_.get());
|
2012-11-02 19:16:28 +01:00
|
|
|
thread->GetChannel()->AddFilter(new CefRenderMessageFilter);
|
2013-04-04 20:10:17 +02:00
|
|
|
thread->RegisterExtension(extensions_v8::LoadTimesExtension::Get());
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-02-02 01:21:59 +01:00
|
|
|
if (content::RenderProcessHost::run_renderer_in_process()) {
|
|
|
|
// When running in single-process mode register as a destruction observer
|
|
|
|
// on the render thread's MessageLoop.
|
2013-04-16 00:16:01 +02:00
|
|
|
base::MessageLoop::current()->AddDestructionObserver(this);
|
2013-02-02 01:21:59 +01:00
|
|
|
}
|
|
|
|
|
2012-12-31 11:41:15 +01:00
|
|
|
// Note that under Linux, the media library will normally already have
|
|
|
|
// been initialized by the Zygote before this instance became a Renderer.
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath media_path;
|
2014-01-14 18:37:02 +01:00
|
|
|
PathService::Get(content::DIR_MEDIA_LIBS, &media_path);
|
2012-12-31 11:41:15 +01:00
|
|
|
if (!media_path.empty())
|
|
|
|
media::InitializeMediaLibrary(media_path);
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebPrerenderingSupport::initialize(new CefPrerenderingSupport());
|
2012-05-29 19:18:33 +02:00
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
// Retrieve the new render thread information synchronously.
|
|
|
|
CefProcessHostMsg_GetNewRenderThreadInfo_Params params;
|
|
|
|
thread->Send(new CefProcessHostMsg_GetNewRenderThreadInfo(¶ms));
|
|
|
|
|
2012-12-31 11:41:15 +01:00
|
|
|
// Cross-origin entries need to be added after WebKit is initialized.
|
|
|
|
cross_origin_whitelist_entries_ = params.cross_origin_whitelist_entries;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Notify the render process handler.
|
|
|
|
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
|
|
|
if (application.get()) {
|
|
|
|
CefRefPtr<CefRenderProcessHandler> handler =
|
|
|
|
application->GetRenderProcessHandler();
|
2012-11-20 21:08:36 +01:00
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefListValueImpl> listValuePtr(
|
|
|
|
new CefListValueImpl(¶ms.extra_info, false, true));
|
|
|
|
handler->OnRenderThreadCreated(listValuePtr.get());
|
|
|
|
listValuePtr->Detach(NULL);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-02 23:41:11 +01:00
|
|
|
void CefContentRendererClient::RenderFrameCreated(
|
|
|
|
content::RenderFrame* render_frame) {
|
2014-04-04 18:50:38 +02:00
|
|
|
new CefRenderFrameObserver(render_frame);
|
2014-01-02 23:41:11 +01:00
|
|
|
BrowserCreated(render_frame->GetRenderView(), render_frame);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefContentRendererClient::RenderViewCreated(
|
|
|
|
content::RenderView* render_view) {
|
2014-01-02 23:41:11 +01:00
|
|
|
BrowserCreated(render_view, render_view->GetMainRenderFrame());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-11-21 21:59:28 +01:00
|
|
|
bool CefContentRendererClient::HandleNavigation(
|
2014-02-05 21:35:45 +01:00
|
|
|
content::RenderFrame* render_frame,
|
2013-12-17 23:04:35 +01:00
|
|
|
content::DocumentState* document_state,
|
|
|
|
int opener_id,
|
2013-11-21 21:59:28 +01:00
|
|
|
blink::WebFrame* frame,
|
|
|
|
const blink::WebURLRequest& request,
|
|
|
|
blink::WebNavigationType type,
|
|
|
|
blink::WebNavigationPolicy default_policy,
|
|
|
|
bool is_redirect) {
|
|
|
|
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
|
|
|
if (application.get()) {
|
|
|
|
CefRefPtr<CefRenderProcessHandler> handler =
|
|
|
|
application->GetRenderProcessHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefBrowserImpl> browserPtr =
|
|
|
|
CefBrowserImpl::GetBrowserForMainFrame(frame->top());
|
|
|
|
DCHECK(browserPtr.get());
|
|
|
|
if (browserPtr.get()) {
|
|
|
|
CefRefPtr<CefFrameImpl> framePtr = browserPtr->GetWebFrameImpl(frame);
|
|
|
|
CefRefPtr<CefRequest> requestPtr(CefRequest::Create());
|
|
|
|
CefRequestImpl* requestImpl =
|
|
|
|
static_cast<CefRequestImpl*>(requestPtr.get());
|
|
|
|
requestImpl->Set(request);
|
|
|
|
requestImpl->SetReadOnly(true);
|
|
|
|
|
|
|
|
cef_navigation_type_t navigation_type = NAVIGATION_OTHER;
|
|
|
|
switch (type) {
|
|
|
|
case blink::WebNavigationTypeLinkClicked:
|
|
|
|
navigation_type = NAVIGATION_LINK_CLICKED;
|
|
|
|
break;
|
|
|
|
case blink::WebNavigationTypeFormSubmitted:
|
|
|
|
navigation_type = NAVIGATION_FORM_SUBMITTED;
|
|
|
|
break;
|
|
|
|
case blink::WebNavigationTypeBackForward:
|
|
|
|
navigation_type = NAVIGATION_BACK_FORWARD;
|
|
|
|
break;
|
|
|
|
case blink::WebNavigationTypeReload:
|
|
|
|
navigation_type = NAVIGATION_RELOAD;
|
|
|
|
break;
|
|
|
|
case blink::WebNavigationTypeFormResubmitted:
|
|
|
|
navigation_type = NAVIGATION_FORM_RESUBMITTED;
|
|
|
|
break;
|
|
|
|
case blink::WebNavigationTypeOther:
|
|
|
|
navigation_type = NAVIGATION_OTHER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handler->OnBeforeNavigation(browserPtr.get(), framePtr.get(),
|
|
|
|
requestPtr.get(), navigation_type,
|
|
|
|
is_redirect)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefContentRendererClient::DidCreateScriptContext(
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebFrame* frame, v8::Handle<v8::Context> context,
|
2012-04-03 03:34:16 +02:00
|
|
|
int extension_group, int world_id) {
|
|
|
|
CefRefPtr<CefBrowserImpl> browserPtr =
|
|
|
|
CefBrowserImpl::GetBrowserForMainFrame(frame->top());
|
|
|
|
DCHECK(browserPtr.get());
|
|
|
|
if (!browserPtr.get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CefRefPtr<CefFrameImpl> framePtr = browserPtr->GetWebFrameImpl(frame);
|
|
|
|
|
2014-02-19 17:27:54 +01:00
|
|
|
v8::Isolate* isolate = blink::mainThreadIsolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2012-04-03 03:34:16 +02:00
|
|
|
v8::Context::Scope scope(context);
|
2012-09-04 17:18:04 +02:00
|
|
|
WebCore::V8RecursionScope recursion_scope(
|
2014-04-30 19:14:40 +02:00
|
|
|
isolate,
|
2013-10-17 01:09:07 +02:00
|
|
|
WebCore::toExecutionContext(context));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8Context> contextPtr(new CefV8ContextImpl(isolate, context));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
// Notify the render process handler.
|
|
|
|
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
|
|
|
if (application.get()) {
|
|
|
|
CefRefPtr<CefRenderProcessHandler> handler =
|
|
|
|
application->GetRenderProcessHandler();
|
|
|
|
if (handler.get())
|
|
|
|
handler->OnContextCreated(browserPtr.get(), framePtr.get(), contextPtr);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefContentRendererClient::WillReleaseScriptContext(
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebFrame* frame, v8::Handle<v8::Context> context, int world_id) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Notify the render process handler.
|
|
|
|
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
2012-10-29 22:50:46 +01:00
|
|
|
if (application.get()) {
|
|
|
|
CefRefPtr<CefRenderProcessHandler> handler =
|
|
|
|
application->GetRenderProcessHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefBrowserImpl> browserPtr =
|
|
|
|
CefBrowserImpl::GetBrowserForMainFrame(frame->top());
|
|
|
|
DCHECK(browserPtr.get());
|
|
|
|
if (browserPtr.get()) {
|
|
|
|
CefRefPtr<CefFrameImpl> framePtr = browserPtr->GetWebFrameImpl(frame);
|
|
|
|
|
2014-02-19 17:27:54 +01:00
|
|
|
v8::Isolate* isolate = blink::mainThreadIsolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2012-10-29 22:50:46 +01:00
|
|
|
v8::Context::Scope scope(context);
|
|
|
|
WebCore::V8RecursionScope recursion_scope(
|
2014-04-30 19:14:40 +02:00
|
|
|
isolate,
|
2013-10-17 01:09:07 +02:00
|
|
|
WebCore::toExecutionContext(context));
|
2012-10-29 22:50:46 +01:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8Context> contextPtr(
|
|
|
|
new CefV8ContextImpl(isolate, context));
|
2012-10-29 22:50:46 +01:00
|
|
|
|
|
|
|
handler->OnContextReleased(browserPtr.get(), framePtr.get(),
|
|
|
|
contextPtr);
|
|
|
|
}
|
|
|
|
}
|
2012-10-29 22:46:02 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-10-29 22:46:02 +01:00
|
|
|
CefV8ReleaseContext(context);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2013-02-02 01:21:59 +01:00
|
|
|
|
|
|
|
void CefContentRendererClient::WillDestroyCurrentMessageLoop() {
|
|
|
|
base::AutoLock lock_scope(single_process_cleanup_lock_);
|
|
|
|
single_process_cleanup_complete_ = true;
|
|
|
|
}
|
|
|
|
|
2014-01-02 23:41:11 +01:00
|
|
|
void CefContentRendererClient::BrowserCreated(
|
|
|
|
content::RenderView* render_view,
|
|
|
|
content::RenderFrame* render_frame) {
|
|
|
|
// Retrieve the browser information synchronously. This will also register
|
|
|
|
// the routing ids with the browser info object in the browser process.
|
|
|
|
CefProcessHostMsg_GetNewBrowserInfo_Params params;
|
|
|
|
content::RenderThread::Get()->Send(
|
|
|
|
new CefProcessHostMsg_GetNewBrowserInfo(
|
|
|
|
render_view->GetRoutingID(),
|
|
|
|
render_frame->GetRoutingID(),
|
|
|
|
¶ms));
|
|
|
|
DCHECK_GT(params.browser_id, 0);
|
|
|
|
|
|
|
|
// Don't create another browser object if one already exists for the view.
|
|
|
|
if (GetBrowserForView(render_view))
|
|
|
|
return;
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserImpl> browser =
|
2014-04-25 03:36:58 +02:00
|
|
|
new CefBrowserImpl(render_view, params.browser_id, params.is_popup);
|
2014-01-02 23:41:11 +01:00
|
|
|
browsers_.insert(std::make_pair(render_view, browser));
|
|
|
|
|
|
|
|
new CefPrerendererClient(render_view);
|
|
|
|
new printing::PrintWebViewHelper(render_view);
|
|
|
|
|
|
|
|
// Notify the render process handler.
|
|
|
|
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
|
|
|
if (application.get()) {
|
|
|
|
CefRefPtr<CefRenderProcessHandler> handler =
|
|
|
|
application->GetRenderProcessHandler();
|
|
|
|
if (handler.get())
|
|
|
|
handler->OnBrowserCreated(browser.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 01:21:59 +01:00
|
|
|
void CefContentRendererClient::RunSingleProcessCleanupOnUIThread() {
|
|
|
|
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
|
|
|
|
|
|
|
// Clean up the single existing RenderProcessHost.
|
|
|
|
content::RenderProcessHost* host = NULL;
|
|
|
|
content::RenderProcessHost::iterator iterator(
|
|
|
|
content::RenderProcessHost::AllHostsIterator());
|
|
|
|
if (!iterator.IsAtEnd()) {
|
|
|
|
host = iterator.GetCurrentValue();
|
|
|
|
host->Cleanup();
|
|
|
|
iterator.Advance();
|
|
|
|
DCHECK(iterator.IsAtEnd());
|
|
|
|
}
|
|
|
|
DCHECK(host);
|
|
|
|
|
|
|
|
// Clear the run_renderer_in_process() flag to avoid a DCHECK in the
|
|
|
|
// RenderProcessHost destructor.
|
|
|
|
content::RenderProcessHost::SetRunRendererInProcess(false);
|
|
|
|
|
|
|
|
// Deletion of the RenderProcessHost object will stop the render thread and
|
|
|
|
// result in a call to WillDestroyCurrentMessageLoop.
|
|
|
|
// Cleanup() will cause deletion to be posted as a task on the UI thread but
|
|
|
|
// this task will only execute when running in multi-threaded message loop
|
|
|
|
// mode (because otherwise the UI message loop has already stopped). Therefore
|
|
|
|
// we need to explicitly delete the object when not running in this mode.
|
2013-09-03 20:06:25 +02:00
|
|
|
if (!CefContext::Get()->settings().multi_threaded_message_loop)
|
2013-02-02 01:21:59 +01:00
|
|
|
delete host;
|
|
|
|
}
|