Commit 2937b1a7 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

FrameLoader: consume transient user activation earlier

The main reason is alignment between start and commit navigation paths,
so that we can later call CommitNavigation directly from StartNavigation.

As a side effect, this patch also ensures that we consume the
activation for any navigation attempt, even if is was ignored
due to frame detach or some other reason.

Bug: 855189
Change-Id: Ib705c0f20d567341d88e0fc3097ebc4246dcfeff
Reviewed-on: https://chromium-review.googlesource.com/1232200
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593029}
parent 123d6c25
...@@ -6381,11 +6381,14 @@ void RenderFrameImpl::OpenURL(const NavigationPolicyInfo& info, ...@@ -6381,11 +6381,14 @@ void RenderFrameImpl::OpenURL(const NavigationPolicyInfo& info,
CloneBlobURLToken(info.blob_url_token.get()).PassHandle().release(); CloneBlobURLToken(info.blob_url_token.get()).PassHandle().release();
params.should_replace_current_entry = params.should_replace_current_entry =
info.replaces_current_history_item && render_view_->history_list_length_; info.replaces_current_history_item && render_view_->history_list_length_;
params.user_gesture = params.user_gesture = info.has_user_gesture;
WebUserGestureIndicator::IsProcessingUserGesture(frame_);
if (GetContentClient()->renderer()->AllowPopup()) if (GetContentClient()->renderer()->AllowPopup())
params.user_gesture = true; params.user_gesture = true;
// TODO(csharrison,dgozman): FrameLoader::StartNavigation already consumes for
// all main frame navigations, except in the case where page A is navigating
// page B (e.g. using anchor targets). This edge case can go away when
// UserActivationV2 ships, which would make the conditional below redundant.
if (is_main_frame_ || policy == blink::kWebNavigationPolicyNewBackgroundTab || if (is_main_frame_ || policy == blink::kWebNavigationPolicyNewBackgroundTab ||
policy == blink::kWebNavigationPolicyNewForegroundTab || policy == blink::kWebNavigationPolicyNewForegroundTab ||
policy == blink::kWebNavigationPolicyNewWindow || policy == blink::kWebNavigationPolicyNewWindow ||
......
...@@ -341,6 +341,7 @@ class BLINK_EXPORT WebLocalFrameClient { ...@@ -341,6 +341,7 @@ class BLINK_EXPORT WebLocalFrameClient {
WebURLRequest& url_request; WebURLRequest& url_request;
WebNavigationType navigation_type; WebNavigationType navigation_type;
WebNavigationPolicy default_policy; WebNavigationPolicy default_policy;
bool has_user_gesture;
bool replaces_current_history_item; bool replaces_current_history_item;
bool is_history_navigation_in_new_child_frame; bool is_history_navigation_in_new_child_frame;
bool is_client_redirect; bool is_client_redirect;
...@@ -362,6 +363,7 @@ class BLINK_EXPORT WebLocalFrameClient { ...@@ -362,6 +363,7 @@ class BLINK_EXPORT WebLocalFrameClient {
: url_request(url_request), : url_request(url_request),
navigation_type(kWebNavigationTypeOther), navigation_type(kWebNavigationTypeOther),
default_policy(kWebNavigationPolicyIgnore), default_policy(kWebNavigationPolicyIgnore),
has_user_gesture(false),
replaces_current_history_item(false), replaces_current_history_item(false),
is_history_navigation_in_new_child_frame(false), is_history_navigation_in_new_child_frame(false),
is_client_redirect(false), is_client_redirect(false),
......
...@@ -520,6 +520,7 @@ NavigationPolicy LocalFrameClientImpl::DecidePolicyForNavigation( ...@@ -520,6 +520,7 @@ NavigationPolicy LocalFrameClientImpl::DecidePolicyForNavigation(
DocumentLoader* document_loader, DocumentLoader* document_loader,
WebNavigationType type, WebNavigationType type,
NavigationPolicy policy, NavigationPolicy policy,
bool has_transient_activation,
bool replaces_current_history_item, bool replaces_current_history_item,
bool is_client_redirect, bool is_client_redirect,
WebTriggeringEventInfo triggering_event_info, WebTriggeringEventInfo triggering_event_info,
...@@ -541,6 +542,7 @@ NavigationPolicy LocalFrameClientImpl::DecidePolicyForNavigation( ...@@ -541,6 +542,7 @@ NavigationPolicy LocalFrameClientImpl::DecidePolicyForNavigation(
navigation_info.default_policy = static_cast<WebNavigationPolicy>(policy); navigation_info.default_policy = static_cast<WebNavigationPolicy>(policy);
// TODO(dgozman): remove this after some Canary coverage. // TODO(dgozman): remove this after some Canary coverage.
CHECK(!web_document_loader || !web_document_loader->GetExtraData()); CHECK(!web_document_loader || !web_document_loader->GetExtraData());
navigation_info.has_user_gesture = has_transient_activation;
navigation_info.replaces_current_history_item = replaces_current_history_item; navigation_info.replaces_current_history_item = replaces_current_history_item;
navigation_info.is_client_redirect = is_client_redirect; navigation_info.is_client_redirect = is_client_redirect;
navigation_info.triggering_event_info = triggering_event_info; navigation_info.triggering_event_info = triggering_event_info;
......
...@@ -117,6 +117,7 @@ class LocalFrameClientImpl final : public LocalFrameClient { ...@@ -117,6 +117,7 @@ class LocalFrameClientImpl final : public LocalFrameClient {
DocumentLoader*, DocumentLoader*,
WebNavigationType, WebNavigationType,
NavigationPolicy, NavigationPolicy,
bool has_transient_activation,
bool should_replace_current_entry, bool should_replace_current_entry,
bool is_client_redirect, bool is_client_redirect,
WebTriggeringEventInfo, WebTriggeringEventInfo,
......
...@@ -152,6 +152,7 @@ class CORE_EXPORT LocalFrameClient : public FrameClient { ...@@ -152,6 +152,7 @@ class CORE_EXPORT LocalFrameClient : public FrameClient {
DocumentLoader*, DocumentLoader*,
WebNavigationType, WebNavigationType,
NavigationPolicy, NavigationPolicy,
bool has_transient_activation,
bool should_replace_current_entry, bool should_replace_current_entry,
bool is_client_redirect, bool is_client_redirect,
WebTriggeringEventInfo, WebTriggeringEventInfo,
......
...@@ -138,7 +138,7 @@ DocumentLoader::DocumentLoader( ...@@ -138,7 +138,7 @@ DocumentLoader::DocumentLoader(
data_buffer_(SharedBuffer::Create()), data_buffer_(SharedBuffer::Create()),
devtools_navigation_token_(devtools_navigation_token), devtools_navigation_token_(devtools_navigation_token),
had_sticky_activation_(false), had_sticky_activation_(false),
had_transient_activation_(Frame::HasTransientUserActivation(frame_)), had_transient_activation_(false),
use_counter_(frame_->GetChromeClient().IsSVGImageChromeClient() use_counter_(frame_->GetChromeClient().IsSVGImageChromeClient()
? UseCounter::kSVGImageContext ? UseCounter::kSVGImageContext
: UseCounter::kDefaultContext) { : UseCounter::kDefaultContext) {
...@@ -466,6 +466,10 @@ void DocumentLoader::SetUserActivated() { ...@@ -466,6 +466,10 @@ void DocumentLoader::SetUserActivated() {
had_sticky_activation_ = true; had_sticky_activation_ = true;
} }
void DocumentLoader::SetHadTransientUserActivation() {
had_transient_activation_ = true;
}
const AtomicString& DocumentLoader::RequiredCSP() { const AtomicString& DocumentLoader::RequiredCSP() {
return GetFrameLoader().RequiredCSP(); return GetFrameLoader().RequiredCSP();
} }
......
...@@ -234,6 +234,7 @@ class CORE_EXPORT DocumentLoader ...@@ -234,6 +234,7 @@ class CORE_EXPORT DocumentLoader
void LoadFailed(const ResourceError&); void LoadFailed(const ResourceError&);
void SetUserActivated(); void SetUserActivated();
void SetHadTransientUserActivation();
const AtomicString& RequiredCSP(); const AtomicString& RequiredCSP();
......
...@@ -103,6 +103,7 @@ NavigationPolicy EmptyLocalFrameClient::DecidePolicyForNavigation( ...@@ -103,6 +103,7 @@ NavigationPolicy EmptyLocalFrameClient::DecidePolicyForNavigation(
NavigationPolicy, NavigationPolicy,
bool, bool,
bool, bool,
bool,
WebTriggeringEventInfo, WebTriggeringEventInfo,
HTMLFormElement*, HTMLFormElement*,
ContentSecurityPolicyDisposition, ContentSecurityPolicyDisposition,
......
...@@ -273,6 +273,7 @@ class CORE_EXPORT EmptyLocalFrameClient : public LocalFrameClient { ...@@ -273,6 +273,7 @@ class CORE_EXPORT EmptyLocalFrameClient : public LocalFrameClient {
NavigationPolicy, NavigationPolicy,
bool, bool,
bool, bool,
bool,
WebTriggeringEventInfo, WebTriggeringEventInfo,
HTMLFormElement*, HTMLFormElement*,
ContentSecurityPolicyDisposition, ContentSecurityPolicyDisposition,
......
...@@ -226,6 +226,8 @@ void FrameLoader::Init() { ...@@ -226,6 +226,8 @@ void FrameLoader::Init() {
ClientRedirectPolicy::kNotClientRedirect, ClientRedirectPolicy::kNotClientRedirect,
base::UnguessableToken::Create(), nullptr /* navigation_params */, base::UnguessableToken::Create(), nullptr /* navigation_params */,
nullptr /* extra_data */); nullptr /* extra_data */);
if (Frame::HasTransientUserActivation(frame_))
provisional_document_loader_->SetHadTransientUserActivation();
provisional_document_loader_->StartLoading(); provisional_document_loader_->StartLoading();
frame_->GetDocument()->CancelParsing(); frame_->GetDocument()->CancelParsing();
...@@ -894,9 +896,19 @@ void FrameLoader::StartNavigation(const FrameLoadRequest& passed_request, ...@@ -894,9 +896,19 @@ void FrameLoader::StartNavigation(const FrameLoadRequest& passed_request,
return; return;
} }
bool has_transient_activation = Frame::HasTransientUserActivation(frame_);
// TODO(csharrison): In M71 when UserActivation v2 should ship, we can remove
// the check that the pages are equal, because consumption should not be
// shared across pages. After that, we can also get rid of consumption call
// in RenderFrameImpl::OpenURL.
if (frame_->IsMainFrame() && origin_document &&
frame_->GetPage() == origin_document->GetPage()) {
Frame::ConsumeTransientUserActivation(frame_);
}
policy = Client()->DecidePolicyForNavigation( policy = Client()->DecidePolicyForNavigation(
resource_request, origin_document, nullptr /* document_loader */, resource_request, origin_document, nullptr /* document_loader */,
navigation_type, policy, navigation_type, policy, has_transient_activation,
frame_load_type == WebFrameLoadType::kReplaceCurrentItem, frame_load_type == WebFrameLoadType::kReplaceCurrentItem,
request.ClientRedirect() == ClientRedirectPolicy::kClientRedirect, request.ClientRedirect() == ClientRedirectPolicy::kClientRedirect,
request.TriggeringEventInfo(), request.Form(), request.TriggeringEventInfo(), request.Form(),
...@@ -947,14 +959,6 @@ void FrameLoader::StartNavigation(const FrameLoadRequest& passed_request, ...@@ -947,14 +959,6 @@ void FrameLoader::StartNavigation(const FrameLoadRequest& passed_request,
resource_request); resource_request);
DCHECK(provisional_document_loader_); DCHECK(provisional_document_loader_);
// TODO(csharrison): In M70 when UserActivation v2 should ship, we can remove
// the check that the pages are equal, because consumption should not be
// shared across pages.
if (frame_->IsMainFrame() && origin_document &&
frame_->GetPage() == origin_document->GetPage()) {
Frame::ConsumeTransientUserActivation(frame_);
}
// TODO(dgozman): there is still a possibility of // TODO(dgozman): there is still a possibility of
// |kNavigationPolicyCurrentTab| when starting a navigation. Perhaps, we can // |kNavigationPolicyCurrentTab| when starting a navigation. Perhaps, we can
// just call CommitNavigation in this case instead, maybe from client side? // just call CommitNavigation in this case instead, maybe from client side?
...@@ -1752,6 +1756,8 @@ DocumentLoader* FrameLoader::CreateDocumentLoader( ...@@ -1752,6 +1756,8 @@ DocumentLoader* FrameLoader::CreateDocumentLoader(
loader->SetLoadType(load_type); loader->SetLoadType(load_type);
loader->SetNavigationType(navigation_type); loader->SetNavigationType(navigation_type);
if (request.HasUserGesture())
loader->SetHadTransientUserActivation();
// TODO(japhet): This is needed because the browser process DCHECKs if the // TODO(japhet): This is needed because the browser process DCHECKs if the
// first entry we commit in a new frame has replacement set. It's unclear // first entry we commit in a new frame has replacement set. It's unclear
// whether the DCHECK is right, investigate removing this special case. // whether the DCHECK is right, investigate removing this special case.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment