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-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/browser_context.h"
|
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"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/context.h"
|
2012-06-25 23:21:27 +02:00
|
|
|
#include "libcef/browser/resource_dispatcher_host_delegate.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"
|
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"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/file_path.h"
|
2012-09-11 00:19:19 +02:00
|
|
|
#include "base/path_service.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"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/media_observer.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"
|
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"
|
|
|
|
#include "googleurl/src/gurl.h"
|
2012-10-22 22:56:38 +02:00
|
|
|
#include "ui/base/ui_base_switches.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-11-21 01:40:15 +01:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "libcef/browser/web_contents_view_osr.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:
|
|
|
|
CefAccessTokenStore() {}
|
|
|
|
|
|
|
|
virtual void LoadAccessTokens(
|
|
|
|
const LoadAccessTokensCallbackType& callback) OVERRIDE {
|
2013-02-23 01:43:28 +01:00
|
|
|
callback.Run(access_token_set_, _Context->request_context());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SaveAccessToken(
|
|
|
|
const GURL& server_url, const string16& access_token) OVERRIDE {
|
|
|
|
access_token_set_[server_url] = access_token;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
AccessTokenSet access_token_set_;
|
|
|
|
};
|
|
|
|
|
2012-09-28 00:52:15 +02:00
|
|
|
class CefQuotaCallbackImpl : public CefQuotaCallback {
|
|
|
|
public:
|
|
|
|
explicit CefQuotaCallbackImpl(
|
|
|
|
const content::QuotaPermissionContext::PermissionCallback& callback)
|
|
|
|
: callback_(callback) {
|
|
|
|
}
|
|
|
|
~CefQuotaCallbackImpl() {
|
|
|
|
if (!callback_.is_null()) {
|
|
|
|
// The callback is still pending. Cancel it now.
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
|
|
|
CancelNow(callback_);
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(&CefQuotaCallbackImpl::CancelNow, callback_));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Continue(bool allow) OVERRIDE {
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
|
|
|
if (!callback_.is_null()) {
|
|
|
|
callback_.Run(allow ?
|
|
|
|
content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW :
|
|
|
|
content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_DISALLOW);
|
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(&CefQuotaCallbackImpl::Continue, this, allow));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Cancel() OVERRIDE {
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
|
|
|
if (!callback_.is_null()) {
|
|
|
|
CancelNow(callback_);
|
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_IOT, base::Bind(&CefQuotaCallbackImpl::Cancel, this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disconnect() {
|
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void CancelNow(
|
|
|
|
const content::QuotaPermissionContext::PermissionCallback& callback) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
callback.Run(
|
|
|
|
content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED);
|
|
|
|
}
|
|
|
|
|
|
|
|
content::QuotaPermissionContext::PermissionCallback callback_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefQuotaCallbackImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CefQuotaPermissionContext : public content::QuotaPermissionContext {
|
|
|
|
public:
|
|
|
|
CefQuotaPermissionContext() {
|
|
|
|
}
|
|
|
|
|
|
|
|
// The callback will be dispatched on the IO thread.
|
|
|
|
virtual void RequestQuotaPermission(
|
|
|
|
const GURL& origin_url,
|
|
|
|
quota::StorageType type,
|
|
|
|
int64 new_quota,
|
|
|
|
int render_process_id,
|
|
|
|
int render_view_id,
|
|
|
|
const PermissionCallback& callback) OVERRIDE {
|
|
|
|
if (type != quota::kStorageTypePersistent) {
|
|
|
|
// 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 =
|
|
|
|
CefBrowserHostImpl::GetBrowserByRoutingID(render_process_id,
|
|
|
|
render_view_id);
|
|
|
|
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));
|
|
|
|
handled = handler->OnQuotaRequest(browser.get(), origin_url.spec(),
|
|
|
|
new_quota, callbackImpl.get());
|
|
|
|
if (!handled)
|
|
|
|
callbackImpl->Disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handled) {
|
|
|
|
// Disallow the request by default.
|
|
|
|
callback.Run(QUOTA_PERMISSION_RESPONSE_DISALLOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~CefQuotaPermissionContext() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-09-28 22:14:02 +02:00
|
|
|
class CefPluginServiceFilter : public content::PluginServiceFilter {
|
|
|
|
public:
|
|
|
|
CefPluginServiceFilter() {}
|
|
|
|
virtual ~CefPluginServiceFilter() {}
|
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
virtual bool IsPluginAvailable(int render_process_id,
|
|
|
|
int render_view_id,
|
|
|
|
const void* context,
|
|
|
|
const GURL& url,
|
|
|
|
const GURL& policy_url,
|
|
|
|
webkit::WebPluginInfo* plugin) OVERRIDE {
|
2012-09-28 22:14:02 +02:00
|
|
|
bool allowed = true;
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
CefBrowserHostImpl::GetBrowserByRoutingID(render_process_id,
|
|
|
|
render_view_id);
|
|
|
|
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
|
|
|
|
|
|
|
virtual bool CanLoadPlugin(int render_process_id,
|
|
|
|
const FilePath& path) OVERRIDE {
|
|
|
|
return true;
|
|
|
|
}
|
2012-09-28 22:14:02 +02:00
|
|
|
};
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
class CefMediaObserver : public content::MediaObserver {
|
|
|
|
public:
|
|
|
|
CefMediaObserver() {}
|
|
|
|
virtual ~CefMediaObserver() {}
|
|
|
|
|
2012-05-18 17:04:56 +02:00
|
|
|
virtual void OnCaptureDevicesOpened(
|
|
|
|
int render_process_id,
|
|
|
|
int render_view_id,
|
|
|
|
const content::MediaStreamDevices& devices) OVERRIDE {}
|
|
|
|
virtual void OnCaptureDevicesClosed(
|
|
|
|
int render_process_id,
|
|
|
|
int render_view_id,
|
|
|
|
const content::MediaStreamDevices& devices) OVERRIDE {}
|
2012-11-30 20:08:20 +01:00
|
|
|
virtual void OnAudioCaptureDevicesChanged(
|
|
|
|
const content::MediaStreamDevices& devices) OVERRIDE {}
|
|
|
|
virtual void OnVideoCaptureDevicesChanged(
|
|
|
|
const content::MediaStreamDevices& devices) OVERRIDE {}
|
2012-11-05 21:18:20 +01:00
|
|
|
virtual void OnMediaRequestStateChanged(
|
|
|
|
int render_process_id,
|
|
|
|
int render_view_id,
|
|
|
|
const content::MediaStreamDevice& device,
|
|
|
|
content::MediaRequestState state) OVERRIDE {}
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
CefContentBrowserClient::CefContentBrowserClient()
|
2012-12-30 12:17:49 +01:00
|
|
|
: browser_main_parts_(NULL),
|
|
|
|
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*>(
|
|
|
|
content::GetContentClient()->browser());
|
|
|
|
}
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
scoped_refptr<CefBrowserInfo> CefContentBrowserClient::CreateBrowserInfo() {
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info =
|
|
|
|
new CefBrowserInfo(++next_browser_id_, false);
|
|
|
|
browser_info_list_.push_back(browser_info);
|
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo>
|
|
|
|
CefContentBrowserClient::GetOrCreateBrowserInfo(int render_process_id,
|
|
|
|
int render_view_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_id_match(render_process_id, render_view_id))
|
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must be a popup if it hasn't already been created.
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info =
|
|
|
|
new CefBrowserInfo(++next_browser_id_, true);
|
|
|
|
browser_info->set_render_ids(render_process_id, render_view_id);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
scoped_refptr<CefBrowserInfo> CefContentBrowserClient::GetBrowserInfo(
|
|
|
|
int render_process_id, int render_view_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_id_match(render_process_id, render_view_id))
|
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
|
2013-02-09 23:38:24 +01:00
|
|
|
LOG(WARNING) << "No browser info matching process id " <<
|
|
|
|
render_process_id << " and view id " << render_view_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
|
|
|
}
|
|
|
|
|
2012-11-21 01:40:15 +01:00
|
|
|
content::WebContentsView*
|
|
|
|
CefContentBrowserClient::OverrideCreateWebContentsView(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
content::RenderViewHostDelegateView** render_view_host_delegate_view) {
|
|
|
|
content::WebContentsView* view = NULL;
|
|
|
|
*render_view_host_delegate_view = NULL;
|
|
|
|
// TODO(port): Implement this method to work on other platforms as part of
|
|
|
|
// off-screen rendering support.
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
CefBrowserContext* browserContext =
|
|
|
|
static_cast<CefBrowserContext*>(web_contents->GetBrowserContext());
|
|
|
|
|
|
|
|
if (browserContext && browserContext->use_osr_next_contents_view()) {
|
|
|
|
CefWebContentsViewOSR* view_or = new CefWebContentsViewOSR(web_contents,
|
|
|
|
GetWebContentsViewDelegate(web_contents));
|
|
|
|
*render_view_host_delegate_view = view_or;
|
|
|
|
view = view_or;
|
|
|
|
}
|
|
|
|
#endif // OS_WIN
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefContentBrowserClient::RenderProcessHostCreated(
|
|
|
|
content::RenderProcessHost* host) {
|
|
|
|
host->GetChannel()->AddFilter(new CefBrowserMessageFilter(host));
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
net::URLRequestContextGetter* CefContentBrowserClient::CreateRequestContext(
|
|
|
|
content::BrowserContext* content_browser_context,
|
|
|
|
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
|
|
|
blob_protocol_handler,
|
|
|
|
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
|
|
|
file_system_protocol_handler,
|
|
|
|
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
|
|
|
developer_protocol_handler,
|
|
|
|
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
|
|
|
chrome_protocol_handler,
|
|
|
|
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
|
|
|
chrome_devtools_protocol_handler) {
|
|
|
|
CefBrowserContext* cef_browser_context =
|
|
|
|
CefBrowserContextForBrowserContext(content_browser_context);
|
|
|
|
return cef_browser_context->CreateRequestContext(
|
|
|
|
blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(),
|
|
|
|
developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(),
|
|
|
|
chrome_devtools_protocol_handler.Pass());
|
|
|
|
}
|
|
|
|
|
|
|
|
net::URLRequestContextGetter*
|
|
|
|
CefContentBrowserClient::CreateRequestContextForStoragePartition(
|
|
|
|
content::BrowserContext* content_browser_context,
|
|
|
|
const base::FilePath& partition_path,
|
|
|
|
bool in_memory,
|
|
|
|
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
|
|
|
blob_protocol_handler,
|
|
|
|
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
|
|
|
file_system_protocol_handler,
|
|
|
|
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
|
|
|
developer_protocol_handler,
|
|
|
|
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
|
|
|
chrome_protocol_handler,
|
|
|
|
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
|
|
|
chrome_devtools_protocol_handler) {
|
|
|
|
CefBrowserContext* cef_browser_context =
|
|
|
|
CefBrowserContextForBrowserContext(content_browser_context);
|
|
|
|
return cef_browser_context->CreateRequestContextForStoragePartition(
|
|
|
|
partition_path, in_memory, blob_protocol_handler.Pass(),
|
|
|
|
file_system_protocol_handler.Pass(),
|
|
|
|
developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(),
|
|
|
|
chrome_devtools_protocol_handler.Pass());
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefContentBrowserClient::AppendExtraCommandLineSwitches(
|
|
|
|
CommandLine* command_line, int child_process_id) {
|
2012-09-10 18:13:51 +02:00
|
|
|
const CommandLine& browser_cmd = *CommandLine::ForCurrentProcess();
|
|
|
|
|
|
|
|
{
|
|
|
|
// 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[] = {
|
2012-10-25 23:19:20 +02:00
|
|
|
switches::kLang,
|
|
|
|
switches::kLocalesDirPath,
|
2012-09-10 18:13:51 +02:00
|
|
|
switches::kLogFile,
|
|
|
|
switches::kLogSeverity,
|
2013-02-07 20:59:40 +01:00
|
|
|
switches::kEnableReleaseDcheck,
|
|
|
|
switches::kDisablePackLoading,
|
2012-10-25 23:19:20 +02:00
|
|
|
switches::kResourcesDirPath,
|
2012-09-10 18:13:51 +02:00
|
|
|
};
|
|
|
|
command_line->CopySwitchesFrom(browser_cmd, kSwitchNames,
|
|
|
|
arraysize(kSwitchNames));
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string process_type =
|
|
|
|
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,
|
2012-09-10 18:13:51 +02:00
|
|
|
switches::kProductVersion,
|
2012-11-02 19:16:28 +01:00
|
|
|
switches::kUncaughtExceptionStackSize,
|
2012-09-10 18:13:51 +02:00
|
|
|
};
|
|
|
|
command_line->CopySwitchesFrom(browser_cmd, kSwitchNames,
|
|
|
|
arraysize(kSwitchNames));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2012-09-27 19:07:31 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefApp> app = _Context->application();
|
|
|
|
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() {
|
|
|
|
// TODO(cef): Return NULL once it's supported. See crbug.com/116113.
|
|
|
|
if (!media_observer_.get())
|
|
|
|
media_observer_.reset(new CefMediaObserver());
|
|
|
|
return media_observer_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::AccessTokenStore* CefContentBrowserClient::CreateAccessTokenStore() {
|
|
|
|
return new CefAccessTokenStore;
|
|
|
|
}
|
|
|
|
|
2013-02-08 01:07:41 +01:00
|
|
|
bool CefContentBrowserClient::CanCreateWindow(
|
|
|
|
const GURL& opener_url,
|
|
|
|
const GURL& origin,
|
|
|
|
WindowContainerType container_type,
|
|
|
|
content::ResourceContext* context,
|
|
|
|
int render_process_id,
|
|
|
|
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 =
|
|
|
|
CefBrowserHostImpl::GetBrowserByRoutingID(
|
2013-02-09 23:38:24 +01:00
|
|
|
last_create_window_params_.opener_process_id,
|
|
|
|
last_create_window_params_.opener_view_id);
|
2013-02-08 01:07:41 +01:00
|
|
|
DCHECK(browser.get());
|
2013-02-09 23:38:24 +01:00
|
|
|
if (!browser.get()) {
|
|
|
|
LOG(WARNING) << "CanCreateWindow called before browser was created";
|
2013-02-08 01:07:41 +01:00
|
|
|
return false;
|
2013-02-09 23:38:24 +01:00
|
|
|
}
|
2013-02-08 01:07:41 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
// TODO(cef): Figure out how to populate CefPopupFeatures.
|
|
|
|
// See: http://crbug.com/110510
|
|
|
|
CefPopupFeatures features;
|
|
|
|
|
|
|
|
#if (defined(OS_WIN) || defined(OS_MACOSX))
|
|
|
|
// Default to the size from the popup features.
|
|
|
|
if (features.xSet)
|
|
|
|
pending_info->window_info.x = features.x;
|
|
|
|
if (features.ySet)
|
|
|
|
pending_info->window_info.y = features.y;
|
|
|
|
if (features.widthSet)
|
|
|
|
pending_info->window_info.width = features.width;
|
|
|
|
if (features.heightSet)
|
|
|
|
pending_info->window_info.height = features.height;
|
|
|
|
#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,
|
2013-02-09 23:38:24 +01:00
|
|
|
features,
|
|
|
|
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) {
|
|
|
|
if (CefBrowserHostImpl::IsWindowRenderingDisabled(
|
|
|
|
pending_info->window_info)) {
|
|
|
|
if (!pending_info->client->GetRenderHandler().get()) {
|
|
|
|
NOTREACHED() << "CefRenderHandler implementation is required";
|
|
|
|
allow = false;
|
|
|
|
}
|
|
|
|
if (pending_info->settings.accelerated_compositing != STATE_DISABLED) {
|
|
|
|
// Accelerated compositing is not supported when window rendering is
|
|
|
|
// disabled.
|
|
|
|
pending_info->settings.accelerated_compositing = STATE_DISABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
const GURL& url,
|
2012-05-18 17:04:56 +02:00
|
|
|
webkit_glue::WebPreferences* prefs) {
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
CefBrowserHostImpl::GetBrowserForHost(rvh);
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK(browser.get());
|
|
|
|
|
|
|
|
// Populate WebPreferences based on CefBrowserSettings.
|
|
|
|
BrowserToWebSettings(browser->settings(), *prefs);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
#endif // defined(OS_WIN)
|
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
|
|
|
|
|
|
|
CefBrowserContext*
|
|
|
|
CefContentBrowserClient::CefBrowserContextForBrowserContext(
|
|
|
|
content::BrowserContext* content_browser_context) {
|
|
|
|
DCHECK_EQ(content_browser_context, browser_main_parts_->browser_context());
|
|
|
|
return browser_main_parts_->browser_context();
|
|
|
|
}
|