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 | 12 |
| 12 /** @type {Array.<string>} */ | 13 /** @type {Array.<string>} */ |
| 13 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', | 14 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', |
| 14 'minwidth', 'maxheight', 'maxwidth']; | 15 'minwidth', 'maxheight', 'maxwidth']; |
| 15 | 16 |
| 16 | 17 |
| 17 // 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 |
| 18 // plugin. | 19 // plugin. |
| 19 var WEB_VIEW_API_METHODS = [ | 20 var WEB_VIEW_API_METHODS = [ |
| 20 'back', | 21 'back', |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 36 'loadabort' : ['url', 'isTopLevel', 'reason'], | 37 'loadabort' : ['url', 'isTopLevel', 'reason'], |
| 37 'loadcommit' : ['url', 'isTopLevel'], | 38 'loadcommit' : ['url', 'isTopLevel'], |
| 38 'loadredirect' : ['oldUrl', 'newUrl', 'isTopLevel'], | 39 'loadredirect' : ['oldUrl', 'newUrl', 'isTopLevel'], |
| 39 'loadstart' : ['url', 'isTopLevel'], | 40 'loadstart' : ['url', 'isTopLevel'], |
| 40 'loadstop' : [], | 41 'loadstop' : [], |
| 41 'responsive' : ['processId'], | 42 'responsive' : ['processId'], |
| 42 'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'], | 43 'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'], |
| 43 'unresponsive' : ['processId'] | 44 'unresponsive' : ['processId'] |
| 44 }; | 45 }; |
| 45 | 46 |
| 47 var createEvent = function(name) { | |
| 48 var eventOpts = {supportsListeners: true, supportsFilters: true}; | |
| 49 return new eventBindings.Event('webview.on' + name, undefined, eventOpts); | |
| 50 }; | |
| 51 | |
| 52 var loadCommitEvent = createEvent('LoadCommit'); | |
|
Matt Perry
2013/06/20 00:31:34
I would put the full name in here as well... easie
Fady Samuel
2013/06/20 00:55:14
Done.
| |
| 53 | |
| 46 window.addEventListener('DOMContentLoaded', function() { | 54 window.addEventListener('DOMContentLoaded', function() { |
| 47 watchForTag('WEBVIEW', function(addedNode) { new WebView(addedNode); }); | 55 watchForTag('WEBVIEW', function(addedNode) { new WebView(addedNode); }); |
| 48 }); | 56 }); |
| 49 | 57 |
| 50 /** | 58 /** |
| 51 * @constructor | 59 * @constructor |
| 52 */ | 60 */ |
| 53 function WebView(webviewNode) { | 61 function WebView(webviewNode) { |
| 54 this.webviewNode_ = webviewNode; | 62 this.webviewNode_ = webviewNode; |
| 55 this.browserPluginNode_ = this.createBrowserPluginNode_(); | 63 this.browserPluginNode_ = this.createBrowserPluginNode_(); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 if (newValue != oldValue) { | 253 if (newValue != oldValue) { |
| 246 this.webviewNode_.setAttribute(mutation.attributeName, newValue); | 254 this.webviewNode_.setAttribute(mutation.attributeName, newValue); |
| 247 } | 255 } |
| 248 } | 256 } |
| 249 }; | 257 }; |
| 250 | 258 |
| 251 /** | 259 /** |
| 252 * @private | 260 * @private |
| 253 */ | 261 */ |
| 254 WebView.prototype.setupWebviewNodeEvents_ = function() { | 262 WebView.prototype.setupWebviewNodeEvents_ = function() { |
| 263 var webviewNode = this.webviewNode_; | |
| 264 // TODO(fsamuel): Generalize this further as we add more events. | |
| 265 var onAttached = function(e) { | |
| 266 var detail = e.detail ? JSON.parse(e.detail) : {}; | |
| 267 loadCommitEvent.addListener(function(event) { | |
| 268 var webviewEvent = new Event('loadcommit', {bubbles: true}); | |
| 269 var attribs = WEB_VIEW_EVENTS['loadcommit']; | |
| 270 $Array.forEach(attribs, function(attribName) { | |
| 271 webviewEvent[attribName] = event[attribName]; | |
| 272 }); | |
| 273 webviewNode.dispatchEvent(webviewEvent); | |
| 274 }, {instanceId: detail.windowId}); | |
| 275 }; | |
| 276 this.browserPluginNode_.addEventListener('-internal-attached', onAttached); | |
| 277 | |
| 255 for (var eventName in WEB_VIEW_EVENTS) { | 278 for (var eventName in WEB_VIEW_EVENTS) { |
| 256 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); | 279 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); |
| 257 } | 280 } |
| 258 this.setupNewWindowEvent_(); | 281 this.setupNewWindowEvent_(); |
| 259 this.setupPermissionEvent_(); | 282 this.setupPermissionEvent_(); |
| 260 }; | 283 }; |
| 261 | 284 |
| 262 /** | 285 /** |
| 263 * @private | 286 * @private |
| 264 */ | 287 */ |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 return []; | 495 return []; |
| 473 }; | 496 }; |
| 474 | 497 |
| 475 /** | 498 /** |
| 476 * Implemented when the experimental API is available. | 499 * Implemented when the experimental API is available. |
| 477 * @private | 500 * @private |
| 478 */ | 501 */ |
| 479 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; | 502 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; |
| 480 | 503 |
| 481 exports.WebView = WebView; | 504 exports.WebView = WebView; |
| OLD | NEW |