Chromium Code Reviews| Index: chrome/renderer/resources/extensions/web_view.js |
| diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js |
| index 189a2f110a7e74f9a2750864ee251fad5ece6d87..04fdd9e9ca95c22193040fc4e5aad547a4c2bb95 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' |
| @@ -130,11 +125,43 @@ 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; |
|
lazyboy
2013/06/22 04:29:15
generally for member vars, declare them in prototy
Fady Samuel
2013/06/25 15:46:12
Done.
|
| + }; |
| + |
| + webviewNode['canGoForward'] = function() { |
| + return self.currentEntryIndex_ >=0 && |
| + self.currentEntryIndex_ < (self.entryCount_ -1); |
|
lazyboy
2013/06/22 04:29:15
nit: space before 1
Fady Samuel
2013/06/25 15:46:12
Done.
|
| + }; |
| + |
| + webviewNode['back'] = function() { |
| + var instanceId = browserPluginNode.getGuestInstanceId(); |
| + if (!instanceId) |
| + return; |
| + chrome.webview.go(instanceId, -1); |
|
lazyboy
2013/06/22 04:29:15
nit: space before 1
Fady Samuel
2013/06/25 15:46:12
Really? This is a unary operator, not a binary ope
lazyboy
2013/06/25 15:58:50
I misread the line 0_0
|
| + }; |
| + |
| + webviewNode['forward'] = function() { |
| + var instanceId = browserPluginNode.getGuestInstanceId(); |
| + if (!instanceId) |
| + return; |
| + chrome.webview.go(instanceId, 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 self.browserPluginNode_[apiMethod].apply( |
| - self.browserPluginNode_, arguments); |
| + webviewNode[apiMethod] = function(var_args) { |
| + return browserPluginNode[apiMethod].apply(browserPluginNode, arguments); |
| }; |
| }, this); |
| this.setupExecuteCodeAPI_(); |
| @@ -260,6 +287,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) { |
| @@ -270,6 +298,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}); |
| }; |