mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-12 18:10:41 +01:00
Merge revision 1433, revision 1436 and revision 1440 changes:
- Expose resource type and transition type via CefRequest (issue #1071). - Add CefRequestHandler::OnBeforeBrowse callback (issue #1076). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1547@1456 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
993232f1a7
commit
586fa3b487
10
cef.gyp
10
cef.gyp
@ -752,6 +752,10 @@
|
||||
'<(SHARED_INTERMEDIATE_DIR)/webkit',
|
||||
],
|
||||
'dependencies': [
|
||||
'<(DEPTH)/base/base.gyp:base',
|
||||
'<(DEPTH)/base/base.gyp:base_prefs',
|
||||
'<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
|
||||
'<(DEPTH)/components/components.gyp:navigation_interception',
|
||||
'<(DEPTH)/content/content.gyp:content_app',
|
||||
'<(DEPTH)/content/content.gyp:content_browser',
|
||||
'<(DEPTH)/content/content.gyp:content_common',
|
||||
@ -762,17 +766,14 @@
|
||||
'<(DEPTH)/content/content.gyp:content_utility',
|
||||
'<(DEPTH)/content/content.gyp:content_worker',
|
||||
'<(DEPTH)/content/content_resources.gyp:content_resources',
|
||||
'<(DEPTH)/base/base.gyp:base',
|
||||
'<(DEPTH)/base/base.gyp:base_prefs',
|
||||
'<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
|
||||
'<(DEPTH)/ipc/ipc.gyp:ipc',
|
||||
'<(DEPTH)/media/media.gyp:media',
|
||||
'<(DEPTH)/net/net.gyp:net',
|
||||
'<(DEPTH)/net/net.gyp:net_with_v8',
|
||||
'<(DEPTH)/skia/skia.gyp:skia',
|
||||
'<(DEPTH)/third_party/libxml/libxml.gyp:libxml',
|
||||
'<(DEPTH)/third_party/WebKit/Source/core/core.gyp:webcore',
|
||||
'<(DEPTH)/third_party/WebKit/public/blink.gyp:blink',
|
||||
'<(DEPTH)/third_party/WebKit/Source/core/core.gyp:webcore',
|
||||
'<(DEPTH)/third_party/zlib/zlib.gyp:minizip',
|
||||
'<(DEPTH)/ui/gl/gl.gyp:gl',
|
||||
'<(DEPTH)/ui/ui.gyp:ui',
|
||||
@ -1236,6 +1237,7 @@
|
||||
'tests/unittests/navigation_unittest.cc',
|
||||
'tests/unittests/process_message_unittest.cc',
|
||||
'tests/unittests/request_handler_unittest.cc',
|
||||
'tests/unittests/request_unittest.cc',
|
||||
'tests/unittests/scheme_handler_unittest.cc',
|
||||
'tests/unittests/urlrequest_unittest.cc',
|
||||
'tests/unittests/test_handler.cc',
|
||||
|
@ -56,7 +56,10 @@ typedef struct _cef_display_handler_t {
|
||||
cef_base_t base;
|
||||
|
||||
///
|
||||
// Called when the loading state has changed.
|
||||
// Called when the loading state has changed. This callback will be executed
|
||||
// twice -- once when loading is initiated either programmatically or by user
|
||||
// action, and once when loading is terminated due to completion, cancellation
|
||||
// of failure.
|
||||
///
|
||||
void (CEF_CALLBACK *on_loading_state_change)(
|
||||
struct _cef_display_handler_t* self, struct _cef_browser_t* browser,
|
||||
|
@ -61,7 +61,8 @@ typedef struct _cef_load_handler_t {
|
||||
// main frame. Multiple frames may be loading at the same time. Sub-frames may
|
||||
// start or continue loading after the main frame load has ended. This
|
||||
// function may not be called for a particular frame if the load request for
|
||||
// that frame fails.
|
||||
// that frame fails. For notification of overall browser load status use
|
||||
// cef_display_handler_t:: OnLoadingStateChange instead.
|
||||
///
|
||||
void (CEF_CALLBACK *on_load_start)(struct _cef_load_handler_t* self,
|
||||
struct _cef_browser_t* browser, struct _cef_frame_t* frame);
|
||||
@ -79,10 +80,10 @@ typedef struct _cef_load_handler_t {
|
||||
int httpStatusCode);
|
||||
|
||||
///
|
||||
// Called when the browser fails to load a resource. |errorCode| is the error
|
||||
// code number, |errorText| is the error text and and |failedUrl| is the URL
|
||||
// that failed to load. See net\base\net_error_list.h for complete
|
||||
// descriptions of the error codes.
|
||||
// Called when the resource load for a navigation fails or is canceled.
|
||||
// |errorCode| is the error code number, |errorText| is the error text and
|
||||
// |failedUrl| is the URL that failed to load. See net\base\net_error_list.h
|
||||
// for complete descriptions of the error codes.
|
||||
///
|
||||
void (CEF_CALLBACK *on_load_error)(struct _cef_load_handler_t* self,
|
||||
struct _cef_browser_t* browser, struct _cef_frame_t* frame,
|
||||
|
@ -142,6 +142,21 @@ typedef struct _cef_request_t {
|
||||
///
|
||||
void (CEF_CALLBACK *set_first_party_for_cookies)(struct _cef_request_t* self,
|
||||
const cef_string_t* url);
|
||||
|
||||
///
|
||||
// Get the resource type for this request. Accurate resource type information
|
||||
// may only be available in the browser process.
|
||||
///
|
||||
enum cef_resource_type_t (CEF_CALLBACK *get_resource_type)(
|
||||
struct _cef_request_t* self);
|
||||
|
||||
///
|
||||
// Get the transition type for this request. Only available in the browser
|
||||
// process and only applies to requests that represent a main frame or sub-
|
||||
// frame navigation.
|
||||
///
|
||||
enum cef_transition_type_t (CEF_CALLBACK *get_transition_type)(
|
||||
struct _cef_request_t* self);
|
||||
} cef_request_t;
|
||||
|
||||
|
||||
|
@ -96,6 +96,20 @@ typedef struct _cef_request_handler_t {
|
||||
///
|
||||
cef_base_t base;
|
||||
|
||||
///
|
||||
// Called on the UI thread before browser navigation. Return true (1) to
|
||||
// cancel the navigation or false (0) to allow the navigation to proceed. The
|
||||
// |request| object cannot be modified in this callback.
|
||||
// cef_display_handler_t::OnLoadingStateChange will be called twice in all
|
||||
// cases. If the navigation is allowed cef_load_handler_t::OnLoadStart and
|
||||
// cef_load_handler_t::OnLoadEnd will be called. If the navigation is canceled
|
||||
// cef_load_handler_t::OnLoadError will be called with an |errorCode| value of
|
||||
// ERR_ABORTED.
|
||||
///
|
||||
int (CEF_CALLBACK *on_before_browse)(struct _cef_request_handler_t* self,
|
||||
struct _cef_browser_t* browser, struct _cef_frame_t* frame,
|
||||
struct _cef_request_t* request, int is_redirect);
|
||||
|
||||
///
|
||||
// Called on the IO thread before a resource request is loaded. The |request|
|
||||
// object may be modified. To cancel the request return true (1) otherwise
|
||||
|
@ -50,7 +50,10 @@
|
||||
class CefDisplayHandler : public virtual CefBase {
|
||||
public:
|
||||
///
|
||||
// Called when the loading state has changed.
|
||||
// Called when the loading state has changed. This callback will be executed
|
||||
// twice -- once when loading is initiated either programmatically or by user
|
||||
// action, and once when loading is terminated due to completion, cancellation
|
||||
// of failure.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
||||
|
@ -58,7 +58,8 @@ class CefLoadHandler : public virtual CefBase {
|
||||
// main frame. Multiple frames may be loading at the same time. Sub-frames may
|
||||
// start or continue loading after the main frame load has ended. This method
|
||||
// may not be called for a particular frame if the load request for that frame
|
||||
// fails.
|
||||
// fails. For notification of overall browser load status use
|
||||
// CefDisplayHandler:: OnLoadingStateChange instead.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
@ -78,10 +79,10 @@ class CefLoadHandler : public virtual CefBase {
|
||||
int httpStatusCode) {}
|
||||
|
||||
///
|
||||
// Called when the browser fails to load a resource. |errorCode| is the error
|
||||
// code number, |errorText| is the error text and and |failedUrl| is the URL
|
||||
// that failed to load. See net\base\net_error_list.h for complete
|
||||
// descriptions of the error codes.
|
||||
// Called when the resource load for a navigation fails or is canceled.
|
||||
// |errorCode| is the error code number, |errorText| is the error text and
|
||||
// |failedUrl| is the URL that failed to load. See net\base\net_error_list.h
|
||||
// for complete descriptions of the error codes.
|
||||
///
|
||||
/*--cef(optional_param=errorText)--*/
|
||||
virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
|
||||
|
@ -53,6 +53,8 @@ class CefPostDataElement;
|
||||
class CefRequest : public virtual CefBase {
|
||||
public:
|
||||
typedef std::multimap<CefString, CefString> HeaderMap;
|
||||
typedef cef_resource_type_t ResourceType;
|
||||
typedef cef_transition_type_t TransitionType;
|
||||
|
||||
///
|
||||
// Create a new CefRequest object.
|
||||
@ -151,6 +153,21 @@ class CefRequest : public virtual CefBase {
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void SetFirstPartyForCookies(const CefString& url) =0;
|
||||
|
||||
///
|
||||
// Get the resource type for this request. Accurate resource type information
|
||||
// may only be available in the browser process.
|
||||
///
|
||||
/*--cef(default_retval=RT_SUB_RESOURCE)--*/
|
||||
virtual ResourceType GetResourceType() =0;
|
||||
|
||||
///
|
||||
// Get the transition type for this request. Only available in the browser
|
||||
// process and only applies to requests that represent a main frame or
|
||||
// sub-frame navigation.
|
||||
///
|
||||
/*--cef(default_retval=TT_EXPLICIT)--*/
|
||||
virtual TransitionType GetTransitionType() =0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -92,6 +92,24 @@ class CefAllowCertificateErrorCallback : public virtual CefBase {
|
||||
/*--cef(source=client)--*/
|
||||
class CefRequestHandler : public virtual CefBase {
|
||||
public:
|
||||
///
|
||||
// Called on the UI thread before browser navigation. Return true to cancel
|
||||
// the navigation or false to allow the navigation to proceed. The |request|
|
||||
// object cannot be modified in this callback.
|
||||
// CefDisplayHandler::OnLoadingStateChange will be called twice in all cases.
|
||||
// If the navigation is allowed CefLoadHandler::OnLoadStart and
|
||||
// CefLoadHandler::OnLoadEnd will be called. If the navigation is canceled
|
||||
// CefLoadHandler::OnLoadError will be called with an |errorCode| value of
|
||||
// ERR_ABORTED.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
bool is_redirect) {
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
// Called on the IO thread before a resource request is loaded. The |request|
|
||||
// object may be modified. To cancel the request return true otherwise return
|
||||
|
@ -792,6 +792,183 @@ enum cef_postdataelement_type_t {
|
||||
PDE_TYPE_FILE,
|
||||
};
|
||||
|
||||
///
|
||||
// Resource type for a request.
|
||||
///
|
||||
enum cef_resource_type_t {
|
||||
///
|
||||
// Top level page.
|
||||
///
|
||||
RT_MAIN_FRAME = 0,
|
||||
|
||||
///
|
||||
// Frame or iframe.
|
||||
///
|
||||
RT_SUB_FRAME,
|
||||
|
||||
///
|
||||
// CSS stylesheet.
|
||||
///
|
||||
RT_STYLESHEET,
|
||||
|
||||
///
|
||||
// External script.
|
||||
///
|
||||
RT_SCRIPT,
|
||||
|
||||
///
|
||||
// Image (jpg/gif/png/etc).
|
||||
///
|
||||
RT_IMAGE,
|
||||
|
||||
///
|
||||
// Font.
|
||||
///
|
||||
RT_FONT_RESOURCE,
|
||||
|
||||
///
|
||||
// Some other subresource. This is the default type if the actual type is
|
||||
// unknown.
|
||||
///
|
||||
RT_SUB_RESOURCE,
|
||||
|
||||
///
|
||||
// Object (or embed) tag for a plugin, or a resource that a plugin requested.
|
||||
///
|
||||
RT_OBJECT,
|
||||
|
||||
///
|
||||
// Media resource.
|
||||
///
|
||||
RT_MEDIA,
|
||||
|
||||
///
|
||||
// Main resource of a dedicated worker.
|
||||
///
|
||||
RT_WORKER,
|
||||
|
||||
///
|
||||
// Main resource of a shared worker.
|
||||
///
|
||||
RT_SHARED_WORKER,
|
||||
|
||||
///
|
||||
// Explicitly requested prefetch.
|
||||
///
|
||||
RT_PREFETCH,
|
||||
|
||||
///
|
||||
// Favicon.
|
||||
///
|
||||
RT_FAVICON,
|
||||
|
||||
///
|
||||
// XMLHttpRequest.
|
||||
///
|
||||
RT_XHR,
|
||||
};
|
||||
|
||||
///
|
||||
// Transition type for a request. Made up of one source value and 0 or more
|
||||
// qualifiers.
|
||||
///
|
||||
enum cef_transition_type_t {
|
||||
///
|
||||
// Source is a link click or the JavaScript window.open function. This is
|
||||
// also the default value for requests like sub-resource loads that are not
|
||||
// navigations.
|
||||
///
|
||||
TT_LINK = 0,
|
||||
|
||||
///
|
||||
// Source is some other "explicit" navigation action such as creating a new
|
||||
// browser or using the LoadURL function. This is also the default value
|
||||
// for navigations where the actual type is unknown.
|
||||
///
|
||||
TT_EXPLICIT = 1,
|
||||
|
||||
///
|
||||
// Source is a subframe navigation. This is any content that is automatically
|
||||
// loaded in a non-toplevel frame. For example, if a page consists of several
|
||||
// frames containing ads, those ad URLs will have this transition type.
|
||||
// The user may not even realize the content in these pages is a separate
|
||||
// frame, so may not care about the URL.
|
||||
///
|
||||
TT_AUTO_SUBFRAME = 3,
|
||||
|
||||
///
|
||||
// Source is a subframe navigation explicitly requested by the user that will
|
||||
// generate new navigation entries in the back/forward list. These are
|
||||
// probably more important than frames that were automatically loaded in
|
||||
// the background because the user probably cares about the fact that this
|
||||
// link was loaded.
|
||||
///
|
||||
TT_MANUAL_SUBFRAME = 4,
|
||||
|
||||
///
|
||||
// Source is a form submission by the user. NOTE: In some situations
|
||||
// submitting a form does not result in this transition type. This can happen
|
||||
// if the form uses a script to submit the contents.
|
||||
///
|
||||
TT_FORM_SUBMIT = 7,
|
||||
|
||||
///
|
||||
// Source is a "reload" of the page via the Reload function or by re-visiting
|
||||
// the same URL. NOTE: This is distinct from the concept of whether a
|
||||
// particular load uses "reload semantics" (i.e. bypasses cached data).
|
||||
///
|
||||
TT_RELOAD = 8,
|
||||
|
||||
///
|
||||
// General mask defining the bits used for the source values.
|
||||
///
|
||||
TT_SOURCE_MASK = 0xFF,
|
||||
|
||||
// Qualifiers.
|
||||
// Any of the core values above can be augmented by one or more qualifiers.
|
||||
// These qualifiers further define the transition.
|
||||
|
||||
///
|
||||
// Attempted to visit a URL but was blocked.
|
||||
///
|
||||
TT_BLOCKED_FLAG = 0x00800000,
|
||||
|
||||
///
|
||||
// Used the Forward or Back function to navigate among browsing history.
|
||||
///
|
||||
TT_FORWARD_BACK_FLAG = 0x01000000,
|
||||
|
||||
///
|
||||
// The beginning of a navigation chain.
|
||||
///
|
||||
TT_CHAIN_START_FLAG = 0x10000000,
|
||||
|
||||
///
|
||||
// The last transition in a redirect chain.
|
||||
///
|
||||
TT_CHAIN_END_FLAG = 0x20000000,
|
||||
|
||||
///
|
||||
// Redirects caused by JavaScript or a meta refresh tag on the page.
|
||||
///
|
||||
TT_CLIENT_REDIRECT_FLAG = 0x40000000,
|
||||
|
||||
///
|
||||
// Redirects sent from the server by HTTP headers.
|
||||
///
|
||||
TT_SERVER_REDIRECT_FLAG = 0x80000000,
|
||||
|
||||
///
|
||||
// Used to test whether a transition involves a redirect.
|
||||
///
|
||||
TT_IS_REDIRECT_MASK = 0xC0000000,
|
||||
|
||||
///
|
||||
// General mask defining the bits used for the qualifiers.
|
||||
///
|
||||
TT_QUALIFIER_MASK = 0xFFFFFF00,
|
||||
};
|
||||
|
||||
///
|
||||
// Flags used to customize the behavior of CefURLRequest.
|
||||
///
|
||||
|
@ -5,16 +5,93 @@
|
||||
#include "libcef/browser/resource_dispatcher_host_delegate.h"
|
||||
#include "libcef/browser/browser_host_impl.h"
|
||||
#include "libcef/browser/origin_whitelist_impl.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/common/request_impl.h"
|
||||
|
||||
#include "base/memory/scoped_vector.h"
|
||||
#include "components/navigation_interception/intercept_navigation_resource_throttle.h"
|
||||
#include "components/navigation_interception/navigation_params.h"
|
||||
#include "content/public/browser/resource_request_info.h"
|
||||
#include "content/public/common/resource_response.h"
|
||||
#include "net/http/http_response_headers.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
|
||||
namespace {
|
||||
|
||||
bool NavigationOnUIThread(
|
||||
int64 frame_id,
|
||||
CefRefPtr<CefRequestImpl> request,
|
||||
content::RenderViewHost* source,
|
||||
const navigation_interception::NavigationParams& params) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
bool ignore_navigation = false;
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> browser =
|
||||
CefBrowserHostImpl::GetBrowserForHost(source);
|
||||
DCHECK(browser.get());
|
||||
if (browser.get()) {
|
||||
CefRefPtr<CefClient> client = browser->GetClient();
|
||||
if (client.get()) {
|
||||
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
||||
if (handler.get()) {
|
||||
CefRefPtr<CefFrame> frame;
|
||||
if (frame_id >= 0)
|
||||
frame = browser->GetFrame(frame_id);
|
||||
DCHECK(frame.get());
|
||||
if (frame.get()) {
|
||||
ignore_navigation = handler->OnBeforeBrowse(
|
||||
browser.get(), frame, request.get(), params.is_redirect());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ignore_navigation;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CefResourceDispatcherHostDelegate::CefResourceDispatcherHostDelegate() {
|
||||
}
|
||||
|
||||
CefResourceDispatcherHostDelegate::~CefResourceDispatcherHostDelegate() {
|
||||
}
|
||||
|
||||
void CefResourceDispatcherHostDelegate::RequestBeginning(
|
||||
net::URLRequest* request,
|
||||
content::ResourceContext* resource_context,
|
||||
appcache::AppCacheService* appcache_service,
|
||||
ResourceType::Type resource_type,
|
||||
int child_id,
|
||||
int route_id,
|
||||
bool is_continuation_of_transferred_request,
|
||||
ScopedVector<content::ResourceThrottle>* throttles) {
|
||||
if (resource_type == ResourceType::MAIN_FRAME ||
|
||||
resource_type == ResourceType::SUB_FRAME) {
|
||||
int64 frame_id = -1;
|
||||
|
||||
// ResourceRequestInfo will not exist for requests originating from
|
||||
// WebURLLoader in the render process.
|
||||
const content::ResourceRequestInfo* info =
|
||||
content::ResourceRequestInfo::ForRequest(request);
|
||||
if (info)
|
||||
frame_id = info->GetFrameID();
|
||||
|
||||
if (frame_id >= 0) {
|
||||
CefRefPtr<CefRequestImpl> cef_request(new CefRequestImpl);
|
||||
cef_request->Set(request);
|
||||
cef_request->SetReadOnly(true);
|
||||
|
||||
content::ResourceThrottle* throttle =
|
||||
new navigation_interception::InterceptNavigationResourceThrottle(
|
||||
request,
|
||||
base::Bind(&NavigationOnUIThread, frame_id, cef_request));
|
||||
throttles->push_back(throttle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CefResourceDispatcherHostDelegate::HandleExternalProtocol(const GURL& url,
|
||||
int child_id,
|
||||
int route_id) {
|
||||
|
@ -17,6 +17,15 @@ class CefResourceDispatcherHostDelegate
|
||||
virtual ~CefResourceDispatcherHostDelegate();
|
||||
|
||||
// ResourceDispatcherHostDelegate methods.
|
||||
virtual void RequestBeginning(
|
||||
net::URLRequest* request,
|
||||
content::ResourceContext* resource_context,
|
||||
appcache::AppCacheService* appcache_service,
|
||||
ResourceType::Type resource_type,
|
||||
int child_id,
|
||||
int route_id,
|
||||
bool is_continuation_of_transferred_request,
|
||||
ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE;
|
||||
virtual bool HandleExternalProtocol(const GURL& url,
|
||||
int child_id,
|
||||
int route_id) OVERRIDE;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "libcef/common/task_runner_impl.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "content/public/browser/resource_request_info.h"
|
||||
#include "net/base/upload_data.h"
|
||||
#include "net/base/upload_data_stream.h"
|
||||
#include "net/base/upload_element_reader.h"
|
||||
@ -22,6 +23,7 @@
|
||||
#include "third_party/WebKit/public/platform/WebURL.h"
|
||||
#include "third_party/WebKit/public/platform/WebURLError.h"
|
||||
#include "third_party/WebKit/public/platform/WebURLRequest.h"
|
||||
#include "webkit/glue/resource_type.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -103,6 +105,8 @@ CefRefPtr<CefRequest> CefRequest::Create() {
|
||||
|
||||
CefRequestImpl::CefRequestImpl()
|
||||
: method_("GET"),
|
||||
resource_type_(RT_SUB_RESOURCE),
|
||||
transition_type_(TT_EXPLICIT),
|
||||
flags_(UR_FLAG_NONE),
|
||||
read_only_(false) {
|
||||
}
|
||||
@ -188,6 +192,16 @@ void CefRequestImpl::SetFirstPartyForCookies(const CefString& url) {
|
||||
first_party_for_cookies_ = url;
|
||||
}
|
||||
|
||||
CefRequestImpl::ResourceType CefRequestImpl::GetResourceType() {
|
||||
AutoLock lock_scope(this);
|
||||
return resource_type_;
|
||||
}
|
||||
|
||||
CefRequestImpl::TransitionType CefRequestImpl::GetTransitionType() {
|
||||
AutoLock lock_scope(this);
|
||||
return transition_type_;
|
||||
}
|
||||
|
||||
void CefRequestImpl::Set(net::URLRequest* request) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
@ -223,6 +237,18 @@ void CefRequestImpl::Set(net::URLRequest* request) {
|
||||
} else if (postdata_.get()) {
|
||||
postdata_ = NULL;
|
||||
}
|
||||
|
||||
const content::ResourceRequestInfo* info =
|
||||
content::ResourceRequestInfo::ForRequest(request);
|
||||
if (info) {
|
||||
resource_type_ =
|
||||
static_cast<cef_resource_type_t>(info->GetResourceType());
|
||||
transition_type_ =
|
||||
static_cast<cef_transition_type_t>(info->GetPageTransition());
|
||||
} else {
|
||||
resource_type_ = RT_SUB_RESOURCE;
|
||||
transition_type_ = TT_EXPLICIT;
|
||||
}
|
||||
}
|
||||
|
||||
void CefRequestImpl::Get(net::URLRequest* request) {
|
||||
@ -291,6 +317,9 @@ void CefRequestImpl::Set(const WebKit::WebURLRequest& request) {
|
||||
flags_ |= UR_FLAG_REPORT_RAW_HEADERS;
|
||||
|
||||
first_party_for_cookies_ = request.firstPartyForCookies().spec().utf16();
|
||||
|
||||
resource_type_ = static_cast<cef_resource_type_t>(
|
||||
::ResourceType::FromTargetType(request.targetType()));
|
||||
}
|
||||
|
||||
void CefRequestImpl::Get(WebKit::WebURLRequest& request) {
|
||||
|
@ -45,6 +45,8 @@ class CefRequestImpl : public CefRequest {
|
||||
virtual void SetFlags(int flags) OVERRIDE;
|
||||
virtual CefString GetFirstPartyForCookies() OVERRIDE;
|
||||
virtual void SetFirstPartyForCookies(const CefString& url) OVERRIDE;
|
||||
virtual ResourceType GetResourceType() OVERRIDE;
|
||||
virtual TransitionType GetTransitionType() OVERRIDE;
|
||||
|
||||
// Populate this object from the URLRequest object.
|
||||
void Set(net::URLRequest* request);
|
||||
@ -72,6 +74,8 @@ class CefRequestImpl : public CefRequest {
|
||||
CefString method_;
|
||||
CefRefPtr<CefPostData> postdata_;
|
||||
HeaderMap headermap_;
|
||||
ResourceType resource_type_;
|
||||
TransitionType transition_type_;
|
||||
|
||||
// The below members are used by CefURLRequest.
|
||||
int flags_;
|
||||
|
@ -278,6 +278,37 @@ void CEF_CALLBACK request_set_first_party_for_cookies(
|
||||
CefString(url));
|
||||
}
|
||||
|
||||
enum cef_resource_type_t CEF_CALLBACK request_get_resource_type(
|
||||
struct _cef_request_t* self) {
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return RT_SUB_RESOURCE;
|
||||
|
||||
// Execute
|
||||
cef_resource_type_t _retval = CefRequestCppToC::Get(self)->GetResourceType();
|
||||
|
||||
// Return type: simple
|
||||
return _retval;
|
||||
}
|
||||
|
||||
enum cef_transition_type_t CEF_CALLBACK request_get_transition_type(
|
||||
struct _cef_request_t* self) {
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return TT_EXPLICIT;
|
||||
|
||||
// Execute
|
||||
cef_transition_type_t _retval = CefRequestCppToC::Get(
|
||||
self)->GetTransitionType();
|
||||
|
||||
// Return type: simple
|
||||
return _retval;
|
||||
}
|
||||
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
@ -299,6 +330,8 @@ CefRequestCppToC::CefRequestCppToC(CefRequest* cls)
|
||||
request_get_first_party_for_cookies;
|
||||
struct_.struct_.set_first_party_for_cookies =
|
||||
request_set_first_party_for_cookies;
|
||||
struct_.struct_.get_resource_type = request_get_resource_type;
|
||||
struct_.struct_.get_transition_type = request_get_transition_type;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
@ -24,6 +24,38 @@
|
||||
|
||||
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||
|
||||
int CEF_CALLBACK request_handler_on_before_browse(
|
||||
struct _cef_request_handler_t* self, cef_browser_t* browser,
|
||||
cef_frame_t* frame, cef_request_t* request, int is_redirect) {
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return 0;
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser);
|
||||
if (!browser)
|
||||
return 0;
|
||||
// Verify param: frame; type: refptr_diff
|
||||
DCHECK(frame);
|
||||
if (!frame)
|
||||
return 0;
|
||||
// Verify param: request; type: refptr_diff
|
||||
DCHECK(request);
|
||||
if (!request)
|
||||
return 0;
|
||||
|
||||
// Execute
|
||||
bool _retval = CefRequestHandlerCppToC::Get(self)->OnBeforeBrowse(
|
||||
CefBrowserCToCpp::Wrap(browser),
|
||||
CefFrameCToCpp::Wrap(frame),
|
||||
CefRequestCToCpp::Wrap(request),
|
||||
is_redirect?true:false);
|
||||
|
||||
// Return type: bool
|
||||
return _retval;
|
||||
}
|
||||
|
||||
int CEF_CALLBACK request_handler_on_before_resource_load(
|
||||
struct _cef_request_handler_t* self, cef_browser_t* browser,
|
||||
cef_frame_t* frame, cef_request_t* request) {
|
||||
@ -330,6 +362,7 @@ int CEF_CALLBACK request_handler_on_certificate_error(
|
||||
CefRequestHandlerCppToC::CefRequestHandlerCppToC(CefRequestHandler* cls)
|
||||
: CefCppToC<CefRequestHandlerCppToC, CefRequestHandler,
|
||||
cef_request_handler_t>(cls) {
|
||||
struct_.struct_.on_before_browse = request_handler_on_before_browse;
|
||||
struct_.struct_.on_before_resource_load =
|
||||
request_handler_on_before_resource_load;
|
||||
struct_.struct_.get_resource_handler = request_handler_get_resource_handler;
|
||||
|
@ -269,6 +269,32 @@ void CefRequestCToCpp::SetFirstPartyForCookies(const CefString& url) {
|
||||
url.GetStruct());
|
||||
}
|
||||
|
||||
CefRequest::ResourceType CefRequestCToCpp::GetResourceType() {
|
||||
if (CEF_MEMBER_MISSING(struct_, get_resource_type))
|
||||
return RT_SUB_RESOURCE;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Execute
|
||||
cef_resource_type_t _retval = struct_->get_resource_type(struct_);
|
||||
|
||||
// Return type: simple
|
||||
return _retval;
|
||||
}
|
||||
|
||||
CefRequest::TransitionType CefRequestCToCpp::GetTransitionType() {
|
||||
if (CEF_MEMBER_MISSING(struct_, get_transition_type))
|
||||
return TT_EXPLICIT;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Execute
|
||||
cef_transition_type_t _retval = struct_->get_transition_type(struct_);
|
||||
|
||||
// Return type: simple
|
||||
return _retval;
|
||||
}
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
template<> long CefCToCpp<CefRequestCToCpp, CefRequest,
|
||||
|
@ -47,6 +47,8 @@ class CefRequestCToCpp
|
||||
virtual void SetFlags(int flags) OVERRIDE;
|
||||
virtual CefString GetFirstPartyForCookies() OVERRIDE;
|
||||
virtual void SetFirstPartyForCookies(const CefString& url) OVERRIDE;
|
||||
virtual ResourceType GetResourceType() OVERRIDE;
|
||||
virtual TransitionType GetTransitionType() OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // USING_CEF_SHARED
|
||||
|
@ -24,6 +24,38 @@
|
||||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
bool CefRequestHandlerCToCpp::OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request,
|
||||
bool is_redirect) {
|
||||
if (CEF_MEMBER_MISSING(struct_, on_before_browse))
|
||||
return false;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser.get());
|
||||
if (!browser.get())
|
||||
return false;
|
||||
// Verify param: frame; type: refptr_diff
|
||||
DCHECK(frame.get());
|
||||
if (!frame.get())
|
||||
return false;
|
||||
// Verify param: request; type: refptr_diff
|
||||
DCHECK(request.get());
|
||||
if (!request.get())
|
||||
return false;
|
||||
|
||||
// Execute
|
||||
int _retval = struct_->on_before_browse(struct_,
|
||||
CefBrowserCppToC::Wrap(browser),
|
||||
CefFrameCppToC::Wrap(frame),
|
||||
CefRequestCppToC::Wrap(request),
|
||||
is_redirect);
|
||||
|
||||
// Return type: bool
|
||||
return _retval?true:false;
|
||||
}
|
||||
|
||||
bool CefRequestHandlerCToCpp::OnBeforeResourceLoad(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request) {
|
||||
|
@ -34,6 +34,9 @@ class CefRequestHandlerCToCpp
|
||||
virtual ~CefRequestHandlerCToCpp() {}
|
||||
|
||||
// CefRequestHandler methods
|
||||
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request,
|
||||
bool is_redirect) OVERRIDE;
|
||||
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request) OVERRIDE;
|
||||
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
|
||||
|
@ -38,6 +38,10 @@ void ClientApp::CreateRenderDelegates(RenderDelegateSet& delegates) {
|
||||
extern void CreateNavigationRendererTests(RenderDelegateSet& delegates);
|
||||
CreateNavigationRendererTests(delegates);
|
||||
|
||||
// Bring in the Request tests.
|
||||
extern void CreateRequestRendererTests(RenderDelegateSet& delegates);
|
||||
CreateRequestRendererTests(delegates);
|
||||
|
||||
// Bring in the RequestHandler tests.
|
||||
extern void CreateRequestHandlerRendererTests(RenderDelegateSet& delegates);
|
||||
CreateRequestHandlerRendererTests(delegates);
|
||||
|
@ -104,6 +104,9 @@ class HistoryNavRendererTest : public ClientApp::RenderDelegate {
|
||||
std::string url = request->GetURL();
|
||||
EXPECT_STREQ(item.target, url.c_str());
|
||||
|
||||
EXPECT_EQ(RT_SUB_RESOURCE, request->GetResourceType());
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
|
||||
if (item.action == NA_LOAD)
|
||||
EXPECT_EQ(NAVIGATION_OTHER, navigation_type);
|
||||
else if (item.action == NA_BACK || item.action == NA_FORWARD)
|
||||
@ -211,11 +214,46 @@ class HistoryNavTestHandler : public TestHandler {
|
||||
RunNav(browser);
|
||||
}
|
||||
|
||||
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
bool is_redirect) OVERRIDE {
|
||||
const NavListItem& item = kHNavList[nav_];
|
||||
|
||||
got_before_browse_[nav_].yes();
|
||||
|
||||
std::string url = request->GetURL();
|
||||
EXPECT_STREQ(item.target, url.c_str());
|
||||
|
||||
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
||||
if (item.action == NA_LOAD)
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
else if (item.action == NA_BACK || item.action == NA_FORWARD)
|
||||
EXPECT_EQ(TT_EXPLICIT | TT_FORWARD_BACK_FLAG, request->GetTransitionType());
|
||||
|
||||
if (nav_ > 0) {
|
||||
const NavListItem& last_item = kHNavList[nav_ - 1];
|
||||
EXPECT_EQ(last_item.can_go_back, browser->CanGoBack());
|
||||
EXPECT_EQ(last_item.can_go_forward, browser->CanGoForward());
|
||||
} else {
|
||||
EXPECT_FALSE(browser->CanGoBack());
|
||||
EXPECT_FALSE(browser->CanGoForward());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request) OVERRIDE {
|
||||
const NavListItem& item = kHNavList[nav_];
|
||||
|
||||
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
||||
if (item.action == NA_LOAD)
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
else if (item.action == NA_BACK || item.action == NA_FORWARD)
|
||||
EXPECT_EQ(TT_EXPLICIT | TT_FORWARD_BACK_FLAG, request->GetTransitionType());
|
||||
|
||||
got_before_resource_load_[nav_].yes();
|
||||
|
||||
std::string url = request->GetURL();
|
||||
@ -304,6 +342,7 @@ class HistoryNavTestHandler : public TestHandler {
|
||||
bool load_end_confirmation_;
|
||||
bool renderer_confirmation_;
|
||||
|
||||
TrackCallback got_before_browse_[NAV_LIST_SIZE()];
|
||||
TrackCallback got_before_navigation_[NAV_LIST_SIZE()];
|
||||
TrackCallback got_before_resource_load_[NAV_LIST_SIZE()];
|
||||
TrackCallback got_correct_target_[NAV_LIST_SIZE()];
|
||||
@ -330,6 +369,7 @@ TEST(NavigationTest, History) {
|
||||
|
||||
for (size_t i = 0; i < NAV_LIST_SIZE(); ++i) {
|
||||
if (kHNavList[i].action != NA_CLEAR) {
|
||||
ASSERT_TRUE(handler->got_before_browse_[i]) << "i = " << i;
|
||||
ASSERT_TRUE(handler->got_before_navigation_[i]) << "i = " << i;
|
||||
ASSERT_TRUE(handler->got_before_resource_load_[i]) << "i = " << i;
|
||||
ASSERT_TRUE(handler->got_correct_target_[i]) << "i = " << i;
|
||||
@ -389,6 +429,9 @@ class FrameNameIdentNavTestHandler : public TestHandler {
|
||||
|
||||
std::string url = request->GetURL();
|
||||
if (url == kFNav1) {
|
||||
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
|
||||
frame1_ident_ = frame->GetIdentifier();
|
||||
if (name == "") {
|
||||
frame1_name_ = name;
|
||||
@ -397,6 +440,9 @@ class FrameNameIdentNavTestHandler : public TestHandler {
|
||||
if (!parent.get())
|
||||
got_frame1_ident_parent_before_.yes();
|
||||
} else if (url == kFNav2) {
|
||||
EXPECT_EQ(RT_SUB_FRAME, request->GetResourceType());
|
||||
EXPECT_EQ(TT_LINK, request->GetTransitionType());
|
||||
|
||||
frame2_ident_ = frame->GetIdentifier();
|
||||
if (name == "nav2") {
|
||||
frame2_name_ = name;
|
||||
@ -405,6 +451,9 @@ class FrameNameIdentNavTestHandler : public TestHandler {
|
||||
if (parent.get() && frame1_ident_ == parent->GetIdentifier())
|
||||
got_frame2_ident_parent_before_.yes();
|
||||
} else if (url == kFNav3) {
|
||||
EXPECT_EQ(RT_SUB_FRAME, request->GetResourceType());
|
||||
EXPECT_EQ(TT_LINK, request->GetTransitionType());
|
||||
|
||||
frame3_ident_ = frame->GetIdentifier();
|
||||
if (name == "<!--framePath //nav2/<!--frame0-->-->") {
|
||||
frame3_name_ = name;
|
||||
@ -648,6 +697,9 @@ class RedirectTestHandler : public TestHandler {
|
||||
// Should be called for all but the second URL.
|
||||
std::string url = request->GetURL();
|
||||
|
||||
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
|
||||
if (url == kRNav1) {
|
||||
got_nav1_before_resource_load_.yes();
|
||||
} else if (url == kRNav3) {
|
||||
@ -921,6 +973,9 @@ class OrderNavRendererTest : public ClientApp::RenderDelegate {
|
||||
EXPECT_TRUE(got_render_thread_created_);
|
||||
EXPECT_TRUE(got_webkit_initialized_);
|
||||
|
||||
EXPECT_EQ(RT_SUB_RESOURCE, request->GetResourceType());
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
|
||||
if (browser->IsPopup()) {
|
||||
EXPECT_TRUE(got_browser_created_popup_);
|
||||
EXPECT_FALSE(got_before_navigation_popup_);
|
||||
@ -1035,13 +1090,46 @@ class OrderNavTestHandler : public TestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
bool is_redirect) OVERRIDE {
|
||||
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
||||
|
||||
if (browser->IsPopup()) {
|
||||
EXPECT_EQ(TT_LINK, request->GetTransitionType());
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
||||
got_before_browse_popup_.yes();
|
||||
} else {
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
||||
got_before_browse_main_.yes();
|
||||
}
|
||||
|
||||
std::string url = request->GetURL();
|
||||
if (url == KONav1)
|
||||
EXPECT_FALSE(browser->IsPopup());
|
||||
else if (url == KONav2)
|
||||
EXPECT_TRUE(browser->IsPopup());
|
||||
else
|
||||
EXPECT_TRUE(false); // not reached
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request) OVERRIDE {
|
||||
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
||||
|
||||
if (browser->IsPopup()) {
|
||||
EXPECT_EQ(TT_LINK, request->GetTransitionType());
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
||||
} else {
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
||||
}
|
||||
@ -1118,10 +1206,21 @@ class OrderNavTestHandler : public TestHandler {
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void DestroyTest() OVERRIDE {
|
||||
// Verify test expectations.
|
||||
EXPECT_TRUE(got_before_browse_main_);
|
||||
EXPECT_TRUE(got_before_browse_popup_);
|
||||
|
||||
TestHandler::DestroyTest();
|
||||
}
|
||||
|
||||
int browser_id_main_;
|
||||
int browser_id_popup_;
|
||||
CefRefPtr<CefBrowser> browser_popup_;
|
||||
|
||||
TrackCallback got_before_browse_main_;
|
||||
TrackCallback got_before_browse_popup_;
|
||||
|
||||
bool got_message_;
|
||||
bool got_load_end_;
|
||||
};
|
||||
@ -1246,6 +1345,9 @@ class CrossOriginNavRendererTest : public ClientApp::RenderDelegate {
|
||||
EXPECT_TRUE(got_render_thread_created_);
|
||||
EXPECT_TRUE(got_webkit_initialized_);
|
||||
|
||||
EXPECT_EQ(RT_SUB_RESOURCE, request->GetResourceType());
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
|
||||
Status* status = GetStatus(browser);
|
||||
EXPECT_TRUE(status);
|
||||
|
||||
@ -1370,9 +1472,25 @@ class CrossOriginNavTestHandler : public TestHandler {
|
||||
EXPECT_GT(browser_id_current_, 0);
|
||||
}
|
||||
|
||||
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
bool is_redirect) OVERRIDE {
|
||||
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
|
||||
EXPECT_GT(browser_id_current_, 0);
|
||||
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request) OVERRIDE {
|
||||
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
|
||||
EXPECT_GT(browser_id_current_, 0);
|
||||
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
||||
|
||||
@ -1544,6 +1662,167 @@ TEST(NavigationTest, PopupDeny) {
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
const char kBrowseNavPageUrl[] = "http://tests-browsenav/nav.html";
|
||||
|
||||
// Browser side.
|
||||
class BrowseNavTestHandler : public TestHandler {
|
||||
public:
|
||||
BrowseNavTestHandler(bool allow)
|
||||
: allow_(allow),
|
||||
destroyed_(false) {}
|
||||
|
||||
virtual void RunTest() OVERRIDE {
|
||||
AddResource(kBrowseNavPageUrl, "<html>Test</html>", "text/html");
|
||||
|
||||
// Create the browser.
|
||||
CreateBrowser(kBrowseNavPageUrl);
|
||||
|
||||
// Time out the test after a reasonable period of time.
|
||||
CefPostDelayedTask(TID_UI,
|
||||
NewCefRunnableMethod(this, &BrowseNavTestHandler::DestroyTest),
|
||||
2000);
|
||||
}
|
||||
|
||||
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
bool is_redirect) OVERRIDE {
|
||||
const std::string& url = request->GetURL();
|
||||
EXPECT_STREQ(kBrowseNavPageUrl, url.c_str());
|
||||
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
||||
EXPECT_TRUE(frame->IsMain());
|
||||
|
||||
got_before_browse_.yes();
|
||||
|
||||
return !allow_;
|
||||
}
|
||||
|
||||
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame) OVERRIDE {
|
||||
const std::string& url = frame->GetURL();
|
||||
EXPECT_STREQ(kBrowseNavPageUrl, url.c_str());
|
||||
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
||||
EXPECT_TRUE(frame->IsMain());
|
||||
|
||||
got_load_start_.yes();
|
||||
}
|
||||
|
||||
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) OVERRIDE {
|
||||
const std::string& url = frame->GetURL();
|
||||
EXPECT_STREQ(kBrowseNavPageUrl, url.c_str());
|
||||
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
||||
EXPECT_TRUE(frame->IsMain());
|
||||
|
||||
got_load_end_.yes();
|
||||
DestroyTestIfDone();
|
||||
}
|
||||
|
||||
virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
ErrorCode errorCode,
|
||||
const CefString& errorText,
|
||||
const CefString& failedUrl) OVERRIDE {
|
||||
const std::string& url = frame->GetURL();
|
||||
EXPECT_STREQ("", url.c_str());
|
||||
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
||||
EXPECT_TRUE(frame->IsMain());
|
||||
|
||||
EXPECT_EQ(ERR_ABORTED, errorCode);
|
||||
EXPECT_STREQ(kBrowseNavPageUrl, failedUrl.ToString().c_str());
|
||||
|
||||
got_load_error_.yes();
|
||||
DestroyTestIfDone();
|
||||
}
|
||||
|
||||
virtual void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
||||
bool isLoading,
|
||||
bool canGoBack,
|
||||
bool canGoForward) OVERRIDE {
|
||||
const std::string& url = browser->GetMainFrame()->GetURL();
|
||||
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
||||
|
||||
if (isLoading) {
|
||||
EXPECT_STREQ("", url.c_str());
|
||||
|
||||
got_loading_state_changed_start_.yes();
|
||||
} else {
|
||||
if (allow_)
|
||||
EXPECT_STREQ(kBrowseNavPageUrl, url.c_str());
|
||||
else
|
||||
EXPECT_STREQ("", url.c_str());
|
||||
|
||||
got_loading_state_changed_end_.yes();
|
||||
DestroyTestIfDone();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void DestroyTestIfDone() {
|
||||
if (destroyed_)
|
||||
return;
|
||||
|
||||
if (got_loading_state_changed_end_) {
|
||||
if (allow_) {
|
||||
if (got_load_end_)
|
||||
DestroyTest();
|
||||
} else if (got_load_error_) {
|
||||
DestroyTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void DestroyTest() OVERRIDE {
|
||||
if (destroyed_)
|
||||
return;
|
||||
destroyed_ = true;
|
||||
|
||||
EXPECT_TRUE(got_before_browse_);
|
||||
EXPECT_TRUE(got_loading_state_changed_start_);
|
||||
EXPECT_TRUE(got_loading_state_changed_end_);
|
||||
|
||||
if (allow_) {
|
||||
EXPECT_TRUE(got_load_start_);
|
||||
EXPECT_TRUE(got_load_end_);
|
||||
EXPECT_FALSE(got_load_error_);
|
||||
} else {
|
||||
EXPECT_FALSE(got_load_start_);
|
||||
EXPECT_FALSE(got_load_end_);
|
||||
EXPECT_TRUE(got_load_error_);
|
||||
}
|
||||
|
||||
TestHandler::DestroyTest();
|
||||
}
|
||||
|
||||
bool allow_;
|
||||
bool destroyed_;
|
||||
|
||||
TrackCallback got_before_browse_;
|
||||
TrackCallback got_load_start_;
|
||||
TrackCallback got_load_end_;
|
||||
TrackCallback got_load_error_;
|
||||
TrackCallback got_loading_state_changed_start_;
|
||||
TrackCallback got_loading_state_changed_end_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Test allowing navigation.
|
||||
TEST(NavigationTest, BrowseAllow) {
|
||||
CefRefPtr<BrowseNavTestHandler> handler = new BrowseNavTestHandler(true);
|
||||
handler->ExecuteTest();
|
||||
}
|
||||
|
||||
// Test denying navigation.
|
||||
TEST(NavigationTest, BrowseDeny) {
|
||||
CefRefPtr<BrowseNavTestHandler> handler = new BrowseNavTestHandler(false);
|
||||
handler->ExecuteTest();
|
||||
}
|
||||
|
||||
|
||||
// Entry point for creating navigation browser test objects.
|
||||
// Called from client_app_delegates.cc.
|
||||
void CreateNavigationBrowserTests(ClientApp::BrowserDelegateSet& delegates) {
|
||||
|
@ -2,7 +2,11 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "include/cef_request.h"
|
||||
#include "include/cef_runnable.h"
|
||||
#include "tests/cefclient/client_app.h"
|
||||
#include "tests/unittests/test_handler.h"
|
||||
#include "tests/unittests/test_util.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -152,6 +156,8 @@ class RequestSendRecvTestHandler : public TestHandler {
|
||||
CefRefPtr<CefRequest> request) OVERRIDE {
|
||||
// Verify that the request is the same
|
||||
TestRequestEqual(request_, request, true);
|
||||
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
||||
EXPECT_EQ(TT_LINK, request->GetTransitionType());
|
||||
|
||||
got_before_resource_load_.yes();
|
||||
|
||||
@ -164,6 +170,8 @@ class RequestSendRecvTestHandler : public TestHandler {
|
||||
CefRefPtr<CefRequest> request) OVERRIDE {
|
||||
// Verify that the request is the same
|
||||
TestRequestEqual(request_, request, true);
|
||||
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
||||
EXPECT_EQ(TT_LINK, request->GetTransitionType());
|
||||
|
||||
got_resource_handler_.yes();
|
||||
|
||||
@ -190,3 +198,335 @@ TEST(RequestTest, SendRecv) {
|
||||
ASSERT_TRUE(handler->got_before_resource_load_);
|
||||
ASSERT_TRUE(handler->got_resource_handler_);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
const char kTypeTestCompleteMsg[] = "RequestTest.Type";
|
||||
const char kTypeTestOrigin[] = "http://tests-requesttt.com/";
|
||||
|
||||
static struct TypeExpected {
|
||||
const char* file;
|
||||
bool browser_side; // True if this expectation applies to the browser side.
|
||||
bool navigation; // True if this expectation represents a navigation.
|
||||
cef_transition_type_t transition_type;
|
||||
cef_resource_type_t resource_type;
|
||||
int expected_count;
|
||||
} g_type_expected[] = {
|
||||
// Initial main frame load due to browser creation.
|
||||
{"main.html", true, true, TT_EXPLICIT, RT_MAIN_FRAME, 1},
|
||||
{"main.html", false, true, TT_EXPLICIT, RT_SUB_RESOURCE, 1},
|
||||
|
||||
// Sub frame load.
|
||||
{"sub.html", true, true, TT_LINK, RT_SUB_FRAME, 1},
|
||||
{"sub.html", false, true, TT_EXPLICIT, RT_SUB_RESOURCE, 1},
|
||||
|
||||
// Stylesheet load.
|
||||
{"style.css", true, false, TT_LINK, RT_STYLESHEET, 1},
|
||||
|
||||
// Script load.
|
||||
{"script.js", true, false, TT_LINK, RT_SCRIPT, 1},
|
||||
|
||||
// Image load.
|
||||
{"image.png", true, false, TT_LINK, RT_IMAGE, 1},
|
||||
|
||||
// Font load.
|
||||
{"font.ttf", true, false, TT_LINK, RT_FONT_RESOURCE, 1},
|
||||
|
||||
// XHR load.
|
||||
{"xhr.html", true, false, TT_LINK, RT_XHR, 1},
|
||||
};
|
||||
|
||||
class TypeExpectations {
|
||||
public:
|
||||
TypeExpectations(bool browser_side, bool navigation)
|
||||
: browser_side_(browser_side),
|
||||
navigation_(navigation) {
|
||||
// Build the map of relevant requests.
|
||||
for (size_t i = 0; i < sizeof(g_type_expected) / sizeof(TypeExpected); ++i) {
|
||||
if (g_type_expected[i].browser_side != browser_side_ ||
|
||||
(navigation_ && g_type_expected[i].navigation != navigation_))
|
||||
continue;
|
||||
|
||||
request_count_.insert(std::make_pair(i, 0));
|
||||
}
|
||||
}
|
||||
|
||||
// Notify that a request has been received. Returns true if the request is
|
||||
// something we care about.
|
||||
bool GotRequest(CefRefPtr<CefRequest> request) {
|
||||
const std::string& url = request->GetURL();
|
||||
if (url.find(kTypeTestOrigin) != 0)
|
||||
return false;
|
||||
|
||||
const std::string& file = url.substr(sizeof(kTypeTestOrigin)-1);
|
||||
cef_transition_type_t transition_type = request->GetTransitionType();
|
||||
cef_resource_type_t resource_type = request->GetResourceType();
|
||||
|
||||
const int index = GetExpectedIndex(file, transition_type, resource_type);
|
||||
EXPECT_GE(index, 0)
|
||||
<< "File: " << file.c_str()
|
||||
<< "; Browser Side: " << browser_side_
|
||||
<< "; Navigation: " << navigation_
|
||||
<< "; Transition Type: " << transition_type
|
||||
<< "; Resource Type: " << resource_type;
|
||||
|
||||
RequestCount::iterator it = request_count_.find(index);
|
||||
EXPECT_TRUE(it != request_count_.end());
|
||||
|
||||
const int actual_count = ++it->second;
|
||||
const int expected_count = g_type_expected[index].expected_count;
|
||||
EXPECT_LE(actual_count, expected_count)
|
||||
<< "File: " << file.c_str()
|
||||
<< "; Browser Side: " << browser_side_
|
||||
<< "; Navigation: " << navigation_
|
||||
<< "; Transition Type: " << transition_type
|
||||
<< "; Resource Type: " << resource_type;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Test if all expectations have been met.
|
||||
bool IsDone(bool assert) {
|
||||
for (size_t i = 0; i < sizeof(g_type_expected) / sizeof(TypeExpected); ++i) {
|
||||
if (g_type_expected[i].browser_side != browser_side_ ||
|
||||
(navigation_ && g_type_expected[i].navigation != navigation_))
|
||||
continue;
|
||||
|
||||
RequestCount::const_iterator it = request_count_.find(i);
|
||||
EXPECT_TRUE(it != request_count_.end());
|
||||
if (it->second != g_type_expected[i].expected_count) {
|
||||
if (assert) {
|
||||
EXPECT_EQ(g_type_expected[i].expected_count, it->second)
|
||||
<< "File: " << g_type_expected[i].file
|
||||
<< "; Browser Side: " << browser_side_
|
||||
<< "; Navigation: " << navigation_
|
||||
<< "; Transition Type: " << g_type_expected[i].transition_type
|
||||
<< "; Resource Type: " << g_type_expected[i].resource_type;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
// Returns the index for the specified navigation.
|
||||
int GetExpectedIndex(const std::string& file,
|
||||
cef_transition_type_t transition_type,
|
||||
cef_resource_type_t resource_type) {
|
||||
for (size_t i = 0; i < sizeof(g_type_expected) / sizeof(TypeExpected); ++i) {
|
||||
if (g_type_expected[i].file == file &&
|
||||
g_type_expected[i].browser_side == browser_side_ &&
|
||||
(!navigation_ || g_type_expected[i].navigation == navigation_) &&
|
||||
g_type_expected[i].transition_type == transition_type &&
|
||||
g_type_expected[i].resource_type == resource_type) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool browser_side_;
|
||||
bool navigation_;
|
||||
|
||||
// Map of TypeExpected index to actual request count.
|
||||
typedef std::map<int, int> RequestCount;
|
||||
RequestCount request_count_;
|
||||
};
|
||||
|
||||
// Renderer side.
|
||||
class TypeRendererTest : public ClientApp::RenderDelegate {
|
||||
public:
|
||||
TypeRendererTest() :
|
||||
expectations_(false, true) {}
|
||||
|
||||
virtual bool OnBeforeNavigation(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
cef_navigation_type_t navigation_type,
|
||||
bool is_redirect) OVERRIDE {
|
||||
if (expectations_.GotRequest(request) && expectations_.IsDone(false))
|
||||
SendTestResults(browser);
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
// Send the test results.
|
||||
void SendTestResults(CefRefPtr<CefBrowser> browser) {
|
||||
// Check if the test has failed.
|
||||
bool result = !TestFailed();
|
||||
|
||||
// Return the result to the browser process.
|
||||
CefRefPtr<CefProcessMessage> return_msg =
|
||||
CefProcessMessage::Create(kTypeTestCompleteMsg);
|
||||
CefRefPtr<CefListValue> args = return_msg->GetArgumentList();
|
||||
EXPECT_TRUE(args.get());
|
||||
EXPECT_TRUE(args->SetBool(0, result));
|
||||
EXPECT_TRUE(browser->SendProcessMessage(PID_BROWSER, return_msg));
|
||||
}
|
||||
|
||||
TypeExpectations expectations_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(TypeRendererTest);
|
||||
};
|
||||
|
||||
// Browser side.
|
||||
class TypeTestHandler : public TestHandler {
|
||||
public:
|
||||
TypeTestHandler() :
|
||||
browse_expectations_(true, true),
|
||||
load_expectations_(true, false),
|
||||
get_expectations_(true, false),
|
||||
completed_browser_side_(false),
|
||||
completed_render_side_(false),
|
||||
destroyed_(false) {}
|
||||
|
||||
virtual void RunTest() OVERRIDE {
|
||||
AddResource(std::string(kTypeTestOrigin) + "main.html",
|
||||
"<html>"
|
||||
"<head>"
|
||||
"<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">"
|
||||
"<script type=\"text/javascript\" src=\"script.js\"></script>"
|
||||
"</head>"
|
||||
"<body><p>Main</p>"
|
||||
"<script>xhr = new XMLHttpRequest();"
|
||||
"xhr.open('GET', 'xhr.html', false);"
|
||||
"xhr.send();</script>"
|
||||
"<iframe src=\"sub.html\"></iframe>"
|
||||
"<img src=\"image.png\">"
|
||||
"</body></html>",
|
||||
"text/html");
|
||||
AddResource(std::string(kTypeTestOrigin) + "sub.html",
|
||||
"<html>Sub</html>",
|
||||
"text/html");
|
||||
AddResource(std::string(kTypeTestOrigin) + "style.css",
|
||||
"@font-face {"
|
||||
" font-family: custom_font;"
|
||||
" src: url('font.ttf');"
|
||||
"}"
|
||||
"p {"
|
||||
" font-family: custom_font;"
|
||||
"}",
|
||||
"text/css");
|
||||
AddResource(std::string(kTypeTestOrigin) + "script.js",
|
||||
"<!-- -->",
|
||||
"text/javascript");
|
||||
AddResource(std::string(kTypeTestOrigin) + "image.png",
|
||||
"<!-- -->",
|
||||
"image/png");
|
||||
AddResource(std::string(kTypeTestOrigin) + "font.ttf",
|
||||
"<!-- -->",
|
||||
"font/ttf");
|
||||
AddResource(std::string(kTypeTestOrigin) + "xhr.html",
|
||||
"<html>XHR</html>",
|
||||
"text/html");
|
||||
|
||||
CreateBrowser(std::string(kTypeTestOrigin) + "main.html");
|
||||
|
||||
// Time out the test after a reasonable period of time.
|
||||
CefPostDelayedTask(TID_UI,
|
||||
NewCefRunnableMethod(this, &TypeTestHandler::DestroyTest),
|
||||
2000);
|
||||
}
|
||||
|
||||
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
bool is_redirect) OVERRIDE {
|
||||
browse_expectations_.GotRequest(request);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request) OVERRIDE {
|
||||
load_expectations_.GotRequest(request);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request) OVERRIDE {
|
||||
if (get_expectations_.GotRequest(request) &&
|
||||
get_expectations_.IsDone(false)) {
|
||||
completed_browser_side_ = true;
|
||||
// Destroy the test on the UI thread.
|
||||
CefPostTask(TID_UI,
|
||||
NewCefRunnableMethod(this, &TypeTestHandler::DestroyTestIfComplete));
|
||||
}
|
||||
|
||||
return TestHandler::GetResourceHandler(browser, frame, request);
|
||||
}
|
||||
|
||||
virtual bool OnProcessMessageReceived(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE {
|
||||
const std::string& msg_name = message->GetName();
|
||||
if (msg_name == kTypeTestCompleteMsg) {
|
||||
// Test that the renderer side succeeded.
|
||||
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||
EXPECT_TRUE(args.get());
|
||||
EXPECT_TRUE(args->GetBool(0));
|
||||
|
||||
completed_render_side_ = true;
|
||||
DestroyTestIfComplete();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Message not handled.
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
void DestroyTestIfComplete() {
|
||||
if (destroyed_)
|
||||
return;
|
||||
|
||||
if (completed_browser_side_ && completed_render_side_)
|
||||
DestroyTest();
|
||||
}
|
||||
|
||||
virtual void DestroyTest() OVERRIDE {
|
||||
if (destroyed_)
|
||||
return;
|
||||
destroyed_ = true;
|
||||
|
||||
// Verify test expectations.
|
||||
EXPECT_TRUE(completed_browser_side_);
|
||||
EXPECT_TRUE(completed_render_side_);
|
||||
EXPECT_TRUE(browse_expectations_.IsDone(true));
|
||||
EXPECT_TRUE(load_expectations_.IsDone(true));
|
||||
EXPECT_TRUE(get_expectations_.IsDone(true));
|
||||
|
||||
TestHandler::DestroyTest();
|
||||
}
|
||||
|
||||
TypeExpectations browse_expectations_;
|
||||
TypeExpectations load_expectations_;
|
||||
TypeExpectations get_expectations_;
|
||||
|
||||
bool completed_browser_side_;
|
||||
bool completed_render_side_;
|
||||
bool destroyed_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Verify the order of navigation-related callbacks.
|
||||
TEST(RequestTest, ResourceAndTransitionType) {
|
||||
CefRefPtr<TypeTestHandler> handler =
|
||||
new TypeTestHandler();
|
||||
handler->ExecuteTest();
|
||||
}
|
||||
|
||||
|
||||
// Entry point for creating request renderer test objects.
|
||||
// Called from client_app_delegates.cc.
|
||||
void CreateRequestRendererTests(ClientApp::RenderDelegateSet& delegates) {
|
||||
delegates.insert(new TypeRendererTest);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user