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