diff options
author | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-26 06:03:40 +0000 |
---|---|---|
committer | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-26 06:03:40 +0000 |
commit | 6bfc220cd4df1577ebae83bf421134222d80b7bf (patch) | |
tree | c6e2b54143e9ed98e43924141111ac0b304d0c1b /chrome/renderer | |
parent | 122503f1d53450ad9065b907333ce84cf8706bb2 (diff) | |
download | chromium_src-6bfc220cd4df1577ebae83bf421134222d80b7bf.zip chromium_src-6bfc220cd4df1577ebae83bf421134222d80b7bf.tar.gz chromium_src-6bfc220cd4df1577ebae83bf421134222d80b7bf.tar.bz2 |
<webview>: Move back, forward, canGoBack, canGoForward, go from content to chrome
BUG=166165
Test=WebViewTest.Navigation
Review URL: https://chromiumcodereview.appspot.com/17447005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208642 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/resources/extensions/web_view.js | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js index f4cc6ef..777bc46 100644 --- a/chrome/renderer/resources/extensions/web_view.js +++ b/chrome/renderer/resources/extensions/web_view.js @@ -18,12 +18,7 @@ var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', // All exposed api methods for <webview>, these are forwarded to the browser // plugin. var WEB_VIEW_API_METHODS = [ - 'back', - 'canGoBack', - 'canGoForward', - 'forward', 'getProcessId', - 'go', 'reload', 'stop', 'terminate' @@ -68,6 +63,13 @@ window.addEventListener('readystatechange', function(e) { }); }, true /* useCapture */); + +/** @type {number} */ +WebView.prototype.entryCount_; + +/** @type {number} */ +WebView.prototype.currentEntryIndex_; + /** * @constructor */ @@ -144,11 +146,37 @@ WebView.prototype.setupFocusPropagation_ = function() { WebView.prototype.setupWebviewNodeMethods_ = function() { // this.browserPluginNode_[apiMethod] are not necessarily defined immediately // after the shadow object is appended to the shadow root. + var webviewNode = this.webviewNode_; + var browserPluginNode = this.browserPluginNode_; var self = this; + + webviewNode['canGoBack'] = function() { + return self.entryCount_ > 1 && self.currentEntryIndex_ > 0; + }; + + webviewNode['canGoForward'] = function() { + return self.currentEntryIndex_ >=0 && + self.currentEntryIndex_ < (self.entryCount_ - 1); + }; + + webviewNode['back'] = function() { + webviewNode.go(-1); + }; + + webviewNode['forward'] = function() { + webviewNode.go(1); + }; + + webviewNode['go'] = function(relativeIndex) { + var instanceId = browserPluginNode.getGuestInstanceId(); + if (!instanceId) + return; + chrome.webview.go(instanceId, relativeIndex); + }; + $Array.forEach(WEB_VIEW_API_METHODS, function(apiMethod) { - self.webviewNode_[apiMethod] = function(var_args) { - return $Function.apply(self.browserPluginNode_[apiMethod], - self.browserPluginNode_, arguments); + webviewNode[apiMethod] = function(var_args) { + return browserPluginNode[apiMethod].apply(browserPluginNode, arguments); }; }, this); this.setupExecuteCodeAPI_(); @@ -274,6 +302,7 @@ WebView.prototype.handleBrowserPluginAttributeMutation_ = function(mutation) { * @private */ WebView.prototype.setupWebviewNodeEvents_ = function() { + var self = this; var webviewNode = this.webviewNode_; // TODO(fsamuel): Generalize this further as we add more events. var onAttached = function(e) { @@ -284,6 +313,8 @@ WebView.prototype.setupWebviewNodeEvents_ = function() { $Array.forEach(attribs, function(attribName) { webviewEvent[attribName] = event[attribName]; }); + self.currentEntryIndex_ = event.currentEntryIndex; + self.entryCount_ = event.entryCount; webviewNode.dispatchEvent(webviewEvent); }, {instanceId: detail.windowId}); }; |