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

Side by Side Diff: chrome/renderer/resources/extensions/ad_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: Merge with ToT Created 7 years, 5 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
« no previous file with comments | « chrome/common/extensions/api/api.gyp ('k') | chrome/renderer/resources/extensions/web_view.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <adview> tag via Mutation Observers. 5 // Shim that simulates a <adview> 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 // TODO(rpaquay): This file is currently very similar to "web_view.js". Do we 10 // TODO(rpaquay): This file is currently very similar to "web_view.js". Do we
11 // want to refactor to extract common pieces? 11 // want to refactor to extract common pieces?
12 12
13 var eventBindings = require('event_bindings');
13 var process = requireNative('process'); 14 var process = requireNative('process');
14 var watchForTag = require('tagWatcher').watchForTag; 15 var watchForTag = require('tagWatcher').watchForTag;
15 16
16 /** 17 /**
17 * Define "allowCustomAdNetworks" function such that the 18 * Define "allowCustomAdNetworks" function such that the
18 * "kEnableAdviewSrcAttribute" flag is respected. 19 * "kEnableAdviewSrcAttribute" flag is respected.
19 */ 20 */
20 function allowCustomAdNetworks() { 21 function allowCustomAdNetworks() {
21 return process.HasSwitch('enable-adview-src-attribute'); 22 return process.HasSwitch('enable-adview-src-attribute');
22 } 23 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 67
67 /** 68 /**
68 * List of events to blindly forward from the browser plugin to the <adview>. 69 * List of events to blindly forward from the browser plugin to the <adview>.
69 */ 70 */
70 var AD_VIEW_EVENTS = { 71 var AD_VIEW_EVENTS = {
71 'loadabort' : ['url', 'isTopLevel', 'reason'], 72 'loadabort' : ['url', 'isTopLevel', 'reason'],
72 'loadcommit' : ['url', 'isTopLevel'], 73 'loadcommit' : ['url', 'isTopLevel'],
73 'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'], 74 'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'],
74 }; 75 };
75 76
77 var createEvent = function(name) {
78 var eventOpts = {supportsListeners: true, supportsFilters: true};
79 return new eventBindings.Event(name, undefined, eventOpts);
80 };
81
82 var AdviewLoadCommitEvent = createEvent('adview.onLoadCommit');
83
76 /** 84 /**
77 * List of supported ad-networks. 85 * List of supported ad-networks.
78 * 86 *
79 * name: identifier of the ad-network, corresponding to a valid value 87 * name: identifier of the ad-network, corresponding to a valid value
80 * of the "ad-network" attribute of an <adview> element. 88 * of the "ad-network" attribute of an <adview> element.
81 * url: url to navigate to when initially displaying the <adview>. 89 * url: url to navigate to when initially displaying the <adview>.
82 * origin: origin of urls the <adview> is allowed navigate to. 90 * origin: origin of urls the <adview> is allowed navigate to.
83 */ 91 */
84 var AD_VIEW_AD_NETWORKS_WHITELIST = [ 92 var AD_VIEW_AD_NETWORKS_WHITELIST = [
85 { 93 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 this.setupAdviewNodeEvents_(); 125 this.setupAdviewNodeEvents_();
118 this.setupBrowserPluginNodeObservers_(); 126 this.setupBrowserPluginNodeObservers_();
119 } 127 }
120 128
121 /** 129 /**
122 * @private 130 * @private
123 */ 131 */
124 AdView.prototype.createBrowserPluginNode_ = function() { 132 AdView.prototype.createBrowserPluginNode_ = function() {
125 var browserPluginNode = document.createElement('object'); 133 var browserPluginNode = document.createElement('object');
126 browserPluginNode.type = 'application/browser-plugin'; 134 browserPluginNode.type = 'application/browser-plugin';
127 // TODO(fsamuel): Change this to 'adview' once AdViewGuest is ready. 135 browserPluginNode.setAttribute('api', 'adview');
128 browserPluginNode.setAttribute('api', 'webview');
129 // The <object> node fills in the <adview> container. 136 // The <object> node fills in the <adview> container.
130 browserPluginNode.style.width = '100%'; 137 browserPluginNode.style.width = '100%';
131 browserPluginNode.style.height = '100%'; 138 browserPluginNode.style.height = '100%';
132 $Array.forEach(AD_VIEW_ATTRIBUTES, function(attributeName) { 139 $Array.forEach(AD_VIEW_ATTRIBUTES, function(attributeName) {
133 // Only copy attributes that have been assigned values, rather than copying 140 // Only copy attributes that have been assigned values, rather than copying
134 // a series of undefined attributes to BrowserPlugin. 141 // a series of undefined attributes to BrowserPlugin.
135 if (this.adviewNode_.hasAttribute(attributeName)) { 142 if (this.adviewNode_.hasAttribute(attributeName)) {
136 browserPluginNode.setAttribute( 143 browserPluginNode.setAttribute(
137 attributeName, this.adviewNode_.getAttribute(attributeName)); 144 attributeName, this.adviewNode_.getAttribute(attributeName));
138 } 145 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 this.adviewNode_.setAttribute('src', ''); 432 this.adviewNode_.setAttribute('src', '');
426 } 433 }
427 } 434 }
428 } 435 }
429 } 436 }
430 437
431 /** 438 /**
432 * @private 439 * @private
433 */ 440 */
434 AdView.prototype.setupAdviewNodeEvents_ = function() { 441 AdView.prototype.setupAdviewNodeEvents_ = function() {
442 var adviewNode = this.adviewNode_;
443 // TODO(fsamuel): Generalize this further as we add more events.
444 var onAttached = function(e) {
445 var detail = e.detail ? JSON.parse(e.detail) : {};
446 AdviewLoadCommitEvent.addListener(function(event) {
447 var adviewEvent = new Event('loadcommit', {bubbles: true});
448 var attribs = AD_VIEW_EVENTS['loadcommit'];
449 $Array.forEach(attribs, function(attribName) {
450 adviewEvent[attribName] = event[attribName];
451 });
452 adviewNode.dispatchEvent(adviewEvent);
453 }, {instanceId: detail.windowId});
454 };
455 this.browserPluginNode_.addEventListener('-internal-attached', onAttached);
456
435 for (var eventName in AD_VIEW_EVENTS) { 457 for (var eventName in AD_VIEW_EVENTS) {
436 this.setupEvent_(eventName, AD_VIEW_EVENTS[eventName]); 458 this.setupEvent_(eventName, AD_VIEW_EVENTS[eventName]);
437 } 459 }
438 } 460 }
439 461
440 /** 462 /**
441 * @private 463 * @private
442 */ 464 */
443 AdView.prototype.setupEvent_ = function(eventname, attribs) { 465 AdView.prototype.setupEvent_ = function(eventname, attribs) {
444 var adviewNode = this.adviewNode_; 466 var adviewNode = this.adviewNode_;
(...skipping 21 matching lines...) Expand all
466 // Dispatch event. 488 // Dispatch event.
467 this.adviewNode_.dispatchEvent(evt); 489 this.adviewNode_.dispatchEvent(evt);
468 } 490 }
469 491
470 // 492 //
471 // Hook up <adview> tag creation in DOM. 493 // Hook up <adview> tag creation in DOM.
472 // 494 //
473 window.addEventListener('DOMContentLoaded', function() { 495 window.addEventListener('DOMContentLoaded', function() {
474 watchForTag('ADVIEW', function(addedNode) { new AdView(addedNode); }); 496 watchForTag('ADVIEW', function(addedNode) { new AdView(addedNode); });
475 }); 497 });
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/api.gyp ('k') | chrome/renderer/resources/extensions/web_view.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698