2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 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.
|
|
|
|
|
|
|
|
#include "libcef/browser/content_browser_client.h"
|
2012-09-11 00:19:19 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
#include "libcef/browser/browser_info.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
|
|
|
#include "libcef/browser/browser_main.h"
|
|
|
|
#include "libcef/browser/browser_message_filter.h"
|
|
|
|
#include "libcef/browser/browser_settings.h"
|
2012-10-08 19:47:37 +02:00
|
|
|
#include "libcef/browser/chrome_scheme_handler.h"
|
2014-04-15 21:02:30 +02:00
|
|
|
#include "libcef/browser/context.h"
|
2014-09-27 01:48:19 +02:00
|
|
|
#include "libcef/browser/devtools_delegate.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/browser/extensions/browser_extensions_util.h"
|
|
|
|
#include "libcef/browser/extensions/extension_system.h"
|
|
|
|
#include "libcef/browser/extensions/plugin_info_message_filter.h"
|
2013-03-07 02:20:24 +01:00
|
|
|
#include "libcef/browser/media_capture_devices_dispatcher.h"
|
2015-03-25 22:22:47 +01:00
|
|
|
#include "libcef/browser/pepper/browser_pepper_host_factory.h"
|
2013-10-23 21:30:47 +02:00
|
|
|
#include "libcef/browser/printing/printing_message_filter.h"
|
2012-06-25 23:21:27 +02:00
|
|
|
#include "libcef/browser/resource_dispatcher_host_delegate.h"
|
2013-03-08 01:41:26 +01:00
|
|
|
#include "libcef/browser/speech_recognition_manager_delegate.h"
|
2015-02-11 19:15:04 +01:00
|
|
|
#include "libcef/browser/ssl_info_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2012-09-28 22:14:02 +02:00
|
|
|
#include "libcef/browser/web_plugin_impl.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/common/cef_messages.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/common/cef_switches.h"
|
2012-09-27 19:07:31 +02:00
|
|
|
#include "libcef/common/command_line_impl.h"
|
2013-04-16 00:16:01 +02:00
|
|
|
#include "libcef/common/content_client.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2013-06-04 19:41:37 +02:00
|
|
|
#include "libcef/common/scheme_registration.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-11-21 23:43:36 +01:00
|
|
|
#include "base/base_switches.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/command_line.h"
|
2013-02-27 18:56:03 +01:00
|
|
|
#include "base/files/file_path.h"
|
2012-09-11 00:19:19 +02:00
|
|
|
#include "base/path_service.h"
|
2014-10-07 22:44:33 +02:00
|
|
|
#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
|
2013-02-06 21:41:54 +01:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
2012-09-28 22:14:02 +02:00
|
|
|
#include "content/browser/plugin_service_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/access_token_store.h"
|
2012-10-08 19:47:37 +02:00
|
|
|
#include "content/public/browser/browser_url_handler.h"
|
2013-06-04 19:41:37 +02:00
|
|
|
#include "content/public/browser/child_process_security_policy.h"
|
2015-05-19 19:55:58 +02:00
|
|
|
#include "content/public/browser/client_certificate_delegate.h"
|
2012-09-28 22:14:02 +02:00
|
|
|
#include "content/public/browser/plugin_service_filter.h"
|
2012-09-28 00:52:15 +02:00
|
|
|
#include "content/public/browser/quota_permission_context.h"
|
2012-04-04 20:18:09 +02:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2015-04-08 17:43:00 +02:00
|
|
|
#include "content/public/browser/render_widget_host_view.h"
|
2012-06-25 23:21:27 +02:00
|
|
|
#include "content/public/browser/resource_dispatcher_host.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
2014-04-30 19:14:40 +02:00
|
|
|
#include "content/public/common/storage_quota_params.h"
|
2014-09-04 19:53:40 +02:00
|
|
|
#include "content/public/common/web_preferences.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "extensions/browser/extension_message_filter.h"
|
|
|
|
#include "extensions/browser/extension_protocols.h"
|
|
|
|
#include "extensions/browser/extension_registry.h"
|
|
|
|
#include "extensions/browser/guest_view/extensions_guest_view_message_filter.h"
|
|
|
|
#include "extensions/browser/io_thread_extension_message_filter.h"
|
|
|
|
#include "extensions/common/constants.h"
|
2015-05-19 19:55:58 +02:00
|
|
|
#include "net/ssl/ssl_cert_request_info.h"
|
2013-08-15 21:38:55 +02:00
|
|
|
#include "third_party/WebKit/public/web/WebWindowFeatures.h"
|
2012-10-22 22:56:38 +02:00
|
|
|
#include "ui/base/ui_base_switches.h"
|
2013-07-24 22:15:18 +02:00
|
|
|
#include "url/gurl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-10-07 22:44:33 +02:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
|
|
|
|
#endif
|
|
|
|
|
2013-11-21 23:43:36 +01:00
|
|
|
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
|
|
|
#include "base/debug/leak_annotations.h"
|
2014-09-04 19:53:40 +02:00
|
|
|
#include "components/crash/app/breakpad_linux.h"
|
|
|
|
#include "components/crash/browser/crash_handler_host_linux.h"
|
2013-11-21 23:43:36 +01:00
|
|
|
#include "content/public/common/content_descriptors.h"
|
|
|
|
#endif
|
|
|
|
|
2015-06-12 01:00:09 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "sandbox/win/src/sandbox_policy.h"
|
|
|
|
#endif
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// In-memory store for access tokens used by geolocation.
|
|
|
|
class CefAccessTokenStore : public content::AccessTokenStore {
|
|
|
|
public:
|
2015-03-02 21:25:14 +01:00
|
|
|
// |system_context| is used by NetworkLocationProvider to communicate with a
|
|
|
|
// remote geolocation service.
|
|
|
|
explicit CefAccessTokenStore(net::URLRequestContextGetter* system_context)
|
|
|
|
: system_context_(system_context) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void LoadAccessTokens(
|
|
|
|
const LoadAccessTokensCallbackType& callback) override {
|
2015-03-02 21:25:14 +01:00
|
|
|
callback.Run(access_token_set_, system_context_);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void SaveAccessToken(
|
|
|
|
const GURL& server_url, const base::string16& access_token) override {
|
2012-04-03 03:34:16 +02:00
|
|
|
access_token_set_[server_url] = access_token;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-03-02 21:25:14 +01:00
|
|
|
net::URLRequestContextGetter* system_context_;
|
2012-04-03 03:34:16 +02:00
|
|
|
AccessTokenSet access_token_set_;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefAccessTokenStore);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
class CefQuotaCallbackImpl : public CefRequestCallback {
|
2012-09-28 00:52:15 +02:00
|
|
|
public:
|
|
|
|
explicit CefQuotaCallbackImpl(
|
|
|
|
const content::QuotaPermissionContext::PermissionCallback& callback)
|
|
|
|
: callback_(callback) {
|
|
|
|
}
|
2014-07-02 20:25:22 +02:00
|
|
|
|
2012-09-28 00:52:15 +02:00
|
|
|
~CefQuotaCallbackImpl() {
|
|
|
|
if (!callback_.is_null()) {
|
|
|
|
// The callback is still pending. Cancel it now.
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
2015-04-02 17:21:46 +02:00
|
|
|
RunNow(callback_, false);
|
2012-09-28 00:52:15 +02:00
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
2015-04-02 17:21:46 +02:00
|
|
|
base::Bind(&CefQuotaCallbackImpl::RunNow, callback_, false));
|
2012-09-28 00:52:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void Continue(bool allow) override {
|
2012-09-28 00:52:15 +02:00
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
|
|
|
if (!callback_.is_null()) {
|
2015-04-02 17:21:46 +02:00
|
|
|
RunNow(callback_, allow);
|
2012-09-28 00:52:15 +02:00
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(&CefQuotaCallbackImpl::Continue, this, allow));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void Cancel() override {
|
2015-04-02 17:21:46 +02:00
|
|
|
Continue(false);
|
2012-09-28 00:52:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Disconnect() {
|
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-04-02 17:21:46 +02:00
|
|
|
static void RunNow(
|
|
|
|
const content::QuotaPermissionContext::PermissionCallback& callback,
|
|
|
|
bool allow) {
|
2012-09-28 00:52:15 +02:00
|
|
|
CEF_REQUIRE_IOT();
|
2015-04-02 17:21:46 +02:00
|
|
|
callback.Run(allow ?
|
|
|
|
content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW :
|
|
|
|
content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_DISALLOW);
|
2012-09-28 00:52:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
content::QuotaPermissionContext::PermissionCallback callback_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefQuotaCallbackImpl);
|
2014-07-01 00:30:29 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefQuotaCallbackImpl);
|
2012-09-28 00:52:15 +02:00
|
|
|
};
|
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
class CefAllowCertificateErrorCallbackImpl : public CefRequestCallback {
|
2013-04-04 19:50:35 +02:00
|
|
|
public:
|
2014-07-02 20:25:22 +02:00
|
|
|
typedef base::Callback<void(bool)> // NOLINT(readability/function)
|
|
|
|
CallbackType;
|
|
|
|
|
|
|
|
explicit CefAllowCertificateErrorCallbackImpl(const CallbackType& callback)
|
|
|
|
: callback_(callback) {
|
2013-04-04 19:50:35 +02:00
|
|
|
}
|
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
~CefAllowCertificateErrorCallbackImpl() {
|
|
|
|
if (!callback_.is_null()) {
|
|
|
|
// The callback is still pending. Cancel it now.
|
|
|
|
if (CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
RunNow(callback_, false);
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
|
|
|
base::Bind(&CefAllowCertificateErrorCallbackImpl::RunNow,
|
|
|
|
callback_, false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void Continue(bool allow) override {
|
2013-04-04 19:50:35 +02:00
|
|
|
if (CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
if (!callback_.is_null()) {
|
2015-04-02 17:21:46 +02:00
|
|
|
RunNow(callback_, allow);
|
2013-04-04 19:50:35 +02:00
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
|
|
|
base::Bind(&CefAllowCertificateErrorCallbackImpl::Continue,
|
2015-04-02 17:21:46 +02:00
|
|
|
this, allow));
|
2013-04-04 19:50:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
void Cancel() override {
|
|
|
|
Continue(false);
|
|
|
|
}
|
|
|
|
|
2013-04-04 19:50:35 +02:00
|
|
|
void Disconnect() {
|
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-04-02 17:21:46 +02:00
|
|
|
static void RunNow(const CallbackType& callback, bool allow) {
|
2015-05-07 16:37:50 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2015-04-02 17:21:46 +02:00
|
|
|
callback.Run(allow);
|
|
|
|
}
|
|
|
|
|
2014-07-02 20:25:22 +02:00
|
|
|
CallbackType callback_;
|
2013-04-04 19:50:35 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefAllowCertificateErrorCallbackImpl);
|
2014-07-01 00:30:29 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefAllowCertificateErrorCallbackImpl);
|
2013-04-04 19:50:35 +02:00
|
|
|
};
|
|
|
|
|
2012-09-28 00:52:15 +02:00
|
|
|
class CefQuotaPermissionContext : public content::QuotaPermissionContext {
|
|
|
|
public:
|
|
|
|
CefQuotaPermissionContext() {
|
|
|
|
}
|
|
|
|
|
|
|
|
// The callback will be dispatched on the IO thread.
|
2014-11-12 20:25:15 +01:00
|
|
|
void RequestQuotaPermission(
|
2014-04-30 19:14:40 +02:00
|
|
|
const content::StorageQuotaParams& params,
|
2012-09-28 00:52:15 +02:00
|
|
|
int render_process_id,
|
2014-11-12 20:25:15 +01:00
|
|
|
const PermissionCallback& callback) override {
|
2014-09-04 19:53:40 +02:00
|
|
|
if (params.storage_type != storage::kStorageTypePersistent) {
|
2012-09-28 00:52:15 +02:00
|
|
|
// To match Chrome behavior we only support requesting quota with this
|
|
|
|
// interface for Persistent storage type.
|
|
|
|
callback.Run(QUOTA_PERMISSION_RESPONSE_DISALLOW);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool handled = false;
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
2014-01-02 23:41:11 +01:00
|
|
|
CefBrowserHostImpl::GetBrowserForView(render_process_id,
|
2014-04-30 19:14:40 +02:00
|
|
|
params.render_view_id);
|
2012-09-28 00:52:15 +02:00
|
|
|
if (browser.get()) {
|
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefQuotaCallbackImpl> callbackImpl(
|
|
|
|
new CefQuotaCallbackImpl(callback));
|
2014-04-30 19:14:40 +02:00
|
|
|
handled = handler->OnQuotaRequest(browser.get(),
|
|
|
|
params.origin_url.spec(),
|
|
|
|
params.requested_size,
|
|
|
|
callbackImpl.get());
|
2012-09-28 00:52:15 +02:00
|
|
|
if (!handled)
|
|
|
|
callbackImpl->Disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handled) {
|
|
|
|
// Disallow the request by default.
|
|
|
|
callback.Run(QUOTA_PERMISSION_RESPONSE_DISALLOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefQuotaPermissionContext() override {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefQuotaPermissionContext);
|
2012-09-28 00:52:15 +02:00
|
|
|
};
|
|
|
|
|
2012-09-28 22:14:02 +02:00
|
|
|
class CefPluginServiceFilter : public content::PluginServiceFilter {
|
|
|
|
public:
|
|
|
|
CefPluginServiceFilter() {}
|
2014-11-12 20:25:15 +01:00
|
|
|
|
|
|
|
bool IsPluginAvailable(int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
const void* context,
|
|
|
|
const GURL& url,
|
|
|
|
const GURL& policy_url,
|
|
|
|
content::WebPluginInfo* plugin) override {
|
2012-09-28 22:14:02 +02:00
|
|
|
bool allowed = true;
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
2014-06-12 22:42:53 +02:00
|
|
|
CefBrowserHostImpl::GetBrowserForFrame(render_process_id,
|
|
|
|
render_frame_id);
|
2012-09-28 22:14:02 +02:00
|
|
|
if (browser.get()) {
|
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefWebPluginInfoImpl> pluginInfo(
|
|
|
|
new CefWebPluginInfoImpl(*plugin));
|
|
|
|
allowed =
|
|
|
|
!handler->OnBeforePluginLoad(browser.get(),
|
|
|
|
url.possibly_invalid_spec(),
|
|
|
|
policy_url.possibly_invalid_spec(),
|
|
|
|
pluginInfo.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return allowed;
|
|
|
|
}
|
2013-02-23 01:43:28 +01:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool CanLoadPlugin(int render_process_id,
|
|
|
|
const base::FilePath& path) override {
|
2013-02-23 01:43:28 +01:00
|
|
|
return true;
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefPluginServiceFilter);
|
2012-09-28 22:14:02 +02:00
|
|
|
};
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
void TranslatePopupFeatures(const blink::WebWindowFeatures& webKitFeatures,
|
2013-08-15 21:38:55 +02:00
|
|
|
CefPopupFeatures& features) {
|
|
|
|
features.x = static_cast<int>(webKitFeatures.x);
|
|
|
|
features.xSet = webKitFeatures.xSet;
|
|
|
|
features.y = static_cast<int>(webKitFeatures.y);
|
|
|
|
features.ySet = webKitFeatures.ySet;
|
|
|
|
features.width = static_cast<int>(webKitFeatures.width);
|
|
|
|
features.widthSet = webKitFeatures.widthSet;
|
|
|
|
features.height = static_cast<int>(webKitFeatures.height);
|
|
|
|
features.heightSet = webKitFeatures.heightSet;
|
|
|
|
|
|
|
|
features.menuBarVisible = webKitFeatures.menuBarVisible;
|
|
|
|
features.statusBarVisible = webKitFeatures.statusBarVisible;
|
|
|
|
features.toolBarVisible = webKitFeatures.toolBarVisible;
|
|
|
|
features.locationBarVisible = webKitFeatures.locationBarVisible;
|
|
|
|
features.scrollbarsVisible = webKitFeatures.scrollbarsVisible;
|
|
|
|
features.resizable = webKitFeatures.resizable;
|
|
|
|
|
|
|
|
features.fullscreen = webKitFeatures.fullscreen;
|
|
|
|
features.dialog = webKitFeatures.dialog;
|
|
|
|
features.additionalFeatures = NULL;
|
|
|
|
if (webKitFeatures.additionalFeatures.size() > 0)
|
|
|
|
features.additionalFeatures = cef_string_list_alloc();
|
|
|
|
|
|
|
|
CefString str;
|
|
|
|
for (unsigned int i = 0; i < webKitFeatures.additionalFeatures.size(); ++i) {
|
2013-12-17 23:04:35 +01:00
|
|
|
str = base::string16(webKitFeatures.additionalFeatures[i]);
|
2013-08-15 21:38:55 +02:00
|
|
|
cef_string_list_append(features.additionalFeatures, str.GetStruct());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 23:43:36 +01:00
|
|
|
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
|
|
|
breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
|
|
|
|
const std::string& process_type) {
|
|
|
|
base::FilePath dumps_path =
|
2014-10-07 22:44:33 +02:00
|
|
|
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
|
2013-11-21 23:43:36 +01:00
|
|
|
switches::kCrashDumpsDir);
|
|
|
|
{
|
|
|
|
ANNOTATE_SCOPED_MEMORY_LEAK;
|
|
|
|
breakpad::CrashHandlerHostLinux* crash_handler =
|
|
|
|
new breakpad::CrashHandlerHostLinux(
|
|
|
|
process_type, dumps_path, false);
|
|
|
|
crash_handler->StartUploaderThread();
|
|
|
|
return crash_handler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 22:44:33 +02:00
|
|
|
int GetCrashSignalFD(const base::CommandLine& command_line) {
|
2013-11-21 23:43:36 +01:00
|
|
|
if (!breakpad::IsCrashReporterEnabled())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
std::string process_type =
|
|
|
|
command_line.GetSwitchValueASCII(switches::kProcessType);
|
|
|
|
|
|
|
|
if (process_type == switches::kRendererProcess) {
|
|
|
|
static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
|
|
|
|
if (!crash_handler)
|
|
|
|
crash_handler = CreateCrashHandlerHost(process_type);
|
|
|
|
return crash_handler->GetDeathSignalSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process_type == switches::kPluginProcess) {
|
|
|
|
static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
|
|
|
|
if (!crash_handler)
|
|
|
|
crash_handler = CreateCrashHandlerHost(process_type);
|
|
|
|
return crash_handler->GetDeathSignalSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process_type == switches::kPpapiPluginProcess) {
|
|
|
|
static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
|
|
|
|
if (!crash_handler)
|
|
|
|
crash_handler = CreateCrashHandlerHost(process_type);
|
|
|
|
return crash_handler->GetDeathSignalSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process_type == switches::kGpuProcess) {
|
|
|
|
static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
|
|
|
|
if (!crash_handler)
|
|
|
|
crash_handler = CreateCrashHandlerHost(process_type);
|
|
|
|
return crash_handler->GetDeathSignalSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
CefContentBrowserClient::CefContentBrowserClient()
|
2012-12-30 12:17:49 +01:00
|
|
|
: browser_main_parts_(NULL),
|
2014-04-25 03:36:58 +02:00
|
|
|
next_browser_id_(0) {
|
2012-09-28 22:14:02 +02:00
|
|
|
plugin_service_filter_.reset(new CefPluginServiceFilter);
|
2012-11-05 21:18:20 +01:00
|
|
|
content::PluginServiceImpl::GetInstance()->SetFilter(
|
|
|
|
plugin_service_filter_.get());
|
2013-02-08 01:07:41 +01:00
|
|
|
|
2013-02-09 23:38:24 +01:00
|
|
|
last_create_window_params_.opener_process_id = MSG_ROUTING_NONE;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefContentBrowserClient::~CefContentBrowserClient() {
|
|
|
|
}
|
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
// static
|
|
|
|
CefContentBrowserClient* CefContentBrowserClient::Get() {
|
|
|
|
return static_cast<CefContentBrowserClient*>(
|
2013-04-16 00:16:01 +02:00
|
|
|
CefContentClient::Get()->browser());
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
scoped_refptr<CefBrowserInfo> CefContentBrowserClient::CreateBrowserInfo(
|
|
|
|
bool is_popup) {
|
2012-12-30 12:17:49 +01:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info =
|
2013-11-08 17:06:06 +01:00
|
|
|
new CefBrowserInfo(++next_browser_id_, is_popup);
|
2012-12-30 12:17:49 +01:00
|
|
|
browser_info_list_.push_back(browser_info);
|
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo>
|
2014-01-02 23:41:11 +01:00
|
|
|
CefContentBrowserClient::GetOrCreateBrowserInfo(
|
|
|
|
int render_view_process_id,
|
|
|
|
int render_view_routing_id,
|
|
|
|
int render_frame_process_id,
|
|
|
|
int render_frame_routing_id) {
|
2012-12-30 12:17:49 +01:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
|
|
|
BrowserInfoList::const_iterator it = browser_info_list_.begin();
|
|
|
|
for (; it != browser_info_list_.end(); ++it) {
|
|
|
|
const scoped_refptr<CefBrowserInfo>& browser_info = *it;
|
2014-01-02 23:41:11 +01:00
|
|
|
if (browser_info->is_render_view_id_match(render_view_process_id,
|
|
|
|
render_view_routing_id)) {
|
|
|
|
// Make sure the frame id is also registered.
|
|
|
|
browser_info->add_render_frame_id(render_frame_process_id,
|
|
|
|
render_frame_routing_id);
|
2012-12-30 12:17:49 +01:00
|
|
|
return browser_info;
|
2014-01-02 23:41:11 +01:00
|
|
|
} else if (browser_info->is_render_frame_id_match(
|
|
|
|
render_frame_process_id,
|
|
|
|
render_frame_routing_id)) {
|
|
|
|
// Make sure the view id is also registered.
|
|
|
|
browser_info->add_render_view_id(render_view_process_id,
|
|
|
|
render_view_routing_id);
|
|
|
|
return browser_info;
|
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Must be a popup if it hasn't already been created.
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info =
|
|
|
|
new CefBrowserInfo(++next_browser_id_, true);
|
2014-01-02 23:41:11 +01:00
|
|
|
browser_info->add_render_view_id(render_view_process_id,
|
|
|
|
render_view_routing_id);
|
|
|
|
browser_info->add_render_frame_id(render_frame_process_id,
|
|
|
|
render_frame_routing_id);
|
2012-12-30 12:17:49 +01:00
|
|
|
browser_info_list_.push_back(browser_info);
|
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefContentBrowserClient::RemoveBrowserInfo(
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info) {
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
|
|
|
BrowserInfoList::iterator it = browser_info_list_.begin();
|
|
|
|
for (; it != browser_info_list_.end(); ++it) {
|
|
|
|
if (*it == browser_info) {
|
|
|
|
browser_info_list_.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefContentBrowserClient::DestroyAllBrowsers() {
|
|
|
|
BrowserInfoList list;
|
|
|
|
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
list = browser_info_list_;
|
|
|
|
}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
// Destroy any remaining browser windows.
|
|
|
|
if (!list.empty()) {
|
|
|
|
BrowserInfoList::iterator it = list.begin();
|
|
|
|
for (; it != list.end(); ++it) {
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser = (*it)->browser();
|
2013-01-04 13:36:39 +01:00
|
|
|
if (browser.get()) {
|
|
|
|
// DestroyBrowser will call RemoveBrowserInfo.
|
2012-12-30 12:17:49 +01:00
|
|
|
browser->DestroyBrowser();
|
2013-01-04 13:36:39 +01:00
|
|
|
} else {
|
|
|
|
// Canceled popup windows may have browser info but no browser because
|
|
|
|
// CefBrowserMessageFilter::OnGetNewBrowserInfo is still called.
|
|
|
|
DCHECK((*it)->is_popup());
|
|
|
|
RemoveBrowserInfo(*it);
|
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
{
|
|
|
|
// Verify that all browser windows have been destroyed.
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
DCHECK(browser_info_list_.empty());
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
|
2014-01-02 23:41:11 +01:00
|
|
|
scoped_refptr<CefBrowserInfo> CefContentBrowserClient::GetBrowserInfoForView(
|
|
|
|
int render_process_id, int render_routing_id) {
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
|
|
|
BrowserInfoList::const_iterator it = browser_info_list_.begin();
|
|
|
|
for (; it != browser_info_list_.end(); ++it) {
|
|
|
|
const scoped_refptr<CefBrowserInfo>& browser_info = *it;
|
|
|
|
if (browser_info->is_render_view_id_match(
|
|
|
|
render_process_id, render_routing_id)) {
|
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(WARNING) << "No browser info matching view process id " <<
|
|
|
|
render_process_id << " and routing id " << render_routing_id;
|
|
|
|
|
|
|
|
return scoped_refptr<CefBrowserInfo>();
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo> CefContentBrowserClient::GetBrowserInfoForFrame(
|
|
|
|
int render_process_id, int render_routing_id) {
|
2012-12-30 12:17:49 +01:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
|
|
|
BrowserInfoList::const_iterator it = browser_info_list_.begin();
|
|
|
|
for (; it != browser_info_list_.end(); ++it) {
|
|
|
|
const scoped_refptr<CefBrowserInfo>& browser_info = *it;
|
2014-01-02 23:41:11 +01:00
|
|
|
if (browser_info->is_render_frame_id_match(
|
|
|
|
render_process_id, render_routing_id)) {
|
2012-12-30 12:17:49 +01:00
|
|
|
return browser_info;
|
2014-01-02 23:41:11 +01:00
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
|
|
|
|
2014-01-02 23:41:11 +01:00
|
|
|
LOG(WARNING) << "No browser info matching frame process id " <<
|
|
|
|
render_process_id << " and routing id " << render_routing_id;
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
return scoped_refptr<CefBrowserInfo>();
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
content::BrowserMainParts* CefContentBrowserClient::CreateBrowserMainParts(
|
|
|
|
const content::MainFunctionParams& parameters) {
|
2012-04-11 20:00:55 +02:00
|
|
|
browser_main_parts_ = new CefBrowserMainParts(parameters);
|
|
|
|
return browser_main_parts_;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-01-02 23:41:11 +01:00
|
|
|
void CefContentBrowserClient::RenderProcessWillLaunch(
|
2012-04-03 03:34:16 +02:00
|
|
|
content::RenderProcessHost* host) {
|
2014-10-07 22:44:33 +02:00
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
const int id = host->GetID();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
host->GetChannel()->AddFilter(new CefBrowserMessageFilter(host));
|
2014-10-07 22:44:33 +02:00
|
|
|
host->AddFilter(new printing::PrintingMessageFilter(id));
|
|
|
|
|
|
|
|
if (!command_line->HasSwitch(switches::kDisableSpellChecking)) {
|
|
|
|
host->AddFilter(new SpellCheckMessageFilter(id));
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
host->AddFilter(new SpellCheckMessageFilterMac(id));
|
|
|
|
#endif
|
|
|
|
}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
content::BrowserContext* browser_context = host->GetBrowserContext();
|
|
|
|
|
|
|
|
if (extensions::ExtensionsEnabled()) {
|
|
|
|
host->AddFilter(
|
|
|
|
new extensions::CefPluginInfoMessageFilter(id, browser_context));
|
|
|
|
host->AddFilter(
|
|
|
|
new extensions::ExtensionMessageFilter(id, browser_context));
|
|
|
|
host->AddFilter(
|
|
|
|
new extensions::IOThreadExtensionMessageFilter(id, browser_context));
|
|
|
|
host->AddFilter(
|
|
|
|
new extensions::ExtensionsGuestViewMessageFilter(id, browser_context));
|
|
|
|
}
|
|
|
|
|
|
|
|
host->Send(new CefProcessMsg_SetIsIncognitoProcess(
|
|
|
|
browser_context->IsOffTheRecord()));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefContentBrowserClient::ShouldUseProcessPerSite(
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& effective_url) {
|
|
|
|
if (!extensions::ExtensionsEnabled())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!effective_url.SchemeIs(extensions::kExtensionScheme))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
extensions::ExtensionRegistry* registry =
|
|
|
|
extensions::ExtensionRegistry::Get(browser_context);
|
|
|
|
if (!registry)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const extensions::Extension* extension =
|
|
|
|
registry->enabled_extensions().GetByID(effective_url.host());
|
|
|
|
if (!extension)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// TODO(extensions): Extra checks required if type is TYPE_HOSTED_APP.
|
|
|
|
|
|
|
|
// Hosted apps that have script access to their background page must use
|
|
|
|
// process per site, since all instances can make synchronous calls to the
|
|
|
|
// background window. Other extensions should use process per site as well.
|
|
|
|
return true;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
net::URLRequestContextGetter* CefContentBrowserClient::CreateRequestContext(
|
|
|
|
content::BrowserContext* content_browser_context,
|
2014-04-04 18:50:38 +02:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-06-12 22:28:58 +02:00
|
|
|
content::URLRequestInterceptorScopedVector request_interceptors) {
|
2015-02-14 00:17:08 +01:00
|
|
|
scoped_refptr<CefBrowserContext> context =
|
2013-09-03 18:43:31 +02:00
|
|
|
static_cast<CefBrowserContext*>(content_browser_context);
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
if (extensions::ExtensionsEnabled()) {
|
|
|
|
// Handle only chrome-extension:// requests. CEF does not support
|
|
|
|
// chrome-extension-resource:// requests (it does not store shared extension
|
|
|
|
// data in its installation directory).
|
|
|
|
extensions::InfoMap* extension_info_map =
|
|
|
|
context->extension_system()->info_map();
|
|
|
|
(*protocol_handlers)[extensions::kExtensionScheme] =
|
|
|
|
linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
|
|
|
|
extensions::CreateExtensionProtocolHandler(
|
|
|
|
context->IsOffTheRecord(), extension_info_map));
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
return context->CreateRequestContext(
|
2014-04-04 18:50:38 +02:00
|
|
|
protocol_handlers,
|
2014-06-12 22:28:58 +02:00
|
|
|
request_interceptors.Pass());
|
2013-02-23 01:43:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
net::URLRequestContextGetter*
|
|
|
|
CefContentBrowserClient::CreateRequestContextForStoragePartition(
|
|
|
|
content::BrowserContext* content_browser_context,
|
|
|
|
const base::FilePath& partition_path,
|
|
|
|
bool in_memory,
|
2014-04-04 18:50:38 +02:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-06-12 22:28:58 +02:00
|
|
|
content::URLRequestInterceptorScopedVector request_interceptors) {
|
2015-02-14 00:17:08 +01:00
|
|
|
scoped_refptr<CefBrowserContext> context =
|
2013-09-03 18:43:31 +02:00
|
|
|
static_cast<CefBrowserContext*>(content_browser_context);
|
2015-02-14 00:17:08 +01:00
|
|
|
return context->CreateRequestContextForStoragePartition(
|
2014-04-04 18:50:38 +02:00
|
|
|
partition_path,
|
|
|
|
in_memory,
|
|
|
|
protocol_handlers,
|
2014-06-12 22:28:58 +02:00
|
|
|
request_interceptors.Pass());
|
2013-02-23 01:43:28 +01:00
|
|
|
}
|
|
|
|
|
2013-06-04 19:41:37 +02:00
|
|
|
bool CefContentBrowserClient::IsHandledURL(const GURL& url) {
|
|
|
|
if (!url.is_valid())
|
|
|
|
return false;
|
|
|
|
const std::string& scheme = url.scheme();
|
2014-09-04 19:53:40 +02:00
|
|
|
DCHECK_EQ(scheme, base::StringToLowerASCII(scheme));
|
2013-06-04 19:41:37 +02:00
|
|
|
|
|
|
|
if (scheme::IsInternalHandledScheme(scheme))
|
|
|
|
return true;
|
|
|
|
|
2013-06-05 01:37:26 +02:00
|
|
|
return CefContentClient::Get()->HasCustomScheme(scheme);
|
2013-06-04 19:41:37 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefContentBrowserClient::AppendExtraCommandLineSwitches(
|
2014-10-07 22:44:33 +02:00
|
|
|
base::CommandLine* command_line, int child_process_id) {
|
2015-01-09 18:22:10 +01:00
|
|
|
const base::CommandLine* browser_cmd =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
2012-09-10 18:13:51 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
// Propagate the following switches to all command lines (along with any
|
|
|
|
// associated values) if present in the browser command line.
|
|
|
|
static const char* const kSwitchNames[] = {
|
2014-01-10 20:49:43 +01:00
|
|
|
#if !defined(OS_WIN)
|
|
|
|
switches::kCrashDumpsDir,
|
|
|
|
#endif
|
|
|
|
switches::kDisablePackLoading,
|
|
|
|
switches::kEnableCrashReporter,
|
2012-10-25 23:19:20 +02:00
|
|
|
switches::kLang,
|
|
|
|
switches::kLocalesDirPath,
|
2012-09-10 18:13:51 +02:00
|
|
|
switches::kLogFile,
|
|
|
|
switches::kLogSeverity,
|
2014-01-10 20:49:43 +01:00
|
|
|
switches::kProductVersion,
|
2014-10-28 00:12:21 +01:00
|
|
|
switches::kResourcesDirPath,
|
|
|
|
switches::kUserAgent,
|
2012-09-10 18:13:51 +02:00
|
|
|
};
|
2015-01-09 18:22:10 +01:00
|
|
|
command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames,
|
2012-09-10 18:13:51 +02:00
|
|
|
arraysize(kSwitchNames));
|
|
|
|
}
|
|
|
|
|
2013-06-10 20:48:09 +02:00
|
|
|
const std::string& process_type =
|
2012-04-03 03:34:16 +02:00
|
|
|
command_line->GetSwitchValueASCII(switches::kProcessType);
|
|
|
|
if (process_type == switches::kRendererProcess) {
|
2012-09-10 18:13:51 +02:00
|
|
|
// Propagate the following switches to the renderer command line (along with
|
|
|
|
// any associated values) if present in the browser command line.
|
|
|
|
static const char* const kSwitchNames[] = {
|
2012-10-29 22:46:02 +01:00
|
|
|
switches::kContextSafetyImplementation,
|
2015-07-16 23:40:01 +02:00
|
|
|
switches::kDisableExtensions,
|
|
|
|
switches::kDisablePdfExtension,
|
2015-04-08 15:16:17 +02:00
|
|
|
switches::kDisableScrollBounce,
|
2014-10-07 22:44:33 +02:00
|
|
|
switches::kDisableSpellChecking,
|
2013-03-08 01:41:26 +01:00
|
|
|
switches::kEnableSpeechInput,
|
2014-10-07 22:44:33 +02:00
|
|
|
switches::kEnableSpellingAutoCorrect,
|
2015-03-25 22:22:47 +01:00
|
|
|
switches::kEnableSystemFlash,
|
|
|
|
switches::kPpapiFlashArgs,
|
|
|
|
switches::kPpapiFlashPath,
|
|
|
|
switches::kPpapiFlashVersion,
|
2012-11-02 19:16:28 +01:00
|
|
|
switches::kUncaughtExceptionStackSize,
|
2012-09-10 18:13:51 +02:00
|
|
|
};
|
2015-01-09 18:22:10 +01:00
|
|
|
command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames,
|
2012-09-10 18:13:51 +02:00
|
|
|
arraysize(kSwitchNames));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2012-09-27 19:07:31 +02:00
|
|
|
|
2013-06-10 20:48:09 +02:00
|
|
|
#if defined(OS_LINUX)
|
2015-03-25 22:22:47 +01:00
|
|
|
if (process_type == switches::kZygoteProcess) {
|
|
|
|
// Propagate the following switches to the zygone command line (along with
|
|
|
|
// any associated values) if present in the browser command line.
|
|
|
|
static const char* const kSwitchNames[] = {
|
|
|
|
switches::kPpapiFlashPath,
|
|
|
|
switches::kPpapiFlashVersion,
|
|
|
|
};
|
|
|
|
command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames,
|
|
|
|
arraysize(kSwitchNames));
|
|
|
|
|
|
|
|
if (browser_cmd->HasSwitch(switches::kBrowserSubprocessPath)) {
|
|
|
|
// Force use of the sub-process executable path for the zygote process.
|
|
|
|
const base::FilePath& subprocess_path =
|
|
|
|
browser_cmd->GetSwitchValuePath(switches::kBrowserSubprocessPath);
|
|
|
|
if (!subprocess_path.empty())
|
|
|
|
command_line->SetProgram(subprocess_path);
|
|
|
|
}
|
2013-06-10 20:48:09 +02:00
|
|
|
}
|
|
|
|
#endif // defined(OS_LINUX)
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
|
2012-09-27 19:07:31 +02:00
|
|
|
if (app.get()) {
|
|
|
|
CefRefPtr<CefBrowserProcessHandler> handler =
|
|
|
|
app->GetBrowserProcessHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefCommandLineImpl> commandLinePtr(
|
|
|
|
new CefCommandLineImpl(command_line, false, false));
|
|
|
|
handler->OnBeforeChildProcessLaunch(commandLinePtr.get());
|
|
|
|
commandLinePtr->Detach(NULL);
|
|
|
|
}
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-09-28 00:52:15 +02:00
|
|
|
content::QuotaPermissionContext*
|
|
|
|
CefContentBrowserClient::CreateQuotaPermissionContext() {
|
|
|
|
return new CefQuotaPermissionContext();
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
content::MediaObserver* CefContentBrowserClient::GetMediaObserver() {
|
2013-03-07 02:20:24 +01:00
|
|
|
return CefMediaCaptureDevicesDispatcher::GetInstance();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-03-08 01:41:26 +01:00
|
|
|
content::SpeechRecognitionManagerDelegate*
|
2014-12-13 21:18:31 +01:00
|
|
|
CefContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
|
2014-10-07 22:44:33 +02:00
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
if (command_line->HasSwitch(switches::kEnableSpeechInput))
|
2013-03-08 01:41:26 +01:00
|
|
|
return new CefSpeechRecognitionManagerDelegate();
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-04 19:50:35 +02:00
|
|
|
void CefContentBrowserClient::AllowCertificateError(
|
|
|
|
int render_process_id,
|
2014-05-12 17:56:24 +02:00
|
|
|
int render_frame_id,
|
2013-04-04 19:50:35 +02:00
|
|
|
int cert_error,
|
|
|
|
const net::SSLInfo& ssl_info,
|
|
|
|
const GURL& request_url,
|
2014-09-04 19:53:40 +02:00
|
|
|
content::ResourceType resource_type,
|
2013-04-04 19:50:35 +02:00
|
|
|
bool overridable,
|
|
|
|
bool strict_enforcement,
|
2014-09-04 19:53:40 +02:00
|
|
|
bool expired_previous_decision,
|
2013-04-04 19:50:35 +02:00
|
|
|
const base::Callback<void(bool)>& callback,
|
2013-06-04 19:41:37 +02:00
|
|
|
content::CertificateRequestResultType* result) {
|
2013-04-04 19:50:35 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2014-09-04 19:53:40 +02:00
|
|
|
if (resource_type != content::ResourceType::RESOURCE_TYPE_MAIN_FRAME) {
|
2013-04-04 19:50:35 +02:00
|
|
|
// A sub-resource has a certificate error. The user doesn't really
|
|
|
|
// have a context for making the right decision, so block the request
|
|
|
|
// hard.
|
2013-06-04 19:41:37 +02:00
|
|
|
*result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
|
2013-04-04 19:50:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
2014-05-12 17:56:24 +02:00
|
|
|
CefBrowserHostImpl::GetBrowserForFrame(render_process_id,
|
|
|
|
render_frame_id);
|
2013-04-04 19:50:35 +02:00
|
|
|
if (!browser.get())
|
|
|
|
return;
|
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
if (!client.get())
|
|
|
|
return;
|
|
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
|
|
if (!handler.get())
|
|
|
|
return;
|
|
|
|
|
2015-02-11 19:15:04 +01:00
|
|
|
CefRefPtr<CefSSLInfo> cef_ssl_info = new CefSSLInfoImpl(ssl_info);
|
|
|
|
|
2013-04-04 19:50:35 +02:00
|
|
|
CefRefPtr<CefAllowCertificateErrorCallbackImpl> callbackImpl;
|
|
|
|
if (overridable && !strict_enforcement)
|
|
|
|
callbackImpl = new CefAllowCertificateErrorCallbackImpl(callback);
|
|
|
|
|
2013-06-04 19:41:37 +02:00
|
|
|
bool proceed = handler->OnCertificateError(
|
2015-02-11 19:15:04 +01:00
|
|
|
browser.get(), static_cast<cef_errorcode_t>(cert_error),
|
|
|
|
request_url.spec(), cef_ssl_info, callbackImpl.get());
|
2013-06-04 19:41:37 +02:00
|
|
|
if (!proceed && callbackImpl.get())
|
2013-04-04 19:50:35 +02:00
|
|
|
callbackImpl->Disconnect();
|
2013-06-04 19:41:37 +02:00
|
|
|
|
|
|
|
*result = proceed ? content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE :
|
|
|
|
content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
|
2013-04-04 19:50:35 +02:00
|
|
|
}
|
|
|
|
|
2015-05-19 19:55:58 +02:00
|
|
|
void CefContentBrowserClient::SelectClientCertificate(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
net::SSLCertRequestInfo* cert_request_info,
|
|
|
|
scoped_ptr<content::ClientCertificateDelegate> delegate) {
|
|
|
|
if (!cert_request_info->client_certs.empty()) {
|
|
|
|
// Use the first certificate.
|
|
|
|
delegate->ContinueWithCertificate(cert_request_info->client_certs[0].get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
content::AccessTokenStore* CefContentBrowserClient::CreateAccessTokenStore() {
|
2015-03-02 21:25:14 +01:00
|
|
|
return new CefAccessTokenStore(
|
|
|
|
browser_main_parts_->browser_context()->request_context().get());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-02-08 01:07:41 +01:00
|
|
|
bool CefContentBrowserClient::CanCreateWindow(
|
|
|
|
const GURL& opener_url,
|
2013-10-16 02:25:38 +02:00
|
|
|
const GURL& opener_top_level_frame_url,
|
2013-08-15 21:38:55 +02:00
|
|
|
const GURL& source_origin,
|
2013-02-08 01:07:41 +01:00
|
|
|
WindowContainerType container_type,
|
2013-08-15 21:38:55 +02:00
|
|
|
const GURL& target_url,
|
|
|
|
const content::Referrer& referrer,
|
|
|
|
WindowOpenDisposition disposition,
|
2013-11-08 22:28:56 +01:00
|
|
|
const blink::WebWindowFeatures& features,
|
2013-08-15 21:38:55 +02:00
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
2013-02-08 01:07:41 +01:00
|
|
|
content::ResourceContext* context,
|
|
|
|
int render_process_id,
|
2015-07-24 02:06:56 +02:00
|
|
|
int opener_render_view_id,
|
|
|
|
int opener_render_frame_id,
|
2013-02-08 01:07:41 +01:00
|
|
|
bool* no_javascript_access) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
*no_javascript_access = false;
|
|
|
|
|
2013-02-09 23:38:24 +01:00
|
|
|
DCHECK_NE(last_create_window_params_.opener_process_id, MSG_ROUTING_NONE);
|
|
|
|
if (last_create_window_params_.opener_process_id == MSG_ROUTING_NONE)
|
2013-02-08 01:07:41 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
2014-01-02 23:41:11 +01:00
|
|
|
CefBrowserHostImpl::GetBrowserForView(
|
2013-02-09 23:38:24 +01:00
|
|
|
last_create_window_params_.opener_process_id,
|
|
|
|
last_create_window_params_.opener_view_id);
|
2015-07-16 23:40:01 +02:00
|
|
|
if (!browser.get())
|
2013-02-08 01:07:41 +01:00
|
|
|
return false;
|
|
|
|
|
2013-02-09 23:38:24 +01:00
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
2013-02-08 01:07:41 +01:00
|
|
|
bool allow = true;
|
|
|
|
|
2013-02-09 23:38:24 +01:00
|
|
|
scoped_ptr<CefBrowserHostImpl::PendingPopupInfo> pending_info;
|
|
|
|
pending_info.reset(new CefBrowserHostImpl::PendingPopupInfo);
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
pending_info->window_info.SetAsPopup(NULL, CefString());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Start with the current browser's settings.
|
|
|
|
pending_info->client = client;
|
|
|
|
pending_info->settings = browser->settings();
|
|
|
|
|
2013-02-08 01:07:41 +01:00
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefLifeSpanHandler> handler = client->GetLifeSpanHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefFrame> frame =
|
|
|
|
browser->GetFrame(last_create_window_params_.opener_frame_id);
|
2013-02-09 23:38:24 +01:00
|
|
|
|
2013-08-15 21:38:55 +02:00
|
|
|
CefPopupFeatures cef_features;
|
|
|
|
TranslatePopupFeatures(features, cef_features);
|
2013-02-09 23:38:24 +01:00
|
|
|
|
|
|
|
#if (defined(OS_WIN) || defined(OS_MACOSX))
|
|
|
|
// Default to the size from the popup features.
|
2013-08-15 21:38:55 +02:00
|
|
|
if (cef_features.xSet)
|
|
|
|
pending_info->window_info.x = cef_features.x;
|
|
|
|
if (cef_features.ySet)
|
|
|
|
pending_info->window_info.y = cef_features.y;
|
|
|
|
if (cef_features.widthSet)
|
|
|
|
pending_info->window_info.width = cef_features.width;
|
|
|
|
if (cef_features.heightSet)
|
|
|
|
pending_info->window_info.height = cef_features.height;
|
2013-02-09 23:38:24 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
allow = !handler->OnBeforePopup(browser.get(),
|
2013-02-08 01:07:41 +01:00
|
|
|
frame,
|
|
|
|
last_create_window_params_.target_url.spec(),
|
|
|
|
last_create_window_params_.target_frame_name,
|
2015-03-06 22:38:38 +01:00
|
|
|
static_cast<cef_window_open_disposition_t>(disposition),
|
|
|
|
user_gesture,
|
2013-08-15 21:38:55 +02:00
|
|
|
cef_features,
|
2013-02-09 23:38:24 +01:00
|
|
|
pending_info->window_info,
|
|
|
|
pending_info->client,
|
|
|
|
pending_info->settings,
|
2013-02-08 01:07:41 +01:00
|
|
|
no_javascript_access);
|
2013-02-09 23:38:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allow) {
|
|
|
|
CefRefPtr<CefClient> pending_client = pending_info->client;
|
|
|
|
allow = browser->SetPendingPopupInfo(pending_info.Pass());
|
|
|
|
if (!allow) {
|
|
|
|
LOG(WARNING) << "Creation of popup window denied because one is already "
|
|
|
|
"pending.";
|
2013-02-08 01:07:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-09 23:38:24 +01:00
|
|
|
last_create_window_params_.opener_process_id = MSG_ROUTING_NONE;
|
2013-02-08 01:07:41 +01:00
|
|
|
|
|
|
|
return allow;
|
|
|
|
}
|
|
|
|
|
2012-06-25 23:21:27 +02:00
|
|
|
void CefContentBrowserClient::ResourceDispatcherHostCreated() {
|
|
|
|
resource_dispatcher_host_delegate_.reset(
|
|
|
|
new CefResourceDispatcherHostDelegate());
|
|
|
|
content::ResourceDispatcherHost::Get()->SetDelegate(
|
|
|
|
resource_dispatcher_host_delegate_.get());
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefContentBrowserClient::OverrideWebkitPrefs(
|
|
|
|
content::RenderViewHost* rvh,
|
2014-09-04 19:53:40 +02:00
|
|
|
content::WebPreferences* prefs) {
|
2014-10-07 22:44:33 +02:00
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
|
2012-05-18 17:04:56 +02:00
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
CefBrowserHostImpl::GetBrowserForHost(rvh);
|
2015-07-16 23:40:01 +02:00
|
|
|
if (!browser.get() && extensions::ExtensionsEnabled()) {
|
|
|
|
// Retrieve the owner browser, if any.
|
|
|
|
content::WebContents* owner = extensions::GetOwnerForGuestContents(
|
|
|
|
content::WebContents::FromRenderViewHost(rvh));
|
|
|
|
if (owner)
|
|
|
|
browser = CefBrowserHostImpl::GetBrowserForContents(owner);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
if (browser.get()) {
|
|
|
|
// Populate WebPreferences based on CefBrowserSettings.
|
|
|
|
BrowserToWebSettings(browser->settings(), *prefs);
|
|
|
|
}
|
2014-04-15 21:02:30 +02:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
prefs->base_background_color = GetBaseBackgroundColor(browser);
|
2015-05-13 15:18:46 +02:00
|
|
|
if (rvh->GetView())
|
|
|
|
rvh->GetView()->SetBackgroundColor(prefs->base_background_color);
|
2014-10-07 22:44:33 +02:00
|
|
|
|
|
|
|
prefs->asynchronous_spell_checking_enabled = true;
|
|
|
|
// Auto-correct does not work in combination with the unified text checker.
|
|
|
|
prefs->unified_textchecker_enabled =
|
|
|
|
!command_line->HasSwitch(switches::kEnableSpellingAutoCorrect);
|
2014-04-15 21:02:30 +02:00
|
|
|
}
|
|
|
|
|
2012-10-08 19:47:37 +02:00
|
|
|
void CefContentBrowserClient::BrowserURLHandlerCreated(
|
|
|
|
content::BrowserURLHandler* handler) {
|
|
|
|
// Used to redirect about: URLs to chrome: URLs.
|
|
|
|
handler->AddHandlerPair(&scheme::WillHandleBrowserAboutURL,
|
|
|
|
content::BrowserURLHandler::null_handler());
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string CefContentBrowserClient::GetDefaultDownloadName() {
|
|
|
|
return "download";
|
|
|
|
}
|
2012-09-11 00:19:19 +02:00
|
|
|
|
2015-03-25 22:22:47 +01:00
|
|
|
void CefContentBrowserClient::DidCreatePpapiPlugin(
|
|
|
|
content::BrowserPpapiHost* browser_host) {
|
|
|
|
browser_host->GetPpapiHost()->AddHostFactoryFilter(
|
|
|
|
scoped_ptr<ppapi::host::HostFactory>(
|
|
|
|
new CefBrowserPepperHostFactory(browser_host)));
|
|
|
|
}
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
content::DevToolsManagerDelegate*
|
|
|
|
CefContentBrowserClient::GetDevToolsManagerDelegate() {
|
2015-03-02 21:25:14 +01:00
|
|
|
return new CefDevToolsManagerDelegate();
|
2014-09-27 01:48:19 +02:00
|
|
|
}
|
2013-11-21 23:43:36 +01:00
|
|
|
|
|
|
|
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
|
|
|
void CefContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
|
2014-04-04 18:50:38 +02:00
|
|
|
const base::CommandLine& command_line,
|
2013-11-21 23:43:36 +01:00
|
|
|
int child_process_id,
|
2014-11-12 20:25:15 +01:00
|
|
|
content::FileDescriptorInfo* mappings) {
|
2013-11-21 23:43:36 +01:00
|
|
|
int crash_signal_fd = GetCrashSignalFD(command_line);
|
|
|
|
if (crash_signal_fd >= 0) {
|
2014-11-12 20:25:15 +01:00
|
|
|
mappings->Share(kCrashDumpSignal, crash_signal_fd);
|
2013-11-21 23:43:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
|
|
|
|
|
|
|
|
|
2012-09-11 00:19:19 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
const wchar_t* CefContentBrowserClient::GetResourceDllName() {
|
|
|
|
static wchar_t file_path[MAX_PATH+1] = {0};
|
|
|
|
|
|
|
|
if (file_path[0] == 0) {
|
|
|
|
// Retrieve the module path (usually libcef.dll).
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath module;
|
2012-09-11 00:19:19 +02:00
|
|
|
PathService::Get(base::FILE_MODULE, &module);
|
|
|
|
const std::wstring wstr = module.value();
|
|
|
|
size_t count = std::min(static_cast<size_t>(MAX_PATH), wstr.size());
|
|
|
|
wcsncpy(file_path, wstr.c_str(), count);
|
|
|
|
file_path[count] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return file_path;
|
|
|
|
}
|
2015-06-12 01:00:09 +02:00
|
|
|
|
|
|
|
void CefContentBrowserClient::PreSpawnRenderer(
|
|
|
|
sandbox::TargetPolicy* policy,
|
|
|
|
bool* success) {
|
|
|
|
// Flash requires this permission to play video files.
|
|
|
|
sandbox::ResultCode result = policy->AddRule(
|
|
|
|
sandbox::TargetPolicy::SUBSYS_HANDLES,
|
|
|
|
sandbox::TargetPolicy::HANDLES_DUP_ANY,
|
|
|
|
L"File");
|
|
|
|
if (result != sandbox::SBOX_ALL_OK) {
|
|
|
|
*success = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-09-11 00:19:19 +02:00
|
|
|
#endif // defined(OS_WIN)
|
2013-02-08 01:07:41 +01:00
|
|
|
|
2013-06-05 01:37:26 +02:00
|
|
|
void CefContentBrowserClient::RegisterCustomScheme(const std::string& scheme) {
|
2013-06-04 19:41:37 +02:00
|
|
|
// Register as a Web-safe scheme so that requests for the scheme from a
|
|
|
|
// render process will be allowed in resource_dispatcher_host_impl.cc
|
|
|
|
// ShouldServiceRequest.
|
|
|
|
content::ChildProcessSecurityPolicy* policy =
|
|
|
|
content::ChildProcessSecurityPolicy::GetInstance();
|
|
|
|
if (!policy->IsWebSafeScheme(scheme))
|
|
|
|
policy->RegisterWebSafeScheme(scheme);
|
|
|
|
}
|
|
|
|
|
2013-02-08 01:07:41 +01:00
|
|
|
void CefContentBrowserClient::set_last_create_window_params(
|
|
|
|
const LastCreateWindowParams& params) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
last_create_window_params_ = params;
|
|
|
|
}
|
2013-02-23 01:43:28 +01:00
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
scoped_refptr<CefBrowserContextImpl>
|
|
|
|
CefContentBrowserClient::browser_context() const {
|
2013-02-23 01:43:28 +01:00
|
|
|
return browser_main_parts_->browser_context();
|
|
|
|
}
|
2013-09-03 18:43:31 +02:00
|
|
|
|
|
|
|
CefDevToolsDelegate* CefContentBrowserClient::devtools_delegate() const {
|
|
|
|
return browser_main_parts_->devtools_delegate();
|
|
|
|
}
|
|
|
|
|
|
|
|
PrefService* CefContentBrowserClient::pref_service() const {
|
|
|
|
return browser_main_parts_->pref_service();
|
|
|
|
}
|
2015-03-04 02:15:50 +01:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
// static
|
2015-03-04 02:15:50 +01:00
|
|
|
SkColor CefContentBrowserClient::GetBaseBackgroundColor(
|
2015-07-16 23:40:01 +02:00
|
|
|
CefRefPtr<CefBrowserHostImpl> browser) {
|
|
|
|
if (browser.get()) {
|
|
|
|
const CefBrowserSettings& browser_settings = browser->settings();
|
|
|
|
if (CefColorGetA(browser_settings.background_color) > 0) {
|
2015-03-04 02:15:50 +01:00
|
|
|
return SkColorSetRGB(
|
2015-07-16 23:40:01 +02:00
|
|
|
CefColorGetR(browser_settings.background_color),
|
|
|
|
CefColorGetG(browser_settings.background_color),
|
|
|
|
CefColorGetB(browser_settings.background_color));
|
2015-03-04 02:15:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
const CefSettings& settings = CefContext::Get()->settings();
|
|
|
|
if (CefColorGetA(settings.background_color) > 0) {
|
|
|
|
return SkColorSetRGB(
|
|
|
|
CefColorGetR(settings.background_color),
|
|
|
|
CefColorGetG(settings.background_color),
|
|
|
|
CefColorGetB(settings.background_color));
|
|
|
|
}
|
|
|
|
|
2015-03-04 02:15:50 +01:00
|
|
|
return SK_ColorWHITE;
|
|
|
|
}
|