| OLD | NEW |
| 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; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 */ | 149 */ |
| 150 WebView.prototype.handleObjectMutation_ = function(mutation) { | 150 WebView.prototype.handleObjectMutation_ = function(mutation) { |
| 151 // This observer monitors mutations to attributes of the BrowserPlugin and | 151 // This observer monitors mutations to attributes of the BrowserPlugin and |
| 152 // updates the <webview> attributes accordingly. | 152 // updates the <webview> attributes accordingly. |
| 153 if (!this.objectNode_.hasAttribute(mutation.attributeName)) { | 153 if (!this.objectNode_.hasAttribute(mutation.attributeName)) { |
| 154 // If an attribute is removed from the BrowserPlugin, then remove it | 154 // If an attribute is removed from the BrowserPlugin, then remove it |
| 155 // from the <webview> as well. | 155 // from the <webview> as well. |
| 156 this.node_.removeAttribute(mutation.attributeName); | 156 this.node_.removeAttribute(mutation.attributeName); |
| 157 } else { | 157 } else { |
| 158 // Update the <webview> attribute to match the BrowserPlugin attribute. | 158 // Update the <webview> attribute to match the BrowserPlugin attribute. |
| 159 this.node_.setAttribute(mutation.attributeName, | 159 // Note: Calling setAttribute on <webview> will trigger its mutation |
| 160 this.objectNode_.getAttribute(mutation.attributeName)); | 160 // observer which will then propagate that attribute to BrowserPlugin. In |
| 161 // cases where we permit assigning a BrowserPlugin attribute the same value |
| 162 // again (such as navigation when crashed), this could end up in an infinite |
| 163 // loop. Thus, we avoid this loop by only updating the <webview> attribute |
| 164 // if the BrowserPlugin attributes differs from it. |
| 165 var oldValue = this.node_.getAttribute(mutation.attributeName); |
| 166 var newValue = this.objectNode_.getAttribute(mutation.attributeName); |
| 167 if (newValue != oldValue) { |
| 168 this.node_.setAttribute(mutation.attributeName, newValue); |
| 169 } |
| 161 } | 170 } |
| 162 }; | 171 }; |
| 163 | 172 |
| 164 /** | 173 /** |
| 165 * @private | 174 * @private |
| 166 */ | 175 */ |
| 167 WebView.prototype.setupEvent_ = function(eventname, attribs) { | 176 WebView.prototype.setupEvent_ = function(eventname, attribs) { |
| 168 var node = this.node_; | 177 var node = this.node_; |
| 169 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { | 178 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { |
| 170 var evt = new Event(eventname, { bubbles: true }); | 179 var evt = new Event(eventname, { bubbles: true }); |
| 171 var detail = e.detail ? JSON.parse(e.detail) : {}; | 180 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 172 attribs.forEach(function(attribName) { | 181 attribs.forEach(function(attribName) { |
| 173 evt[attribName] = detail[attribName]; | 182 evt[attribName] = detail[attribName]; |
| 174 }); | 183 }); |
| 175 node.dispatchEvent(evt); | 184 node.dispatchEvent(evt); |
| 176 }); | 185 }); |
| 177 } | 186 } |
| OLD | NEW |