| 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 var guestViewInternalNatives = requireNative('guest_view_internal'); | 12 var guestViewInternalNatives = requireNative('guest_view_internal'); |
| 13 | 13 |
| 14 // Mapping of the autosize attribute names to default values | 14 // Mapping of the autosize attribute names to default values |
| 15 var AUTO_SIZE_ATTRIBUTES = { | 15 var AUTO_SIZE_ATTRIBUTES = { |
| 16 'autosize': 'on', | 16 'autosize': 'on', |
| 17 'maxheight': window.innerHeight, | 17 'maxheight': window.innerHeight, |
| 18 'maxwidth': window.innerWidth, | 18 'maxwidth': window.innerWidth, |
| 19 'minheight': 32, | 19 'minheight': 32, |
| 20 'minwidth': 32 | 20 'minwidth': 32 |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 function ExtensionOptionsInternal(extensionoptionsNode) { | 23 function ExtensionOptionsInternal(extensionoptionsNode) { |
| 24 privates(extensionoptionsNode).internal = this; | 24 privates(extensionoptionsNode).internal = this; |
| 25 this.extensionoptionsNode = extensionoptionsNode; | 25 this.extensionoptionsNode = extensionoptionsNode; |
| 26 this.viewInstanceId = IdGenerator.GetNextId(); | 26 this.viewInstanceId = IdGenerator.GetNextId(); |
| 27 this.guestInstanceId = 0; |
| 27 | 28 |
| 28 this.autosizeDeferred = false; | 29 this.autosizeDeferred = false; |
| 29 | 30 |
| 30 // on* Event handlers. | 31 // on* Event handlers. |
| 31 this.eventHandlers = {}; | 32 this.eventHandlers = {}; |
| 32 | 33 |
| 33 // setupEventProperty is normally called in extension_options_events.js to | 34 // setupEventProperty is normally called in extension_options_events.js to |
| 34 // register events, but the createfailed event is registered here because | 35 // register events, but the createfailed event is registered here because |
| 35 // the event is fired from here instead of through | 36 // the event is fired from here instead of through |
| 36 // extension_options_events.js. | 37 // extension_options_events.js. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 61 'minwidth': parseInt(this.minwidth || 0) | 62 'minwidth': parseInt(this.minwidth || 0) |
| 62 }); | 63 }); |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 ExtensionOptionsInternal.prototype.createBrowserPluginNode = function() { | 66 ExtensionOptionsInternal.prototype.createBrowserPluginNode = function() { |
| 66 var browserPluginNode = new ExtensionOptionsInternal.BrowserPlugin(); | 67 var browserPluginNode = new ExtensionOptionsInternal.BrowserPlugin(); |
| 67 privates(browserPluginNode).internal = this; | 68 privates(browserPluginNode).internal = this; |
| 68 return browserPluginNode; | 69 return browserPluginNode; |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 ExtensionOptionsInternal.prototype.createGuest = function() { | 72 ExtensionOptionsInternal.prototype.createGuestIfNecessary = function() { |
| 73 if (this.guestInstanceId != 0) { |
| 74 this.attachWindow(); |
| 75 return; |
| 76 } |
| 72 var params = { | 77 var params = { |
| 73 'extensionId': this.extensionId, | 78 'extensionId': this.extensionId, |
| 74 }; | 79 }; |
| 75 GuestViewInternal.createGuest( | 80 GuestViewInternal.createGuest( |
| 76 'extensionoptions', | 81 'extensionoptions', |
| 77 params, | 82 params, |
| 78 function(guestInstanceId) { | 83 function(guestInstanceId) { |
| 79 if (guestInstanceId == 0) { | 84 if (guestInstanceId == 0) { |
| 80 // Fire a createfailed event here rather than in ExtensionOptionsGuest | 85 // Fire a createfailed event here rather than in ExtensionOptionsGuest |
| 81 // because the guest will not be created, and cannot fire an event. | 86 // because the guest will not be created, and cannot fire an event. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 }); | 143 }); |
| 139 } | 144 } |
| 140 }; | 145 }; |
| 141 | 146 |
| 142 ExtensionOptionsInternal.prototype.handleBrowserPluginAttributeMutation = | 147 ExtensionOptionsInternal.prototype.handleBrowserPluginAttributeMutation = |
| 143 function(name, oldValue, newValue) { | 148 function(name, oldValue, newValue) { |
| 144 if (name == 'internalinstanceid' && !oldValue && !!newValue) { | 149 if (name == 'internalinstanceid' && !oldValue && !!newValue) { |
| 145 this.internalInstanceId = parseInt(newValue); | 150 this.internalInstanceId = parseInt(newValue); |
| 146 this.browserPluginNode.removeAttribute('internalinstanceid'); | 151 this.browserPluginNode.removeAttribute('internalinstanceid'); |
| 147 if (this.extensionId) | 152 if (this.extensionId) |
| 148 this.createGuest(); | 153 this.createGuestIfNecessary(); |
| 149 | 154 |
| 150 } | 155 } |
| 151 }; | 156 }; |
| 152 | 157 |
| 153 ExtensionOptionsInternal.prototype.onSizeChanged = | 158 ExtensionOptionsInternal.prototype.onSizeChanged = |
| 154 function(newWidth, newHeight, oldWidth, oldHeight) { | 159 function(newWidth, newHeight, oldWidth, oldHeight) { |
| 155 if (this.autosizeDeferred) { | 160 if (this.autosizeDeferred) { |
| 156 this.deferredAutoSizeState = { | 161 this.deferredAutoSizeState = { |
| 157 newWidth: newWidth, | 162 newWidth: newWidth, |
| 158 newHeight: newHeight, | 163 newHeight: newHeight, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 */ | 291 */ |
| 287 ExtensionOptionsInternal.prototype.resumeDeferredAutoSize = function() { | 292 ExtensionOptionsInternal.prototype.resumeDeferredAutoSize = function() { |
| 288 if (this.autosizeDeferred) { | 293 if (this.autosizeDeferred) { |
| 289 this.resize(this.deferredAutoSizeState.newWidth, | 294 this.resize(this.deferredAutoSizeState.newWidth, |
| 290 this.deferredAutoSizeState.newHeight, | 295 this.deferredAutoSizeState.newHeight, |
| 291 this.deferredAutoSizeState.oldWidth, | 296 this.deferredAutoSizeState.oldWidth, |
| 292 this.deferredAutoSizeState.oldHeight); | 297 this.deferredAutoSizeState.oldHeight); |
| 293 } | 298 } |
| 294 }; | 299 }; |
| 295 | 300 |
| 301 ExtensionOptionsInternal.prototype.reset = function() { |
| 302 if (this.guestInstanceId) { |
| 303 GuestViewInternal.destroyGuest(this.guestInstanceId); |
| 304 this.guestInstanceId = undefined; |
| 305 } |
| 306 }; |
| 307 |
| 296 function registerBrowserPluginElement() { | 308 function registerBrowserPluginElement() { |
| 297 var proto = Object.create(HTMLObjectElement.prototype); | 309 var proto = Object.create(HTMLObjectElement.prototype); |
| 298 | 310 |
| 299 proto.createdCallback = function() { | 311 proto.createdCallback = function() { |
| 300 this.setAttribute('type', 'application/browser-plugin'); | 312 this.setAttribute('type', 'application/browser-plugin'); |
| 301 this.style.width = '100%'; | 313 this.style.width = '100%'; |
| 302 this.style.height = '100%'; | 314 this.style.height = '100%'; |
| 303 }; | 315 }; |
| 304 | 316 |
| 305 proto.attributeChangedCallback = function(name, oldValue, newValue) { | 317 proto.attributeChangedCallback = function(name, oldValue, newValue) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 324 delete proto.attributeChangedCallback; | 336 delete proto.attributeChangedCallback; |
| 325 } | 337 } |
| 326 | 338 |
| 327 function registerExtensionOptionsElement() { | 339 function registerExtensionOptionsElement() { |
| 328 var proto = Object.create(HTMLElement.prototype); | 340 var proto = Object.create(HTMLElement.prototype); |
| 329 | 341 |
| 330 proto.createdCallback = function() { | 342 proto.createdCallback = function() { |
| 331 new ExtensionOptionsInternal(this); | 343 new ExtensionOptionsInternal(this); |
| 332 }; | 344 }; |
| 333 | 345 |
| 346 proto.detachedCallback = function() { |
| 347 var internal = privates(this).internal; |
| 348 if (!internal) { |
| 349 return; |
| 350 } |
| 351 internal.reset(); |
| 352 }; |
| 353 |
| 334 proto.attributeChangedCallback = function(name, oldValue, newValue) { | 354 proto.attributeChangedCallback = function(name, oldValue, newValue) { |
| 335 var internal = privates(this).internal; | 355 var internal = privates(this).internal; |
| 336 if (!internal) | 356 if (!internal) { |
| 337 return; | 357 return; |
| 358 } |
| 338 internal.handleExtensionOptionsAttributeMutation(name, oldValue, newValue); | 359 internal.handleExtensionOptionsAttributeMutation(name, oldValue, newValue); |
| 339 }; | 360 }; |
| 340 | 361 |
| 341 var methods = [ | 362 var methods = [ |
| 342 'setDeferAutoSize', | 363 'setDeferAutoSize', |
| 343 'resumeDeferredAutoSize' | 364 'resumeDeferredAutoSize' |
| 344 ]; | 365 ]; |
| 345 | 366 |
| 346 // Forward proto.foo* method calls to ExtensionOptionsInternal.foo*. | 367 // Forward proto.foo* method calls to ExtensionOptionsInternal.foo*. |
| 347 for (var i = 0; methods[i]; ++i) { | 368 for (var i = 0; methods[i]; ++i) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 367 | 388 |
| 368 var useCapture = true; | 389 var useCapture = true; |
| 369 window.addEventListener('readystatechange', function listener(event) { | 390 window.addEventListener('readystatechange', function listener(event) { |
| 370 if (document.readyState == 'loading') | 391 if (document.readyState == 'loading') |
| 371 return; | 392 return; |
| 372 | 393 |
| 373 registerBrowserPluginElement(); | 394 registerBrowserPluginElement(); |
| 374 registerExtensionOptionsElement(); | 395 registerExtensionOptionsElement(); |
| 375 window.removeEventListener(event.type, listener, useCapture); | 396 window.removeEventListener(event.type, listener, useCapture); |
| 376 }, useCapture); | 397 }, useCapture); |
| OLD | NEW |