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

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

Issue 11415279: Revert 170866 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/renderer/browser_plugin/browser_plugin.h » ('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 (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 WEB_VIEW_ATTRIBUTES = ['src', 'partition']; 10 var WEB_VIEW_ATTRIBUTES = ['src', 'partition'];
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Map attribute modifications on the <webview> tag to property changes in 83 // Map attribute modifications on the <webview> tag to property changes in
84 // the underlying <object> node. 84 // the underlying <object> node.
85 var handleMutation = this.handleMutation_.bind(this); 85 var handleMutation = this.handleMutation_.bind(this);
86 var observer = new WebKitMutationObserver(function(mutations) { 86 var observer = new WebKitMutationObserver(function(mutations) {
87 mutations.forEach(handleMutation); 87 mutations.forEach(handleMutation);
88 }); 88 });
89 observer.observe( 89 observer.observe(
90 this.node_, 90 this.node_,
91 {attributes: true, attributeFilter: WEB_VIEW_ATTRIBUTES}); 91 {attributes: true, attributeFilter: WEB_VIEW_ATTRIBUTES});
92 92
93 var handleObjectMutation = this.handleObjectMutation_.bind(this);
94 var objectObserver = new WebKitMutationObserver(function(mutations) {
95 mutations.forEach(handleObjectMutation);
96 });
97 objectObserver.observe(
98 this.objectNode_,
99 {attributes: true, attributeFilter: WEB_VIEW_ATTRIBUTES});
100
101 var objectNode = this.objectNode_; 93 var objectNode = this.objectNode_;
102 // Expose getters and setters for the attributes. 94 // Expose getters and setters for the attributes.
103 WEB_VIEW_ATTRIBUTES.forEach(function(attributeName) { 95 WEB_VIEW_ATTRIBUTES.forEach(function(attributeName) {
104 Object.defineProperty(this.node_, attributeName, { 96 Object.defineProperty(this.node_, attributeName, {
105 get: function() { 97 get: function() {
106 return objectNode[attributeName]; 98 return objectNode[attributeName];
107 }, 99 },
108 set: function(value) { 100 set: function(value) {
109 objectNode[attributeName] = value; 101 objectNode[attributeName] = value;
110 }, 102 },
(...skipping 16 matching lines...) Expand all
127 119
128 for (var eventName in WEB_VIEW_EVENTS) { 120 for (var eventName in WEB_VIEW_EVENTS) {
129 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); 121 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]);
130 } 122 }
131 } 123 }
132 124
133 /** 125 /**
134 * @private 126 * @private
135 */ 127 */
136 WebView.prototype.handleMutation_ = function(mutation) { 128 WebView.prototype.handleMutation_ = function(mutation) {
137 this.objectNode_[mutation.attributeName] = 129 this.node_[mutation.attributeName] =
138 this.node_.getAttribute(mutation.attributeName); 130 this.node_.getAttribute(mutation.attributeName);
139 }; 131 };
140 132
141 /** 133 /**
142 * @private 134 * @private
143 */ 135 */
144 WebView.prototype.handleObjectMutation_ = function(mutation) {
145 this.node_.setAttribute(mutation.attributeName,
146 this.objectNode_.getAttribute(mutation.attributeName));
147 };
148
149 /**
150 * @private
151 */
152 WebView.prototype.setupEvent_ = function(eventname, attribs) { 136 WebView.prototype.setupEvent_ = function(eventname, attribs) {
153 var node = this.node_; 137 var node = this.node_;
154 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { 138 this.objectNode_.addEventListener('-internal-' + eventname, function(e) {
155 var evt = new Event(eventname); 139 var evt = new Event(eventname);
156 var detail = e.detail ? JSON.parse(e.detail) : {}; 140 var detail = e.detail ? JSON.parse(e.detail) : {};
157 attribs.forEach(function(attribName) { 141 attribs.forEach(function(attribName) {
158 evt[attribName] = detail[attribName]; 142 evt[attribName] = detail[attribName];
159 }); 143 });
160 node.dispatchEvent(evt); 144 node.dispatchEvent(evt);
161 }); 145 });
162 } 146 }
OLDNEW
« no previous file with comments | « no previous file | content/renderer/browser_plugin/browser_plugin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698