Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Shim that simulates a <webview> tag via Mutation Observers. | 5 // Shim that simulates a <webview> tag via Mutation Observers. |
| 6 // | 6 // |
| 7 // The actual tag is implemented via the browser plugin. The internals of this | 7 // The actual tag is implemented via the browser plugin. The internals of this |
| 8 // are hidden via Shadow DOM. | 8 // are hidden via Shadow DOM. |
| 9 | 9 |
| 10 var watchForTag = require('tagWatcher').watchForTag; | 10 var watchForTag = require('tagWatcher').watchForTag; |
| 11 var eventBindings = require('event_bindings'); | 11 var eventBindings = require('event_bindings'); |
| 12 | 12 |
| 13 /** @type {Array.<string>} */ | 13 /** @type {Array.<string>} */ |
| 14 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', | 14 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', |
| 15 'minwidth', 'maxheight', 'maxwidth']; | 15 'minwidth', 'maxheight', 'maxwidth']; |
| 16 | 16 |
| 17 | 17 |
| 18 // All exposed api methods for <webview>, these are forwarded to the browser | 18 // All exposed api methods for <webview>, these are forwarded to the browser |
| 19 // plugin. | 19 // plugin. |
| 20 var WEB_VIEW_API_METHODS = [ | 20 var WEB_VIEW_API_METHODS = [ |
| 21 'back', | |
| 22 'canGoBack', | |
| 23 'canGoForward', | |
| 24 'forward', | |
| 25 'getProcessId', | 21 'getProcessId', |
| 26 'go', | |
| 27 'reload', | 22 'reload', |
| 28 'stop', | 23 'stop', |
| 29 'terminate' | 24 'terminate' |
| 30 ]; | 25 ]; |
| 31 | 26 |
| 32 var WEB_VIEW_EVENTS = { | 27 var WEB_VIEW_EVENTS = { |
| 33 'close': [], | 28 'close': [], |
| 34 'consolemessage': ['level', 'message', 'line', 'sourceId'], | 29 'consolemessage': ['level', 'message', 'line', 'sourceId'], |
| 35 'contentload' : [], | 30 'contentload' : [], |
| 36 'exit' : ['processId', 'reason'], | 31 'exit' : ['processId', 'reason'], |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 self.browserPluginNode_.blur(); | 118 self.browserPluginNode_.blur(); |
| 124 }); | 119 }); |
| 125 }; | 120 }; |
| 126 | 121 |
| 127 /** | 122 /** |
| 128 * @private | 123 * @private |
| 129 */ | 124 */ |
| 130 WebView.prototype.setupWebviewNodeMethods_ = function() { | 125 WebView.prototype.setupWebviewNodeMethods_ = function() { |
| 131 // this.browserPluginNode_[apiMethod] are not necessarily defined immediately | 126 // this.browserPluginNode_[apiMethod] are not necessarily defined immediately |
| 132 // after the shadow object is appended to the shadow root. | 127 // after the shadow object is appended to the shadow root. |
| 128 var webviewNode = this.webviewNode_; | |
| 129 var browserPluginNode = this.browserPluginNode_; | |
| 133 var self = this; | 130 var self = this; |
| 131 | |
| 132 webviewNode['canGoBack'] = function() { | |
| 133 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.
| |
| 134 }; | |
| 135 | |
| 136 webviewNode['canGoForward'] = function() { | |
| 137 return self.currentEntryIndex_ >=0 && | |
| 138 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.
| |
| 139 }; | |
| 140 | |
| 141 webviewNode['back'] = function() { | |
| 142 var instanceId = browserPluginNode.getGuestInstanceId(); | |
| 143 if (!instanceId) | |
| 144 return; | |
| 145 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
| |
| 146 }; | |
| 147 | |
| 148 webviewNode['forward'] = function() { | |
| 149 var instanceId = browserPluginNode.getGuestInstanceId(); | |
| 150 if (!instanceId) | |
| 151 return; | |
| 152 chrome.webview.go(instanceId, 1); | |
| 153 }; | |
| 154 | |
| 155 webviewNode['go'] = function(relativeIndex) { | |
| 156 var instanceId = browserPluginNode.getGuestInstanceId(); | |
| 157 if (!instanceId) | |
| 158 return; | |
| 159 chrome.webview.go(instanceId, relativeIndex); | |
| 160 }; | |
| 161 | |
| 134 $Array.forEach(WEB_VIEW_API_METHODS, function(apiMethod) { | 162 $Array.forEach(WEB_VIEW_API_METHODS, function(apiMethod) { |
| 135 self.webviewNode_[apiMethod] = function(var_args) { | 163 webviewNode[apiMethod] = function(var_args) { |
| 136 return self.browserPluginNode_[apiMethod].apply( | 164 return browserPluginNode[apiMethod].apply(browserPluginNode, arguments); |
| 137 self.browserPluginNode_, arguments); | |
| 138 }; | 165 }; |
| 139 }, this); | 166 }, this); |
| 140 this.setupExecuteCodeAPI_(); | 167 this.setupExecuteCodeAPI_(); |
| 141 }; | 168 }; |
| 142 | 169 |
| 143 /** | 170 /** |
| 144 * @private | 171 * @private |
| 145 */ | 172 */ |
| 146 WebView.prototype.setupWebviewNodeProperties_ = function() { | 173 WebView.prototype.setupWebviewNodeProperties_ = function() { |
| 147 var ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE = '<webview>: ' + | 174 var ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE = '<webview>: ' + |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 if (newValue != oldValue) { | 280 if (newValue != oldValue) { |
| 254 this.webviewNode_.setAttribute(mutation.attributeName, newValue); | 281 this.webviewNode_.setAttribute(mutation.attributeName, newValue); |
| 255 } | 282 } |
| 256 } | 283 } |
| 257 }; | 284 }; |
| 258 | 285 |
| 259 /** | 286 /** |
| 260 * @private | 287 * @private |
| 261 */ | 288 */ |
| 262 WebView.prototype.setupWebviewNodeEvents_ = function() { | 289 WebView.prototype.setupWebviewNodeEvents_ = function() { |
| 290 var self = this; | |
| 263 var webviewNode = this.webviewNode_; | 291 var webviewNode = this.webviewNode_; |
| 264 // TODO(fsamuel): Generalize this further as we add more events. | 292 // TODO(fsamuel): Generalize this further as we add more events. |
| 265 var onAttached = function(e) { | 293 var onAttached = function(e) { |
| 266 var detail = e.detail ? JSON.parse(e.detail) : {}; | 294 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 267 loadCommitEvent.addListener(function(event) { | 295 loadCommitEvent.addListener(function(event) { |
| 268 var webviewEvent = new Event('loadcommit', {bubbles: true}); | 296 var webviewEvent = new Event('loadcommit', {bubbles: true}); |
| 269 var attribs = WEB_VIEW_EVENTS['loadcommit']; | 297 var attribs = WEB_VIEW_EVENTS['loadcommit']; |
| 270 $Array.forEach(attribs, function(attribName) { | 298 $Array.forEach(attribs, function(attribName) { |
| 271 webviewEvent[attribName] = event[attribName]; | 299 webviewEvent[attribName] = event[attribName]; |
| 272 }); | 300 }); |
| 301 self.currentEntryIndex_ = event.currentEntryIndex; | |
| 302 self.entryCount_ = event.entryCount; | |
| 273 webviewNode.dispatchEvent(webviewEvent); | 303 webviewNode.dispatchEvent(webviewEvent); |
| 274 }, {instanceId: detail.windowId}); | 304 }, {instanceId: detail.windowId}); |
| 275 }; | 305 }; |
| 276 this.browserPluginNode_.addEventListener('-internal-attached', onAttached); | 306 this.browserPluginNode_.addEventListener('-internal-attached', onAttached); |
| 277 | 307 |
| 278 for (var eventName in WEB_VIEW_EVENTS) { | 308 for (var eventName in WEB_VIEW_EVENTS) { |
| 279 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); | 309 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); |
| 280 } | 310 } |
| 281 this.setupNewWindowEvent_(); | 311 this.setupNewWindowEvent_(); |
| 282 this.setupPermissionEvent_(); | 312 this.setupPermissionEvent_(); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 return []; | 525 return []; |
| 496 }; | 526 }; |
| 497 | 527 |
| 498 /** | 528 /** |
| 499 * Implemented when the experimental API is available. | 529 * Implemented when the experimental API is available. |
| 500 * @private | 530 * @private |
| 501 */ | 531 */ |
| 502 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; | 532 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; |
| 503 | 533 |
| 504 exports.WebView = WebView; | 534 exports.WebView = WebView; |
| OLD | NEW |