| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 return objectNode[attributeName]; | 113 return objectNode[attributeName]; |
| 114 }, | 114 }, |
| 115 // No setter. | 115 // No setter. |
| 116 enumerable: true | 116 enumerable: true |
| 117 }) | 117 }) |
| 118 }, this); | 118 }, this); |
| 119 | 119 |
| 120 for (var eventName in WEB_VIEW_EVENTS) { | 120 for (var eventName in WEB_VIEW_EVENTS) { |
| 121 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); | 121 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); |
| 122 } | 122 } |
| 123 this.maybeSetupPermissionEvent_(); |
| 123 } | 124 } |
| 124 | 125 |
| 125 /** | 126 /** |
| 126 * @private | 127 * @private |
| 127 */ | 128 */ |
| 128 WebView.prototype.handleMutation_ = function(mutation) { | 129 WebView.prototype.handleMutation_ = function(mutation) { |
| 129 this.node_[mutation.attributeName] = | 130 this.node_[mutation.attributeName] = |
| 130 this.node_.getAttribute(mutation.attributeName); | 131 this.node_.getAttribute(mutation.attributeName); |
| 131 }; | 132 }; |
| 132 | 133 |
| 133 /** | 134 /** |
| 134 * @private | 135 * @private |
| 135 */ | 136 */ |
| 136 WebView.prototype.setupEvent_ = function(eventname, attribs) { | 137 WebView.prototype.setupEvent_ = function(eventname, attribs, opt_prepareEvent) { |
| 137 var node = this.node_; | 138 var node = this.node_; |
| 138 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { | 139 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { |
| 139 var evt = new Event(eventname); | 140 var evt = new Event(eventname); |
| 140 var detail = e.detail ? JSON.parse(e.detail) : {}; | 141 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 141 attribs.forEach(function(attribName) { | 142 attribs.forEach(function(attribName) { |
| 142 evt[attribName] = detail[attribName]; | 143 evt[attribName] = detail[attribName]; |
| 143 }); | 144 }); |
| 145 if (opt_prepareEvent) { |
| 146 opt_prepareEvent(evt, detail); |
| 147 } |
| 144 node.dispatchEvent(evt); | 148 node.dispatchEvent(evt); |
| 145 }); | 149 }); |
| 146 } | 150 }; |
| 151 |
| 152 /** |
| 153 * Implemented when webview.permissionAPI permission is available. |
| 154 * @private |
| 155 */ |
| 156 WebView.prototype.maybeSetupPermissionEvent_ = function() {}; |
| 157 |
| 158 exports.WebView = WebView; |
| OLD | NEW |