| 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 WEB_VIEW_ATTRIBUTES = ['src', 'partition']; | 10 var WEB_VIEW_ATTRIBUTES = ['src', 'partition']; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 return objectNode[attributeName]; | 121 return objectNode[attributeName]; |
| 122 }, | 122 }, |
| 123 // No setter. | 123 // No setter. |
| 124 enumerable: true | 124 enumerable: true |
| 125 }) | 125 }) |
| 126 }, this); | 126 }, this); |
| 127 | 127 |
| 128 for (var eventName in WEB_VIEW_EVENTS) { | 128 for (var eventName in WEB_VIEW_EVENTS) { |
| 129 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); | 129 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); |
| 130 } | 130 } |
| 131 this.maybeSetupPermissionEvent_(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 /** | 134 /** |
| 134 * @private | 135 * @private |
| 135 */ | 136 */ |
| 136 WebView.prototype.handleMutation_ = function(mutation) { | 137 WebView.prototype.handleMutation_ = function(mutation) { |
| 137 this.objectNode_[mutation.attributeName] = | 138 this.objectNode_[mutation.attributeName] = |
| 138 this.node_.getAttribute(mutation.attributeName); | 139 this.node_.getAttribute(mutation.attributeName); |
| 139 }; | 140 }; |
| 140 | 141 |
| 141 /** | 142 /** |
| 142 * @private | 143 * @private |
| 143 */ | 144 */ |
| 144 WebView.prototype.handleObjectMutation_ = function(mutation) { | 145 WebView.prototype.handleObjectMutation_ = function(mutation) { |
| 145 this.node_.setAttribute(mutation.attributeName, | 146 this.node_.setAttribute(mutation.attributeName, |
| 146 this.objectNode_.getAttribute(mutation.attributeName)); | 147 this.objectNode_.getAttribute(mutation.attributeName)); |
| 147 }; | 148 }; |
| 148 | 149 |
| 149 /** | 150 /** |
| 150 * @private | 151 * @private |
| 151 */ | 152 */ |
| 152 WebView.prototype.setupEvent_ = function(eventname, attribs) { | 153 WebView.prototype.setupEvent_ = function(eventname, attribs, opt_prepareEvent) { |
| 153 var node = this.node_; | 154 var node = this.node_; |
| 154 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { | 155 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { |
| 155 var evt = new Event(eventname); | 156 var evt = new Event(eventname); |
| 156 var detail = e.detail ? JSON.parse(e.detail) : {}; | 157 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 157 attribs.forEach(function(attribName) { | 158 attribs.forEach(function(attribName) { |
| 158 evt[attribName] = detail[attribName]; | 159 evt[attribName] = detail[attribName]; |
| 159 }); | 160 }); |
| 161 if (opt_prepareEvent) { |
| 162 opt_prepareEvent(evt, detail); |
| 163 } |
| 160 node.dispatchEvent(evt); | 164 node.dispatchEvent(evt); |
| 161 }); | 165 }); |
| 162 } | 166 }; |
| 167 |
| 168 /** |
| 169 * Implemented when webview.permissionAPI permission is available. |
| 170 * @private |
| 171 */ |
| 172 WebView.prototype.maybeSetupPermissionEvent_ = function() {}; |
| 173 |
| 174 exports.WebView = WebView; |
| OLD | NEW |