summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorpaulmeyer <paulmeyer@chromium.org>2014-10-09 07:37:16 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-09 14:37:33 +0000
commit82e31991f1597daae41b8fc54edcddedac83aacb (patch)
treead8c320ee3f64ffefc6dc27409d182bf65fb930e /extensions
parent8012df46f572e5a7bc2f33ff41e5d470e0da8a69 (diff)
downloadchromium_src-82e31991f1597daae41b8fc54edcddedac83aacb.zip
chromium_src-82e31991f1597daae41b8fc54edcddedac83aacb.tar.gz
chromium_src-82e31991f1597daae41b8fc54edcddedac83aacb.tar.bz2
Added optional callbacks to webview.go(), webview.back(), and webview.forward().
The callback have a single parameter, "success", that indicates whether the navigation was successful. Previously, there was no way to check if these API functions actually resulted in navigation when called (for instance, when calling webview.back() when there is no page to go back to). Review URL: https://codereview.chromium.org/638193002 Cr-Commit-Position: refs/heads/master@{#298877}
Diffstat (limited to 'extensions')
-rw-r--r--extensions/browser/api/web_view/web_view_internal_api.cc4
-rw-r--r--extensions/browser/guest_view/web_view/web_view_guest.cc9
-rw-r--r--extensions/browser/guest_view/web_view/web_view_guest.h4
-rw-r--r--extensions/common/api/web_view_internal.json12
-rw-r--r--extensions/renderer/resources/web_view.js12
5 files changed, 30 insertions, 11 deletions
diff --git a/extensions/browser/api/web_view/web_view_internal_api.cc b/extensions/browser/api/web_view/web_view_internal_api.cc
index 62b3497..1b308fa 100644
--- a/extensions/browser/api/web_view/web_view_internal_api.cc
+++ b/extensions/browser/api/web_view/web_view_internal_api.cc
@@ -336,7 +336,9 @@ bool WebViewInternalGoFunction::RunAsyncSafe(WebViewGuest* guest) {
scoped_ptr<webview::Go::Params> params(webview::Go::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
- guest->Go(params->relative_index);
+ bool successful = guest->Go(params->relative_index);
+ SetResult(new base::FundamentalValue(successful));
+ SendResponse(true);
return true;
}
diff --git a/extensions/browser/guest_view/web_view/web_view_guest.cc b/extensions/browser/guest_view/web_view/web_view_guest.cc
index eb1bd4e..0d9a161 100644
--- a/extensions/browser/guest_view/web_view/web_view_guest.cc
+++ b/extensions/browser/guest_view/web_view/web_view_guest.cc
@@ -600,8 +600,13 @@ void WebViewGuest::StopFinding(content::StopFindAction action) {
web_contents()->StopFinding(action);
}
-void WebViewGuest::Go(int relative_index) {
- web_contents()->GetController().GoToOffset(relative_index);
+bool WebViewGuest::Go(int relative_index) {
+ content::NavigationController& controller = web_contents()->GetController();
+ if (!controller.CanGoToOffset(relative_index))
+ return false;
+
+ controller.GoToOffset(relative_index);
+ return true;
}
void WebViewGuest::Reload() {
diff --git a/extensions/browser/guest_view/web_view/web_view_guest.h b/extensions/browser/guest_view/web_view/web_view_guest.h
index 63cf750..8b3c8e7 100644
--- a/extensions/browser/guest_view/web_view/web_view_guest.h
+++ b/extensions/browser/guest_view/web_view/web_view_guest.h
@@ -185,8 +185,8 @@ class WebViewGuest : public GuestView<WebViewGuest>,
void StopFinding(content::StopFindAction);
// If possible, navigate the guest to |relative_index| entries away from the
- // current navigation entry.
- void Go(int relative_index);
+ // current navigation entry. Returns true on success.
+ bool Go(int relative_index);
// Reload the guest.
void Reload();
diff --git a/extensions/common/api/web_view_internal.json b/extensions/common/api/web_view_internal.json
index 43c1a3b..02dc854 100644
--- a/extensions/common/api/web_view_internal.json
+++ b/extensions/common/api/web_view_internal.json
@@ -338,6 +338,18 @@
{
"type": "integer",
"name": "relativeIndex"
+ },
+ {
+ "type": "function",
+ "name": "callback",
+ "optional": true,
+ "parameters": [
+ {
+ "name": "success",
+ "type": "boolean",
+ "description": "Indicates whether the navigation was successful."
+ }
+ ]
}
]
},
diff --git a/extensions/renderer/resources/web_view.js b/extensions/renderer/resources/web_view.js
index 91774b8..88540fb 100644
--- a/extensions/renderer/resources/web_view.js
+++ b/extensions/renderer/resources/web_view.js
@@ -181,13 +181,13 @@ WebViewInternal.prototype.setupFocusPropagation = function() {
};
// Navigates to the previous history entry.
-WebViewInternal.prototype.back = function() {
- return this.go(-1);
+WebViewInternal.prototype.back = function(callback) {
+ return this.go(-1, callback);
};
// Navigates to the subsequent history entry.
-WebViewInternal.prototype.forward = function() {
- return this.go(1);
+WebViewInternal.prototype.forward = function(callback) {
+ return this.go(1, callback);
};
// Returns whether there is a previous history entry to navigate to.
@@ -218,11 +218,11 @@ WebViewInternal.prototype.getProcessId = function() {
// Navigates to a history entry using a history index relative to the current
// navigation.
-WebViewInternal.prototype.go = function(relativeIndex) {
+WebViewInternal.prototype.go = function(relativeIndex, callback) {
if (!this.guestInstanceId) {
return;
}
- WebView.go(this.guestInstanceId, relativeIndex);
+ WebView.go(this.guestInstanceId, relativeIndex, callback);
};
// Prints the contents of the webview.