Structural improvements for request handling (issue #1044)

- Add new CefRequestContext and CefRequestContextHandler classes.
- Add CefRequestContext argument to CefBrowserHost static factory methods.
- Move GetCookieManager from CefRequestHandler to CefRequestContextHandler.
- Use BrowserContext as the root proxy object for network requests.
- Move accessors for CefBrowserMainParts members from CefContext to CefContentBrowserClient.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1424 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2013-09-03 16:43:31 +00:00
parent 935a35f21c
commit 385be456c3
57 changed files with 2288 additions and 440 deletions

View File

@ -261,6 +261,7 @@
'tests/unittests/navigation_unittest.cc',
'tests/unittests/os_rendering_unittest.cc',
'tests/unittests/process_message_unittest.cc',
'tests/unittests/request_context_unittest.cc',
'tests/unittests/request_handler_unittest.cc',
'tests/unittests/request_unittest.cc',
'tests/cefclient/resource_util.h',
@ -808,8 +809,11 @@
'<@(includes_common)',
'libcef/browser/backing_store_osr.cc',
'libcef/browser/backing_store_osr.h',
'libcef/browser/browser_context.cc',
'libcef/browser/browser_context.h',
'libcef/browser/browser_context_impl.cc',
'libcef/browser/browser_context_impl.h',
'libcef/browser/browser_context_proxy.cc',
'libcef/browser/browser_context_proxy.h',
'libcef/browser/browser_host_impl.cc',
'libcef/browser/browser_host_impl.h',
'libcef/browser/browser_info.cc',
@ -871,6 +875,8 @@
'libcef/browser/resource_dispatcher_host_delegate.h',
'libcef/browser/resource_request_job.cc',
'libcef/browser/resource_request_job.h',
'libcef/browser/request_context_impl.cc',
'libcef/browser/request_context_impl.h',
'libcef/browser/scheme_handler.cc',
'libcef/browser/scheme_handler.h',
'libcef/browser/scheme_impl.cc',

View File

@ -44,6 +44,8 @@
'include/cef_render_handler.h',
'include/cef_render_process_handler.h',
'include/cef_request.h',
'include/cef_request_context.h',
'include/cef_request_context_handler.h',
'include/cef_request_handler.h',
'include/cef_resource_bundle_handler.h',
'include/cef_resource_handler.h',
@ -94,6 +96,8 @@
'include/capi/cef_render_handler_capi.h',
'include/capi/cef_render_process_handler_capi.h',
'include/capi/cef_request_capi.h',
'include/capi/cef_request_context_capi.h',
'include/capi/cef_request_context_handler_capi.h',
'include/capi/cef_request_handler_capi.h',
'include/capi/cef_resource_bundle_handler_capi.h',
'include/capi/cef_resource_handler_capi.h',
@ -212,6 +216,10 @@
'libcef_dll/ctocpp/render_process_handler_ctocpp.h',
'libcef_dll/cpptoc/request_cpptoc.cc',
'libcef_dll/cpptoc/request_cpptoc.h',
'libcef_dll/cpptoc/request_context_cpptoc.cc',
'libcef_dll/cpptoc/request_context_cpptoc.h',
'libcef_dll/ctocpp/request_context_handler_ctocpp.cc',
'libcef_dll/ctocpp/request_context_handler_ctocpp.h',
'libcef_dll/ctocpp/request_handler_ctocpp.cc',
'libcef_dll/ctocpp/request_handler_ctocpp.h',
'libcef_dll/ctocpp/resource_bundle_handler_ctocpp.cc',
@ -370,6 +378,10 @@
'libcef_dll/cpptoc/render_process_handler_cpptoc.h',
'libcef_dll/ctocpp/request_ctocpp.cc',
'libcef_dll/ctocpp/request_ctocpp.h',
'libcef_dll/ctocpp/request_context_ctocpp.cc',
'libcef_dll/ctocpp/request_context_ctocpp.h',
'libcef_dll/cpptoc/request_context_handler_cpptoc.cc',
'libcef_dll/cpptoc/request_context_handler_cpptoc.h',
'libcef_dll/cpptoc/request_handler_cpptoc.cc',
'libcef_dll/cpptoc/request_handler_cpptoc.h',
'libcef_dll/cpptoc/resource_bundle_handler_cpptoc.cc',

View File

@ -264,6 +264,12 @@ typedef struct _cef_browser_host_t {
struct _cef_client_t* (CEF_CALLBACK *get_client)(
struct _cef_browser_host_t* self);
///
// Returns the request context for this browser.
///
struct _cef_request_context_t* (CEF_CALLBACK *get_request_context)(
struct _cef_browser_host_t* self);
///
// Returns the DevTools URL for this browser. If |http_scheme| is true (1) the
// returned URL will use the http scheme instead of the chrome-devtools
@ -433,21 +439,24 @@ typedef struct _cef_browser_host_t {
///
// Create a new browser window using the window parameters specified by
// |windowInfo|. All values will be copied internally and the actual window will
// be created on the UI thread. This function can be called on any browser
// process thread and will not block.
// be created on the UI thread. If |request_context| is NULL the global request
// context will be used. This function can be called on any browser process
// thread and will not block.
///
CEF_EXPORT int cef_browser_host_create_browser(
const cef_window_info_t* windowInfo, struct _cef_client_t* client,
const cef_string_t* url, const struct _cef_browser_settings_t* settings);
const cef_string_t* url, const struct _cef_browser_settings_t* settings,
struct _cef_request_context_t* request_context);
///
// Create a new browser window using the window parameters specified by
// |windowInfo|. This function can only be called on the browser process UI
// thread.
// |windowInfo|. If |request_context| is NULL the global request context will be
// used. This function can only be called on the browser process UI thread.
///
CEF_EXPORT cef_browser_t* cef_browser_host_create_browser_sync(
const cef_window_info_t* windowInfo, struct _cef_client_t* client,
const cef_string_t* url, const struct _cef_browser_settings_t* settings);
const cef_string_t* url, const struct _cef_browser_settings_t* settings,
struct _cef_request_context_t* request_context);
#ifdef __cplusplus

View File

@ -0,0 +1,105 @@
// Copyright (c) 2013 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool and should not edited
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
#ifndef CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_CAPI_H_
#define CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_CAPI_H_
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "include/capi/cef_base_capi.h"
///
// A request context provides request handling for a set of related browser
// objects. A request context is specified when creating a new browser object
// via the cef_browser_host_t static factory functions. Browser objects with
// different request contexts will never be hosted in the same render process.
// Browser objects with the same request context may or may not be hosted in the
// same render process depending on the process model. Browser objects created
// indirectly via the JavaScript window.open function or targeted links will
// share the same render process and the same request context as the source
// browser. When running in single-process mode there is only a single render
// process (the main process) and so all browsers created in single-process mode
// will share the same request context. This will be the first request context
// passed into a cef_browser_host_t static factory function and all other
// request context objects will be ignored.
///
typedef struct _cef_request_context_t {
///
// Base structure.
///
cef_base_t base;
///
// Returns true (1) if this object is pointing to the same context as |that|
// object.
///
int (CEF_CALLBACK *is_same)(struct _cef_request_context_t* self,
struct _cef_request_context_t* other);
///
// Returns true (1) if this object is the global context.
///
int (CEF_CALLBACK *is_global)(struct _cef_request_context_t* self);
///
// Returns the handler for this context if any.
///
struct _cef_request_context_handler_t* (CEF_CALLBACK *get_handler)(
struct _cef_request_context_t* self);
} cef_request_context_t;
///
// Returns the global context object.
///
CEF_EXPORT cef_request_context_t* cef_request_context_get_global_context();
///
// Creates a new context object with the specified handler.
///
CEF_EXPORT cef_request_context_t* cef_request_context_create_context(
struct _cef_request_context_handler_t* handler);
#ifdef __cplusplus
}
#endif
#endif // CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_CAPI_H_

View File

@ -0,0 +1,70 @@
// Copyright (c) 2013 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool and should not edited
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
#ifndef CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_HANDLER_CAPI_H_
#define CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_HANDLER_CAPI_H_
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "include/capi/cef_base_capi.h"
///
// Implement this structure to provide handler implementations.
///
typedef struct _cef_request_context_handler_t {
///
// Base structure.
///
cef_base_t base;
///
// Called on the IO thread to retrieve the cookie manager. The global cookie
// manager will be used if this function returns NULL.
///
struct _cef_cookie_manager_t* (CEF_CALLBACK *get_cookie_manager)(
struct _cef_request_context_handler_t* self);
} cef_request_context_handler_t;
#ifdef __cplusplus
}
#endif
#endif // CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_HANDLER_CAPI_H_

View File

@ -148,16 +148,6 @@ typedef struct _cef_request_handler_t {
struct _cef_browser_t* browser, const cef_string_t* origin_url,
int64 new_size, struct _cef_quota_callback_t* callback);
///
// Called on the IO thread to retrieve the cookie manager. |main_url| is the
// URL of the top-level frame. Cookies managers can be unique per browser or
// shared across multiple browsers. The global cookie manager will be used if
// this function returns NULL.
///
struct _cef_cookie_manager_t* (CEF_CALLBACK *get_cookie_manager)(
struct _cef_request_handler_t* self, struct _cef_browser_t* browser,
const cef_string_t* main_url);
///
// Called on the UI thread to handle requests for URLs with an unknown
// protocol component. Set |allow_os_execution| to true (1) to attempt

View File

@ -41,6 +41,7 @@
#include "include/cef_base.h"
#include "include/cef_frame.h"
#include "include/cef_process_message.h"
#include "include/cef_request_context.h"
#include <vector>
class CefBrowserHost;
@ -224,26 +225,32 @@ class CefBrowserHost : public virtual CefBase {
///
// Create a new browser window using the window parameters specified by
// |windowInfo|. All values will be copied internally and the actual window
// will be created on the UI thread. This method can be called on any browser
// process thread and will not block.
// will be created on the UI thread. If |request_context| is empty the
// global request context will be used. This method can be called on any
// browser process thread and will not block.
///
/*--cef(optional_param=client,optional_param=url)--*/
/*--cef(optional_param=client,optional_param=url,
optional_param=request_context)--*/
static bool CreateBrowser(const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings);
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context);
///
// Create a new browser window using the window parameters specified by
// |windowInfo|. This method can only be called on the browser process UI
// |windowInfo|. If |request_context| is empty the global request context
// will be used. This method can only be called on the browser process UI
// thread.
///
/*--cef(optional_param=client,optional_param=url)--*/
/*--cef(optional_param=client,optional_param=url,
optional_param=request_context)--*/
static CefRefPtr<CefBrowser> CreateBrowserSync(
const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings);
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context);
///
// Returns the hosted browser object.
@ -300,6 +307,12 @@ class CefBrowserHost : public virtual CefBase {
/*--cef()--*/
virtual CefRefPtr<CefClient> GetClient() =0;
///
// Returns the request context for this browser.
///
/*--cef()--*/
virtual CefRefPtr<CefRequestContext> GetRequestContext() =0;
///
// Returns the DevTools URL for this browser. If |http_scheme| is true the
// returned URL will use the http scheme instead of the chrome-devtools

View File

@ -0,0 +1,94 @@
// Copyright (c) 2013 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ---------------------------------------------------------------------------
//
// The contents of this file must follow a specific format in order to
// support the CEF translator tool. See the translator.README.txt file in the
// tools directory for more information.
//
#ifndef CEF_INCLUDE_CEF_REQUEST_CONTEXT_H_
#define CEF_INCLUDE_CEF_REQUEST_CONTEXT_H_
#pragma once
#include "include/cef_request_context_handler.h"
///
// A request context provides request handling for a set of related browser
// objects. A request context is specified when creating a new browser object
// via the CefBrowserHost static factory methods. Browser objects with different
// request contexts will never be hosted in the same render process. Browser
// objects with the same request context may or may not be hosted in the same
// render process depending on the process model. Browser objects created
// indirectly via the JavaScript window.open function or targeted links will
// share the same render process and the same request context as the source
// browser. When running in single-process mode there is only a single render
// process (the main process) and so all browsers created in single-process mode
// will share the same request context. This will be the first request context
// passed into a CefBrowserHost static factory method and all other request
// context objects will be ignored.
///
/*--cef(source=library,no_debugct_check)--*/
class CefRequestContext : public virtual CefBase {
public:
///
// Returns the global context object.
///
/*--cef()--*/
static CefRefPtr<CefRequestContext> GetGlobalContext();
///
// Creates a new context object with the specified handler.
///
/*--cef(optional_param=handler)--*/
static CefRefPtr<CefRequestContext> CreateContext(
CefRefPtr<CefRequestContextHandler> handler);
///
// Returns true if this object is pointing to the same context as |that|
// object.
///
/*--cef()--*/
virtual bool IsSame(CefRefPtr<CefRequestContext> other) =0;
///
// Returns true if this object is the global context.
///
/*--cef()--*/
virtual bool IsGlobal() =0;
///
// Returns the handler for this context if any.
///
/*--cef()--*/
virtual CefRefPtr<CefRequestContextHandler> GetHandler() =0;
};
#endif // CEF_INCLUDE_CEF_REQUEST_CONTEXT_H_

View File

@ -0,0 +1,58 @@
// Copyright (c) 2013 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ---------------------------------------------------------------------------
//
// The contents of this file must follow a specific format in order to
// support the CEF translator tool. See the translator.README.txt file in the
// tools directory for more information.
//
#ifndef CEF_INCLUDE_CEF_REQUEST_CONTEXT_HANDLER_H_
#define CEF_INCLUDE_CEF_REQUEST_CONTEXT_HANDLER_H_
#pragma once
#include "include/cef_base.h"
#include "include/cef_cookie.h"
///
// Implement this interface to provide handler implementations.
///
/*--cef(source=client,no_debugct_check)--*/
class CefRequestContextHandler : public virtual CefBase {
public:
///
// Called on the IO thread to retrieve the cookie manager. The global cookie
// manager will be used if this method returns NULL.
///
/*--cef()--*/
virtual CefRefPtr<CefCookieManager> GetCookieManager() { return NULL; }
};
#endif // CEF_INCLUDE_CEF_REQUEST_CONTEXT_HANDLER_H_

View File

@ -41,7 +41,6 @@
#include "include/cef_auth_callback.h"
#include "include/cef_base.h"
#include "include/cef_browser.h"
#include "include/cef_cookie.h"
#include "include/cef_frame.h"
#include "include/cef_resource_handler.h"
#include "include/cef_response.h"
@ -164,17 +163,6 @@ class CefRequestHandler : public virtual CefBase {
return false;
}
///
// Called on the IO thread to retrieve the cookie manager. |main_url| is the
// URL of the top-level frame. Cookies managers can be unique per browser or
// shared across multiple browsers. The global cookie manager will be used if
// this method returns NULL.
///
/*--cef()--*/
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefBrowser> browser,
const CefString& main_url) { return NULL; }
///
// Called on the UI thread to handle requests for URLs with an unknown
// protocol component. Set |allow_os_execution| to true to attempt execution

