| 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 | 13 |
| 13 // Mapping of the autosize attribute names to default values | 14 // Mapping of the autosize attribute names to default values |
| 14 var AUTO_SIZE_ATTRIBUTES = { | 15 var AUTO_SIZE_ATTRIBUTES = { |
| 15 'autosize': 'on', | 16 'autosize': 'on', |
| 16 'maxheight': 600, | 17 'maxheight': 600, |
| 17 'maxwidth': 800, | 18 'maxwidth': 800, |
| 18 'minheight': 32, | 19 'minheight': 32, |
| 19 'minwidth': 80 | 20 'minwidth': 80 |
| 20 }; | 21 }; |
| 21 | 22 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 this.setupEventProperty('createfailed'); | 35 this.setupEventProperty('createfailed'); |
| 35 | 36 |
| 36 new ExtensionOptionsEvents(this, this.viewInstanceId); | 37 new ExtensionOptionsEvents(this, this.viewInstanceId); |
| 37 | 38 |
| 38 this.setupNodeProperties(); | 39 this.setupNodeProperties(); |
| 39 | 40 |
| 40 if (this.parseExtensionAttribute()) | 41 if (this.parseExtensionAttribute()) |
| 41 this.init(); | 42 this.init(); |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 ExtensionOptionsInternal.prototype.attachWindow = function(instanceId) { | 45 ExtensionOptionsInternal.prototype.attachWindow = function(guestInstanceId) { |
| 45 this.instanceId = instanceId; | 46 this.guestInstanceId = guestInstanceId; |
| 46 var params = { | 47 var params = { |
| 47 'autosize': this.autosize, | 48 'autosize': this.autosize, |
| 48 'instanceId': this.viewInstanceId, | 49 'instanceId': this.viewInstanceId, |
| 49 'maxheight': parseInt(this.maxheight || 0), | 50 'maxheight': parseInt(this.maxheight || 0), |
| 50 'maxwidth': parseInt(this.maxwidth || 0), | 51 'maxwidth': parseInt(this.maxwidth || 0), |
| 51 'minheight': parseInt(this.minheight || 0), | 52 'minheight': parseInt(this.minheight || 0), |
| 52 'minwidth': parseInt(this.minwidth || 0) | 53 'minwidth': parseInt(this.minwidth || 0) |
| 53 } | 54 }; |
| 54 return this.browserPluginNode['-internal-attach'](instanceId, params); | 55 return guestViewInternalNatives.AttachGuest( |
| 56 parseInt(this.browserPluginNode.getAttribute('internalinstanceid')), |
| 57 guestInstanceId, |
| 58 params); |
| 55 }; | 59 }; |
| 56 | 60 |
| 57 ExtensionOptionsInternal.prototype.createBrowserPluginNode = function() { | 61 ExtensionOptionsInternal.prototype.createBrowserPluginNode = function() { |
| 58 var browserPluginNode = new ExtensionOptionsInternal.BrowserPlugin(); | 62 var browserPluginNode = new ExtensionOptionsInternal.BrowserPlugin(); |
| 59 privates(browserPluginNode).internal = this; | 63 privates(browserPluginNode).internal = this; |
| 60 return browserPluginNode; | 64 return browserPluginNode; |
| 61 }; | 65 }; |
| 62 | 66 |
| 63 ExtensionOptionsInternal.prototype.createGuest = function() { | 67 ExtensionOptionsInternal.prototype.createGuest = function() { |
| 64 var params = { | 68 var params = { |
| 65 'extensionId': this.extensionId, | 69 'extensionId': this.extensionId, |
| 66 }; | 70 }; |
| 67 GuestViewInternal.createGuest( | 71 GuestViewInternal.createGuest( |
| 68 'extensionoptions', | 72 'extensionoptions', |
| 69 params, | 73 params, |
| 70 function(instanceId) { | 74 function(guestInstanceId) { |
| 71 if (instanceId == 0) { | 75 if (guestInstanceId == 0) { |
| 72 // Fire a createfailed event here rather than in ExtensionOptionsGuest | 76 // Fire a createfailed event here rather than in ExtensionOptionsGuest |
| 73 // because the guest will not be created, and cannot fire an event. | 77 // because the guest will not be created, and cannot fire an event. |
| 74 this.initCalled = false; | 78 this.initCalled = false; |
| 75 var createFailedEvent = new Event('createfailed', { bubbles: true }); | 79 var createFailedEvent = new Event('createfailed', { bubbles: true }); |
| 76 this.dispatchEvent(createFailedEvent); | 80 this.dispatchEvent(createFailedEvent); |
| 77 } else { | 81 } else { |
| 78 this.attachWindow(instanceId); | 82 this.attachWindow(guestInstanceId); |
| 79 } | 83 } |
| 80 }.bind(this)); | 84 }.bind(this)); |
| 81 }; | 85 }; |
| 82 | 86 |
| 83 ExtensionOptionsInternal.prototype.dispatchEvent = | 87 ExtensionOptionsInternal.prototype.dispatchEvent = |
| 84 function(extensionOptionsEvent) { | 88 function(extensionOptionsEvent) { |
| 85 return this.extensionoptionsNode.dispatchEvent(extensionOptionsEvent); | 89 return this.extensionoptionsNode.dispatchEvent(extensionOptionsEvent); |
| 86 }; | 90 }; |
| 87 | 91 |
| 88 ExtensionOptionsInternal.prototype.handleExtensionOptionsAttributeMutation = | 92 ExtensionOptionsInternal.prototype.handleExtensionOptionsAttributeMutation = |
| 89 function(name, oldValue, newValue) { | 93 function(name, oldValue, newValue) { |
| 90 // We treat null attribute (attribute removed) and the empty string as | 94 // We treat null attribute (attribute removed) and the empty string as |
| 91 // one case. | 95 // one case. |
| 92 oldValue = oldValue || ''; | 96 oldValue = oldValue || ''; |
| 93 newValue = newValue || ''; | 97 newValue = newValue || ''; |
| 94 | 98 |
| 95 if (oldValue === newValue) | 99 if (oldValue === newValue) |
| 96 return; | 100 return; |
| 97 | 101 |
| 98 if (name == 'extension') { | 102 if (name == 'extension') { |
| 99 this.extensionId = newValue; | 103 this.extensionId = newValue; |
| 100 // Create new guest view if one hasn't been created for this element. | 104 // Create new guest view if one hasn't been created for this element. |
| 101 if (!this.instanceId && this.parseExtensionAttribute()) | 105 if (!this.guestInstanceId && this.parseExtensionAttribute()) |
| 102 this.init(); | 106 this.init(); |
| 103 // TODO(ericzeng): Implement navigation to another guest view if we want | 107 // TODO(ericzeng): Implement navigation to another guest view if we want |
| 104 // that functionality. | 108 // that functionality. |
| 105 } else if (AUTO_SIZE_ATTRIBUTES.hasOwnProperty(name) > -1) { | 109 } else if (AUTO_SIZE_ATTRIBUTES.hasOwnProperty(name) > -1) { |
| 106 this[name] = newValue; | 110 this[name] = newValue; |
| 107 this.resetSizeConstraintsIfInvalid(); | 111 this.resetSizeConstraintsIfInvalid(); |
| 108 | 112 |
| 109 if (!this.instanceId) | 113 if (!this.guestInstanceId) |
| 110 return; | 114 return; |
| 111 | 115 |
| 112 GuestViewInternal.setAutoSize(this.instanceId, { | 116 GuestViewInternal.setAutoSize(this.guestInstanceId, { |
| 113 'enableAutoSize': this.extensionoptionsNode.hasAttribute('autosize'), | 117 'enableAutoSize': this.extensionoptionsNode.hasAttribute('autosize'), |
| 114 'min': { | 118 'min': { |
| 115 'width': parseInt(this.minwidth || 0), | 119 'width': parseInt(this.minwidth || 0), |
| 116 'height': parseInt(this.minheight || 0) | 120 'height': parseInt(this.minheight || 0) |
| 117 }, | 121 }, |
| 118 'max': { | 122 'max': { |
| 119 'width': parseInt(this.maxwidth || 0), | 123 'width': parseInt(this.maxwidth || 0), |
| 120 'height': parseInt(this.maxheight || 0) | 124 'height': parseInt(this.maxheight || 0) |
| 121 } | 125 } |
| 122 }); | 126 }); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 268 |
| 265 var useCapture = true; | 269 var useCapture = true; |
| 266 window.addEventListener('readystatechange', function listener(event) { | 270 window.addEventListener('readystatechange', function listener(event) { |
| 267 if (document.readyState == 'loading') | 271 if (document.readyState == 'loading') |
| 268 return; | 272 return; |
| 269 | 273 |
| 270 registerBrowserPluginElement(); | 274 registerBrowserPluginElement(); |
| 271 registerExtensionOptionsElement(); | 275 registerExtensionOptionsElement(); |
| 272 window.removeEventListener(event.type, listener, useCapture); | 276 window.removeEventListener(event.type, listener, useCapture); |
| 273 }, useCapture); | 277 }, useCapture); |
| OLD | NEW |