| 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(name, undefined, eventOpts); |
| 50 }; |
| 51 |
| 52 var loadCommitEvent = createEvent('webview.onLoadCommit'); |
| 53 |
| 46 // The <webview> tags we wish to watch for (watchForTag) does not belong to the | 54 // The <webview> tags we wish to watch for (watchForTag) does not belong to the |
| 47 // current scope's "document" reference. We need to wait until the document | 55 // current scope's "document" reference. We need to wait until the document |
| 48 // begins loading, since only then will the "document" reference | 56 // begins loading, since only then will the "document" reference |
| 49 // point to the page's document (it will be reset between now and then). | 57 // point to the page's document (it will be reset between now and then). |
| 50 // We can't listen for the "readystatechange" event on the document (because | 58 // We can't listen for the "readystatechange" event on the document (because |
| 51 // the object that it's dispatched on doesn't exist yet), but we can instead | 59 // the object that it's dispatched on doesn't exist yet), but we can instead |
| 52 // do it at the window level in the capturing phase. | 60 // do it at the window level in the capturing phase. |
| 53 window.addEventListener('readystatechange', function(e) { | 61 window.addEventListener('readystatechange', function(e) { |
| 54 if (document.readyState != 'loading') { | 62 if (document.readyState != 'loading') { |
| 55 return; | 63 return; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (newValue != oldValue) { | 267 if (newValue != oldValue) { |
| 260 this.webviewNode_.setAttribute(mutation.attributeName, newValue); | 268 this.webviewNode_.setAttribute(mutation.attributeName, newValue); |
| 261 } | 269 } |
| 262 } | 270 } |
| 263 }; | 271 }; |
| 264 | 272 |
| 265 /** | 273 /** |
| 266 * @private | 274 * @private |
| 267 */ | 275 */ |
| 268 WebView.prototype.setupWebviewNodeEvents_ = function() { | 276 WebView.prototype.setupWebviewNodeEvents_ = function() { |
| 277 var webviewNode = this.webviewNode_; |
| 278 // TODO(fsamuel): Generalize this further as we add more events. |
| 279 var onAttached = function(e) { |
| 280 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 281 loadCommitEvent.addListener(function(event) { |
| 282 var webviewEvent = new Event('loadcommit', {bubbles: true}); |
| 283 var attribs = WEB_VIEW_EVENTS['loadcommit']; |
| 284 $Array.forEach(attribs, function(attribName) { |
| 285 webviewEvent[attribName] = event[attribName]; |
| 286 }); |
| 287 webviewNode.dispatchEvent(webviewEvent); |
| 288 }, {instanceId: detail.windowId}); |
| 289 }; |
| 290 this.browserPluginNode_.addEventListener('-internal-attached', onAttached); |
| 291 |
| 269 for (var eventName in WEB_VIEW_EVENTS) { | 292 for (var eventName in WEB_VIEW_EVENTS) { |
| 270 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); | 293 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); |
| 271 } | 294 } |
| 272 this.setupNewWindowEvent_(); | 295 this.setupNewWindowEvent_(); |
| 273 this.setupPermissionEvent_(); | 296 this.setupPermissionEvent_(); |
| 274 }; | 297 }; |
| 275 | 298 |
| 276 /** | 299 /** |
| 277 * @private | 300 * @private |
| 278 */ | 301 */ |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 return []; | 509 return []; |
| 487 }; | 510 }; |
| 488 | 511 |
| 489 /** | 512 /** |
| 490 * Implemented when the experimental API is available. | 513 * Implemented when the experimental API is available. |
| 491 * @private | 514 * @private |
| 492 */ | 515 */ |
| 493 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; | 516 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; |
| 494 | 517 |
| 495 exports.WebView = WebView; | 518 exports.WebView = WebView; |
| OLD | NEW |