| 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * @constructor | 43 * @constructor |
| 44 */ | 44 */ |
| 45 function WebView(node) { | 45 function WebView(node) { |
| 46 this.node_ = node; | 46 this.node_ = node; |
| 47 var shadowRoot = node.webkitCreateShadowRoot(); | 47 var shadowRoot = node.webkitCreateShadowRoot(); |
| 48 | 48 |
| 49 this.objectNode_ = document.createElement('object'); | 49 this.objectNode_ = document.createElement('object'); |
| 50 this.objectNode_.type = 'application/browser-plugin'; | 50 this.objectNode_.type = 'application/browser-plugin'; |
| 51 // The <object> node fills in the <browser> container. | 51 // The <object> node fills in the <webview> container. |
| 52 this.objectNode_.style.width = '100%'; | 52 this.objectNode_.style.width = '100%'; |
| 53 this.objectNode_.style.height = '100%'; | 53 this.objectNode_.style.height = '100%'; |
| 54 WEB_VIEW_ATTRIBUTES.forEach(function(attributeName) { | 54 WEB_VIEW_ATTRIBUTES.forEach(function(attributeName) { |
| 55 this.objectNode_.setAttribute( | 55 // Only copy attributes that have been assigned values, rather than copying |
| 56 attributeName, this.node_.getAttribute(attributeName)); | 56 // a series of undefined attributes to BrowserPlugin. |
| 57 if (this.node_.hasAttribute(attributeName)) { |
| 58 this.objectNode_.setAttribute( |
| 59 attributeName, this.node_.getAttribute(attributeName)); |
| 60 } |
| 57 }, this); | 61 }, this); |
| 58 | 62 |
| 59 shadowRoot.appendChild(this.objectNode_); | 63 shadowRoot.appendChild(this.objectNode_); |
| 60 | 64 |
| 61 // this.objectNode_[apiMethod] are not necessarily defined immediately after | 65 // this.objectNode_[apiMethod] are not necessarily defined immediately after |
| 62 // the shadow object is appended to the shadow root. | 66 // the shadow object is appended to the shadow root. |
| 63 var self = this; | 67 var self = this; |
| 64 WEB_VIEW_API_METHODS.forEach(function(apiMethod) { | 68 WEB_VIEW_API_METHODS.forEach(function(apiMethod) { |
| 65 node[apiMethod] = function(var_args) { | 69 node[apiMethod] = function(var_args) { |
| 66 return self.objectNode_[apiMethod].apply(self.objectNode_, arguments); | 70 return self.objectNode_[apiMethod].apply(self.objectNode_, arguments); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 var node = this.node_; | 157 var node = this.node_; |
| 154 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { | 158 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { |
| 155 var evt = new Event(eventname); | 159 var evt = new Event(eventname); |
| 156 var detail = e.detail ? JSON.parse(e.detail) : {}; | 160 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 157 attribs.forEach(function(attribName) { | 161 attribs.forEach(function(attribName) { |
| 158 evt[attribName] = detail[attribName]; | 162 evt[attribName] = detail[attribName]; |
| 159 }); | 163 }); |
| 160 node.dispatchEvent(evt); | 164 node.dispatchEvent(evt); |
| 161 }); | 165 }); |
| 162 } | 166 } |
| OLD | NEW |