summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorfsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 20:42:55 +0000
committerfsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 20:42:55 +0000
commit1869937705df919aff92cb54888527ccbaf62702 (patch)
treef56f5b67c9ad9b9330697b019a60337980303a65 /chrome/renderer
parented2fa729af0311cc4d5f30be5f0368fad248d64a (diff)
downloadchromium_src-1869937705df919aff92cb54888527ccbaf62702.zip
chromium_src-1869937705df919aff92cb54888527ccbaf62702.tar.gz
chromium_src-1869937705df919aff92cb54888527ccbaf62702.tar.bz2
<webview>: Partially migrate loadcommit event from content to chrome
All the pieces are now in place for upstreaming the big content->chrome <webview> refactor. This first patch puts in the first set of pieces in place for migrating loadcommit to chrome. BUG=166165 Test=WebViewTest.* Review URL: https://chromiumcodereview.appspot.com/17165004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208542 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/resources/extensions/ad_view.js26
-rw-r--r--chrome/renderer/resources/extensions/web_view.js23
2 files changed, 47 insertions, 2 deletions
diff --git a/chrome/renderer/resources/extensions/ad_view.js b/chrome/renderer/resources/extensions/ad_view.js
index fa1c0cf..1efda0e 100644
--- a/chrome/renderer/resources/extensions/ad_view.js
+++ b/chrome/renderer/resources/extensions/ad_view.js
@@ -10,6 +10,7 @@
// TODO(rpaquay): This file is currently very similar to "web_view.js". Do we
// want to refactor to extract common pieces?
+var eventBindings = require('event_bindings');
var process = requireNative('process');
var watchForTag = require('tagWatcher').watchForTag;
@@ -73,6 +74,13 @@ var AD_VIEW_EVENTS = {
'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'],
};
+var createEvent = function(name) {
+ var eventOpts = {supportsListeners: true, supportsFilters: true};
+ return new eventBindings.Event(name, undefined, eventOpts);
+};
+
+var AdviewLoadCommitEvent = createEvent('adview.onLoadCommit');
+
/**
* List of supported ad-networks.
*
@@ -124,8 +132,7 @@ function AdView(adviewNode) {
AdView.prototype.createBrowserPluginNode_ = function() {
var browserPluginNode = document.createElement('object');
browserPluginNode.type = 'application/browser-plugin';
- // TODO(fsamuel): Change this to 'adview' once AdViewGuest is ready.
- browserPluginNode.setAttribute('api', 'webview');
+ browserPluginNode.setAttribute('api', 'adview');
// The <object> node fills in the <adview> container.
browserPluginNode.style.width = '100%';
browserPluginNode.style.height = '100%';
@@ -432,6 +439,21 @@ AdView.prototype.handleSrcMutation = function(mutation) {
* @private
*/
AdView.prototype.setupAdviewNodeEvents_ = function() {
+ var adviewNode = this.adviewNode_;
+ // TODO(fsamuel): Generalize this further as we add more events.
+ var onAttached = function(e) {
+ var detail = e.detail ? JSON.parse(e.detail) : {};
+ AdviewLoadCommitEvent.addListener(function(event) {
+ var adviewEvent = new Event('loadcommit', {bubbles: true});
+ var attribs = AD_VIEW_EVENTS['loadcommit'];
+ $Array.forEach(attribs, function(attribName) {
+ adviewEvent[attribName] = event[attribName];
+ });
+ adviewNode.dispatchEvent(adviewEvent);
+ }, {instanceId: detail.windowId});
+ };
+ this.browserPluginNode_.addEventListener('-internal-attached', onAttached);
+
for (var eventName in AD_VIEW_EVENTS) {
this.setupEvent_(eventName, AD_VIEW_EVENTS[eventName]);
}
diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js
index bfb3498..f4cc6ef 100644
--- a/chrome/renderer/resources/extensions/web_view.js
+++ b/chrome/renderer/resources/extensions/web_view.js
@@ -8,6 +8,7 @@
// are hidden via Shadow DOM.
var watchForTag = require('tagWatcher').watchForTag;
+var eventBindings = require('event_bindings');
/** @type {Array.<string>} */
var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight',
@@ -43,6 +44,13 @@ var WEB_VIEW_EVENTS = {
'unresponsive' : ['processId']
};
+var createEvent = function(name) {
+ var eventOpts = {supportsListeners: true, supportsFilters: true};
+ return new eventBindings.Event(name, undefined, eventOpts);
+};
+
+var loadCommitEvent = createEvent('webview.onLoadCommit');
+
// The <webview> tags we wish to watch for (watchForTag) does not belong to the
// current scope's "document" reference. We need to wait until the document
// begins loading, since only then will the "document" reference
@@ -266,6 +274,21 @@ WebView.prototype.handleBrowserPluginAttributeMutation_ = function(mutation) {
* @private
*/
WebView.prototype.setupWebviewNodeEvents_ = function() {
+ var webviewNode = this.webviewNode_;
+ // TODO(fsamuel): Generalize this further as we add more events.
+ var onAttached = function(e) {
+ var detail = e.detail ? JSON.parse(e.detail) : {};
+ loadCommitEvent.addListener(function(event) {
+ var webviewEvent = new Event('loadcommit', {bubbles: true});
+ var attribs = WEB_VIEW_EVENTS['loadcommit'];
+ $Array.forEach(attribs, function(attribName) {
+ webviewEvent[attribName] = event[attribName];
+ });
+ webviewNode.dispatchEvent(webviewEvent);
+ }, {instanceId: detail.windowId});
+ };
+ this.browserPluginNode_.addEventListener('-internal-attached', onAttached);
+
for (var eventName in WEB_VIEW_EVENTS) {
this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]);
}