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; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 'responsive' : ['processId'], | 37 'responsive' : ['processId'], |
| 38 'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'], | 38 'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'], |
| 39 'unresponsive' : ['processId'] | 39 'unresponsive' : ['processId'] |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 var createEvent = function(name) { | 42 var createEvent = function(name) { |
| 43 var eventOpts = {supportsListeners: true, supportsFilters: true}; | 43 var eventOpts = {supportsListeners: true, supportsFilters: true}; |
| 44 return new eventBindings.Event(name, undefined, eventOpts); | 44 return new eventBindings.Event(name, undefined, eventOpts); |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 var contentLoadEvent = createEvent('webview.onContentLoad'); | |
| 47 var loadCommitEvent = createEvent('webview.onLoadCommit'); | 48 var loadCommitEvent = createEvent('webview.onLoadCommit'); |
| 48 var loadStopEvent = createEvent('webview.onLoadStop'); | 49 var loadStopEvent = createEvent('webview.onLoadStop'); |
| 49 | 50 |
| 50 // The <webview> tags we wish to watch for (watchForTag) does not belong to the | 51 // The <webview> tags we wish to watch for (watchForTag) does not belong to the |
| 51 // current scope's "document" reference. We need to wait until the document | 52 // current scope's "document" reference. We need to wait until the document |
| 52 // begins loading, since only then will the "document" reference | 53 // begins loading, since only then will the "document" reference |
| 53 // point to the page's document (it will be reset between now and then). | 54 // point to the page's document (it will be reset between now and then). |
| 54 // We can't listen for the "readystatechange" event on the document (because | 55 // We can't listen for the "readystatechange" event on the document (because |
| 55 // the object that it's dispatched on doesn't exist yet), but we can instead | 56 // the object that it's dispatched on doesn't exist yet), but we can instead |
| 56 // do it at the window level in the capturing phase. | 57 // do it at the window level in the capturing phase. |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 | 303 |
| 303 /** | 304 /** |
| 304 * @private | 305 * @private |
| 305 */ | 306 */ |
| 306 WebView.prototype.setupWebviewNodeEvents_ = function() { | 307 WebView.prototype.setupWebviewNodeEvents_ = function() { |
| 307 var self = this; | 308 var self = this; |
| 308 var webviewNode = this.webviewNode_; | 309 var webviewNode = this.webviewNode_; |
| 309 // TODO(fsamuel): Generalize this further as we add more events. | 310 // TODO(fsamuel): Generalize this further as we add more events. |
| 310 var onAttached = function(e) { | 311 var onAttached = function(e) { |
| 311 var detail = e.detail ? JSON.parse(e.detail) : {}; | 312 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 313 contentLoadEvent.addListener(function(event) { | |
|
lazyboy
2013/06/28 18:55:08
We now see a pattern here, so
foo_events = {
'co
Fady Samuel
2013/06/28 21:24:35
Done.
| |
| 314 var webviewEvent = new Event('contentload', {bubbles: true}); | |
| 315 var attribs = WEB_VIEW_EVENTS['contentload']; | |
| 316 $Array.forEach(attribs, function(attribName) { | |
| 317 webviewEvent[attribName] = event[attribName]; | |
| 318 }); | |
| 319 webviewNode.dispatchEvent(webviewEvent); | |
| 320 }, {instanceId: detail.windowId}); | |
| 321 | |
| 312 loadCommitEvent.addListener(function(event) { | 322 loadCommitEvent.addListener(function(event) { |
| 313 var webviewEvent = new Event('loadcommit', {bubbles: true}); | 323 var webviewEvent = new Event('loadcommit', {bubbles: true}); |
| 314 var attribs = WEB_VIEW_EVENTS['loadcommit']; | 324 var attribs = WEB_VIEW_EVENTS['loadcommit']; |
| 315 $Array.forEach(attribs, function(attribName) { | 325 $Array.forEach(attribs, function(attribName) { |
| 316 webviewEvent[attribName] = event[attribName]; | 326 webviewEvent[attribName] = event[attribName]; |
| 317 }); | 327 }); |
| 318 self.currentEntryIndex_ = event.currentEntryIndex; | 328 self.currentEntryIndex_ = event.currentEntryIndex; |
| 319 self.entryCount_ = event.entryCount; | 329 self.entryCount_ = event.entryCount; |
| 320 webviewNode.dispatchEvent(webviewEvent); | 330 webviewNode.dispatchEvent(webviewEvent); |
| 321 }, {instanceId: detail.windowId}); | 331 }, {instanceId: detail.windowId}); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 return []; | 561 return []; |
| 552 }; | 562 }; |
| 553 | 563 |
| 554 /** | 564 /** |
| 555 * Implemented when the experimental API is available. | 565 * Implemented when the experimental API is available. |
| 556 * @private | 566 * @private |
| 557 */ | 567 */ |
| 558 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; | 568 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; |
| 559 | 569 |
| 560 exports.WebView = WebView; | 570 exports.WebView = WebView; |
| OLD | NEW |