Commit 56717754 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

[DevTools] Include disposition in Page.frameRequestedNavigation

We issue Page.frameRequestedNavigation for any navigation initiated by
the frame. However, when this navigation is intended for another page,
for example opening a new tab, it is important to differentiate from
the navigation in the frame itself.

Bug: 1073211
Change-Id: I3024abd194bd2bae87dfb6855611f53a979e02a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2159762
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarPeter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762485}
parent 2e61a48b
......@@ -5542,6 +5542,13 @@ domain Page
reload
anchorClick
experimental type ClientNavigationDisposition extends string
enum
currentTab
newTab
newWindow
download
experimental type InstallabilityErrorArgument extends object
properties
# Argument name (e.g. name:'minimum-icon-size-in-pixels').
......@@ -6118,6 +6125,8 @@ domain Page
ClientNavigationReason reason
# The destination URL for the requested navigation.
string url
# The disposition for the navigation.
ClientNavigationDisposition disposition
# Fired when frame schedules a potential navigation.
deprecated event frameScheduledNavigation
......
......@@ -154,7 +154,8 @@ void RemoteFrame::Navigate(FrameLoadRequest& frame_request,
initiator_frame_is_ad = frame->IsAdSubframe();
if (frame_request.ClientRedirectReason() != ClientNavigationReason::kNone) {
probe::FrameRequestedNavigation(frame, this, url,
frame_request.ClientRedirectReason());
frame_request.ClientRedirectReason(),
kNavigationPolicyCurrentTab);
}
}
......
......@@ -116,6 +116,25 @@ String ClientNavigationReasonToProtocol(ClientNavigationReason reason) {
return ReasonEnum::Reload;
}
String NavigationPolicyToProtocol(NavigationPolicy policy) {
namespace DispositionEnum = protocol::Page::ClientNavigationDispositionEnum;
switch (policy) {
case kNavigationPolicyDownload:
return DispositionEnum::Download;
case kNavigationPolicyCurrentTab:
return DispositionEnum::CurrentTab;
case kNavigationPolicyNewBackgroundTab:
return DispositionEnum::NewTab;
case kNavigationPolicyNewForegroundTab:
return DispositionEnum::NewTab;
case kNavigationPolicyNewWindow:
return DispositionEnum::NewWindow;
case kNavigationPolicyNewPopup:
return DispositionEnum::NewWindow;
}
return DispositionEnum::CurrentTab;
}
Resource* CachedResource(LocalFrame* frame,
const KURL& url,
InspectorResourceContentLoader* loader) {
......@@ -944,13 +963,14 @@ void InspectorPageAgent::FrameStoppedLoading(LocalFrame* frame) {
GetFrontend()->flush();
}
void InspectorPageAgent::FrameRequestedNavigation(
Frame* target_frame,
const KURL& url,
ClientNavigationReason reason) {
void InspectorPageAgent::FrameRequestedNavigation(Frame* target_frame,
const KURL& url,
ClientNavigationReason reason,
NavigationPolicy policy) {
GetFrontend()->frameRequestedNavigation(
IdentifiersFactory::FrameId(target_frame),
ClientNavigationReasonToProtocol(reason), url.GetString());
ClientNavigationReasonToProtocol(reason), url.GetString(),
NavigationPolicyToProtocol(policy));
GetFrontend()->flush();
}
......
......@@ -181,7 +181,8 @@ class CORE_EXPORT InspectorPageAgent final
void FrameStoppedLoading(LocalFrame*);
void FrameRequestedNavigation(Frame* target_frame,
const KURL&,
ClientNavigationReason);
ClientNavigationReason,
NavigationPolicy);
void FrameScheduledNavigation(LocalFrame*,
const KURL&,
base::TimeDelta delay,
......
......@@ -835,7 +835,8 @@ void FrameLoader::StartNavigation(FrameLoadRequest& request,
if (request.ClientRedirectReason() != ClientNavigationReason::kNone) {
probe::FrameRequestedNavigation(frame_, frame_, url,
request.ClientRedirectReason());
request.ClientRedirectReason(),
request.GetNavigationPolicy());
}
const network::mojom::IPAddressSpace initiator_address_space =
......
......@@ -121,7 +121,7 @@ interface CoreProbes {
void FrameOwnerContentUpdated([Keep] LocalFrame*, HTMLFrameOwnerElement*);
void FrameStartedLoading([Keep] LocalFrame*);
void FrameStoppedLoading([Keep] LocalFrame*);
void FrameRequestedNavigation(LocalFrame*, Frame* target_frame, const KURL& url, ClientNavigationReason reason);
void FrameRequestedNavigation(LocalFrame*, Frame* target_frame, const KURL& url, ClientNavigationReason reason, NavigationPolicy policy);
void FrameScheduledNavigation([Keep] LocalFrame*, const KURL& url, base::TimeDelta delay, ClientNavigationReason reason);
void FrameClearedScheduledNavigation([Keep] LocalFrame*);
void DidCreateWebSocket([Keep] ExecutionContext*, uint64_t identifier, const KURL& request_url, const String& protocol);
......
Tests that dispostion for client-requested navigation is properly reported.
New window
{
disposition : newWindow
frameId : <string>
reason : anchorClick
url : http://127.0.0.1:8000/inspector-protocol/page/resources/frame-requested-navigation-disposition.html?done
}
New tab
{
disposition : newTab
frameId : <string>
reason : anchorClick
url : http://127.0.0.1:8000/inspector-protocol/page/resources/frame-requested-navigation-disposition.html?done
}
Current tab
{
disposition : currentTab
frameId : <string>
reason : anchorClick
url : http://127.0.0.1:8000/inspector-protocol/page/resources/frame-requested-navigation-disposition.html?done
}
(async function(testRunner) {
const {page, session, dp} = await testRunner.startURL('resources/frame-requested-navigation-disposition.html', 'Tests that dispostion for client-requested navigation is properly reported.');
await dp.Page.enable();
testRunner.log('New window');
const [{params: newWindow}] = await Promise.all([
dp.Page.onceFrameRequestedNavigation(),
dp.Input.dispatchMouseEvent({
type: 'mousePressed',
button: 'left',
buttons: 1,
clickCount: 1,
modifiers: 8,
x: 5,
y: 5,
}),
dp.Input.dispatchMouseEvent({
type: 'mouseReleased',
button: 'left',
buttons: 1,
clickCount: 1,
modifiers: 8,
x: 5,
y: 5,
}),
]);
testRunner.log(newWindow);
testRunner.log('New tab');
const [{params: newTab}] = await Promise.all([
dp.Page.onceFrameRequestedNavigation(),
dp.Input.dispatchMouseEvent({
type: 'mousePressed',
button: 'middle',
buttons: 2,
clickCount: 1,
x: 5,
y: 5,
}),
dp.Input.dispatchMouseEvent({
type: 'mouseReleased',
button: 'middle',
buttons: 2,
clickCount: 1,
x: 5,
y: 5,
}),
]);
testRunner.log(newTab);
testRunner.log('Current tab');
const [{params: currentTab}] = await Promise.all([
dp.Page.onceFrameRequestedNavigation(),
dp.Input.dispatchMouseEvent({
type: 'mousePressed',
button: 'left',
buttons: 1,
clickCount: 1,
x: 5,
y: 5,
}),
dp.Input.dispatchMouseEvent({
type: 'mouseReleased',
button: 'left',
buttons: 1,
clickCount: 1,
x: 5,
y: 5,
}),
]);
testRunner.log(currentTab);
testRunner.completeTest();
})
......@@ -3,6 +3,7 @@ Before release
{
method : Page.frameRequestedNavigation
params : {
disposition : currentTab
frameId : <string>
reason : anchorClick
url : http://127.0.0.1:8000/inspector-protocol/resources/inspector-protocol-page.html
......
......@@ -3,6 +3,7 @@ Before release
{
method : Page.frameRequestedNavigation
params : {
disposition : currentTab
frameId : <string>
reason : anchorClick
url : http://127.0.0.1:8000/inspector-protocol/resources/inspector-protocol-page.html
......
<style>
body, html {
margin: 0;
padding: 0;
}
</style>
<a href="frame-requested-navigation-disposition.html?done">Click me</a>
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