Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/renderer/resources/extensions/web_view.js

Issue 17165004: <webview>: Partially migrate loadcommit event from content to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unnecessary line of code Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 };
lazyboy 2013/06/19 19:22:16 nit: here and below: no space after { and before }
Fady Samuel 2013/06/19 19:42:11 Done.
49 return new eventBindings.Event('webview.on' + name, undefined, eventOpts);
50 };
51
52 var loadCommitEvent = createEvent('loadcommit');
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
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) {
lazyboy 2013/06/19 19:22:16 How is it ensured that loadcommit event doesn't re
Fady Samuel 2013/06/19 19:42:11 No content is loaded prior to attachment. We fire
268 var evt = new Event('loadcommit', { bubbles: true });
lazyboy 2013/06/19 19:22:16 e event evt are kind of hard to read here. s/evt/w
Fady Samuel 2013/06/19 19:42:11 Done.
269 var attribs = WEB_VIEW_EVENTS['loadcommit'];
270 $Array.forEach(attribs, function(attribName) {
271 evt[attribName] = event[attribName];
272 });
273 webviewNode.dispatchEvent(evt);
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
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;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698