Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 var DocumentNatives = requireNative('document_natives'); | 5 var DocumentNatives = requireNative('document_natives'); |
| 6 var ExtensionOptionsEvents = | 6 var ExtensionOptionsEvents = |
| 7 require('extensionOptionsEvents').ExtensionOptionsEvents; | 7 require('extensionOptionsEvents').ExtensionOptionsEvents; |
| 8 var GuestViewInternal = | 8 var GuestViewInternal = |
| 9 require('binding').Binding.create('guestViewInternal').generate(); | 9 require('binding').Binding.create('guestViewInternal').generate(); |
| 10 var IdGenerator = requireNative('id_generator'); | 10 var IdGenerator = requireNative('id_generator'); |
| 11 var utils = require('utils'); | 11 var utils = require('utils'); |
| 12 | 12 |
| 13 // Mapping of the autosize attribute names to default values | 13 // Mapping of the autosize attribute names to default values |
| 14 var AUTO_SIZE_ATTRIBUTES = { | 14 var AUTO_SIZE_ATTRIBUTES = { |
| 15 'autosize': 'on', | 15 'autosize': 'on', |
| 16 'maxheight': 600, | 16 'maxheight': 600, |
| 17 'maxwidth': 800, | 17 'maxwidth': 800, |
| 18 'minheight': 32, | 18 'minheight': 32, |
| 19 'minwidth': 80 | 19 'minwidth': 80 |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 function ExtensionOptionsInternal(extensionoptionsNode) { | 22 function ExtensionOptionsInternal(extensionoptionsNode) { |
| 23 privates(extensionoptionsNode).internal = this; | 23 privates(extensionoptionsNode).internal = this; |
| 24 this.extensionoptionsNode = extensionoptionsNode; | 24 this.extensionoptionsNode = extensionoptionsNode; |
| 25 this.viewInstanceId = IdGenerator.GetNextId(); | 25 this.viewInstanceId = IdGenerator.GetNextId(); |
| 26 | 26 |
| 27 // Flag that is set when attempting the attach the guest view, but <object> | |
| 28 // bindings are not available. When the bindings become available, the | |
| 29 // attaching will resume. | |
| 30 this.deferredAttachState = false; | |
| 31 | |
| 27 // on* Event handlers. | 32 // on* Event handlers. |
| 28 this.eventHandlers = {}; | 33 this.eventHandlers = {}; |
| 29 | 34 |
| 30 // setupEventProperty is normally called in extension_options_events.js to | 35 // setupEventProperty is normally called in extension_options_events.js to |
| 31 // register events, but the createfailed event is registered here because | 36 // register events, but the createfailed event is registered here because |
| 32 // the event is fired from here instead of through | 37 // the event is fired from here instead of through |
| 33 // extension_options_events.js. | 38 // extension_options_events.js. |
| 34 this.setupEventProperty('createfailed'); | 39 this.setupEventProperty('createfailed'); |
| 35 | |
| 36 new ExtensionOptionsEvents(this, this.viewInstanceId); | 40 new ExtensionOptionsEvents(this, this.viewInstanceId); |
| 37 | 41 |
| 38 this.setupNodeProperties(); | 42 this.setupNodeProperties(); |
| 39 | |
| 40 if (this.parseExtensionAttribute()) | 43 if (this.parseExtensionAttribute()) |
| 41 this.init(); | 44 this.init(); |
| 42 }; | 45 }; |
| 43 | 46 |
| 44 ExtensionOptionsInternal.prototype.attachWindow = function(instanceId) { | 47 ExtensionOptionsInternal.prototype.attachWindow = function(instanceId) { |
| 45 this.instanceId = instanceId; | 48 this.instanceId = instanceId; |
| 46 var params = { | 49 if (!this.hasBindings()) { |
| 50 this.deferredAttachState = true; | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 var params = this.buildAttachParams(); | |
| 55 return this.browserPluginNode['-internal-attach'](instanceId, params); | |
| 56 }; | |
| 57 | |
| 58 ExtensionOptionsInternal.prototype.buildAttachParams = function() { | |
| 59 return { | |
| 47 'autosize': this.autosize, | 60 'autosize': this.autosize, |
| 48 'instanceId': this.viewInstanceId, | 61 'instanceId': this.viewInstanceId, |
| 49 'maxheight': parseInt(this.maxheight || 0), | 62 'maxheight': parseInt(this.maxheight || 0), |
| 50 'maxwidth': parseInt(this.maxwidth || 0), | 63 'maxwidth': parseInt(this.maxwidth || 0), |
| 51 'minheight': parseInt(this.minheight || 0), | 64 'minheight': parseInt(this.minheight || 0), |
| 52 'minwidth': parseInt(this.minwidth || 0) | 65 'minwidth': parseInt(this.minwidth || 0) |
| 53 } | 66 }; |
| 54 return this.browserPluginNode['-internal-attach'](instanceId, params); | 67 } |
| 55 }; | |
| 56 | 68 |
| 57 ExtensionOptionsInternal.prototype.createBrowserPluginNode = function() { | 69 ExtensionOptionsInternal.prototype.createBrowserPluginNode = function() { |
| 58 var browserPluginNode = new ExtensionOptionsInternal.BrowserPlugin(); | 70 var browserPluginNode = new ExtensionOptionsInternal.BrowserPlugin(); |
| 59 privates(browserPluginNode).internal = this; | 71 privates(browserPluginNode).internal = this; |
| 60 return browserPluginNode; | 72 return browserPluginNode; |
| 61 }; | 73 }; |
| 62 | 74 |
| 63 ExtensionOptionsInternal.prototype.createGuest = function() { | 75 ExtensionOptionsInternal.prototype.createGuest = function() { |
| 64 var params = { | 76 var params = { |
| 65 'extensionId': this.extensionId, | 77 'extensionId': this.extensionId, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 'height': parseInt(this.minheight || 0) | 128 'height': parseInt(this.minheight || 0) |
| 117 }, | 129 }, |
| 118 'max': { | 130 'max': { |
| 119 'width': parseInt(this.maxwidth || 0), | 131 'width': parseInt(this.maxwidth || 0), |
| 120 'height': parseInt(this.maxheight || 0) | 132 'height': parseInt(this.maxheight || 0) |
| 121 } | 133 } |
| 122 }); | 134 }); |
| 123 } | 135 } |
| 124 }; | 136 }; |
| 125 | 137 |
| 138 ExtensionOptionsInternal.prototype.handleBrowserPluginAttributeMutation = | |
| 139 function(name, oldValue, newValue) { | |
| 140 if (name == 'internalbindings' && !oldValue && newValue) { | |
|
not at google - send to devlin
2014/08/12 19:58:29
I guess that 'internalbindings' is some magical th
Fady Samuel
2014/08/12 21:36:39
internalbindings is a browserplugin attribute that
| |
| 141 this.browserPluginNode.removeAttribute('internalbindings'); | |
| 142 | |
| 143 if (this.deferredAttachState) { | |
| 144 // A setTimeout is necessary for the binding to be initialized properly. | |
| 145 window.setTimeout(function() { | |
| 146 if (this.hasBindings()) { | |
| 147 var params = this.buildAttachParams(); | |
| 148 this.browserPluginNode['-internal-attach'](this.instanceId, params); | |
| 149 this.deferredAttachState = false; | |
| 150 } else { | |
| 151 } | |
|
not at google - send to devlin
2014/08/12 19:58:29
Empty else block?
| |
| 152 }.bind(this), 0); | |
| 153 } | |
| 154 return; | |
| 155 } | |
| 156 }; | |
| 157 | |
| 158 // Returns true if Browser Plugin bindings is available. | |
| 159 // Bindings are unavailable if <object> is not in the render tree. | |
| 160 ExtensionOptionsInternal.prototype.hasBindings = function() { | |
| 161 return 'function' == typeof this.browserPluginNode['-internal-attach']; | |
|
not at google - send to devlin
2014/08/12 19:58:29
No yoda condition preferably.
Though I find this
ericzeng
2014/08/12 21:53:33
I'm not very happy with the whole flow of the scri
| |
| 162 }; | |
| 163 | |
| 126 ExtensionOptionsInternal.prototype.init = function() { | 164 ExtensionOptionsInternal.prototype.init = function() { |
| 127 if (this.initCalled) | 165 if (this.initCalled) |
| 128 return; | 166 return; |
| 129 | 167 |
| 130 this.initCalled = true; | 168 this.initCalled = true; |
| 131 this.browserPluginNode = this.createBrowserPluginNode(); | 169 this.browserPluginNode = this.createBrowserPluginNode(); |
| 132 var shadowRoot = this.extensionoptionsNode.createShadowRoot(); | 170 var shadowRoot = this.extensionoptionsNode.createShadowRoot(); |
| 133 shadowRoot.appendChild(this.browserPluginNode); | 171 shadowRoot.appendChild(this.browserPluginNode); |
| 134 this.createGuest(); | 172 this.createGuest(); |
| 135 }; | 173 }; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 | 254 |
| 217 function registerBrowserPluginElement() { | 255 function registerBrowserPluginElement() { |
| 218 var proto = Object.create(HTMLObjectElement.prototype); | 256 var proto = Object.create(HTMLObjectElement.prototype); |
| 219 | 257 |
| 220 proto.createdCallback = function() { | 258 proto.createdCallback = function() { |
| 221 this.setAttribute('type', 'application/browser-plugin'); | 259 this.setAttribute('type', 'application/browser-plugin'); |
| 222 this.style.width = '100%'; | 260 this.style.width = '100%'; |
| 223 this.style.height = '100%'; | 261 this.style.height = '100%'; |
| 224 }; | 262 }; |
| 225 | 263 |
| 264 proto.attributeChangedCallback = function(name, oldValue, newValue) { | |
| 265 var internal = privates(this).internal; | |
| 266 if (!internal) { | |
| 267 return; | |
| 268 } | |
| 269 internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue); | |
| 270 }; | |
| 271 | |
| 226 proto.attachedCallback = function() { | 272 proto.attachedCallback = function() { |
| 227 // Load the plugin immediately. | 273 // Load the plugin immediately. |
| 228 var unused = this.nonExistentAttribute; | 274 var unused = this.nonExistentAttribute; |
| 229 }; | 275 }; |
| 230 | 276 |
| 231 ExtensionOptionsInternal.BrowserPlugin = | 277 ExtensionOptionsInternal.BrowserPlugin = |
| 232 DocumentNatives.RegisterElement('extensionoptionsplugin', | 278 DocumentNatives.RegisterElement('extensionoptionsplugin', |
| 233 {extends: 'object', prototype: proto}); | 279 {extends: 'object', prototype: proto}); |
| 234 delete proto.createdCallback; | 280 delete proto.createdCallback; |
| 235 delete proto.attachedCallback; | 281 delete proto.attachedCallback; |
| 236 delete proto.detachedCallback; | 282 delete proto.detachedCallback; |
| 237 delete proto.attributeChangedCallback; | 283 delete proto.attributeChangedCallback; |
| 238 } | 284 } |
| 239 | 285 |
| 240 function registerExtensionOptionsElement() { | 286 function registerExtensionOptionsElement() { |
| 241 var proto = Object.create(HTMLElement.prototype); | 287 var proto = Object.create(HTMLElement.prototype); |
| 242 | 288 |
| 243 proto.createdCallback = function() { | 289 proto.createdCallback = function() { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 264 | 310 |
| 265 var useCapture = true; | 311 var useCapture = true; |
| 266 window.addEventListener('readystatechange', function listener(event) { | 312 window.addEventListener('readystatechange', function listener(event) { |
| 267 if (document.readyState == 'loading') | 313 if (document.readyState == 'loading') |
| 268 return; | 314 return; |
| 269 | 315 |
| 270 registerBrowserPluginElement(); | 316 registerBrowserPluginElement(); |
| 271 registerExtensionOptionsElement(); | 317 registerExtensionOptionsElement(); |
| 272 window.removeEventListener(event.type, listener, useCapture); | 318 window.removeEventListener(event.type, listener, useCapture); |
| 273 }, useCapture); | 319 }, useCapture); |
| OLD | NEW |