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

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

Issue 11418261: Browser Plugin: Update DOM Node attributes when properties are updated (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits 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
93 var objectNode = this.objectNode_; 101 var objectNode = this.objectNode_;
94 // Expose getters and setters for the attributes. 102 // Expose getters and setters for the attributes.
95 WEB_VIEW_ATTRIBUTES.forEach(function(attributeName) { 103 WEB_VIEW_ATTRIBUTES.forEach(function(attributeName) {
96 Object.defineProperty(this.node_, attributeName, { 104 Object.defineProperty(this.node_, attributeName, {
97 get: function() { 105 get: function() {
98 return objectNode[attributeName]; 106 return objectNode[attributeName];
99 }, 107 },
100 set: function(value) { 108 set: function(value) {
101 objectNode[attributeName] = value; 109 objectNode[attributeName] = value;
102 }, 110 },
(...skipping 16 matching lines...) Expand all
119 127
120 for (var eventName in WEB_VIEW_EVENTS) { 128 for (var eventName in WEB_VIEW_EVENTS) {
121 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); 129 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]);
122 } 130 }
123 } 131 }
124 132
125 /** 133 /**
126 * @private 134 * @private
127 */ 135 */
128 WebView.prototype.handleMutation_ = function(mutation) { 136 WebView.prototype.handleMutation_ = function(mutation) {
129 this.node_[mutation.attributeName] = 137 this.objectNode_[mutation.attributeName] =
130 this.node_.getAttribute(mutation.attributeName); 138 this.node_.getAttribute(mutation.attributeName);
131 }; 139 };
132 140
133 /** 141 /**
134 * @private 142 * @private
135 */ 143 */
144 WebView.prototype.handleObjectMutation_ = function(mutation) {
145 this.node_.setAttribute(mutation.attributeName,
146 this.objectNode_.getAttribute(mutation.attributeName));
147 };
148
149 /**
150 * @private
151 */
136 WebView.prototype.setupEvent_ = function(eventname, attribs) { 152 WebView.prototype.setupEvent_ = function(eventname, attribs) {
137 var node = this.node_; 153 var node = this.node_;
138 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { 154 this.objectNode_.addEventListener('-internal-' + eventname, function(e) {
139 var evt = new Event(eventname); 155 var evt = new Event(eventname);
140 var detail = e.detail ? JSON.parse(e.detail) : {}; 156 var detail = e.detail ? JSON.parse(e.detail) : {};
141 attribs.forEach(function(attribName) { 157 attribs.forEach(function(attribName) {
142 evt[attribName] = detail[attribName]; 158 evt[attribName] = detail[attribName];
143 }); 159 });
144 node.dispatchEvent(evt); 160 node.dispatchEvent(evt);
145 }); 161 });
146 } 162 }
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