View File

@ -1,73 +1,22 @@
// Copyright (c) 2011 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.
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_
#pragma once
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
#include "net/url_request/url_request_job_factory.h"
namespace content {
class DownloadManagerDelegate;
class SpeechRecognitionPreferences;
}
class CefDownloadManagerDelegate;
class CefURLRequestContextGetter;
class CefBrowserContext : public content::BrowserContext {
public:
CefBrowserContext();
virtual ~CefBrowserContext();
// BrowserContext methods.
virtual base::FilePath GetPath() const OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter*
GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) OVERRIDE;
virtual void RequestMIDISysExPermission(
int render_process_id,
int render_view_id,
const GURL& requesting_frame,
const MIDISysExPermissionCallback& callback) OVERRIDE;
virtual content::ResourceContext* GetResourceContext() OVERRIDE;
virtual content::GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers);
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
virtual net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers) = 0;
virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers);
private:
class CefResourceContext;
scoped_ptr<CefResourceContext> resource_context_;
scoped_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<CefURLRequestContextGetter> url_request_getter_;
scoped_refptr<content::GeolocationPermissionContext>
geolocation_permission_context_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContext);
content::ProtocolHandlerMap* protocol_handlers) = 0;
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_context_impl.h"
#include <map>
@ -157,7 +157,7 @@ class CefGeolocationPermissionContext
} // namespace
class CefBrowserContext::CefResourceContext : public content::ResourceContext {
class CefBrowserContextImpl::CefResourceContext : public content::ResourceContext {
public:
CefResourceContext() : getter_(NULL) {}
virtual ~CefResourceContext() {}
@ -188,11 +188,11 @@ class CefBrowserContext::CefResourceContext : public content::ResourceContext {
DISALLOW_COPY_AND_ASSIGN(CefResourceContext);
};
CefBrowserContext::CefBrowserContext()
CefBrowserContextImpl::CefBrowserContextImpl()
: resource_context_(new CefResourceContext) {
}
CefBrowserContext::~CefBrowserContext() {
CefBrowserContextImpl::~CefBrowserContextImpl() {
// Delete the download manager delegate here because otherwise we'll crash
// when it's accessed from the content::BrowserContext destructor.
if (download_manager_delegate_.get())
@ -204,16 +204,16 @@ CefBrowserContext::~CefBrowserContext() {
}
}
base::FilePath CefBrowserContext::GetPath() const {
base::FilePath CefBrowserContextImpl::GetPath() const {
return _Context->cache_path();
}
bool CefBrowserContext::IsOffTheRecord() const {
bool CefBrowserContextImpl::IsOffTheRecord() const {
return false;
}
content::DownloadManagerDelegate*
CefBrowserContext::GetDownloadManagerDelegate() {
CefBrowserContextImpl::GetDownloadManagerDelegate() {
DCHECK(!download_manager_delegate_.get());
content::DownloadManager* manager = BrowserContext::GetDownloadManager(this);
@ -221,40 +221,36 @@ content::DownloadManagerDelegate*
return download_manager_delegate_.get();
}
net::URLRequestContextGetter* CefBrowserContext::GetRequestContext() {
net::URLRequestContextGetter* CefBrowserContextImpl::GetRequestContext() {
CEF_REQUIRE_UIT();
return GetDefaultStoragePartition(this)->GetURLRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContext::GetRequestContextForRenderProcess(
int renderer_child_id) {
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::GetBrowserByChildID(renderer_child_id);
if (browser.get())
return browser->GetRequestContext();
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContext::GetMediaRequestContext() {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContext::GetMediaRequestContextForRenderProcess(
CefBrowserContextImpl::GetRequestContextForRenderProcess(
int renderer_child_id) {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContext::GetMediaRequestContextForStoragePartition(
CefBrowserContextImpl::GetMediaRequestContext() {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContextImpl::GetMediaRequestContextForRenderProcess(
int renderer_child_id) {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContextImpl::GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) {
return GetRequestContext();
}
void CefBrowserContext::RequestMIDISysExPermission(
void CefBrowserContextImpl::RequestMIDISysExPermission(
int render_process_id,
int render_view_id,
const GURL& requesting_frame,
@ -263,12 +259,12 @@ void CefBrowserContext::RequestMIDISysExPermission(
callback.Run(false);
}
content::ResourceContext* CefBrowserContext::GetResourceContext() {
content::ResourceContext* CefBrowserContextImpl::GetResourceContext() {
return resource_context_.get();
}
content::GeolocationPermissionContext*
CefBrowserContext::GetGeolocationPermissionContext() {
CefBrowserContextImpl::GetGeolocationPermissionContext() {
if (!geolocation_permission_context_) {
geolocation_permission_context_ =
new CefGeolocationPermissionContext();
@ -276,11 +272,11 @@ content::GeolocationPermissionContext*
return geolocation_permission_context_;
}
quota::SpecialStoragePolicy* CefBrowserContext::GetSpecialStoragePolicy() {
quota::SpecialStoragePolicy* CefBrowserContextImpl::GetSpecialStoragePolicy() {
return NULL;
}
net::URLRequestContextGetter* CefBrowserContext::CreateRequestContext(
net::URLRequestContextGetter* CefBrowserContextImpl::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers) {
DCHECK(!url_request_getter_);
url_request_getter_ = new CefURLRequestContextGetter(
@ -292,7 +288,7 @@ net::URLRequestContextGetter* CefBrowserContext::CreateRequestContext(
}
net::URLRequestContextGetter*
CefBrowserContext::CreateRequestContextForStoragePartition(
CefBrowserContextImpl::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers) {

View File

@ -0,0 +1,72 @@
// Copyright (c) 2011 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.
#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_
#pragma once
#include "libcef/browser/browser_context.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
namespace content {
class DownloadManagerDelegate;
class SpeechRecognitionPreferences;
}
class CefDownloadManagerDelegate;
class CefURLRequestContextGetter;
class CefBrowserContextImpl : public CefBrowserContext {
public:
CefBrowserContextImpl();
virtual ~CefBrowserContextImpl();
// BrowserContext methods.
virtual base::FilePath GetPath() const OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter*
GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) OVERRIDE;
virtual void RequestMIDISysExPermission(
int render_process_id,
int render_view_id,
const GURL& requesting_frame,
const MIDISysExPermissionCallback& callback) OVERRIDE;
virtual content::ResourceContext* GetResourceContext() OVERRIDE;
virtual content::GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
// CefBrowserContext methods.
virtual net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
private:
class CefResourceContext;
scoped_ptr<CefResourceContext> resource_context_;
scoped_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<CefURLRequestContextGetter> url_request_getter_;
scoped_refptr<content::GeolocationPermissionContext>
geolocation_permission_context_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContextImpl);
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_

View File

@ -0,0 +1,154 @@
// 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/browser_context_proxy.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/download_manager_delegate.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_context_getter.h"
#include "libcef/browser/url_request_context_getter_proxy.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/threading/thread.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/storage_partition.h"
using content::BrowserThread;
class CefBrowserContextProxy::CefResourceContext : public content::ResourceContext {
public:
CefResourceContext() : getter_(NULL) {}
virtual ~CefResourceContext() {}
// ResourceContext implementation:
virtual net::HostResolver* GetHostResolver() OVERRIDE {
CHECK(getter_);
return getter_->GetHostResolver();
}
virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
CHECK(getter_);
return getter_->GetURLRequestContext();
}
virtual bool AllowMicAccess(const GURL& origin) OVERRIDE {
return true;
}
virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE {
return true;
}
void set_url_request_context_getter(CefURLRequestContextGetterProxy* getter) {
getter_ = getter;
}
private:
CefURLRequestContextGetterProxy* getter_;
DISALLOW_COPY_AND_ASSIGN(CefResourceContext);
};
CefBrowserContextProxy::CefBrowserContextProxy(
CefRefPtr<CefRequestContextHandler> handler,
CefBrowserContext* parent)
: refct_(0),
handler_(handler),
parent_(parent),
resource_context_(new CefResourceContext) {
}
CefBrowserContextProxy::~CefBrowserContextProxy() {
if (resource_context_.get()) {
BrowserThread::DeleteSoon(
BrowserThread::IO, FROM_HERE, resource_context_.release());
}
}
base::FilePath CefBrowserContextProxy::GetPath() const {
return parent_->GetPath();
}
bool CefBrowserContextProxy::IsOffTheRecord() const {
return parent_->IsOffTheRecord();
}
content::DownloadManagerDelegate*
CefBrowserContextProxy::GetDownloadManagerDelegate() {
DCHECK(!download_manager_delegate_.get());
content::DownloadManager* manager = BrowserContext::GetDownloadManager(this);
download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager));
return download_manager_delegate_.get();
}
net::URLRequestContextGetter* CefBrowserContextProxy::GetRequestContext() {
CEF_REQUIRE_UIT();
return GetDefaultStoragePartition(this)->GetURLRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContextProxy::GetRequestContextForRenderProcess(
int renderer_child_id) {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContextProxy::GetMediaRequestContext() {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContextProxy::GetMediaRequestContextForRenderProcess(
int renderer_child_id) {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContextProxy::GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) {
return GetRequestContext();
}
void CefBrowserContextProxy::RequestMIDISysExPermission(
int render_process_id,
int render_view_id,
const GURL& requesting_frame,
const MIDISysExPermissionCallback& callback) {
// TODO(CEF): Implement Web MIDI API permission handling.
callback.Run(false);
}
content::ResourceContext* CefBrowserContextProxy::GetResourceContext() {
return resource_context_.get();
}
content::GeolocationPermissionContext*
CefBrowserContextProxy::GetGeolocationPermissionContext() {
return parent_->GetGeolocationPermissionContext();
}
quota::SpecialStoragePolicy* CefBrowserContextProxy::GetSpecialStoragePolicy() {
return parent_->GetSpecialStoragePolicy();
}
net::URLRequestContextGetter* CefBrowserContextProxy::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers) {
DCHECK(!url_request_getter_);
url_request_getter_ =
new CefURLRequestContextGetterProxy(handler_,
static_cast<CefURLRequestContextGetter*>(
CefContentBrowserClient::Get()->request_context().get()));
resource_context_->set_url_request_context_getter(url_request_getter_.get());
return url_request_getter_.get();
}
net::URLRequestContextGetter*
CefBrowserContextProxy::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers) {
return NULL;
}

View File

@ -0,0 +1,83 @@
// Copyright (c) 2011 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.
#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_
#pragma once
#include "include/cef_request_context_handler.h"
#include "libcef/browser/browser_context.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
namespace content {
class DownloadManagerDelegate;
class SpeechRecognitionPreferences;
}
class CefDownloadManagerDelegate;
class CefURLRequestContextGetterProxy;
// This class is only accessed on the UI thread.
class CefBrowserContextProxy : public CefBrowserContext {
public:
CefBrowserContextProxy(CefRefPtr<CefRequestContextHandler> handler,
CefBrowserContext* parent);
virtual ~CefBrowserContextProxy();
// Reference counting and object life span is managed by
// CefContentBrowserClient.
void AddRef() { refct_++; }
bool Release() { return (--refct_ == 0); }
// BrowserContext methods.
virtual base::FilePath GetPath() const OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter*
GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) OVERRIDE;
virtual void RequestMIDISysExPermission(
int render_process_id,
int render_view_id,
const GURL& requesting_frame,
const MIDISysExPermissionCallback& callback) OVERRIDE;
virtual content::ResourceContext* GetResourceContext() OVERRIDE;
virtual content::GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
// CefBrowserContext methods.
virtual net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
CefRefPtr<CefRequestContextHandler> handler() const { return handler_; }
private:
class CefResourceContext;
int refct_;
CefRefPtr<CefRequestContextHandler> handler_;
CefBrowserContext* parent_;
scoped_ptr<CefResourceContext> resource_context_;
scoped_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<CefURLRequestContextGetterProxy> url_request_getter_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContextProxy);
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_

View File

@ -18,10 +18,9 @@
#include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/navigate_params.h"
#include "libcef/browser/render_widget_host_view_osr.h"
#include "libcef/browser/request_context_impl.h"
#include "libcef/browser/scheme_handler.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_context_getter.h"
#include "libcef/browser/url_request_context_getter_proxy.h"
#include "libcef/browser/web_contents_view_osr.h"
#include "libcef/common/cef_messages.h"
#include "libcef/common/cef_switches.h"
@ -57,21 +56,24 @@ class CreateBrowserHelper {
CreateBrowserHelper(const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings)
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context)
: window_info_(windowInfo),
client_(client),
url_(url),
settings_(settings) {}
settings_(settings),
request_context_(request_context) {}
CefWindowInfo window_info_;
CefRefPtr<CefClient> client_;
CefString url_;
CefBrowserSettings settings_;
CefRefPtr<CefRequestContext> request_context_;
};
void CreateBrowserWithHelper(CreateBrowserHelper* helper) {
CefBrowserHost::CreateBrowserSync(helper->window_info_, helper->client_,
helper->url_, helper->settings_);
helper->url_, helper->settings_, helper->request_context_);
delete helper;
}
@ -215,10 +217,12 @@ class CefRunFileDialogCallbackWrapper
// -----------------------------------------------------------------------------
// static
bool CefBrowserHost::CreateBrowser(const CefWindowInfo& windowInfo,
bool CefBrowserHost::CreateBrowser(
const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings) {
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context) {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
@ -248,7 +252,8 @@ bool CefBrowserHost::CreateBrowser(const CefWindowInfo& windowInfo,
// Create the browser on the UI thread.
CreateBrowserHelper* helper =
new CreateBrowserHelper(windowInfo, client, url, new_settings);
new CreateBrowserHelper(windowInfo, client, url, new_settings,
request_context);
CEF_POST_TASK(CEF_UIT, base::Bind(CreateBrowserWithHelper, helper));
return true;
@ -259,7 +264,8 @@ CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings) {
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context) {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
@ -304,7 +310,7 @@ CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
DCHECK(!info->is_popup());
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::Create(windowInfo, new_settings, client, NULL, info,
NULL);
NULL, request_context);
if (!url.empty()) {
browser->LoadURL(CefFrameHostImpl::kMainFrameId, url, content::Referrer(),
content::PAGE_TRANSITION_TYPED, std::string());
@ -326,16 +332,27 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
CefRefPtr<CefClient> client,
content::WebContents* web_contents,
scoped_refptr<CefBrowserInfo> browser_info,
CefWindowHandle opener) {
CefWindowHandle opener,
CefRefPtr<CefRequestContext> request_context) {
CEF_REQUIRE_UIT();
DCHECK(browser_info.get());
// If |opener| is non-NULL it must be a popup window.
DCHECK(opener == NULL || browser_info->is_popup());
if (web_contents == NULL) {
if (!web_contents) {
CefBrowserContext* browser_context = NULL;
if (request_context.get()) {
CefRequestContextImpl* request_context_impl =
static_cast<CefRequestContextImpl*>(request_context.get());
browser_context = request_context_impl->GetOrCreateBrowserContext();
} else {
browser_context = CefContentBrowserClient::Get()->browser_context();
}
DCHECK(browser_context);
content::WebContents::CreateParams create_params(
_Context->browser_context());
browser_context);
web_contents = content::WebContents::Create(create_params);
}
@ -347,14 +364,6 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
return NULL;
}
if (browser->IsWindowRenderingDisabled()) {
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents->GetRenderViewHost()->GetView());
if (view)
view->set_browser_impl(browser);
}
if (client.get()) {
CefRefPtr<CefLifeSpanHandler> handler = client->GetLifeSpanHandler();
if (handler.get())
@ -417,28 +426,19 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::GetBrowserByRoutingID(
return GetBrowserForHost(render_view_host);
} else {
// Use the thread-safe approach.
return _Context->GetBrowserByRoutingID(render_process_id, render_view_id);
scoped_refptr<CefBrowserInfo> info =
CefContentBrowserClient::Get()->GetBrowserInfo(render_process_id,
render_view_id);
if (info.get()) {
CefRefPtr<CefBrowserHostImpl> browser = info->browser();
if (!browser.get()) {
LOG(WARNING) << "Found browser id " << info->browser_id() <<
" but no browser object matching process id " <<
render_process_id << " and view id " << render_view_id;
}
}
// static
CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::GetBrowserByChildID(
int render_process_id) {
if (CEF_CURRENTLY_ON_UIT()) {
// Use the non-thread-safe but potentially faster approach.
content::RenderWidgetHost::List widgets =
content::RenderWidgetHost::GetRenderWidgetHosts();
for (size_t i = 0; i < widgets.size(); ++i) {
if (widgets[i]->GetProcess()->GetID() == render_process_id &&
widgets[i]->IsRenderView()) {
return GetBrowserForHost(content::RenderViewHost::From(widgets[i]));
return browser;
}
}
return NULL;
} else {
// Use the thread-safe approach.
return _Context->GetBrowserByRoutingID(render_process_id, -1);
}
}
@ -504,6 +504,10 @@ CefRefPtr<CefClient> CefBrowserHostImpl::GetClient() {
return client_;
}
CefRefPtr<CefRequestContext> CefBrowserHostImpl::GetRequestContext() {
return request_context_;
}
CefString CefBrowserHostImpl::GetDevToolsURL(bool http_scheme) {
base::AutoLock lock_scope(state_lock_);
return (http_scheme ? devtools_url_http_ : devtools_url_chrome_);
@ -583,7 +587,8 @@ void CefBrowserHostImpl::StartDownload(const CefString& url) {
if (!web_contents())
return;
CefBrowserContext* context = _Context->browser_context();
CefBrowserContext* context =
static_cast<CefBrowserContext*>(web_contents()->GetBrowserContext());
if (!context)
return;
@ -1103,8 +1108,6 @@ void CefBrowserHostImpl::DestroyBrowser() {
DetachAllFrames();
request_context_proxy_ = NULL;
CefContentBrowserClient::Get()->RemoveBrowserInfo(browser_info_);
browser_info_->set_browser(NULL);
}
@ -1121,17 +1124,6 @@ content::WebContents* CefBrowserHostImpl::GetWebContents() const {
return web_contents_.get();
}
net::URLRequestContextGetter* CefBrowserHostImpl::GetRequestContext() {
CEF_REQUIRE_UIT();
if (!request_context_proxy_) {
request_context_proxy_ =
new CefURLRequestContextGetterProxy(this,
static_cast<CefURLRequestContextGetter*>(
_Context->request_context().get()));
}
return request_context_proxy_.get();
}
CefRefPtr<CefFrame> CefBrowserHostImpl::GetFrameForRequest(
net::URLRequest* request) {
CEF_REQUIRE_IOT();
@ -1695,7 +1687,7 @@ void CefBrowserHostImpl::WebContentsCreated(
CefRefPtr<CefBrowserHostImpl> browser = CefBrowserHostImpl::Create(
pending_popup_info->window_info, pending_popup_info->settings,
pending_popup_info->client, new_contents, info, opener);
pending_popup_info->client, new_contents, info, opener, NULL);
}
void CefBrowserHostImpl::DidNavigateMainFramePostCommit(
@ -1774,7 +1766,7 @@ void CefBrowserHostImpl::RequestMediaAccessPermission(
case content::MEDIA_ENUMERATE_DEVICES:
// Get the default devices for the request.
CefMediaCaptureDevicesDispatcher::GetInstance()->
GetDefaultDevices(_Context->pref_service(),
GetDefaultDevices(CefContentBrowserClient::Get()->pref_service(),
microphone_requested,
webcam_requested,
&devices);
@ -1795,7 +1787,8 @@ void CefBrowserHostImpl::RenderViewCreated(
render_view_host->GetRoutingID());
// Update the DevTools URLs, if any.
CefDevToolsDelegate* devtools_delegate = _Context->devtools_delegate();
CefDevToolsDelegate* devtools_delegate =
CefContentBrowserClient::Get()->devtools_delegate();
if (devtools_delegate) {
base::AutoLock lock_scope(state_lock_);
devtools_url_http_ =
@ -2096,6 +2089,10 @@ CefBrowserHostImpl::CefBrowserHostImpl(
web_contents_.reset(web_contents);
web_contents->SetDelegate(this);
CefBrowserContext* browser_context =
static_cast<CefBrowserContext*>(web_contents->GetBrowserContext());
request_context_ = new CefRequestContextImpl(browser_context);
registrar_.reset(new content::NotificationRegistrar);
registrar_->Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
content::Source<content::WebContents>(web_contents));
@ -2118,6 +2115,14 @@ CefBrowserHostImpl::CefBrowserHostImpl(
// Make sure RenderViewCreated is called at least one time.
RenderViewCreated(web_contents->GetRenderViewHost());
if (IsWindowRenderingDisabled()) {
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents->GetRenderViewHost()->GetView());
if (view)
view->set_browser_impl(this);
}
}
CefRefPtr<CefFrame> CefBrowserHostImpl::GetOrCreateFrame(

View File

@ -29,7 +29,6 @@
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/file_chooser_params.h"
#include "net/url_request/url_request_context_getter.h"
namespace content {
struct NativeWebKeyboardEvent;
@ -87,7 +86,8 @@ class CefBrowserHostImpl : public CefBrowserHost,
CefRefPtr<CefClient> client,
content::WebContents* web_contents,
scoped_refptr<CefBrowserInfo> browser_info,
CefWindowHandle opener);
CefWindowHandle opener,
CefRefPtr<CefRequestContext> request_context);
// Returns the browser associated with the specified RenderViewHost.
static CefRefPtr<CefBrowserHostImpl> GetBrowserForHost(
@ -101,11 +101,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
// Returns the browser associated with the specified routing IDs.
static CefRefPtr<CefBrowserHostImpl> GetBrowserByRoutingID(
int render_process_id, int render_view_id);
// Returns the first browser associated with the specified child process ID.
// There may be multiple browsers using the same render process so this method
// should be used with caution.
static CefRefPtr<CefBrowserHostImpl> GetBrowserByChildID(
int render_process_id);
// Returns true if window rendering is disabled in CefWindowInfo.
static bool IsWindowRenderingDisabled(const CefWindowInfo& info);
@ -118,6 +113,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
virtual CefWindowHandle GetWindowHandle() OVERRIDE;
virtual CefWindowHandle GetOpenerWindowHandle() OVERRIDE;
virtual CefRefPtr<CefClient> GetClient() OVERRIDE;
virtual CefRefPtr<CefRequestContext> GetRequestContext() OVERRIDE;
virtual CefString GetDevToolsURL(bool http_scheme) OVERRIDE;
virtual double GetZoomLevel() OVERRIDE;
virtual void SetZoomLevel(double zoomLevel) OVERRIDE;
@ -190,9 +186,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
// Returns a pointer to the WebContents.
content::WebContents* GetWebContents() const;
// Returns the browser-specific request context.
net::URLRequestContextGetter* GetRequestContext();
// Returns the frame associated with the specified URLRequest.
CefRefPtr<CefFrame> GetFrameForRequest(net::URLRequest* request);
@ -487,6 +480,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
scoped_ptr<content::WebContents> web_contents_;
scoped_refptr<CefBrowserInfo> browser_info_;
CefWindowHandle opener_;
CefRefPtr<CefRequestContext> request_context_;
// Pending popup information. Access must be protected by
// |pending_popup_info_lock_|.
@ -541,9 +535,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
// Used for managing notification subscriptions.
scoped_ptr<content::NotificationRegistrar> registrar_;
// Used for proxying cookie requests.
scoped_refptr<net::URLRequestContextGetter> request_context_proxy_;
// Manages response registrations.
scoped_ptr<CefResponseManager> response_manager_;

View File

@ -6,9 +6,9 @@
#include <string>
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_message_loop.h"
#include "libcef/browser/context.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/devtools_delegate.h"
#include "libcef/common/net_resource_provider.h"
@ -81,7 +81,8 @@ int CefBrowserMainParts::PreCreateThreads() {
}
void CefBrowserMainParts::PreMainMessageLoopRun() {
browser_context_.reset(new CefBrowserContext());
// Create the global browser context.
global_browser_context_.reset(new CefBrowserContextImpl());
// Initialize the proxy configuration service. This needs to occur before
// CefURLRequestContextGetter::GetURLRequestContext() is called for the
@ -92,7 +93,7 @@ void CefBrowserMainParts::PreMainMessageLoopRun() {
// Initialize the request context getter. This indirectly triggers a call
// to CefURLRequestContextGetter::GetURLRequestContext() on the IO thread.
_Context->set_request_context(browser_context_->GetRequestContext());
global_request_context_ = global_browser_context_->GetRequestContext();
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
@ -111,8 +112,13 @@ void CefBrowserMainParts::PostMainMessageLoopRun() {
if (devtools_delegate_)
devtools_delegate_->Stop();
pref_proxy_config_tracker_->DetachFromPrefService();
_Context->set_request_context(NULL);
browser_context_.reset();
// Only the global browser context should still exist.
DCHECK(browser_contexts_.empty());
browser_contexts_.clear();
global_request_context_ = NULL;
global_browser_context_.reset();
}
void CefBrowserMainParts::PostDestroyThreads() {
@ -125,3 +131,19 @@ void CefBrowserMainParts::PostDestroyThreads() {
PlatformCleanup();
}
void CefBrowserMainParts::AddBrowserContext(CefBrowserContext* context) {
browser_contexts_.push_back(context);
}
void CefBrowserMainParts::RemoveBrowserContext(CefBrowserContext* context) {
ScopedVector<CefBrowserContext>::iterator it = browser_contexts_.begin();
for (; it != browser_contexts_.end(); ++it) {
if (*it == context) {
browser_contexts_.erase(it);
return;
}
}
NOTREACHED();
}

View File

@ -10,11 +10,13 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_piece.h"
#include "chrome/browser/net/pref_proxy_config_tracker.h"
#include "content/public/browser/browser_main_parts.h"
#include "net/proxy/proxy_config_service.h"
#include "net/url_request/url_request_context_getter.h"
namespace base {
class MessageLoop;
@ -44,18 +46,30 @@ class CefBrowserMainParts : public content::BrowserMainParts {
virtual void PostMainMessageLoopRun() OVERRIDE;
virtual void PostDestroyThreads() OVERRIDE;
CefBrowserContext* browser_context() const { return browser_context_.get(); }
CefDevToolsDelegate* devtools_delegate() const { return devtools_delegate_.get(); }
CefBrowserContext* browser_context() const {
return global_browser_context_.get();
}
scoped_refptr<net::URLRequestContextGetter> request_context() const {
return global_request_context_;
}
CefDevToolsDelegate* devtools_delegate() const {
return devtools_delegate_.get();
}
PrefService* pref_service() const { return pref_service_.get(); }
scoped_ptr<net::ProxyConfigService> proxy_config_service() {
return proxy_config_service_.Pass();
}
void AddBrowserContext(CefBrowserContext* context);
void RemoveBrowserContext(CefBrowserContext* context);
private:
void PlatformInitialize();
void PlatformCleanup();
scoped_ptr<CefBrowserContext> browser_context_;
scoped_ptr<CefBrowserContext> global_browser_context_;
scoped_refptr<net::URLRequestContextGetter> global_request_context_;
ScopedVector<CefBrowserContext> browser_contexts_;
scoped_ptr<CefDevToolsDelegate> devtools_delegate_;
scoped_ptr<base::MessageLoop> message_loop_;
scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;

View File

@ -12,6 +12,7 @@
#include "libcef/browser/origin_whitelist_impl.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/cef_messages.h"
#include "libcef/common/content_client.h"
#include "libcef/common/values_impl.h"
#include "base/compiler_specific.h"
@ -61,7 +62,7 @@ void CefBrowserMessageFilter::OnGetNewRenderThreadInfo(
CefProcessHostMsg_GetNewRenderThreadInfo_Params* params) {
GetCrossOriginWhitelistEntries(&params->cross_origin_whitelist_entries);
CefRefPtr<CefApp> app = _Context->application();
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
if (app.get()) {
CefRefPtr<CefBrowserProcessHandler> handler =
app->GetBrowserProcessHandler();

View File

@ -7,7 +7,7 @@
#include <string>
#include "libcef/browser/browser_context.h"
#include "libcef/browser/context.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_user_data.h"
#include "libcef/common/http_header_utils.h"
@ -119,7 +119,8 @@ class CefBrowserURLRequest::Context
fetcher_.reset(net::URLFetcher::Create(url, request_type,
fetcher_delegate_.get()));
fetcher_->SetRequestContext(_Context->request_context());
fetcher_->SetRequestContext(
CefContentBrowserClient::Get()->request_context());
CefRequest::HeaderMap headerMap;
request_->GetHeaderMap(headerMap);

View File

@ -7,13 +7,13 @@
#include <algorithm>
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_context_proxy.h"
#include "libcef/browser/browser_info.h"
#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"
#include "libcef/browser/chrome_scheme_handler.h"
#include "libcef/browser/context.h"
#include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/resource_dispatcher_host_delegate.h"
#include "libcef/browser/speech_recognition_manager_delegate.h"
@ -51,7 +51,8 @@ class CefAccessTokenStore : public content::AccessTokenStore {
virtual void LoadAccessTokens(
const LoadAccessTokensCallbackType& callback) OVERRIDE {
callback.Run(access_token_set_, _Context->request_context());
callback.Run(access_token_set_,
CefContentBrowserClient::Get()->request_context());
}
virtual void SaveAccessToken(
@ -394,6 +395,39 @@ scoped_refptr<CefBrowserInfo> CefContentBrowserClient::GetBrowserInfo(
return scoped_refptr<CefBrowserInfo>();
}
CefBrowserContext* CefContentBrowserClient::CreateBrowserContextProxy(
CefRefPtr<CefRequestContextHandler> handler) {
CEF_REQUIRE_UIT();
CefBrowserContextProxy* context =
new CefBrowserContextProxy(handler, browser_context());
browser_main_parts_->AddBrowserContext(context);
context->AddRef();
return context;
}
void CefContentBrowserClient::AddBrowserContextReference(
CefBrowserContext* context) {
CEF_REQUIRE_UIT();
// Skip the global browser context.
if (context == browser_context())
return;
CefBrowserContextProxy* proxy = static_cast<CefBrowserContextProxy*>(context);
proxy->AddRef();
}
void CefContentBrowserClient::RemoveBrowserContextReference(
CefBrowserContext* context) {
CEF_REQUIRE_UIT();
// Skip the global browser context.
if (context == browser_context())
return;
CefBrowserContextProxy* proxy = static_cast<CefBrowserContextProxy*>(context);
if (proxy->Release())
browser_main_parts_->RemoveBrowserContext(proxy);
}
content::BrowserMainParts* CefContentBrowserClient::CreateBrowserMainParts(
const content::MainFunctionParams& parameters) {
browser_main_parts_ = new CefBrowserMainParts(parameters);
@ -420,13 +454,15 @@ CefContentBrowserClient::OverrideCreateWebContentsView(
void CefContentBrowserClient::RenderProcessHostCreated(
content::RenderProcessHost* host) {
host->GetChannel()->AddFilter(new CefBrowserMessageFilter(host));
AddBrowserContextReference(
static_cast<CefBrowserContext*>(host->GetBrowserContext()));
}
net::URLRequestContextGetter* CefContentBrowserClient::CreateRequestContext(
content::BrowserContext* content_browser_context,
content::ProtocolHandlerMap* protocol_handlers) {
CefBrowserContext* cef_browser_context =
CefBrowserContextForBrowserContext(content_browser_context);
static_cast<CefBrowserContext*>(content_browser_context);
return cef_browser_context->CreateRequestContext(protocol_handlers);
}
@ -437,7 +473,7 @@ CefContentBrowserClient::CreateRequestContextForStoragePartition(
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers) {
CefBrowserContext* cef_browser_context =
CefBrowserContextForBrowserContext(content_browser_context);
static_cast<CefBrowserContext*>(content_browser_context);
return cef_browser_context->CreateRequestContextForStoragePartition(
partition_path, in_memory, protocol_handlers);
}
@ -501,7 +537,7 @@ void CefContentBrowserClient::AppendExtraCommandLineSwitches(
}
#endif // defined(OS_LINUX)
CefRefPtr<CefApp> app = _Context->application();
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
if (app.get()) {
CefRefPtr<CefBrowserProcessHandler> handler =
app->GetBrowserProcessHandler();
@ -756,9 +792,24 @@ void CefContentBrowserClient::set_last_create_window_params(
last_create_window_params_ = params;
}
CefBrowserContext*
CefContentBrowserClient::CefBrowserContextForBrowserContext(
content::BrowserContext* content_browser_context) {
DCHECK_EQ(content_browser_context, browser_main_parts_->browser_context());
CefBrowserContext* CefContentBrowserClient::browser_context() const {
return browser_main_parts_->browser_context();
}
scoped_refptr<net::URLRequestContextGetter>
CefContentBrowserClient::request_context() const {
return browser_main_parts_->request_context();
}
CefDevToolsDelegate* CefContentBrowserClient::devtools_delegate() const {
return browser_main_parts_->devtools_delegate();
}
PrefService* CefContentBrowserClient::pref_service() const {
return browser_main_parts_->pref_service();
}
scoped_ptr<net::ProxyConfigService>
CefContentBrowserClient::proxy_config_service() const {
return browser_main_parts_->proxy_config_service();
}

View File

@ -12,17 +12,23 @@
#include <string>
#include <utility>
#include "include/cef_request_context_handler.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
#include "content/public/browser/content_browser_client.h"
#include "net/proxy/proxy_config_service.h"
#include "net/url_request/url_request_context_getter.h"
#include "url/gurl.h"
class CefBrowserContext;
class CefBrowserInfo;
class CefBrowserMainParts;
class CefDevToolsDelegate;
class CefResourceDispatcherHostDelegate;
class PrefService;
namespace content {
class PluginServiceFilter;
@ -37,10 +43,6 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
// Returns the singleton CefContentBrowserClient instance.
static CefContentBrowserClient* Get();
CefBrowserMainParts* browser_main_parts() const {
return browser_main_parts_;
}
// Methods for managing CefBrowserInfo life span. Do not add new callers of
// these methods.
// During popup window creation there is a race between the call to
@ -56,10 +58,22 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
// Retrieves the CefBrowserInfo matching the specified IDs or an empty
// pointer if no match is found. It is allowed to add new callers of this
// method but consider using CefContext::GetBrowserByRoutingID() instead.
// method but consider using CefBrowserHostImpl::GetBrowserByRoutingID()
// instead.
scoped_refptr<CefBrowserInfo> GetBrowserInfo(int render_process_id,
int render_view_id);
// Create and return a new CefBrowserContextProxy object.
CefBrowserContext* CreateBrowserContextProxy(
CefRefPtr<CefRequestContextHandler> handler);
// BrowserContexts are nominally owned by RenderViewHosts and
// CefRequestContextImpls. Keep track of how many objects reference a given
// context and delete the context when the reference count reaches zero.
void AddBrowserContextReference(CefBrowserContext* context);
void RemoveBrowserContextReference(CefBrowserContext* context);
// ContentBrowserClient implementation.
virtual content::BrowserMainParts* CreateBrowserMainParts(
const content::MainFunctionParams& parameters) OVERRIDE;
virtual content::WebContentsViewPort* OverrideCreateWebContentsView(
@ -145,10 +159,15 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
return use_osr_next_contents_view_;
}
private:
CefBrowserContext* CefBrowserContextForBrowserContext(
content::BrowserContext* content_browser_context);
CefBrowserContext* browser_context() const;
scoped_refptr<net::URLRequestContextGetter> request_context() const;
CefDevToolsDelegate* devtools_delegate() const;
PrefService* pref_service() const;
// Passes ownership.
scoped_ptr<net::ProxyConfigService> proxy_config_service() const;
private:
CefBrowserMainParts* browser_main_parts_;
scoped_ptr<content::PluginServiceFilter> plugin_service_filter_;

View File

@ -21,6 +21,8 @@
#include "base/synchronization/waitable_event.h"
#include "content/public/app/content_main.h"
#include "content/public/app/content_main_runner.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_switches.h"
#include "ui/base/ui_base_switches.h"
@ -284,46 +286,6 @@ bool CefContext::OnInitThread() {
return (base::PlatformThread::CurrentId() == init_thread_id_);
}
CefRefPtr<CefBrowserHostImpl> CefContext::GetBrowserByRoutingID(
int render_process_id, int render_view_id) {
scoped_refptr<CefBrowserInfo> info =
CefContentBrowserClient::Get()->GetBrowserInfo(render_process_id,
render_view_id);
if (info.get()) {
CefRefPtr<CefBrowserHostImpl> browser = info->browser();
if (!browser.get()) {
LOG(WARNING) << "Found browser id " << info->browser_id() <<
" but no browser object matching process id " <<
render_process_id << " and view id " << render_view_id;
}
return browser;
}
return NULL;
}
CefRefPtr<CefApp> CefContext::application() const {
return main_delegate_->content_client()->application();
}
CefBrowserContext* CefContext::browser_context() const {
return main_delegate_->browser_client()->browser_main_parts()->
browser_context();
}
CefDevToolsDelegate* CefContext::devtools_delegate() const {
return main_delegate_->browser_client()->browser_main_parts()->
devtools_delegate();
}
scoped_ptr<net::ProxyConfigService> CefContext::proxy_config_service() const {
return main_delegate_->browser_client()->browser_main_parts()->
proxy_config_service();
}
PrefService* CefContext::pref_service() const {
return main_delegate_->browser_client()->browser_main_parts()->pref_service();
}
CefTraceSubscriber* CefContext::GetTraceSubscriber() {
CEF_REQUIRE_UIT();
if (shutting_down_)
@ -339,8 +301,15 @@ void CefContext::OnContextInitialized() {
// Register internal scheme handlers.
scheme::RegisterInternalHandlers();
// Register for notifications.
registrar_.reset(new content::NotificationRegistrar());
registrar_->Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::NotificationService::AllBrowserContextsAndSources());
registrar_->Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
content::NotificationService::AllBrowserContextsAndSources());
// Notify the handler.
CefRefPtr<CefApp> app = application();
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
if (app.get()) {
CefRefPtr<CefBrowserProcessHandler> handler =
app->GetBrowserProcessHandler();
@ -355,6 +324,8 @@ void CefContext::FinishShutdownOnUIThread(
CefContentBrowserClient::Get()->DestroyAllBrowsers();
registrar_.reset();
if (trace_subscriber_.get())
trace_subscriber_.reset(NULL);
@ -377,3 +348,16 @@ void CefContext::FinalizeShutdown() {
main_runner_.reset(NULL);
main_delegate_.reset(NULL);
}
void CefContext::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED ||
type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED);
content::RenderProcessHost* rph =
content::Source<content::RenderProcessHost>(source).ptr();
DCHECK(rph);
CefContentBrowserClient::Get()->RemoveBrowserContextReference(
static_cast<CefBrowserContext*>(rph->GetBrowserContext()));
}

View File

@ -17,8 +17,8 @@
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/platform_thread.h"
#include "net/proxy/proxy_config_service.h"
#include "net/url_request/url_request_context_getter.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
namespace base {
class WaitableEvent;
@ -28,14 +28,12 @@ namespace content {
class ContentMainRunner;
}
class CefBrowserContext;
class CefBrowserHostImpl;
class CefDevToolsDelegate;
class CefMainDelegate;
class CefTraceSubscriber;
class PrefService;
class CefContext : public CefBase {
class CefContext : public CefBase,
public content::NotificationObserver {
public:
typedef std::list<CefRefPtr<CefBrowserHostImpl> > BrowserList;
@ -57,28 +55,10 @@ class CefContext : public CefBase {
// Returns true if the context is shutting down.
bool shutting_down() { return shutting_down_; }
CefRefPtr<CefBrowserHostImpl> GetBrowserByRoutingID(int render_process_id,
int render_view_id);
// Retrieve the path at which cache data will be stored on disk. If empty,
// cache data will be stored in-memory.
// Retrieve the path at which cache data will be stored on disk.
const base::FilePath& cache_path() const { return cache_path_; }
const CefSettings& settings() const { return settings_; }
CefRefPtr<CefApp> application() const;
CefBrowserContext* browser_context() const;
CefDevToolsDelegate* devtools_delegate() const;
PrefService* pref_service() const;
scoped_refptr<net::URLRequestContextGetter> request_context() const {
return request_context_;
}
void set_request_context(scoped_refptr<net::URLRequestContextGetter> context) {
request_context_ = context;
}
// Passes ownership.
scoped_ptr<net::ProxyConfigService> proxy_config_service() const;
CefTraceSubscriber* GetTraceSubscriber();
@ -92,6 +72,11 @@ class CefContext : public CefBase {
// Destroys the main runner and related objects.
void FinalizeShutdown();
// NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Track context state.
bool initialized_;
bool shutting_down_;
@ -107,7 +92,8 @@ class CefContext : public CefBase {
scoped_ptr<content::ContentMainRunner> main_runner_;
scoped_ptr<CefTraceSubscriber> trace_subscriber_;
scoped_refptr<net::URLRequestContextGetter> request_context_;
// Only accessed on the UI Thread.
scoped_ptr<content::NotificationRegistrar> registrar_;
IMPLEMENT_REFCOUNTING(CefContext);
IMPLEMENT_LOCKING(CefContext);

View File

@ -9,6 +9,7 @@
#include <vector>
#include "libcef/browser/browser_context.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_context_getter.h"
@ -113,7 +114,7 @@ void CefCookieManagerImpl::SetSupportedSchemes(
// Global changes are handled by the request context.
scoped_refptr<CefURLRequestContextGetter> getter =
static_cast<CefURLRequestContextGetter*>(
_Context->request_context().get());
CefContentBrowserClient::Get()->request_context().get());
std::vector<std::string> scheme_vec;
std::vector<CefString>::const_iterator it = schemes.begin();
@ -267,7 +268,7 @@ bool CefCookieManagerImpl::SetStoragePath(
// Global path changes are handled by the request context.
scoped_refptr<CefURLRequestContextGetter> getter =
static_cast<CefURLRequestContextGetter*>(
_Context->request_context().get());
CefContentBrowserClient::Get()->request_context().get());
getter->SetCookieStoragePath(new_path, persist_session_cookies);
cookie_monster_ = getter->GetURLRequestContext()->cookie_store()->
GetCookieMonster();
@ -348,9 +349,9 @@ bool CefCookieManagerImpl::FlushStore(CefRefPtr<CefCompletionHandler> handler) {
void CefCookieManagerImpl::SetGlobal() {
if (CEF_CURRENTLY_ON_IOT()) {
if (_Context->browser_context()) {
cookie_monster_ = _Context->request_context()->GetURLRequestContext()->
cookie_store()->GetCookieMonster();
if (CefContentBrowserClient::Get()->request_context()) {
cookie_monster_ = CefContentBrowserClient::Get()->request_context()->
GetURLRequestContext()->cookie_store()->GetCookieMonster();
DCHECK(cookie_monster_);
}
} else {

View File

@ -0,0 +1,112 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "libcef/browser/request_context_impl.h"
#include "libcef/browser/browser_context_proxy.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/thread_util.h"
#include "base/atomic_sequence_num.h"
#include "base/logging.h"
namespace {
void RemoveContextRef(CefBrowserContext* browser_context) {
CefContentBrowserClient::Get()->RemoveBrowserContextReference(
browser_context);
}
base::StaticAtomicSequenceNumber g_next_id;
} // namespace
// Static functions
CefRefPtr<CefRequestContext> CefRequestContext::GetGlobalContext() {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return NULL;
}
return new CefRequestContextImpl(
CefContentBrowserClient::Get()->browser_context());
}
CefRefPtr<CefRequestContext> CefRequestContext::CreateContext(
CefRefPtr<CefRequestContextHandler> handler) {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return NULL;
}
return new CefRequestContextImpl(handler);
}
// CefBrowserContextImpl
CefRequestContextImpl::CefRequestContextImpl(
CefBrowserContext* browser_context)
: browser_context_(browser_context),
unique_id_(0) {
DCHECK(browser_context);
if (!IsGlobal()) {
CEF_REQUIRE_UIT();
CefBrowserContextProxy* proxy =
static_cast<CefBrowserContextProxy*>(browser_context);
handler_ = proxy->handler();
CefContentBrowserClient::Get()->AddBrowserContextReference(browser_context);
}
}
CefRequestContextImpl::CefRequestContextImpl(
CefRefPtr<CefRequestContextHandler> handler)
: browser_context_(NULL),
handler_(handler),
unique_id_(g_next_id.GetNext()) {
}
CefRequestContextImpl::~CefRequestContextImpl() {
if (browser_context_) {
if (CEF_CURRENTLY_ON_UIT())
RemoveContextRef(browser_context_);
else
CEF_POST_TASK(CEF_UIT, base::Bind(RemoveContextRef, browser_context_));
}
}
CefBrowserContext* CefRequestContextImpl::GetOrCreateBrowserContext() {
CEF_REQUIRE_UIT();
if (!browser_context_) {
browser_context_ =
CefContentBrowserClient::Get()->CreateBrowserContextProxy(handler_);
}
return browser_context_;
}
bool CefRequestContextImpl::IsSame(CefRefPtr<CefRequestContext> other) {
CefRequestContextImpl* impl =
static_cast<CefRequestContextImpl*>(other.get());
if (!impl)
return false;
// Compare CefBrowserContext points if one has been associated.
if (browser_context_ && impl->browser_context_)
return (browser_context_ == impl->browser_context_);
else if (browser_context_ || impl->browser_context_)
return false;
// Otherwise compare unique IDs.
return (unique_id_ == impl->unique_id_);
}
bool CefRequestContextImpl::IsGlobal() {
return (browser_context_ ==
CefContentBrowserClient::Get()->browser_context());
}
CefRefPtr<CefRequestContextHandler> CefRequestContextImpl::GetHandler() {
return handler_;
}

View File

@ -0,0 +1,37 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_
#define CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_
#pragma once
#include "include/cef_request_context.h"
class CefBrowserContext;
class CefRequestContextImpl : public CefRequestContext {
public:
explicit CefRequestContextImpl(CefBrowserContext* browser_context);
explicit CefRequestContextImpl(CefRefPtr<CefRequestContextHandler> handler);
virtual ~CefRequestContextImpl();
CefBrowserContext* GetOrCreateBrowserContext();
virtual bool IsSame(CefRefPtr<CefRequestContext> other) OVERRIDE;
virtual bool IsGlobal() OVERRIDE;
virtual CefRefPtr<CefRequestContextHandler> GetHandler() OVERRIDE;
protected:
CefBrowserContext* browser_context_;
CefRefPtr<CefRequestContextHandler> handler_;
// Used to uniquely identify CefRequestContext objects before an associated
// CefBrowserContext has been created.
int unique_id_;
IMPLEMENT_REFCOUNTING(CefRequestContextImpl);
DISALLOW_COPY_AND_ASSIGN(CefRequestContextImpl);
};
#endif // CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_

View File

@ -9,6 +9,7 @@
#include "include/cef_scheme.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/resource_request_job.h"
#include "libcef/browser/scheme_handler.h"
@ -195,7 +196,8 @@ class CefUrlRequestManager {
private:
net::URLRequestJobFactoryImpl* GetJobFactoryImpl() {
return static_cast<CefURLRequestContextGetter*>(
_Context->request_context().get())->job_factory_impl();
CefContentBrowserClient::Get()->request_context().get())->
job_factory_impl();
}
// Add or remove the protocol handler if necessary. |scheme| will already be

View File

@ -10,6 +10,7 @@
#include <string>
#include <vector>
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/scheme_handler.h"
#include "libcef/browser/thread_util.h"
@ -107,7 +108,7 @@ net::URLRequestContext* CefURLRequestContextGetter::GetURLRequestContext() {
NULL,
url_request_context_.get(),
url_request_context_->network_delegate(),
_Context->proxy_config_service().release(),
CefContentBrowserClient::Get()->proxy_config_service().release(),
command_line));
storage_->set_proxy_service(system_proxy_service.release());

View File

@ -8,12 +8,11 @@
#include "libcef/browser/url_request_context_proxy.h"
CefURLRequestContextGetterProxy::CefURLRequestContextGetterProxy(
CefBrowserHostImpl* browser,
CefRefPtr<CefRequestContextHandler> handler,
CefURLRequestContextGetter* parent)
: browser_(browser),
: handler_(handler),
parent_(parent),
context_proxy_(NULL) {
DCHECK(browser);
DCHECK(parent);
}
@ -28,7 +27,7 @@ net::URLRequestContext*
CEF_REQUIRE_IOT();
if (!context_proxy_) {
context_proxy_ = parent_->CreateURLRequestContextProxy();
context_proxy_->Initialize(browser_);
context_proxy_->Initialize(handler_);
}
return context_proxy_;
}
@ -37,3 +36,7 @@ scoped_refptr<base::SingleThreadTaskRunner>
CefURLRequestContextGetterProxy::GetNetworkTaskRunner() const {
return parent_->GetNetworkTaskRunner();
}
net::HostResolver* CefURLRequestContextGetterProxy::GetHostResolver() const {
return parent_->host_resolver();
}

View File

@ -6,16 +6,21 @@
#define CEF_LIBCEF_BROWSER_URL_REQUEST_CONTEXT_GETTER_PROXY_H_
#pragma once
#include "include/cef_request_context_handler.h"
#include "base/memory/scoped_ptr.h"
#include "net/url_request/url_request_context_getter.h"
class CefBrowserHostImpl;
class CefURLRequestContextGetter;
class CefURLRequestContextProxy;
namespace net {
class HostResolver;
}
class CefURLRequestContextGetterProxy : public net::URLRequestContextGetter {
public:
CefURLRequestContextGetterProxy(CefBrowserHostImpl* browser,
CefURLRequestContextGetterProxy(CefRefPtr<CefRequestContextHandler> handler,
CefURLRequestContextGetter* parent);
virtual ~CefURLRequestContextGetterProxy();
@ -24,8 +29,12 @@ class CefURLRequestContextGetterProxy : public net::URLRequestContextGetter {
virtual scoped_refptr<base::SingleThreadTaskRunner>
GetNetworkTaskRunner() const OVERRIDE;
net::HostResolver* GetHostResolver() const;
CefRefPtr<CefRequestContextHandler> handler() const { return handler_; }
private:
CefBrowserHostImpl* browser_;
CefRefPtr<CefRequestContextHandler> handler_;
scoped_refptr<CefURLRequestContextGetter> parent_;
// The |context_proxy_| object is owned by |parent_|.

View File

@ -19,10 +19,10 @@ namespace {
class CefCookieStoreProxy : public net::CookieStore {
public:
explicit CefCookieStoreProxy(CefBrowserHostImpl* browser,
net::URLRequestContext* parent)
CefCookieStoreProxy(net::URLRequestContext* parent,
CefRefPtr<CefRequestContextHandler> handler)
: parent_(parent),
browser_(browser) {
handler_(handler) {
}
virtual ~CefCookieStoreProxy() {
CEF_REQUIRE_IOT();
@ -79,14 +79,9 @@ class CefCookieStoreProxy : public net::CookieStore {
scoped_refptr<net::CookieStore> cookie_store;
CefRefPtr<CefClient> client = browser_->GetClient();
if (client.get()) {
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
if (handler.get()) {
if (handler_.get()) {
// Get the manager from the handler.
CefRefPtr<CefCookieManager> manager =
handler->GetCookieManager(browser_.get(),
browser_->GetLoadingURL().spec());
CefRefPtr<CefCookieManager> manager = handler_->GetCookieManager();
if (manager.get()) {
cookie_store =
reinterpret_cast<CefCookieManagerImpl*>(
@ -94,7 +89,6 @@ class CefCookieStoreProxy : public net::CookieStore {
DCHECK(cookie_store);
}
}
}
if (!cookie_store) {
// Use the global cookie store.
@ -107,7 +101,7 @@ class CefCookieStoreProxy : public net::CookieStore {
// This pointer is guaranteed by the CefRequestContextProxy object.
net::URLRequestContext* parent_;
CefRefPtr<CefBrowserHostImpl> browser_;
CefRefPtr<CefRequestContextHandler> handler_;
DISALLOW_COPY_AND_ASSIGN(CefCookieStoreProxy);
};
@ -125,13 +119,14 @@ CefURLRequestContextProxy::~CefURLRequestContextProxy() {
CEF_REQUIRE_IOT();
}
void CefURLRequestContextProxy::Initialize(CefBrowserHostImpl* browser) {
void CefURLRequestContextProxy::Initialize(
CefRefPtr<CefRequestContextHandler> handler) {
CEF_REQUIRE_IOT();
net::URLRequestContext* context = parent_->GetURLRequestContext();
// Cookie store that proxies to the browser implementation.
cookie_store_proxy_ = new CefCookieStoreProxy(browser, context);
cookie_store_proxy_ = new CefCookieStoreProxy(context, handler);
set_cookie_store(cookie_store_proxy_);
// All other values refer to the parent request context.

View File

@ -6,6 +6,8 @@
#define CEF_LIBCEF_BROWSER_URL_REQUEST_CONTEXT_PROXY_H_
#pragma once
#include "include/cef_request_context_handler.h"
#include "base/memory/scoped_ptr.h"
#include "net/url_request/url_request_context.h"
@ -21,7 +23,7 @@ class CefURLRequestContextProxy : public net::URLRequestContext {
explicit CefURLRequestContextProxy(net::URLRequestContextGetter* parent);
virtual ~CefURLRequestContextProxy();
void Initialize(CefBrowserHostImpl* browser);
void Initialize(CefRefPtr<CefRequestContextHandler> handler);
// We may try to delete this proxy multiple times if URLRequests are still
// pending. Keep track of the number of tries so that they don't become

View File

@ -12,6 +12,7 @@
#include "libcef_dll/cpptoc/browser_cpptoc.h"
#include "libcef_dll/cpptoc/browser_host_cpptoc.h"
#include "libcef_dll/cpptoc/request_context_cpptoc.h"
#include "libcef_dll/ctocpp/client_ctocpp.h"
#include "libcef_dll/ctocpp/run_file_dialog_callback_ctocpp.h"
#include "libcef_dll/transfer_util.h"
@ -21,7 +22,8 @@
CEF_EXPORT int cef_browser_host_create_browser(
const cef_window_info_t* windowInfo, struct _cef_client_t* client,
const cef_string_t* url, const struct _cef_browser_settings_t* settings) {
const cef_string_t* url, const struct _cef_browser_settings_t* settings,
struct _cef_request_context_t* request_context) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: windowInfo; type: struct_byref_const
@ -32,7 +34,7 @@ CEF_EXPORT int cef_browser_host_create_browser(
DCHECK(settings);
if (!settings)
return 0;
// Unverified params: client, url
// Unverified params: client, url, request_context
// Translate param: windowInfo; type: struct_byref_const
CefWindowInfo windowInfoObj;
@ -48,7 +50,8 @@ CEF_EXPORT int cef_browser_host_create_browser(
windowInfoObj,
CefClientCToCpp::Wrap(client),
CefString(url),
settingsObj);
settingsObj,
CefRequestContextCppToC::Unwrap(request_context));
// Return type: bool
return _retval;
@ -56,7 +59,8 @@ CEF_EXPORT int cef_browser_host_create_browser(
CEF_EXPORT cef_browser_t* cef_browser_host_create_browser_sync(
const cef_window_info_t* windowInfo, struct _cef_client_t* client,
const cef_string_t* url, const struct _cef_browser_settings_t* settings) {
const cef_string_t* url, const struct _cef_browser_settings_t* settings,
struct _cef_request_context_t* request_context) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: windowInfo; type: struct_byref_const
@ -67,7 +71,7 @@ CEF_EXPORT cef_browser_t* cef_browser_host_create_browser_sync(
DCHECK(settings);
if (!settings)
return NULL;
// Unverified params: client, url
// Unverified params: client, url, request_context
// Translate param: windowInfo; type: struct_byref_const
CefWindowInfo windowInfoObj;
@ -83,7 +87,8 @@ CEF_EXPORT cef_browser_t* cef_browser_host_create_browser_sync(
windowInfoObj,
CefClientCToCpp::Wrap(client),
CefString(url),
settingsObj);
settingsObj,
CefRequestContextCppToC::Unwrap(request_context));
// Return type: refptr_same
return CefBrowserCppToC::Wrap(_retval);
@ -192,6 +197,22 @@ struct _cef_client_t* CEF_CALLBACK browser_host_get_client(
return CefClientCToCpp::Unwrap(_retval);
}
struct _cef_request_context_t* CEF_CALLBACK browser_host_get_request_context(
struct _cef_browser_host_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Execute
CefRefPtr<CefRequestContext> _retval = CefBrowserHostCppToC::Get(
self)->GetRequestContext();
// Return type: refptr_same
return CefRequestContextCppToC::Wrap(_retval);
}
cef_string_userfree_t CEF_CALLBACK browser_host_get_dev_tools_url(
struct _cef_browser_host_t* self, int http_scheme) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
@ -559,6 +580,7 @@ CefBrowserHostCppToC::CefBrowserHostCppToC(CefBrowserHost* cls)
struct_.struct_.get_opener_window_handle =
browser_host_get_opener_window_handle;
struct_.struct_.get_client = browser_host_get_client;
struct_.struct_.get_request_context = browser_host_get_request_context;
struct_.struct_.get_dev_tools_url = browser_host_get_dev_tools_url;
struct_.struct_.get_zoom_level = browser_host_get_zoom_level;
struct_.struct_.set_zoom_level = browser_host_set_zoom_level;

View File

@ -0,0 +1,112 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/request_context_cpptoc.h"
#include "libcef_dll/ctocpp/request_context_handler_ctocpp.h"
// GLOBAL FUNCTIONS - Body may be edited by hand.
CEF_EXPORT cef_request_context_t* cef_request_context_get_global_context() {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
CefRefPtr<CefRequestContext> _retval = CefRequestContext::GetGlobalContext();
// Return type: refptr_same
return CefRequestContextCppToC::Wrap(_retval);
}
CEF_EXPORT cef_request_context_t* cef_request_context_create_context(
struct _cef_request_context_handler_t* handler) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: handler
// Execute
CefRefPtr<CefRequestContext> _retval = CefRequestContext::CreateContext(
CefRequestContextHandlerCToCpp::Wrap(handler));
// Return type: refptr_same
return CefRequestContextCppToC::Wrap(_retval);
}
// MEMBER FUNCTIONS - Body may be edited by hand.
int CEF_CALLBACK request_context_is_same(struct _cef_request_context_t* self,
struct _cef_request_context_t* other) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: other; type: refptr_same
DCHECK(other);
if (!other)
return 0;
// Execute
bool _retval = CefRequestContextCppToC::Get(self)->IsSame(
CefRequestContextCppToC::Unwrap(other));
// Return type: bool
return _retval;
}
int CEF_CALLBACK request_context_is_global(
struct _cef_request_context_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Execute
bool _retval = CefRequestContextCppToC::Get(self)->IsGlobal();
// Return type: bool
return _retval;
}
struct _cef_request_context_handler_t* CEF_CALLBACK request_context_get_handler(
struct _cef_request_context_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Execute
CefRefPtr<CefRequestContextHandler> _retval = CefRequestContextCppToC::Get(
self)->GetHandler();
// Return type: refptr_diff
return CefRequestContextHandlerCToCpp::Unwrap(_retval);
}
// CONSTRUCTOR - Do not edit by hand.
CefRequestContextCppToC::CefRequestContextCppToC(CefRequestContext* cls)
: CefCppToC<CefRequestContextCppToC, CefRequestContext,
cef_request_context_t>(cls) {
struct_.struct_.is_same = request_context_is_same;
struct_.struct_.is_global = request_context_is_global;
struct_.struct_.get_handler = request_context_get_handler;
}
#ifndef NDEBUG
template<> long CefCppToC<CefRequestContextCppToC, CefRequestContext,
cef_request_context_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,37 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef CEF_LIBCEF_DLL_CPPTOC_REQUEST_CONTEXT_CPPTOC_H_
#define CEF_LIBCEF_DLL_CPPTOC_REQUEST_CONTEXT_CPPTOC_H_
#pragma once
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "include/cef_request_context.h"
#include "include/capi/cef_request_context_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed DLL-side only.
class CefRequestContextCppToC
: public CefCppToC<CefRequestContextCppToC, CefRequestContext,
cef_request_context_t> {
public:
explicit CefRequestContextCppToC(CefRequestContext* cls);
virtual ~CefRequestContextCppToC() {}
};
#endif // BUILDING_CEF_SHARED
#endif // CEF_LIBCEF_DLL_CPPTOC_REQUEST_CONTEXT_CPPTOC_H_

View File

@ -0,0 +1,50 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/request_context_handler_cpptoc.h"
#include "libcef_dll/ctocpp/cookie_manager_ctocpp.h"
// MEMBER FUNCTIONS - Body may be edited by hand.
cef_cookie_manager_t* CEF_CALLBACK request_context_handler_get_cookie_manager(
struct _cef_request_context_handler_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Execute
CefRefPtr<CefCookieManager> _retval = CefRequestContextHandlerCppToC::Get(
self)->GetCookieManager();
// Return type: refptr_diff
return CefCookieManagerCToCpp::Unwrap(_retval);
}
// CONSTRUCTOR - Do not edit by hand.
CefRequestContextHandlerCppToC::CefRequestContextHandlerCppToC(
CefRequestContextHandler* cls)
: CefCppToC<CefRequestContextHandlerCppToC, CefRequestContextHandler,
cef_request_context_handler_t>(cls) {
struct_.struct_.get_cookie_manager =
request_context_handler_get_cookie_manager;
}
#ifndef NDEBUG
template<> long CefCppToC<CefRequestContextHandlerCppToC,
CefRequestContextHandler, cef_request_context_handler_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,37 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef CEF_LIBCEF_DLL_CPPTOC_REQUEST_CONTEXT_HANDLER_CPPTOC_H_
#define CEF_LIBCEF_DLL_CPPTOC_REQUEST_CONTEXT_HANDLER_CPPTOC_H_
#pragma once
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "include/cef_request_context_handler.h"
#include "include/capi/cef_request_context_handler_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed wrapper-side only.
class CefRequestContextHandlerCppToC
: public CefCppToC<CefRequestContextHandlerCppToC, CefRequestContextHandler,
cef_request_context_handler_t> {
public:
explicit CefRequestContextHandlerCppToC(CefRequestContextHandler* cls);
virtual ~CefRequestContextHandlerCppToC() {}
};
#endif // USING_CEF_SHARED
#endif // CEF_LIBCEF_DLL_CPPTOC_REQUEST_CONTEXT_HANDLER_CPPTOC_H_

View File

@ -15,7 +15,6 @@
#include "libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.h"
#include "libcef_dll/ctocpp/auth_callback_ctocpp.h"
#include "libcef_dll/ctocpp/browser_ctocpp.h"
#include "libcef_dll/ctocpp/cookie_manager_ctocpp.h"
#include "libcef_dll/ctocpp/frame_ctocpp.h"
#include "libcef_dll/ctocpp/quota_callback_ctocpp.h"
#include "libcef_dll/ctocpp/request_ctocpp.h"
@ -203,33 +202,6 @@ int CEF_CALLBACK request_handler_on_quota_request(
return _retval;
}
cef_cookie_manager_t* CEF_CALLBACK request_handler_get_cookie_manager(
struct _cef_request_handler_t* self, cef_browser_t* browser,
const cef_string_t* main_url) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return NULL;
// Verify param: main_url; type: string_byref_const
DCHECK(main_url);
if (!main_url)
return NULL;
// Execute
CefRefPtr<CefCookieManager> _retval = CefRequestHandlerCppToC::Get(
self)->GetCookieManager(
CefBrowserCToCpp::Wrap(browser),
CefString(main_url));
// Return type: refptr_diff
return CefCookieManagerCToCpp::Unwrap(_retval);
}
void CEF_CALLBACK request_handler_on_protocol_execution(
struct _cef_request_handler_t* self, cef_browser_t* browser,
const cef_string_t* url, int* allow_os_execution) {
@ -336,7 +308,6 @@ CefRequestHandlerCppToC::CefRequestHandlerCppToC(CefRequestHandler* cls)
struct_.struct_.on_resource_redirect = request_handler_on_resource_redirect;
struct_.struct_.get_auth_credentials = request_handler_get_auth_credentials;
struct_.struct_.on_quota_request = request_handler_on_quota_request;
struct_.struct_.get_cookie_manager = request_handler_get_cookie_manager;
struct_.struct_.on_protocol_execution = request_handler_on_protocol_execution;
struct_.struct_.on_before_plugin_load = request_handler_on_before_plugin_load;
struct_.struct_.on_certificate_error = request_handler_on_certificate_error;

View File

@ -14,6 +14,7 @@
#include "libcef_dll/cpptoc/run_file_dialog_callback_cpptoc.h"
#include "libcef_dll/ctocpp/browser_ctocpp.h"
#include "libcef_dll/ctocpp/browser_host_ctocpp.h"
#include "libcef_dll/ctocpp/request_context_ctocpp.h"
#include "libcef_dll/transfer_util.h"
@ -21,17 +22,19 @@
bool CefBrowserHost::CreateBrowser(const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client, const CefString& url,
const CefBrowserSettings& settings) {
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: client, url
// Unverified params: client, url, request_context
// Execute
int _retval = cef_browser_host_create_browser(
&windowInfo,
CefClientCppToC::Wrap(client),
url.GetStruct(),
&settings);
&settings,
CefRequestContextCToCpp::Unwrap(request_context));
// Return type: bool
return _retval?true:false;
@ -39,17 +42,19 @@ bool CefBrowserHost::CreateBrowser(const CefWindowInfo& windowInfo,
CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
const CefWindowInfo& windowInfo, CefRefPtr<CefClient> client,
const CefString& url, const CefBrowserSettings& settings) {
const CefString& url, const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: client, url
// Unverified params: client, url, request_context
// Execute
cef_browser_t* _retval = cef_browser_host_create_browser_sync(
&windowInfo,
CefClientCppToC::Wrap(client),
url.GetStruct(),
&settings);
&settings,
CefRequestContextCToCpp::Unwrap(request_context));
// Return type: refptr_same
return CefBrowserCToCpp::Wrap(_retval);
@ -142,6 +147,19 @@ CefRefPtr<CefClient> CefBrowserHostCToCpp::GetClient() {
return CefClientCppToC::Unwrap(_retval);
}
CefRefPtr<CefRequestContext> CefBrowserHostCToCpp::GetRequestContext() {
if (CEF_MEMBER_MISSING(struct_, get_request_context))
return NULL;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
cef_request_context_t* _retval = struct_->get_request_context(struct_);
// Return type: refptr_same
return CefRequestContextCToCpp::Wrap(_retval);
}
CefString CefBrowserHostCToCpp::GetDevToolsURL(bool http_scheme) {
if (CEF_MEMBER_MISSING(struct_, get_dev_tools_url))
return CefString();

View File

@ -44,6 +44,7 @@ class CefBrowserHostCToCpp
virtual CefWindowHandle GetWindowHandle() OVERRIDE;
virtual CefWindowHandle GetOpenerWindowHandle() OVERRIDE;
virtual CefRefPtr<CefClient> GetClient() OVERRIDE;
virtual CefRefPtr<CefRequestContext> GetRequestContext() OVERRIDE;
virtual CefString GetDevToolsURL(bool http_scheme) OVERRIDE;
virtual double GetZoomLevel() OVERRIDE;
virtual void SetZoomLevel(double zoomLevel) OVERRIDE;

View File

@ -0,0 +1,96 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/request_context_handler_cpptoc.h"
#include "libcef_dll/ctocpp/request_context_ctocpp.h"
// STATIC METHODS - Body may be edited by hand.
CefRefPtr<CefRequestContext> CefRequestContext::GetGlobalContext() {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
cef_request_context_t* _retval = cef_request_context_get_global_context();
// Return type: refptr_same
return CefRequestContextCToCpp::Wrap(_retval);
}
CefRefPtr<CefRequestContext> CefRequestContext::CreateContext(
CefRefPtr<CefRequestContextHandler> handler) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: handler
// Execute
cef_request_context_t* _retval = cef_request_context_create_context(
CefRequestContextHandlerCppToC::Wrap(handler));
// Return type: refptr_same
return CefRequestContextCToCpp::Wrap(_retval);
}
// VIRTUAL METHODS - Body may be edited by hand.
bool CefRequestContextCToCpp::IsSame(CefRefPtr<CefRequestContext> other) {
if (CEF_MEMBER_MISSING(struct_, is_same))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: other; type: refptr_same
DCHECK(other.get());
if (!other.get())
return false;
// Execute
int _retval = struct_->is_same(struct_,
CefRequestContextCToCpp::Unwrap(other));
// Return type: bool
return _retval?true:false;
}
bool CefRequestContextCToCpp::IsGlobal() {
if (CEF_MEMBER_MISSING(struct_, is_global))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
int _retval = struct_->is_global(struct_);
// Return type: bool
return _retval?true:false;
}
CefRefPtr<CefRequestContextHandler> CefRequestContextCToCpp::GetHandler() {
if (CEF_MEMBER_MISSING(struct_, get_handler))
return NULL;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
cef_request_context_handler_t* _retval = struct_->get_handler(struct_);
// Return type: refptr_diff
return CefRequestContextHandlerCppToC::Unwrap(_retval);
}
#ifndef NDEBUG
template<> long CefCToCpp<CefRequestContextCToCpp, CefRequestContext,
cef_request_context_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,44 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_REQUEST_CONTEXT_CTOCPP_H_
#define CEF_LIBCEF_DLL_CTOCPP_REQUEST_CONTEXT_CTOCPP_H_
#pragma once
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "include/cef_request_context.h"
#include "include/capi/cef_request_context_capi.h"
#include "libcef_dll/ctocpp/ctocpp.h"
// Wrap a C structure with a C++ class.
// This class may be instantiated and accessed wrapper-side only.
class CefRequestContextCToCpp
: public CefCToCpp<CefRequestContextCToCpp, CefRequestContext,
cef_request_context_t> {
public:
explicit CefRequestContextCToCpp(cef_request_context_t* str)
: CefCToCpp<CefRequestContextCToCpp, CefRequestContext,
cef_request_context_t>(str) {}
virtual ~CefRequestContextCToCpp() {}
// CefRequestContext methods
virtual bool IsSame(CefRefPtr<CefRequestContext> other) OVERRIDE;
virtual bool IsGlobal() OVERRIDE;
virtual CefRefPtr<CefRequestContextHandler> GetHandler() OVERRIDE;
};
#endif // USING_CEF_SHARED
#endif // CEF_LIBCEF_DLL_CTOCPP_REQUEST_CONTEXT_CTOCPP_H_

View File

@ -0,0 +1,37 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/cookie_manager_cpptoc.h"
#include "libcef_dll/ctocpp/request_context_handler_ctocpp.h"
// VIRTUAL METHODS - Body may be edited by hand.
CefRefPtr<CefCookieManager> CefRequestContextHandlerCToCpp::GetCookieManager() {
if (CEF_MEMBER_MISSING(struct_, get_cookie_manager))
return NULL;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
cef_cookie_manager_t* _retval = struct_->get_cookie_manager(struct_);
// Return type: refptr_diff
return CefCookieManagerCppToC::Unwrap(_retval);
}
#ifndef NDEBUG
template<> long CefCToCpp<CefRequestContextHandlerCToCpp,
CefRequestContextHandler, cef_request_context_handler_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,42 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_REQUEST_CONTEXT_HANDLER_CTOCPP_H_
#define CEF_LIBCEF_DLL_CTOCPP_REQUEST_CONTEXT_HANDLER_CTOCPP_H_
#pragma once
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "include/cef_request_context_handler.h"
#include "include/capi/cef_request_context_handler_capi.h"
#include "libcef_dll/ctocpp/ctocpp.h"
// Wrap a C structure with a C++ class.
// This class may be instantiated and accessed DLL-side only.
class CefRequestContextHandlerCToCpp
: public CefCToCpp<CefRequestContextHandlerCToCpp, CefRequestContextHandler,
cef_request_context_handler_t> {
public:
explicit CefRequestContextHandlerCToCpp(cef_request_context_handler_t* str)
: CefCToCpp<CefRequestContextHandlerCToCpp, CefRequestContextHandler,
cef_request_context_handler_t>(str) {}
virtual ~CefRequestContextHandlerCToCpp() {}
// CefRequestContextHandler methods
virtual CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE;
};
#endif // BUILDING_CEF_SHARED
#endif // CEF_LIBCEF_DLL_CTOCPP_REQUEST_CONTEXT_HANDLER_CTOCPP_H_

View File

@ -13,7 +13,6 @@
#include "libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.h"
#include "libcef_dll/cpptoc/auth_callback_cpptoc.h"
#include "libcef_dll/cpptoc/browser_cpptoc.h"
#include "libcef_dll/cpptoc/cookie_manager_cpptoc.h"
#include "libcef_dll/cpptoc/frame_cpptoc.h"
#include "libcef_dll/cpptoc/quota_callback_cpptoc.h"
#include "libcef_dll/cpptoc/request_cpptoc.h"
@ -192,31 +191,6 @@ bool CefRequestHandlerCToCpp::OnQuotaRequest(CefRefPtr<CefBrowser> browser,
return _retval?true:false;
}
CefRefPtr<CefCookieManager> CefRequestHandlerCToCpp::GetCookieManager(
CefRefPtr<CefBrowser> browser, const CefString& main_url) {
if (CEF_MEMBER_MISSING(struct_, get_cookie_manager))
return NULL;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return NULL;
// Verify param: main_url; type: string_byref_const
DCHECK(!main_url.empty());
if (main_url.empty())
return NULL;
// Execute
cef_cookie_manager_t* _retval = struct_->get_cookie_manager(struct_,
CefBrowserCppToC::Wrap(browser),
main_url.GetStruct());
// Return type: refptr_diff
return CefCookieManagerCppToC::Unwrap(_retval);
}
void CefRequestHandlerCToCpp::OnProtocolExecution(CefRefPtr<CefBrowser> browser,
const CefString& url, bool& allow_os_execution) {
if (CEF_MEMBER_MISSING(struct_, on_protocol_execution))

View File

@ -49,8 +49,6 @@ class CefRequestHandlerCToCpp
virtual bool OnQuotaRequest(CefRefPtr<CefBrowser> browser,
const CefString& origin_url, int64 new_size,
CefRefPtr<CefQuotaCallback> callback) OVERRIDE;
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefBrowser> browser, const CefString& main_url) OVERRIDE;
virtual void OnProtocolExecution(CefRefPtr<CefBrowser> browser,
const CefString& url, bool& allow_os_execution) OVERRIDE;
virtual bool OnBeforePluginLoad(CefRefPtr<CefBrowser> browser,

View File

@ -359,7 +359,7 @@ int main(int argc, char* argv[]) {
CefBrowserHost::CreateBrowserSync(
window_info, g_handler.get(),
g_handler->GetStartupURL(), browserSettings);
g_handler->GetStartupURL(), browserSettings, NULL);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(GTK_WIDGET(window));

View File

@ -360,7 +360,7 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
}
CefBrowserHost::CreateBrowser(window_info, g_handler.get(),
g_handler->GetStartupURL(), settings);
g_handler->GetStartupURL(), settings, NULL);
// Show the window.
[mainWnd makeKeyAndOrderFront: nil];

View File

@ -329,7 +329,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
// Creat the new child browser window
CefBrowserHost::CreateBrowser(info, g_handler.get(),
g_handler->GetStartupURL(), settings);
g_handler->GetStartupURL(), settings, NULL);
return 0;
}

View File

@ -659,6 +659,41 @@ const char* kCookieJSUrl2 = "http://tests/cookie2.html";
class CookieTestJSHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(CookieTestJSHandler* handler)
: handler_(handler) {}
virtual CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE {
EXPECT_TRUE(handler_);
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
if (url_ == kCookieJSUrl1) {
// Return the first cookie manager.
handler_->got_cookie_manager1_.yes();
return handler_->manager1_;
} else {
// Return the second cookie manager.
handler_->got_cookie_manager2_.yes();
return handler_->manager2_;
}
}
void SetURL(const std::string& url) {
url_ = url;
}
void Detach() {
handler_ = NULL;
}
private:
std::string url_;
CookieTestJSHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
CookieTestJSHandler() {}
virtual void RunTest() OVERRIDE {
@ -682,8 +717,12 @@ class CookieTestJSHandler : public TestHandler {
"</head><body>COOKIE TEST2</body></html>";
AddResource(kCookieJSUrl2, page, "text/html");
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(kCookieJSUrl1);
// Create the browser
CreateBrowser(kCookieJSUrl1);
CreateBrowser(kCookieJSUrl1,
CefRequestContext::CreateContext(context_handler_.get()));
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
@ -695,6 +734,7 @@ class CookieTestJSHandler : public TestHandler {
VerifyCookie(manager1_, url, "name1", "value1", got_cookie1_);
// Go to the next URL
context_handler_->SetURL(kCookieJSUrl2);
frame->LoadURL(kCookieJSUrl2);
} else {
got_load_end2_.yes();
@ -704,18 +744,11 @@ class CookieTestJSHandler : public TestHandler {
}
}
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefBrowser> browser,
const CefString& main_url) OVERRIDE {
if (main_url == kCookieJSUrl1) {
// Return the first cookie manager.
got_cookie_manager1_.yes();
return manager1_;
} else {
// Return the second cookie manager.
got_cookie_manager2_.yes();
return manager2_;
}
virtual void DestroyTest() OVERRIDE {
context_handler_->Detach();
context_handler_ = NULL;
TestHandler::DestroyTest();
}
// Verify that the cookie was set successfully.
@ -736,6 +769,8 @@ class CookieTestJSHandler : public TestHandler {
}
}
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> manager1_;
CefRefPtr<CefCookieManager> manager2_;
@ -880,6 +915,41 @@ class CookieTestSchemeHandler : public TestHandler {
IMPLEMENT_REFCOUNTING(SchemeHandlerFactory);
};
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(CookieTestSchemeHandler* handler)
: handler_(handler) {}
virtual CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE {
EXPECT_TRUE(handler_);
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
if (url_ == handler_->url1_) {
// Return the first cookie manager.
handler_->got_cookie_manager1_.yes();
return handler_->manager1_;
} else {
// Return the second cookie manager.
handler_->got_cookie_manager2_.yes();
return handler_->manager2_;
}
}
void SetURL(const std::string& url) {
url_ = url;
}
void Detach() {
handler_ = NULL;
}
private:
std::string url_;
CookieTestSchemeHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
CookieTestSchemeHandler(const std::string& scheme) : scheme_(scheme) {
url1_ = scheme + "://cookie-tests/cookie1.html";
url2_ = scheme + "://cookie-tests/cookie2.html";
@ -905,8 +975,12 @@ class CookieTestSchemeHandler : public TestHandler {
CefRegisterSchemeHandlerFactory(scheme_, "cookie-tests",
new SchemeHandlerFactory(this));
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(url1_);
// Create the browser
CreateBrowser(url1_);
CreateBrowser(url1_,
CefRequestContext::CreateContext(context_handler_.get()));
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
@ -918,12 +992,14 @@ class CookieTestSchemeHandler : public TestHandler {
VerifyCookie(manager1_, url, "name1", "value1", got_cookie1_);
// Go to the next URL
context_handler_->SetURL(url2_);
frame->LoadURL(url2_);
} else if (url == url2_) {
got_load_end2_.yes();
VerifyCookie(manager2_, url, "name2", "value2", got_cookie2_);
// Go to the next URL
context_handler_->SetURL(url3_);
frame->LoadURL(url3_);
} else {
got_load_end3_.yes();
@ -936,18 +1012,11 @@ class CookieTestSchemeHandler : public TestHandler {
}
}
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefBrowser> browser,
const CefString& main_url) OVERRIDE {
if (main_url == url1_) {
// Return the first cookie manager.
got_cookie_manager1_.yes();
return manager1_;
} else {
// Return the second cookie manager.
got_cookie_manager2_.yes();
return manager2_;
}
virtual void DestroyTest() OVERRIDE {
context_handler_->Detach();
context_handler_ = NULL;
TestHandler::DestroyTest();
}
// Verify that the cookie was set successfully.
@ -973,6 +1042,8 @@ class CookieTestSchemeHandler : public TestHandler {
std::string url2_;
std::string url3_;
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> manager1_;
CefRefPtr<CefCookieManager> manager2_;

View File

@ -845,7 +845,7 @@ class OSRTestHandler : public TestHandler,
#endif
if (test_type_ == OSR_TEST_TRANSPARENCY)
windowInfo.SetTransparentPainting(TRUE);
CefBrowserHost::CreateBrowser(windowInfo, this, url, settings);
CefBrowserHost::CreateBrowser(windowInfo, this, url, settings, NULL);
}
bool IsFullRepaint(const CefRect& rc, int width = kOsrWidth,

View File

@ -0,0 +1,472 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "tests/unittests/test_handler.h"
#include "include/cef_request_context.h"
#include "include/cef_request_context_handler.h"
#include "include/cef_runnable.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(RequestContextTest, GetGlobalContext) {
CefRefPtr<CefRequestContext> context1 =
CefRequestContext::GetGlobalContext();
EXPECT_TRUE(context1.get());
EXPECT_TRUE(context1->IsGlobal());
EXPECT_TRUE(context1->IsSame(context1));
CefRefPtr<CefRequestContext> context2 =
CefRequestContext::GetGlobalContext();
EXPECT_TRUE(context2.get());
EXPECT_TRUE(context2->IsGlobal());
EXPECT_TRUE(context2->IsSame(context2));
EXPECT_TRUE(context1->IsSame(context2));
EXPECT_TRUE(context2->IsSame(context1));
}
TEST(RequestContextTest, CreateContext) {
class Handler : public CefRequestContextHandler {
public:
Handler() {}
virtual CefRefPtr<CefCookieManager> GetCookieManager() { return NULL; }
private:
IMPLEMENT_REFCOUNTING(Handler);
};
CefRefPtr<Handler> handler = new Handler();
CefRefPtr<CefRequestContext> context1 =
CefRequestContext::CreateContext(handler.get());
EXPECT_TRUE(context1.get());
EXPECT_FALSE(context1->IsGlobal());
EXPECT_TRUE(context1->IsSame(context1));
EXPECT_EQ(context1->GetHandler().get(), handler.get());
CefRefPtr<CefRequestContext> context2 =
CefRequestContext::CreateContext(handler.get());
EXPECT_TRUE(context2.get());
EXPECT_FALSE(context2->IsGlobal());
EXPECT_TRUE(context2->IsSame(context2));
EXPECT_EQ(context2->GetHandler().get(), handler.get());
EXPECT_FALSE(context1->IsSame(context2));
EXPECT_FALSE(context2->IsSame(context1));
CefRefPtr<CefRequestContext> context3 =
CefRequestContext::GetGlobalContext();
EXPECT_TRUE(context3.get());
EXPECT_FALSE(context3->IsSame(context1));
EXPECT_FALSE(context3->IsSame(context2));
EXPECT_FALSE(context1->IsSame(context3));
EXPECT_FALSE(context2->IsSame(context3));
}
TEST(RequestContextTest, CreateContextNoHandler) {
CefRefPtr<CefRequestContext> context1 =
CefRequestContext::CreateContext(NULL);
EXPECT_TRUE(context1.get());
EXPECT_FALSE(context1->IsGlobal());
EXPECT_TRUE(context1->IsSame(context1));
EXPECT_FALSE(context1->GetHandler().get());
CefRefPtr<CefRequestContext> context2 =
CefRequestContext::CreateContext(NULL);
EXPECT_TRUE(context2.get());
EXPECT_FALSE(context2->IsGlobal());
EXPECT_TRUE(context2->IsSame(context2));
EXPECT_FALSE(context2->GetHandler().get());
EXPECT_FALSE(context1->IsSame(context2));
EXPECT_FALSE(context2->IsSame(context1));
CefRefPtr<CefRequestContext> context3 =
CefRequestContext::GetGlobalContext();
EXPECT_TRUE(context3.get());
EXPECT_FALSE(context3->IsSame(context1));
EXPECT_FALSE(context3->IsSame(context2));
EXPECT_FALSE(context1->IsSame(context3));
EXPECT_FALSE(context2->IsSame(context3));
}
namespace {
class CookieTestHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(CookieTestHandler* handler)
: handler_(handler) {}
virtual CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE {
EXPECT_TRUE(handler_);
handler_->got_get_cookie_manager_.yes();
return handler_->cookie_manager_;
}
void Detach() {
handler_ = NULL;
}
private:
CookieTestHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
CookieTestHandler(const std::string& url)
: url_(url) {}
virtual void RunTest() OVERRIDE {
AddResource(url_,
"<html>"
"<head><script>document.cookie='name1=value1';</script></head>"
"<body>Nav1</body>"
"</html>", "text/html");
context_handler_ = new RequestContextHandler(this);
context_ = CefRequestContext::CreateContext(context_handler_.get());
cookie_manager_ = CefCookieManager::CreateManager(CefString(), true);
// Create browser that loads the 1st URL.
CreateBrowser(url_, context_);
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
CefRefPtr<CefRequestContext> context = browser->GetHost()->GetRequestContext();
EXPECT_TRUE(context.get());
EXPECT_TRUE(context->IsSame(context_));
EXPECT_FALSE(context->IsGlobal());
EXPECT_EQ(context->GetHandler().get(), context_handler_.get());
FinishTest();
}
protected:
void FinishTest() {
// Verify that the cookie was set correctly.
class TestVisitor : public CefCookieVisitor {
public:
explicit TestVisitor(CookieTestHandler* handler)
: handler_(handler) {
}
virtual ~TestVisitor() {
// Destroy the test.
CefPostTask(TID_UI,
NewCefRunnableMethod(handler_, &CookieTestHandler::DestroyTest));
}
virtual bool Visit(const CefCookie& cookie, int count, int total,
bool& deleteCookie) {
const std::string& name = CefString(&cookie.name);
const std::string& value = CefString(&cookie.value);
if (name == "name1" && value == "value1")
handler_->got_cookie_.yes();
return true;
}
private:
CookieTestHandler* handler_;
IMPLEMENT_REFCOUNTING(TestVisitor);
};
cookie_manager_->VisitAllCookies(new TestVisitor(this));
}
virtual void DestroyTest() OVERRIDE {
// Verify test expectations.
EXPECT_TRUE(got_get_cookie_manager_);
EXPECT_TRUE(got_cookie_);
context_handler_->Detach();
context_handler_ = NULL;
context_ = NULL;
TestHandler::DestroyTest();
}
std::string url_;
CefRefPtr<CefRequestContext> context_;
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> cookie_manager_;
TrackCallback got_get_cookie_manager_;
TrackCallback got_cookie_;
};
} // namespace
// Test that the cookie manager is retrieved via the associated request context.
TEST(RequestContextTest, GetCookieManager) {
CefRefPtr<CookieTestHandler> handler =
new CookieTestHandler(
"http://tests-simple-rch.com/nav1.html");
handler->ExecuteTest();
}
namespace {
class PopupTestHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(PopupTestHandler* handler)
: handler_(handler) {}
virtual CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE {
EXPECT_TRUE(handler_);
if (url_ == handler_->url_)
handler_->got_get_cookie_manager1_.yes();
else if (url_ == handler_->popup_url_)
handler_->got_get_cookie_manager2_.yes();
return handler_->cookie_manager_;
}
void SetURL(const std::string& url) {
url_ = url;
}
void Detach() {
handler_ = NULL;
}
private:
PopupTestHandler* handler_;
std::string url_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
enum Mode {
MODE_WINDOW_OPEN,
MODE_TARGETED_LINK,
MODE_NOREFERRER_LINK,
};
PopupTestHandler(bool same_origin,
Mode mode)
: mode_(mode) {
url_ = "http://tests-simple-rch1.com/nav1.html";
if (same_origin)
popup_url_ = "http://tests-simple-rch1.com/pop1.html";
else
popup_url_ = "http://tests-simple-rch2.com/pop1.html";
}
virtual void RunTest() OVERRIDE {
std::string link;
if (mode_ == MODE_TARGETED_LINK) {
link = "<a href=\"" + std::string(popup_url_) +
"\" target=\"mytarget\"\">CLICK ME</a>";
} else if (mode_ == MODE_NOREFERRER_LINK) {
link = "<a href=\"" + std::string(popup_url_) +
"\" rel=\"noreferrer\" target=\"_blank\"\">CLICK ME</a>";
}
AddResource(url_,
"<html>"
"<head><script>document.cookie='name1=value1';"
"function doPopup() { window.open('" + std::string(popup_url_) + "'); }"
"</script></head>"
"<body><h1>" + link + "</h1></body>"
"</html>", "text/html");
AddResource(popup_url_,
"<html>"
"<head><script>document.cookie='name2=value2';</script></head>"
"<body>Nav1</body>"
"</html>", "text/html");
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(url_);
context_ = CefRequestContext::CreateContext(context_handler_.get());
cookie_manager_ = CefCookieManager::CreateManager(CefString(), true);
// Create browser that loads the 1st URL.
CreateBrowser(url_, context_);
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
CefRefPtr<CefRequestContext> context = browser->GetHost()->GetRequestContext();
EXPECT_TRUE(context.get());
EXPECT_TRUE(context->IsSame(context_));
EXPECT_FALSE(context->IsGlobal());
EXPECT_TRUE(frame->IsMain());
const std::string& url = frame->GetURL();
if (url == url_) {
got_load_end1_.yes();
context_handler_->SetURL(popup_url_);
LaunchPopup(browser);
} if (url == popup_url_) {
got_load_end2_.yes();
EXPECT_TRUE(browser->IsPopup());
// Close the popup window.
browser->GetHost()->CloseBrowser(true);
}
}
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& target_url,
const CefString& target_frame_name,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings,
bool* no_javascript_access) OVERRIDE {
got_on_before_popup_.yes();
const std::string& url = target_url;
EXPECT_STREQ(url.c_str(), popup_url_.c_str());
return false;
}
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) {
TestHandler::OnBeforeClose(browser);
if (browser->IsPopup())
FinishTest();
}
protected:
void LaunchPopup(CefRefPtr<CefBrowser> browser) {
if (mode_ == MODE_WINDOW_OPEN) {
browser->GetMainFrame()->ExecuteJavaScript("doPopup()", url_, 0);
} else if (mode_ == MODE_TARGETED_LINK ||
mode_ == MODE_NOREFERRER_LINK) {
CefMouseEvent mouse_event;
mouse_event.x = 20;
mouse_event.y = 20;
mouse_event.modifiers = 0;
browser->GetHost()->SendMouseClickEvent(
mouse_event, MBT_LEFT, false, 1);
browser->GetHost()->SendMouseClickEvent(
mouse_event, MBT_LEFT, true, 1);
} else {
EXPECT_TRUE(false); // Not reached.
}
}
void FinishTest() {
// Verify that the cookies were set correctly.
class TestVisitor : public CefCookieVisitor {
public:
explicit TestVisitor(PopupTestHandler* handler)
: handler_(handler) {
}
virtual ~TestVisitor() {
// Destroy the test.
CefPostTask(TID_UI,
NewCefRunnableMethod(handler_, &PopupTestHandler::DestroyTest));
}
virtual bool Visit(const CefCookie& cookie, int count, int total,
bool& deleteCookie) {
const std::string& name = CefString(&cookie.name);
const std::string& value = CefString(&cookie.value);
if (name == "name1" && value == "value1")
handler_->got_cookie1_.yes();
else if (name == "name2" && value == "value2")
handler_->got_cookie2_.yes();
return true;
}
private:
PopupTestHandler* handler_;
IMPLEMENT_REFCOUNTING(TestVisitor);
};
cookie_manager_->VisitAllCookies(new TestVisitor(this));
}
virtual void DestroyTest() OVERRIDE {
// Verify test expectations.
EXPECT_TRUE(got_get_cookie_manager1_);
EXPECT_TRUE(got_load_end1_);
EXPECT_TRUE(got_on_before_popup_);
EXPECT_TRUE(got_get_cookie_manager2_);
EXPECT_TRUE(got_load_end2_);
EXPECT_TRUE(got_cookie1_);
EXPECT_TRUE(got_cookie2_);
context_handler_->Detach();
context_handler_ = NULL;
context_ = NULL;
TestHandler::DestroyTest();
}
std::string url_;
std::string popup_url_;
Mode mode_;
CefRefPtr<CefRequestContext> context_;
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> cookie_manager_;
TrackCallback got_get_cookie_manager1_;
TrackCallback got_load_end1_;
TrackCallback got_on_before_popup_;
TrackCallback got_get_cookie_manager2_;
TrackCallback got_load_end2_;
TrackCallback got_cookie1_;
TrackCallback got_cookie2_;
};
} // namespace
// Test that a popup created using window.open() will get the same request
// context as the parent browser.
TEST(RequestContextTest, WindowOpenSameOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(true,
PopupTestHandler::MODE_WINDOW_OPEN);
handler->ExecuteTest();
}
TEST(RequestContextTest, WindowOpenDifferentOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(false,
PopupTestHandler::MODE_WINDOW_OPEN);
handler->ExecuteTest();
}
// Test that a popup created using a targeted link will get the same request
// context as the parent browser.
TEST(RequestContextTest, TargetedLinkSameOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(true,
PopupTestHandler::MODE_TARGETED_LINK);
handler->ExecuteTest();
}
TEST(RequestContextTest, TargetedLinkDifferentOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(false,
PopupTestHandler::MODE_TARGETED_LINK);
handler->ExecuteTest();
}
// Test that a popup created using a noreferrer link will get the same
// request context as the parent browser. A new render process will
// be created for the popup browser.
TEST(RequestContextTest, NoReferrerLinkSameOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(true,
PopupTestHandler::MODE_NOREFERRER_LINK);
handler->ExecuteTest();
}
TEST(RequestContextTest, NoReferrerLinkDifferentOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(false,
PopupTestHandler::MODE_NOREFERRER_LINK);
handler->ExecuteTest();
}

View File

@ -26,6 +26,40 @@ const char kNetNotifyMsg[] = "RequestHandlerTest.NetNotify";
// Browser side.
class NetNotifyTestHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(NetNotifyTestHandler* handler)
: handler_(handler) {}
virtual CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE {
EXPECT_TRUE(handler_);
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
if (url_.find(handler_->url1_) == 0)
handler_->got_get_cookie_manager1_.yes();
else if (url_.find(handler_->url2_) == 0)
handler_->got_get_cookie_manager2_.yes();
else
EXPECT_TRUE(false); // Not reached
return handler_->cookie_manager_;
}
void SetURL(const std::string& url) {
url_ = url;
}
void Detach() {
handler_ = NULL;
}
private:
std::string url_;
NetNotifyTestHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
NetNotifyTestHandler(CompletionState* completion_state,
NetNotifyTestType test_type,
bool same_origin)
@ -52,12 +86,17 @@ class NetNotifyTestHandler : public TestHandler {
"<body>Nav2</body>"
"</html>", "text/html");
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(url1_);
// Create browser that loads the 1st URL.
CreateBrowser(url1_);
CreateBrowser(url1_,
CefRequestContext::CreateContext(context_handler_.get()));
}
virtual void RunTest() OVERRIDE {
// Navigate to the 2nd URL.
context_handler_->SetURL(url2_);
GetBrowser()->GetMainFrame()->LoadURL(url2_);
}
@ -94,22 +133,6 @@ class NetNotifyTestHandler : public TestHandler {
return TestHandler::GetResourceHandler(browser, frame, request);
}
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefBrowser> browser,
const CefString& main_url) OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
const std::string& url = main_url;
if (url.find(url1_) == 0)
got_get_cookie_manager1_.yes();
else if (url.find(url2_) == 0)
got_get_cookie_manager2_.yes();
else
EXPECT_TRUE(false); // Not reached
return cookie_manager_;
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
@ -227,6 +250,8 @@ class NetNotifyTestHandler : public TestHandler {
EXPECT_FALSE(got_process_message2_) << " browser " << browser_id;
}
context_handler_->Detach();
context_handler_ = NULL;
cookie_manager_ = NULL;
TestHandler::DestroyTest();
@ -237,6 +262,8 @@ class NetNotifyTestHandler : public TestHandler {
std::string url1_;
std::string url2_;
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> cookie_manager_;
TrackCallback got_load_end1_;

View File

@ -171,14 +171,17 @@ void TestHandler::DestroyTest() {
browser_->GetHost()->CloseBrowser(false);
}
void TestHandler::CreateBrowser(const CefString& url) {
void TestHandler::CreateBrowser(
const CefString& url,
CefRefPtr<CefRequestContext> request_context) {
CefWindowInfo windowInfo;
CefBrowserSettings settings;
#if defined(OS_WIN)
windowInfo.SetAsPopup(NULL, "CefUnitTest");
windowInfo.style |= WS_VISIBLE;
#endif
CefBrowserHost::CreateBrowser(windowInfo, this, url, settings);
CefBrowserHost::CreateBrowser(windowInfo, this, url, settings,
request_context);
}
void TestHandler::AddResource(const std::string& url,

View File

@ -170,7 +170,8 @@ class TestHandler : public CefClient,
// will be signaled.
virtual void DestroyTest();
void CreateBrowser(const CefString& url);
void CreateBrowser(const CefString& url,
CefRefPtr<CefRequestContext> request_context = NULL);
void AddResource(const std::string& url,
const std::string& content,