mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Pass the originating browser to CefSchemeHandlerFactory::Create() (issue #362).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@305 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@ -2575,10 +2575,13 @@ class CefSchemeHandlerFactory : public virtual CefBase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
// Return a new scheme handler instance to handle the request.
|
// Return a new scheme handler instance to handle the request. |browser| will
|
||||||
|
// be the browser window that initiated the request. If the request was
|
||||||
|
// initiated using the CefWebURLRequest API |browser| will be NULL.
|
||||||
///
|
///
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
virtual CefRefPtr<CefSchemeHandler> Create(const CefString& scheme_name,
|
virtual CefRefPtr<CefSchemeHandler> Create(CefRefPtr<CefBrowser> browser,
|
||||||
|
const CefString& scheme_name,
|
||||||
CefRefPtr<CefRequest> request) =0;
|
CefRefPtr<CefRequest> request) =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2359,11 +2359,14 @@ typedef struct _cef_scheme_handler_factory_t
|
|||||||
cef_base_t base;
|
cef_base_t base;
|
||||||
|
|
||||||
///
|
///
|
||||||
// Return a new scheme handler instance to handle the request.
|
// Return a new scheme handler instance to handle the request. |browser| will
|
||||||
|
// be the browser window that initiated the request. If the request was
|
||||||
|
// initiated using the cef_web_urlrequest_t API |browser| will be NULL.
|
||||||
///
|
///
|
||||||
struct _cef_scheme_handler_t* (CEF_CALLBACK *create)(
|
struct _cef_scheme_handler_t* (CEF_CALLBACK *create)(
|
||||||
struct _cef_scheme_handler_factory_t* self,
|
struct _cef_scheme_handler_factory_t* self,
|
||||||
const cef_string_t* scheme_name, struct _cef_request_t* request);
|
struct _cef_browser_t* browser, const cef_string_t* scheme_name,
|
||||||
|
struct _cef_request_t* request);
|
||||||
|
|
||||||
} cef_scheme_handler_factory_t;
|
} cef_scheme_handler_factory_t;
|
||||||
|
|
||||||
|
@ -77,7 +77,8 @@ class DevToolsSchemeHandlerFactory : public CefSchemeHandlerFactory
|
|||||||
public:
|
public:
|
||||||
DevToolsSchemeHandlerFactory() {}
|
DevToolsSchemeHandlerFactory() {}
|
||||||
|
|
||||||
virtual CefRefPtr<CefSchemeHandler> Create(const CefString& scheme_name,
|
virtual CefRefPtr<CefSchemeHandler> Create(CefRefPtr<CefBrowser> browser,
|
||||||
|
const CefString& scheme_name,
|
||||||
CefRefPtr<CefRequest> request)
|
CefRefPtr<CefRequest> request)
|
||||||
OVERRIDE
|
OVERRIDE
|
||||||
{
|
{
|
||||||
|
@ -111,17 +111,24 @@ static const int kUpdateUploadProgressIntervalMsec = 100;
|
|||||||
|
|
||||||
class ExtraRequestInfo : public net::URLRequest::UserData {
|
class ExtraRequestInfo : public net::URLRequest::UserData {
|
||||||
public:
|
public:
|
||||||
ExtraRequestInfo(ResourceType::Type resource_type)
|
ExtraRequestInfo(CefBrowser* browser, ResourceType::Type resource_type)
|
||||||
: resource_type_(resource_type),
|
: browser_(browser),
|
||||||
|
resource_type_(resource_type),
|
||||||
allow_download_(resource_type == ResourceType::MAIN_FRAME ||
|
allow_download_(resource_type == ResourceType::MAIN_FRAME ||
|
||||||
resource_type == ResourceType::SUB_FRAME)
|
resource_type == ResourceType::SUB_FRAME)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
// The browser pointer is guaranteed to be valid for the lifespan of the
|
||||||
|
// request. The pointer will be NULL in cases where the request was
|
||||||
|
// initiated via the CefWebURLRequest API instead of by a browser window.
|
||||||
|
CefBrowser* browser() const { return browser_; }
|
||||||
|
|
||||||
// Identifies the type of resource, such as subframe, media, etc.
|
// Identifies the type of resource, such as subframe, media, etc.
|
||||||
ResourceType::Type resource_type() const { return resource_type_; }
|
ResourceType::Type resource_type() const { return resource_type_; }
|
||||||
bool allow_download() const { return allow_download_; }
|
bool allow_download() const { return allow_download_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CefBrowser* browser_;
|
||||||
ResourceType::Type resource_type_;
|
ResourceType::Type resource_type_;
|
||||||
bool allow_download_;
|
bool allow_download_;
|
||||||
};
|
};
|
||||||
@ -514,7 +521,8 @@ class RequestProxy : public net::URLRequest::Delegate,
|
|||||||
request_->set_load_flags(params->load_flags);
|
request_->set_load_flags(params->load_flags);
|
||||||
request_->set_upload(params->upload.get());
|
request_->set_upload(params->upload.get());
|
||||||
request_->set_context(_Context->request_context());
|
request_->set_context(_Context->request_context());
|
||||||
request_->SetUserData(NULL, new ExtraRequestInfo(params->request_type));
|
request_->SetUserData(NULL,
|
||||||
|
new ExtraRequestInfo(browser_.get(), params->request_type));
|
||||||
BrowserAppCacheSystem::SetExtraRequestInfo(
|
BrowserAppCacheSystem::SetExtraRequestInfo(
|
||||||
request_.get(), params->appcache_host_id, params->request_type);
|
request_.get(), params->appcache_host_id, params->request_type);
|
||||||
|
|
||||||
@ -1130,6 +1138,17 @@ void BrowserResourceLoaderBridge::SetAcceptAllCookies(bool accept_all_cookies) {
|
|||||||
&BrowserRequestContext::SetAcceptAllCookies, accept_all_cookies));
|
&BrowserRequestContext::SetAcceptAllCookies, accept_all_cookies));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
CefRefPtr<CefBrowser> BrowserResourceLoaderBridge::GetBrowserForRequest(
|
||||||
|
net::URLRequest* request) {
|
||||||
|
REQUIRE_IOT();
|
||||||
|
ExtraRequestInfo* extra_info =
|
||||||
|
static_cast<ExtraRequestInfo*>(request->GetUserData(NULL));
|
||||||
|
if (extra_info)
|
||||||
|
return extra_info->browser();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
//static
|
//static
|
||||||
scoped_refptr<base::MessageLoopProxy>
|
scoped_refptr<base::MessageLoopProxy>
|
||||||
BrowserResourceLoaderBridge::GetCacheThread() {
|
BrowserResourceLoaderBridge::GetCacheThread() {
|
||||||
|
@ -6,11 +6,16 @@
|
|||||||
#ifndef _BROWSER_RESOURCE_LOADER_BRIDGE_H
|
#ifndef _BROWSER_RESOURCE_LOADER_BRIDGE_H
|
||||||
#define _BROWSER_RESOURCE_LOADER_BRIDGE_H
|
#define _BROWSER_RESOURCE_LOADER_BRIDGE_H
|
||||||
|
|
||||||
#include <string>
|
#include "include/cef.h"
|
||||||
#include "base/message_loop_proxy.h"
|
#include "base/message_loop_proxy.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class GURL;
|
class GURL;
|
||||||
|
|
||||||
|
namespace net {
|
||||||
|
class URLRequest;
|
||||||
|
};
|
||||||
|
|
||||||
class BrowserResourceLoaderBridge {
|
class BrowserResourceLoaderBridge {
|
||||||
public:
|
public:
|
||||||
// May only be called after Init.
|
// May only be called after Init.
|
||||||
@ -21,6 +26,11 @@ class BrowserResourceLoaderBridge {
|
|||||||
const GURL& first_party_for_cookies);
|
const GURL& first_party_for_cookies);
|
||||||
static void SetAcceptAllCookies(bool accept_all_cookies);
|
static void SetAcceptAllCookies(bool accept_all_cookies);
|
||||||
|
|
||||||
|
// Return the CefBrowser associated with the specified request. The browser
|
||||||
|
// will be NULL in cases where the request was initiated using the
|
||||||
|
// CefWebURLRequest API.
|
||||||
|
static CefRefPtr<CefBrowser> GetBrowserForRequest(net::URLRequest* request);
|
||||||
|
|
||||||
static scoped_refptr<base::MessageLoopProxy> GetCacheThread();
|
static scoped_refptr<base::MessageLoopProxy> GetCacheThread();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "include/cef.h"
|
#include "include/cef.h"
|
||||||
|
#include "browser_resource_loader_bridge.h"
|
||||||
#include "cef_context.h"
|
#include "cef_context.h"
|
||||||
#include "cef_thread.h"
|
#include "cef_thread.h"
|
||||||
#include "request_impl.h"
|
#include "request_impl.h"
|
||||||
@ -546,7 +547,10 @@ private:
|
|||||||
// Call the handler factory to create the handler for the request.
|
// Call the handler factory to create the handler for the request.
|
||||||
CefRefPtr<CefRequest> requestPtr(new CefRequestImpl());
|
CefRefPtr<CefRequest> requestPtr(new CefRequestImpl());
|
||||||
static_cast<CefRequestImpl*>(requestPtr.get())->Set(request);
|
static_cast<CefRequestImpl*>(requestPtr.get())->Set(request);
|
||||||
CefRefPtr<CefSchemeHandler> handler = factory->Create(scheme, requestPtr);
|
CefRefPtr<CefBrowser> browser =
|
||||||
|
BrowserResourceLoaderBridge::GetBrowserForRequest(request);
|
||||||
|
CefRefPtr<CefSchemeHandler> handler =
|
||||||
|
factory->Create(browser, scheme, requestPtr);
|
||||||
if (handler.get())
|
if (handler.get())
|
||||||
job = new CefUrlRequestJob(request, handler);
|
job = new CefUrlRequestJob(request, handler);
|
||||||
}
|
}
|
||||||
|
@ -12,18 +12,23 @@
|
|||||||
|
|
||||||
#include "libcef_dll/cpptoc/scheme_handler_cpptoc.h"
|
#include "libcef_dll/cpptoc/scheme_handler_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h"
|
#include "libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h"
|
||||||
|
#include "libcef_dll/ctocpp/browser_ctocpp.h"
|
||||||
#include "libcef_dll/ctocpp/request_ctocpp.h"
|
#include "libcef_dll/ctocpp/request_ctocpp.h"
|
||||||
|
|
||||||
|
|
||||||
// MEMBER FUNCTIONS - Body may be edited by hand.
|
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||||
|
|
||||||
struct _cef_scheme_handler_t* CEF_CALLBACK scheme_handler_factory_create(
|
struct _cef_scheme_handler_t* CEF_CALLBACK scheme_handler_factory_create(
|
||||||
struct _cef_scheme_handler_factory_t* self, const cef_string_t* scheme_name,
|
struct _cef_scheme_handler_factory_t* self, cef_browser_t* browser,
|
||||||
cef_request_t* request)
|
const cef_string_t* scheme_name, cef_request_t* request)
|
||||||
{
|
{
|
||||||
|
CefRefPtr<CefBrowser> browserPtr;
|
||||||
|
if (browser)
|
||||||
|
browserPtr = CefBrowserCToCpp::Wrap(browser);
|
||||||
|
|
||||||
CefRefPtr<CefSchemeHandler> rv =
|
CefRefPtr<CefSchemeHandler> rv =
|
||||||
CefSchemeHandlerFactoryCppToC::Get(self)->Create(CefString(scheme_name),
|
CefSchemeHandlerFactoryCppToC::Get(self)->Create(browserPtr,
|
||||||
CefRequestCToCpp::Wrap(request));
|
CefString(scheme_name), CefRequestCToCpp::Wrap(request));
|
||||||
if (rv.get())
|
if (rv.get())
|
||||||
return CefSchemeHandlerCppToC::Wrap(rv);
|
return CefSchemeHandlerCppToC::Wrap(rv);
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
// tools directory for more information.
|
// tools directory for more information.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include "libcef_dll/cpptoc/browser_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
||||||
#include "libcef_dll/ctocpp/scheme_handler_ctocpp.h"
|
#include "libcef_dll/ctocpp/scheme_handler_ctocpp.h"
|
||||||
#include "libcef_dll/ctocpp/scheme_handler_factory_ctocpp.h"
|
#include "libcef_dll/ctocpp/scheme_handler_factory_ctocpp.h"
|
||||||
@ -18,13 +19,18 @@
|
|||||||
// VIRTUAL METHODS - Body may be edited by hand.
|
// VIRTUAL METHODS - Body may be edited by hand.
|
||||||
|
|
||||||
CefRefPtr<CefSchemeHandler> CefSchemeHandlerFactoryCToCpp::Create(
|
CefRefPtr<CefSchemeHandler> CefSchemeHandlerFactoryCToCpp::Create(
|
||||||
const CefString& scheme_name, CefRefPtr<CefRequest> request)
|
CefRefPtr<CefBrowser> browser, const CefString& scheme_name,
|
||||||
|
CefRefPtr<CefRequest> request)
|
||||||
{
|
{
|
||||||
if(CEF_MEMBER_MISSING(struct_, create))
|
if(CEF_MEMBER_MISSING(struct_, create))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
cef_scheme_handler_t* rv = struct_->create(struct_, scheme_name.GetStruct(),
|
cef_browser_t* browserStruct = NULL;
|
||||||
CefRequestCppToC::Wrap(request));
|
if (browser.get())
|
||||||
|
browserStruct = CefBrowserCppToC::Wrap(browser);
|
||||||
|
|
||||||
|
cef_scheme_handler_t* rv = struct_->create(struct_, browserStruct,
|
||||||
|
scheme_name.GetStruct(), CefRequestCppToC::Wrap(request));
|
||||||
if (rv)
|
if (rv)
|
||||||
return CefSchemeHandlerCToCpp::Wrap(rv);
|
return CefSchemeHandlerCToCpp::Wrap(rv);
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ public:
|
|||||||
virtual ~CefSchemeHandlerFactoryCToCpp() {}
|
virtual ~CefSchemeHandlerFactoryCToCpp() {}
|
||||||
|
|
||||||
// CefSchemeHandlerFactory methods
|
// CefSchemeHandlerFactory methods
|
||||||
virtual CefRefPtr<CefSchemeHandler> Create(const CefString& scheme_name,
|
virtual CefRefPtr<CefSchemeHandler> Create(CefRefPtr<CefBrowser> browser,
|
||||||
CefRefPtr<CefRequest> request) OVERRIDE;
|
const CefString& scheme_name, CefRefPtr<CefRequest> request) OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BUILDING_CEF_SHARED
|
#endif // BUILDING_CEF_SHARED
|
||||||
|
@ -145,8 +145,10 @@ class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Return a new scheme handler instance to handle the request.
|
// Return a new scheme handler instance to handle the request.
|
||||||
virtual CefRefPtr<CefSchemeHandler> Create(const CefString& scheme_name,
|
virtual CefRefPtr<CefSchemeHandler> Create(CefRefPtr<CefBrowser> browser,
|
||||||
|
const CefString& scheme_name,
|
||||||
CefRefPtr<CefRequest> request)
|
CefRefPtr<CefRequest> request)
|
||||||
|
OVERRIDE
|
||||||
{
|
{
|
||||||
REQUIRE_IO_THREAD();
|
REQUIRE_IO_THREAD();
|
||||||
return new ClientSchemeHandler();
|
return new ClientSchemeHandler();
|
||||||
|
@ -308,8 +308,10 @@ public:
|
|||||||
ClientSchemeHandlerFactory(TestResults* tr)
|
ClientSchemeHandlerFactory(TestResults* tr)
|
||||||
: test_results_(tr){}
|
: test_results_(tr){}
|
||||||
|
|
||||||
virtual CefRefPtr<CefSchemeHandler> Create(const CefString& scheme_name,
|
virtual CefRefPtr<CefSchemeHandler> Create(CefRefPtr<CefBrowser> browser,
|
||||||
|
const CefString& scheme_name,
|
||||||
CefRefPtr<CefRequest> request)
|
CefRefPtr<CefRequest> request)
|
||||||
|
OVERRIDE
|
||||||
{
|
{
|
||||||
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
||||||
return new ClientSchemeHandler(test_results_);
|
return new ClientSchemeHandler(test_results_);
|
||||||
|
Reference in New Issue
Block a user