Enable browser-side navigation by default and remove CefRenderHandler::OnBeforeNavigation (issue #2290)

This commit is contained in:
Marshall Greenblatt 2018-02-12 18:01:43 -05:00
parent 98de8e79db
commit de1bd286f8
21 changed files with 41 additions and 580 deletions

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=44b61ca19efaae0a664d6d502d550755fbf326fa$
// $hash=fb34d81715ada28d5509cd33aa36f37829933a91$
//
#ifndef CEF_INCLUDE_CAPI_CEF_RENDER_PROCESS_HANDLER_CAPI_H_
@ -102,19 +102,6 @@ typedef struct _cef_render_process_handler_t {
struct _cef_load_handler_t*(CEF_CALLBACK* get_load_handler)(
struct _cef_render_process_handler_t* self);
///
// Called 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.
///
int(CEF_CALLBACK* on_before_navigation)(
struct _cef_render_process_handler_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
struct _cef_request_t* request,
cef_navigation_type_t navigation_type,
int is_redirect);
///
// Called immediately after the V8 context for a frame has been created. To
// retrieve the JavaScript 'window' object use the

View File

@ -92,20 +92,6 @@ class CefRenderProcessHandler : public virtual CefBaseRefCounted {
/*--cef()--*/
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() { return NULL; }
///
// Called 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.
///
/*--cef()--*/
virtual bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavigationType navigation_type,
bool is_redirect) {
return false;
}
///
// Called immediately after the V8 context for a frame has been created. To
// retrieve the JavaScript 'window' object use the CefV8Context::GetGlobal()

View File

@ -435,13 +435,6 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) {
switches::kUncaughtExceptionStackSize,
base::IntToString(settings.uncaught_exception_stack_size));
}
// If browser-side navigation is not explicitly enabled or disabled, disable
// it. See https://crbug.com/776884.
if (!command_line->HasSwitch(switches::kDisableBrowserSideNavigation) &&
!command_line->HasSwitch(switches::kEnableBrowserSideNavigation)) {
command_line->AppendSwitch(switches::kDisableBrowserSideNavigation);
}
}
if (content_client_.application().get()) {

View File

@ -33,7 +33,6 @@
#include "net/http/http_util.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request.h"
#include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/platform/WebURLError.h"
@ -160,18 +159,6 @@ blink::mojom::FetchCacheMode GetFetchCacheMode(int ur_flags) {
return blink::mojom::FetchCacheMode::kDefault;
}
// Convert blink::WebCachePolicy to cef_urlrequest_flags_t.
int GetURCachePolicy(blink::mojom::FetchCacheMode cache_mode) {
if (cache_mode == blink::mojom::FetchCacheMode::kUnspecifiedForceCacheMiss) {
return kURCachePolicyMask;
} else if (cache_mode == blink::mojom::FetchCacheMode::kBypassCache) {
return UR_FLAG_SKIP_CACHE;
} else if (cache_mode == blink::mojom::FetchCacheMode::kOnlyIfCached) {
return UR_FLAG_ONLY_FROM_CACHE;
}
return 0;
}
blink::WebString FilePathStringToWebString(
const base::FilePath::StringType& str) {
#if defined(OS_POSIX)
@ -199,37 +186,6 @@ void GetHeaderMap(const net::HttpRequestHeaders& headers,
};
}
// Read |request| into |map|. If a Referer value is specified populate
// |referrer|.
void GetHeaderMap(const blink::WebURLRequest& request,
CefRequest::HeaderMap& map,
GURL& referrer) {
map.clear();
class HeaderVisitor : public blink::WebHTTPHeaderVisitor {
public:
HeaderVisitor(CefRequest::HeaderMap* map, GURL* referrer)
: map_(map), referrer_(referrer) {}
void VisitHeader(const blink::WebString& name,
const blink::WebString& value) override {
const base::string16& nameStr = name.Utf16();
const base::string16& valueStr = value.Utf16();
if (base::LowerCaseEqualsASCII(nameStr, kReferrerLowerCase))
*referrer_ = GURL(valueStr);
else
map_->insert(std::make_pair(nameStr, valueStr));
}
private:
CefRequest::HeaderMap* map_;
GURL* referrer_;
};
HeaderVisitor visitor(&map, &referrer);
request.VisitHTTPHeaderFields(&visitor);
}
// Read |source| into |map|.
void GetHeaderMap(const CefRequest::HeaderMap& source,
CefRequest::HeaderMap& map) {
@ -543,36 +499,6 @@ void CefRequestImpl::Set(
static_cast<cef_transition_type_t>(params.transition_type());
}
void CefRequestImpl::Set(const blink::WebURLRequest& request) {
DCHECK(!request.IsNull());
base::AutoLock lock_scope(lock_);
CHECK_READONLY_RETURN_VOID();
Reset();
url_ = request.Url();
method_ = request.HttpMethod().Utf8();
::GetHeaderMap(request, headermap_, referrer_url_);
referrer_policy_ =
BlinkReferrerPolicyToNetReferrerPolicy(request.GetReferrerPolicy());
const blink::WebHTTPBody& body = request.HttpBody();
if (!body.IsNull()) {
postdata_ = new CefPostDataImpl();
static_cast<CefPostDataImpl*>(postdata_.get())->Set(body);
}
site_for_cookies_ = request.SiteForCookies();
flags_ |= GetURCachePolicy(request.GetCacheMode());
if (request.AllowStoredCredentials())
flags_ |= UR_FLAG_ALLOW_STORED_CREDENTIALS;
if (request.ReportUploadProgress())
flags_ |= UR_FLAG_REPORT_UPLOAD_PROGRESS;
}
void CefRequestImpl::Get(blink::WebURLRequest& request,
int64& upload_data_size) const {
base::AutoLock lock_scope(lock_);

View File

@ -93,10 +93,6 @@ class CefRequestImpl : public CefRequest {
void Set(const navigation_interception::NavigationParams& params,
bool is_main_frame);
// Populate this object from a WebURLRequest object.
// Called from CefContentRendererClient::HandleNavigation().
void Set(const blink::WebURLRequest& request);
// Populate the WebURLRequest object from this object.
// Called from CefRenderURLRequest::Context::Start().
void Get(blink::WebURLRequest& request, int64& upload_data_size) const;

View File

@ -488,68 +488,6 @@ bool CefContentRendererClient::OverrideCreatePlugin(
return true;
}
bool CefContentRendererClient::HandleNavigation(
content::RenderFrame* render_frame,
bool is_content_initiated,
bool render_view_was_created_by_renderer,
blink::WebFrame* frame,
const blink::WebURLRequest& request,
blink::WebNavigationType type,
blink::WebNavigationPolicy default_policy,
bool is_redirect) {
if (!frame->IsWebLocalFrame())
return false;
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
if (application.get()) {
CefRefPtr<CefRenderProcessHandler> handler =
application->GetRenderProcessHandler();
if (handler.get()) {
CefRefPtr<CefBrowserImpl> browserPtr =
CefBrowserImpl::GetBrowserForMainFrame(frame->Top());
if (browserPtr.get()) {
CefRefPtr<CefFrameImpl> framePtr =
browserPtr->GetWebFrameImpl(frame->ToWebLocalFrame());
CefRefPtr<CefRequest> requestPtr(CefRequest::Create());
CefRequestImpl* requestImpl =
static_cast<CefRequestImpl*>(requestPtr.get());
requestImpl->Set(request);
requestImpl->SetReadOnly(true);
cef_navigation_type_t navigation_type = NAVIGATION_OTHER;
switch (type) {
case blink::kWebNavigationTypeLinkClicked:
navigation_type = NAVIGATION_LINK_CLICKED;
break;
case blink::kWebNavigationTypeFormSubmitted:
navigation_type = NAVIGATION_FORM_SUBMITTED;
break;
case blink::kWebNavigationTypeBackForward:
navigation_type = NAVIGATION_BACK_FORWARD;
break;
case blink::kWebNavigationTypeReload:
navigation_type = NAVIGATION_RELOAD;
break;
case blink::kWebNavigationTypeFormResubmitted:
navigation_type = NAVIGATION_FORM_RESUBMITTED;
break;
case blink::kWebNavigationTypeOther:
navigation_type = NAVIGATION_OTHER;
break;
}
if (handler->OnBeforeNavigation(browserPtr.get(), framePtr.get(),
requestPtr.get(), navigation_type,
is_redirect)) {
return true;
}
}
}
}
return false;
}
bool CefContentRendererClient::ShouldFork(blink::WebLocalFrame* frame,
const GURL& url,
const std::string& http_method,

View File

@ -104,14 +104,6 @@ class CefContentRendererClient : public content::ContentRendererClient,
bool OverrideCreatePlugin(content::RenderFrame* render_frame,
const blink::WebPluginParams& params,
blink::WebPlugin** plugin) override;
bool HandleNavigation(content::RenderFrame* render_frame,
bool is_content_initiated,
bool render_view_was_created_by_renderer,
blink::WebFrame* frame,
const blink::WebURLRequest& request,
blink::WebNavigationType type,
blink::WebNavigationPolicy default_policy,
bool is_redirect) override;
bool ShouldFork(blink::WebLocalFrame* frame,
const GURL& url,
const std::string& http_method,

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=85fd88a37b43603229556458e4060cc997403873$
// $hash=5fcac7caa6064922f745b0dc9beb5537fa3bc479$
//
#include "libcef_dll/cpptoc/render_process_handler_cpptoc.h"
@ -19,7 +19,6 @@
#include "libcef_dll/ctocpp/frame_ctocpp.h"
#include "libcef_dll/ctocpp/list_value_ctocpp.h"
#include "libcef_dll/ctocpp/process_message_ctocpp.h"
#include "libcef_dll/ctocpp/request_ctocpp.h"
#include "libcef_dll/ctocpp/v8context_ctocpp.h"
#include "libcef_dll/ctocpp/v8exception_ctocpp.h"
#include "libcef_dll/ctocpp/v8stack_trace_ctocpp.h"
@ -110,41 +109,6 @@ cef_load_handler_t* CEF_CALLBACK render_process_handler_get_load_handler(
return CefLoadHandlerCppToC::Wrap(_retval);
}
int CEF_CALLBACK render_process_handler_on_before_navigation(
struct _cef_render_process_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
struct _cef_request_t* request,
cef_navigation_type_t navigation_type,
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 = CefRenderProcessHandlerCppToC::Get(self)->OnBeforeNavigation(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request), navigation_type,
is_redirect ? true : false);
// Return type: bool
return _retval;
}
void CEF_CALLBACK render_process_handler_on_context_created(
struct _cef_render_process_handler_t* self,
cef_browser_t* browser,
@ -307,8 +271,6 @@ CefRenderProcessHandlerCppToC::CefRenderProcessHandlerCppToC() {
GetStruct()->on_browser_destroyed =
render_process_handler_on_browser_destroyed;
GetStruct()->get_load_handler = render_process_handler_get_load_handler;
GetStruct()->on_before_navigation =
render_process_handler_on_before_navigation;
GetStruct()->on_context_created = render_process_handler_on_context_created;
GetStruct()->on_context_released = render_process_handler_on_context_released;
GetStruct()->on_uncaught_exception =

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=d3eec11738f8a75aba830ba813dd095c7eeb0738$
// $hash=b1925c4cbcf5889e56f005d7f7255366e0daf073$
//
#include "libcef_dll/ctocpp/render_process_handler_ctocpp.h"
@ -18,7 +18,6 @@
#include "libcef_dll/cpptoc/frame_cpptoc.h"
#include "libcef_dll/cpptoc/list_value_cpptoc.h"
#include "libcef_dll/cpptoc/process_message_cpptoc.h"
#include "libcef_dll/cpptoc/request_cpptoc.h"
#include "libcef_dll/cpptoc/v8context_cpptoc.h"
#include "libcef_dll/cpptoc/v8exception_cpptoc.h"
#include "libcef_dll/cpptoc/v8stack_trace_cpptoc.h"
@ -103,40 +102,6 @@ CefRefPtr<CefLoadHandler> CefRenderProcessHandlerCToCpp::GetLoadHandler() {
return CefLoadHandlerCToCpp::Wrap(_retval);
}
bool CefRenderProcessHandlerCToCpp::OnBeforeNavigation(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavigationType navigation_type,
bool is_redirect) {
cef_render_process_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, on_before_navigation))
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_navigation(
_struct, CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
CefRequestCppToC::Wrap(request), navigation_type, is_redirect);
// Return type: bool
return _retval ? true : false;
}
void CefRenderProcessHandlerCToCpp::OnContextCreated(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=dc50857b856d7bc0a536ebb52152eb78a1b9db6c$
// $hash=1bc7b7dd592df33e6e5b7a3beb85e465d5e9e5a7$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_RENDER_PROCESS_HANDLER_CTOCPP_H_
@ -39,11 +39,6 @@ class CefRenderProcessHandlerCToCpp
void OnBrowserCreated(CefRefPtr<CefBrowser> browser) override;
void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) override;
CefRefPtr<CefLoadHandler> GetLoadHandler() override;
bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavigationType navigation_type,
bool is_redirect) override;
void OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) override;

View File

@ -289,9 +289,6 @@ patches = [
'name': 'rwh_background_color_1984',
},
{
# Allow continued use of ContentRendererClient::HandleNavigation.
# https://bitbucket.org/chromiumembedded/cef/issues/1129
#
# Pass is_main_frame to PluginServiceFilter::IsPluginAvailable.
# https://bitbucket.org/chromiumembedded/cef/issues/2015
#
@ -308,7 +305,7 @@ patches = [
# Add RenderFrameObserver::FrameFocused method.
#
# Add ContentRendererClient::DevToolsAgent[Attached|Detached] methods.
'name': 'content_1129_2015',
'name': 'content_2015',
},
{
# Pass is_main_frame to PluginServiceFilter::IsPluginAvailable.

View File

@ -324,28 +324,8 @@ index 3b610b1f554e..7c439e060779 100644
const url::Origin& main_frame_origin,
WebPluginInfo* plugin) = 0;
diff --git content/public/renderer/content_renderer_client.cc content/public/renderer/content_renderer_client.cc
index 3e3d132705a8..4a972b4475e6 100644
--- content/public/renderer/content_renderer_client.cc
+++ content/public/renderer/content_renderer_client.cc
@@ -101,7 +101,6 @@ bool ContentRendererClient::AllowPopup() {
return false;
}
-#if defined(OS_ANDROID)
bool ContentRendererClient::HandleNavigation(
RenderFrame* render_frame,
bool is_content_initiated,
@@ -114,6 +113,7 @@ bool ContentRendererClient::HandleNavigation(
return false;
}
+#if defined(OS_ANDROID)
bool ContentRendererClient::ShouldUseMediaPlayerForURL(const GURL& url) {
return false;
}
diff --git content/public/renderer/content_renderer_client.h content/public/renderer/content_renderer_client.h
index 3d34633700dd..6cee67f439f7 100644
index 3d34633700dd..b175fff52d6c 100644
--- content/public/renderer/content_renderer_client.h
+++ content/public/renderer/content_renderer_client.h
@@ -73,6 +73,9 @@ class CONTENT_EXPORT ContentRendererClient {
@ -358,22 +338,6 @@ index 3d34633700dd..6cee67f439f7 100644
// Notifies that a new RenderFrame has been created.
virtual void RenderFrameCreated(RenderFrame* render_frame) {}
@@ -190,7 +193,6 @@ class CONTENT_EXPORT ContentRendererClient {
// Returns true if a popup window should be allowed.
virtual bool AllowPopup();
-#if defined(OS_ANDROID)
// TODO(sgurun) This callback is deprecated and will be removed as soon
// as android webview completes implementation of a resource throttle based
// shouldoverrideurl implementation. See crbug.com/325351
@@ -206,6 +208,7 @@ class CONTENT_EXPORT ContentRendererClient {
blink::WebNavigationPolicy default_policy,
bool is_redirect);
+#if defined(OS_ANDROID)
// Indicates if the Android MediaPlayer should be used instead of Chrome's
// built in media player for the given |url|. Defaults to false.
virtual bool ShouldUseMediaPlayerForURL(const GURL& url);
@@ -331,6 +334,12 @@ class CONTENT_EXPORT ContentRendererClient {
// This method may invalidate the frame.
virtual void RunScriptsAtDocumentIdle(RenderFrame* render_frame) {}
@ -445,7 +409,7 @@ index 685c39f6aca2..cee77800770a 100644
io_sessions_.clear();
sessions_.clear();
diff --git content/renderer/render_frame_impl.cc content/renderer/render_frame_impl.cc
index 40f9cef599dc..323084e643d7 100644
index 40f9cef599dc..ebbc6078b611 100644
--- content/renderer/render_frame_impl.cc
+++ content/renderer/render_frame_impl.cc
@@ -3210,7 +3210,8 @@ blink::WebPlugin* RenderFrameImpl::CreatePlugin(
@ -467,26 +431,6 @@ index 40f9cef599dc..323084e643d7 100644
}
void RenderFrameImpl::WillCommitProvisionalLoad() {
@@ -5643,9 +5646,8 @@ WebNavigationPolicy RenderFrameImpl::DecidePolicyForNavigation(
(!IsBrowserSideNavigationEnabled() ||
url != pending_navigation_params_->request_params.redirects[0]));
-#ifdef OS_ANDROID
- bool render_view_was_created_by_renderer =
- render_view_->was_created_by_renderer_;
+ // CEF doesn't use this value, so just pass false.
+ bool render_view_was_created_by_renderer = false;
// The handlenavigation API is deprecated and will be removed once
// crbug.com/325351 is resolved.
if ((!IsBrowserSideNavigationEnabled() || !IsURLHandledByNetworkStack(url)) &&
@@ -5655,7 +5657,6 @@ WebNavigationPolicy RenderFrameImpl::DecidePolicyForNavigation(
is_redirect)) {
return blink::kWebNavigationPolicyIgnore;
}
-#endif
// If the browser is interested, then give it a chance to look at the request.
if (is_content_initiated && IsTopLevelNavigation(frame_) &&
diff --git content/renderer/render_thread_impl.cc content/renderer/render_thread_impl.cc
index 10b32b1254c6..6ba3dfbe9d15 100644
--- content/renderer/render_thread_impl.cc

View File

@ -70,11 +70,6 @@ void CreateRenderDelegates(ClientAppRenderer::DelegateSet& delegates) {
delegates);
CreateRequestHandlerRendererTests(delegates);
// Bring in the Request tests.
extern void CreateRequestRendererTests(ClientAppRenderer::DelegateSet &
delegates);
CreateRequestRendererTests(delegates);
// Bring in the routing test handler delegate.
extern void CreateRoutingTestHandlerDelegate(ClientAppRenderer::DelegateSet &
delegates);

View File

@ -204,12 +204,6 @@ class FrameNavExpectationsRenderer : public FrameNavExpectations {
public:
explicit FrameNavExpectationsRenderer(int nav)
: FrameNavExpectations(nav, true) {}
// Renderer-only notifications.
virtual bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame) {
return true;
}
};
// Abstract base class for the factory that creates expectations objects.
@ -366,21 +360,6 @@ class FrameNavRendererTest : public ClientAppRenderer::Delegate,
EXPECT_TRUE(expectations_->OnLoadEnd(browser, frame)) << "nav = " << nav_;
}
bool OnBeforeNavigation(CefRefPtr<ClientAppRenderer> app,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
cef_navigation_type_t navigation_type,
bool is_redirect) override {
if (!run_test_)
return false;
CreateExpectationsIfNecessary();
EXPECT_TRUE(expectations_->OnBeforeNavigation(browser, frame))
<< "nav = " << nav_;
return false;
}
protected:
// Create a new expectations object if one does not already exist for the
// current navigation.
@ -723,13 +702,6 @@ class FrameNavExpectationsRendererSingleNav
return true;
}
bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame) override {
EXPECT_FALSE(got_before_navigation_);
got_before_navigation_.yes();
return true;
}
bool Finalize() override {
V_DECLARE();
V_EXPECT_TRUE(got_load_start_);
@ -738,12 +710,6 @@ class FrameNavExpectationsRendererSingleNav
V_EXPECT_TRUE(got_loading_state_change_end_);
V_EXPECT_FALSE(got_finalize_);
if (IsBrowserSideNavigationEnabled()) {
V_EXPECT_FALSE(got_before_navigation_);
} else {
V_EXPECT_TRUE(got_before_navigation_);
}
got_finalize_.yes();
V_RETURN();
@ -759,7 +725,6 @@ class FrameNavExpectationsRendererSingleNav
TrackCallback got_load_end_;
TrackCallback got_loading_state_change_start_;
TrackCallback got_loading_state_change_end_;
TrackCallback got_before_navigation_;
TrackCallback got_finalize_;
};
@ -1026,7 +991,7 @@ class FrameNavExpectationsBrowserTestSingleNav
// When browser-side navigation is enabled this method will be called
// before the frame is created.
V_EXPECT_TRUE(VerifySingleBrowserFrames(
browser, frame, !IsBrowserSideNavigationEnabled(), std::string()));
browser, frame, false, std::string()));
V_EXPECT_TRUE(parent::OnBeforeBrowse(browser, frame, url));
V_RETURN();
}
@ -1037,7 +1002,7 @@ class FrameNavExpectationsBrowserTestSingleNav
// When browser-side navigation is enabled this method will be called
// before the frame is created.
V_EXPECT_TRUE(VerifySingleBrowserFrames(
browser, frame, !IsBrowserSideNavigationEnabled(), std::string()));
browser, frame, false, std::string()));
V_EXPECT_TRUE(parent::GetResourceHandler(browser, frame));
V_RETURN();
}
@ -1539,7 +1504,7 @@ class FrameNavExpectationsBrowserTestMultiNav
// When browser-side navigation is enabled this method will be called
// before the frame is created for the first navigation.
V_EXPECT_TRUE(VerifySingleBrowserFrames(
browser, frame, nav() == 0 ? !IsBrowserSideNavigationEnabled() : true,
browser, frame, nav() == 0 ? false : true,
expected_url));
V_EXPECT_TRUE(parent::OnBeforeBrowse(browser, frame, url));
V_RETURN();
@ -1554,7 +1519,7 @@ class FrameNavExpectationsBrowserTestMultiNav
// When browser-side navigation is enabled this method will be called
// before the frame is created for the first navigation.
V_EXPECT_TRUE(VerifySingleBrowserFrames(
browser, frame, nav() == 0 ? !IsBrowserSideNavigationEnabled() : true,
browser, frame, nav() == 0 ? false : true,
expected_url));
V_EXPECT_TRUE(parent::GetResourceHandler(browser, frame));
V_RETURN();

