DevTools: allow resetting navigation history over protocol.
Change-Id: Iae6008c364972304b2233818ad64e62335605693
Reviewed-on: https://chromium-review.googlesource.com/c/1378851
Reviewed-by: Andrey Lushnikov <lushnikov@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#616928}
diff --git a/content/browser/devtools/protocol/page_handler.cc b/content/browser/devtools/protocol/page_handler.cc
index 68cf811..734f274 100644
--- a/content/browser/devtools/protocol/page_handler.cc
+++ b/content/browser/devtools/protocol/page_handler.cc
@@ -591,6 +591,20 @@
return Response::InvalidParams("No entry with passed id");
}
+static bool ReturnTrue(const NavigationEntry& entry) {
+ return true;
+}
+
+Response PageHandler::ResetNavigationHistory() {
+ WebContentsImpl* web_contents = GetWebContents();
+ if (!web_contents)
+ return Response::InternalError();
+
+ NavigationController& controller = web_contents->GetController();
+ controller.DeleteNavigationEntries(base::BindRepeating(&ReturnTrue));
+ return Response::OK();
+}
+
void PageHandler::CaptureSnapshot(
Maybe<std::string> format,
std::unique_ptr<CaptureSnapshotCallback> callback) {
diff --git a/content/browser/devtools/protocol/page_handler.h b/content/browser/devtools/protocol/page_handler.h
index 39e7bcb3..2361d21 100644
--- a/content/browser/devtools/protocol/page_handler.h
+++ b/content/browser/devtools/protocol/page_handler.h
@@ -108,6 +108,7 @@
int* current_index,
std::unique_ptr<NavigationEntries>* entries) override;
Response NavigateToHistoryEntry(int entry_id) override;
+ Response ResetNavigationHistory() override;
void CaptureScreenshot(
Maybe<std::string> format,
diff --git a/content/browser/devtools/protocol_config.json b/content/browser/devtools/protocol_config.json
index c5af076..f77a66a5 100644
--- a/content/browser/devtools/protocol_config.json
+++ b/content/browser/devtools/protocol_config.json
@@ -47,7 +47,7 @@
},
{
"domain": "Page",
- "include": ["enable", "disable", "reload", "navigate", "stopLoading", "getNavigationHistory", "navigateToHistoryEntry", "captureScreenshot",
+ "include": ["enable", "disable", "reload", "navigate", "stopLoading", "getNavigationHistory", "navigateToHistoryEntry", "resetNavigationHistory", "captureScreenshot",
"startScreencast", "stopScreencast", "screencastFrameAck", "handleJavaScriptDialog", "setColorPickerEnabled", "requestAppBanner",
"printToPDF", "bringToFront", "setDownloadBehavior", "getAppManifest", "crash", "close", "setWebLifecycleState", "captureSnapshot"],
"include_events": ["colorPicked", "interstitialShown", "interstitialHidden", "javascriptDialogOpening", "javascriptDialogClosed", "screencastVisibilityChanged", "screencastFrame"],
diff --git a/third_party/blink/renderer/core/inspector/browser_protocol.pdl b/third_party/blink/renderer/core/inspector/browser_protocol.pdl
index 17039d4..45c4823 100644
--- a/third_party/blink/renderer/core/inspector/browser_protocol.pdl
+++ b/third_party/blink/renderer/core/inspector/browser_protocol.pdl
@@ -5047,6 +5047,9 @@
# Array of navigation history entries.
array of NavigationEntry entries
+ # Resets navigation history for the current page.
+ command resetNavigationHistory
+
# Returns content of the given resource.
experimental command getResourceContent
parameters
diff --git a/third_party/blink/renderer/core/inspector/inspector_protocol_config.json b/third_party/blink/renderer/core/inspector/inspector_protocol_config.json
index 5441041..92d6511 100644
--- a/third_party/blink/renderer/core/inspector/inspector_protocol_config.json
+++ b/third_party/blink/renderer/core/inspector/inspector_protocol_config.json
@@ -73,7 +73,7 @@
},
{
"domain": "Page",
- "exclude": ["getNavigationHistory", "navigateToHistoryEntry", "captureScreenshot", "screencastFrameAck", "handleJavaScriptDialog", "setColorPickerEnabled",
+ "exclude": ["getNavigationHistory", "navigateToHistoryEntry", "resetNavigationHistory", "captureScreenshot", "screencastFrameAck", "handleJavaScriptDialog", "setColorPickerEnabled",
"getAppManifest", "requestAppBanner", "setControlNavigations", "processNavigation", "printToPDF", "bringToFront", "setDownloadBehavior", "navigate", "crash", "close", "setWebLifecycleState", "captureSnapshot"],
"async": ["getResourceContent", "searchInResource"],
"exclude_events": ["screencastFrame", "screencastVisibilityChanged", "colorPicked", "interstitialShown", "interstitialHidden", "javascriptDialogOpening", "javascriptDialogClosed", "navigationRequested"]
diff --git a/third_party/blink/web_tests/inspector-protocol/page/page-resetNavigationHistory-expected.txt b/third_party/blink/web_tests/inspector-protocol/page/page-resetNavigationHistory-expected.txt
new file mode 100644
index 0000000..86836d1c
--- /dev/null
+++ b/third_party/blink/web_tests/inspector-protocol/page/page-resetNavigationHistory-expected.txt
@@ -0,0 +1,4 @@
+Tests Page.resetNavigationHistory
+Length before reset: 4
+Length after reset: 1
+
diff --git a/third_party/blink/web_tests/inspector-protocol/page/page-resetNavigationHistory.js b/third_party/blink/web_tests/inspector-protocol/page/page-resetNavigationHistory.js
new file mode 100644
index 0000000..cd0c0a8
--- /dev/null
+++ b/third_party/blink/web_tests/inspector-protocol/page/page-resetNavigationHistory.js
@@ -0,0 +1,15 @@
+(async function(testRunner) {
+ const {page, session, dp} = await testRunner.startBlank(
+ 'Tests Page.resetNavigationHistory');
+ await session.evaluate(`history.pushState({}, '', window.location.href + '&foo')`);
+ await session.evaluate(`history.pushState({}, '', window.location.href + '&bar')`);
+
+ let length = await session.evaluate(`history.length`);
+ testRunner.log('Length before reset: ' + length);
+
+ await dp.Page.resetNavigationHistory();
+ length = await session.evaluate(`history.length`);
+ testRunner.log('Length after reset: ' + length);
+
+ testRunner.completeTest();
+})