Commit 4bc98b37 authored by Andrey Lushnikov's avatar Andrey Lushnikov Committed by Commit Bot

DevTools: introduce Page.close() protocol method

This patch adds new experimental Page.close() protocol method
that closes the page, running page's beforeunload hooks.

R=dgozman

Change-Id: I4c091bb150e8d88e99c94920e92b1bdcf0ccb234
Reviewed-on: https://chromium-review.googlesource.com/1014676Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552071}
parent ff1f496d
...@@ -395,6 +395,14 @@ Response PageHandler::Crash() { ...@@ -395,6 +395,14 @@ Response PageHandler::Crash() {
return Response::FallThrough(); return Response::FallThrough();
} }
Response PageHandler::Close() {
WebContentsImpl* web_contents = GetWebContents();
if (!web_contents)
return Response::Error("Not attached to a page");
web_contents->DispatchBeforeUnload();
return Response::OK();
}
Response PageHandler::Reload(Maybe<bool> bypassCache, Response PageHandler::Reload(Maybe<bool> bypassCache,
Maybe<std::string> script_to_evaluate_on_load) { Maybe<std::string> script_to_evaluate_on_load) {
WebContentsImpl* web_contents = GetWebContents(); WebContentsImpl* web_contents = GetWebContents();
......
...@@ -95,6 +95,7 @@ class PageHandler : public DevToolsDomainHandler, ...@@ -95,6 +95,7 @@ class PageHandler : public DevToolsDomainHandler,
Response Disable() override; Response Disable() override;
Response Crash() override; Response Crash() override;
Response Close() override;
Response Reload(Maybe<bool> bypassCache, Response Reload(Maybe<bool> bypassCache,
Maybe<std::string> script_to_evaluate_on_load) override; Maybe<std::string> script_to_evaluate_on_load) override;
void Navigate(const std::string& url, void Navigate(const std::string& url,
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
"domain": "Page", "domain": "Page",
"include": ["enable", "disable", "reload", "navigate", "stopLoading", "getNavigationHistory", "navigateToHistoryEntry", "captureScreenshot", "include": ["enable", "disable", "reload", "navigate", "stopLoading", "getNavigationHistory", "navigateToHistoryEntry", "captureScreenshot",
"startScreencast", "stopScreencast", "screencastFrameAck", "handleJavaScriptDialog", "setColorPickerEnabled", "requestAppBanner", "startScreencast", "stopScreencast", "screencastFrameAck", "handleJavaScriptDialog", "setColorPickerEnabled", "requestAppBanner",
"printToPDF", "bringToFront", "setDownloadBehavior", "getAppManifest", "crash"], "printToPDF", "bringToFront", "setDownloadBehavior", "getAppManifest", "crash", "close"],
"include_events": ["colorPicked", "interstitialShown", "interstitialHidden", "javascriptDialogOpening", "javascriptDialogClosed", "screencastVisibilityChanged", "screencastFrame"], "include_events": ["colorPicked", "interstitialShown", "interstitialHidden", "javascriptDialogOpening", "javascriptDialogClosed", "screencastVisibilityChanged", "screencastFrame"],
"async": ["captureScreenshot", "printToPDF", "navigate", "getAppManifest"] "async": ["captureScreenshot", "printToPDF", "navigate", "getAppManifest"]
}, },
......
Tests that page.requestClose method runs beforeunload hooks.
SUCCESS!
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank('Tests that page.requestClose method runs beforeunload hooks.');
await dp.Runtime.enable();
await session.evaluate(() => {
window.addEventListener('beforeunload', function (event) {
console.log('YES');
}, false);
});
dp.Page.close();
// Console message should be emitted from-inside the beforeunload handler.
await dp.Runtime.onceConsoleAPICalled();
testRunner.log('SUCCESS!');
testRunner.completeTest();
})
...@@ -4893,6 +4893,9 @@ domain Page ...@@ -4893,6 +4893,9 @@ domain Page
# Crashes renderer on the IO thread, generates minidumps. # Crashes renderer on the IO thread, generates minidumps.
experimental command crash experimental command crash
# Tries to close page, running its beforeunload hooks, if any.
experimental command close
# Stops sending each frame in the `screencastFrame`. # Stops sending each frame in the `screencastFrame`.
experimental command stopScreencast experimental command stopScreencast
......
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
{ {
"domain": "Page", "domain": "Page",
"exclude": ["getNavigationHistory", "navigateToHistoryEntry", "captureScreenshot", "screencastFrameAck", "handleJavaScriptDialog", "setColorPickerEnabled", "exclude": ["getNavigationHistory", "navigateToHistoryEntry", "captureScreenshot", "screencastFrameAck", "handleJavaScriptDialog", "setColorPickerEnabled",
"getAppManifest", "requestAppBanner", "setControlNavigations", "processNavigation", "printToPDF", "bringToFront", "setDownloadBehavior", "navigate", "crash"], "getAppManifest", "requestAppBanner", "setControlNavigations", "processNavigation", "printToPDF", "bringToFront", "setDownloadBehavior", "navigate", "crash", "close"],
"async": ["getResourceContent", "searchInResource"], "async": ["getResourceContent", "searchInResource"],
"exclude_events": ["screencastFrame", "screencastVisibilityChanged", "colorPicked", "interstitialShown", "interstitialHidden", "javascriptDialogOpening", "javascriptDialogClosed", "navigationRequested"] "exclude_events": ["screencastFrame", "screencastVisibilityChanged", "colorPicked", "interstitialShown", "interstitialHidden", "javascriptDialogOpening", "javascriptDialogClosed", "navigationRequested"]
}, },
......
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