View File

@ -168,41 +168,6 @@ class HistoryNavRendererTest : public ClientAppRenderer::Delegate,
SendTestResultsIfDone(browser);
}
bool OnBeforeNavigation(CefRefPtr<ClientAppRenderer> app,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
cef_navigation_type_t navigation_type,
bool is_redirect) override {
if (!run_test_)
return false;
const NavListItem& item = kHNavList[nav_];
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) {
EXPECT_EQ(NAVIGATION_BACK_FORWARD, navigation_type);
}
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;
}
protected:
void SendTestResultsIfDone(CefRefPtr<CefBrowser> browser) {
if (got_load_end_ && got_loading_state_end_)
@ -2448,13 +2413,11 @@ class PopupJSWindowOpenTestHandler : public TestHandler {
EXPECT_TRUE(browser->IsSame(popup2_));
popup2_ = nullptr;
if (IsBrowserSideNavigationEnabled()) {
// OnLoadingStateChange is not currently called for browser-side
// navigations of empty popups. See https://crbug.com/789252.
// Explicitly close the empty popup here as a workaround.
CloseBrowser(popup1_, true);
popup1_ = nullptr;
}
// OnLoadingStateChange is not currently called for browser-side
// navigations of empty popups. See https://crbug.com/789252.
// Explicitly close the empty popup here as a workaround.
CloseBrowser(popup1_, true);
popup1_ = nullptr;
} else {
// Empty popup.
EXPECT_TRUE(url.empty());
@ -2498,13 +2461,9 @@ class PopupJSWindowOpenTestHandler : public TestHandler {
EXPECT_EQ(2U, after_created_ct_);
EXPECT_EQ(2U, before_close_ct_);
if (IsBrowserSideNavigationEnabled()) {
// OnLoadingStateChange is not currently called for browser-side
// navigations of empty popups. See https://crbug.com/789252.
EXPECT_EQ(1U, load_end_ct_);
} else {
EXPECT_EQ(2U, load_end_ct_);
}
// OnLoadingStateChange is not currently called for browser-side
// navigations of empty popups. See https://crbug.com/789252.
EXPECT_EQ(1U, load_end_ct_);
TestHandler::DestroyTest();
}
@ -3295,7 +3254,7 @@ class CancelAfterNavTestHandler : public TestHandler {
// The required delay is longer when browser-side navigation is enabled.
CefPostDelayedTask(TID_UI,
base::Bind(&CancelAfterNavTestHandler::CancelLoad, this),
IsBrowserSideNavigationEnabled() ? 1000 : 100);
1000);
return new StalledSchemeHandler();
}

View File

@ -838,13 +838,11 @@ class PopupNavTestHandler : public TestHandler {
EXPECT_FALSE(got_popup_load_end2_);
} else if (mode_ == NAVIGATE_AFTER_CREATION) {
EXPECT_FALSE(got_popup_load_start_);
if (IsBrowserSideNavigationEnabled()) {
// With browser-side navigation we will never actually begin the
// navigation to the 1st popup URL, so there will be no load error.
EXPECT_FALSE(got_popup_load_error_);
} else {
EXPECT_TRUE(got_popup_load_error_);
}
// With browser-side navigation we will never actually begin the
// navigation to the 1st popup URL, so there will be no load error.
EXPECT_FALSE(got_popup_load_error_);
EXPECT_FALSE(got_popup_load_end_);
EXPECT_TRUE(got_popup_load_start2_);
EXPECT_FALSE(got_popup_load_error2_);

View File

@ -309,51 +309,46 @@ TEST(RequestTest, SendRecv) {
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},
{"main.html", true, TT_EXPLICIT, RT_MAIN_FRAME, 1},
// Sub frame load.
{"sub.html", true, true, TT_LINK, RT_SUB_FRAME, 1},
{"sub.html", false, true, TT_EXPLICIT, RT_SUB_RESOURCE, 1},
{"sub.html", true, TT_LINK, RT_SUB_FRAME, 1},
// Stylesheet load.
{"style.css", true, false, TT_LINK, RT_STYLESHEET, 1},
{"style.css", false, TT_LINK, RT_STYLESHEET, 1},
// Script load.
{"script.js", true, false, TT_LINK, RT_SCRIPT, 1},
{"script.js", false, TT_LINK, RT_SCRIPT, 1},
// Image load.
{"image.png", true, false, TT_LINK, RT_IMAGE, 1},
{"image.png", false, TT_LINK, RT_IMAGE, 1},
// Font load.
{"font.ttf", true, false, TT_LINK, RT_FONT_RESOURCE, 1},
{"font.ttf", false, TT_LINK, RT_FONT_RESOURCE, 1},
// XHR load.
{"xhr.html", true, false, TT_LINK, RT_XHR, 1},
{"xhr.html", false, TT_LINK, RT_XHR, 1},
};
class TypeExpectations {
public:
TypeExpectations(bool browser_side, bool navigation)
: browser_side_(browser_side), navigation_(navigation) {
explicit TypeExpectations(bool navigation)
: navigation_(navigation) {
// Build the map of relevant requests.
for (int i = 0;
i < static_cast<int>(sizeof(g_type_expected) / sizeof(TypeExpected));
++i) {
if (g_type_expected[i].browser_side != browser_side_ ||
(navigation_ && g_type_expected[i].navigation != navigation_))
if (navigation_ && g_type_expected[i].navigation != navigation_)
continue;
request_count_.insert(std::make_pair(i, 0));
@ -373,7 +368,6 @@ class TypeExpectations {
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;
@ -384,7 +378,7 @@ class TypeExpectations {
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_
<< "File: " << file.c_str()
<< "; Navigation: " << navigation_
<< "; Transition Type: " << transition_type
<< "; Resource Type: " << resource_type;
@ -397,8 +391,7 @@ class TypeExpectations {
for (int i = 0;
i < static_cast<int>(sizeof(g_type_expected) / sizeof(TypeExpected));
++i) {
if (g_type_expected[i].browser_side != browser_side_ ||
(navigation_ && g_type_expected[i].navigation != navigation_))
if (navigation_ && g_type_expected[i].navigation != navigation_)
continue;
RequestCount::const_iterator it = request_count_.find(i);
@ -407,7 +400,6 @@ class TypeExpectations {
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;
@ -427,7 +419,6 @@ class TypeExpectations {
i < static_cast<int>(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) {
@ -437,7 +428,6 @@ class TypeExpectations {
return -1;
}
bool browser_side_;
bool navigation_;
// Map of TypeExpected index to actual request count.
@ -445,51 +435,14 @@ class TypeExpectations {
RequestCount request_count_;
};
// Renderer side.
class TypeRendererTest : public ClientAppRenderer::Delegate {
public:
TypeRendererTest() : expectations_(false, true) {}
bool OnBeforeNavigation(CefRefPtr<ClientAppRenderer> 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),
: browse_expectations_(true),
load_expectations_(false),
get_expectations_(false),
completed_browser_side_(false),
completed_render_side_(false),
destroyed_(false) {}
void RunTest() override {
@ -561,42 +514,13 @@ class TypeTestHandler : public TestHandler {
completed_browser_side_ = true;
// Destroy the test on the UI thread.
CefPostTask(TID_UI,
base::Bind(&TypeTestHandler::DestroyTestIfComplete, this));
base::Bind(&TypeTestHandler::DestroyTest, this));
}
return TestHandler::GetResourceHandler(browser, frame, request);
}
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_ || IsBrowserSideNavigationEnabled())) {
DestroyTest();
}
}
void DestroyTest() override {
if (destroyed_)
return;
@ -604,11 +528,6 @@ class TypeTestHandler : public TestHandler {
// Verify test expectations.
EXPECT_TRUE(completed_browser_side_);
if (IsBrowserSideNavigationEnabled()) {
EXPECT_FALSE(completed_render_side_);
} else {
EXPECT_TRUE(completed_render_side_);
}
EXPECT_TRUE(browse_expectations_.IsDone(true));
EXPECT_TRUE(load_expectations_.IsDone(true));
EXPECT_TRUE(get_expectations_.IsDone(true));
@ -621,7 +540,6 @@ class TypeTestHandler : public TestHandler {
TypeExpectations get_expectations_;
bool completed_browser_side_;
bool completed_render_side_;
bool destroyed_;
IMPLEMENT_REFCOUNTING(TypeTestHandler);
@ -635,9 +553,3 @@ TEST(RequestTest, ResourceAndTransitionType) {
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
// Entry point for creating request renderer test objects.
// Called from client_app_delegates.cc.
void CreateRequestRendererTests(ClientAppRenderer::DelegateSet& delegates) {
delegates.insert(new TypeRendererTest);
}

View File

@ -490,19 +490,3 @@ bool TestFailed() {
return ::testing::UnitTest::GetInstance()->Failed();
}
}
bool IsBrowserSideNavigationEnabled() {
static bool initialized = false;
static bool value = false; // Default value.
if (!initialized) {
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
if (command_line->HasSwitch("enable-browser-side-navigation")) {
value = true;
} else if (command_line->HasSwitch("disable-browser-side-navigation")) {
value = false;
}
initialized = true;
}
return value;
}

View File

@ -327,9 +327,6 @@ void ReleaseAndWaitForDestructor(CefRefPtr<T>& handler, int delay_ms = 2000) {
// Returns true if the currently running test has failed.
bool TestFailed();
// Returns true if browser-side navigation is enabled.
bool IsBrowserSideNavigationEnabled();
// Helper macros for executing checks in a method with a boolean return value.
// For example:
//

View File

@ -46,22 +46,6 @@ CefRefPtr<CefLoadHandler> ClientAppRenderer::GetLoadHandler() {
return load_handler;
}
bool ClientAppRenderer::OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavigationType navigation_type,
bool is_redirect) {
DelegateSet::iterator it = delegates_.begin();
for (; it != delegates_.end(); ++it) {
if ((*it)->OnBeforeNavigation(this, browser, frame, request,
navigation_type, is_redirect)) {
return true;
}
}
return false;
}
void ClientAppRenderer::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {

View File

@ -36,15 +36,6 @@ class ClientAppRenderer : public ClientApp, public CefRenderProcessHandler {
return NULL;
}
virtual bool OnBeforeNavigation(CefRefPtr<ClientAppRenderer> app,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
cef_navigation_type_t navigation_type,
bool is_redirect) {
return false;
}
virtual void OnContextCreated(CefRefPtr<ClientAppRenderer> app,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
@ -100,11 +91,6 @@ class ClientAppRenderer : public ClientApp, public CefRenderProcessHandler {
void OnBrowserCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) OVERRIDE;
CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE;
bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavigationType navigation_type,
bool is_redirect) OVERRIDE;
void OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) OVERRIDE;