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 GuestViewInternal.setAutoSize(this.instanceId, { | 83 GuestViewInternal.setAutoSize(this.guestInstanceId, { |
80 'enableAutoSize': | 84 'enableAutoSize': |
81 this.extensionoptionsNode.hasAttribute('autosize'), | 85 this.extensionoptionsNode.hasAttribute('autosize'), |
82 'min': { | 86 'min': { |
83 'width': parseInt(this.minwidth || 0), | 87 'width': parseInt(this.minwidth || 0), |
84 'height': parseInt(this.minheight || 0) | 88 'height': parseInt(this.minheight || 0) |
85 }, | 89 }, |
86 'max': { | 90 'max': { |
87 'width': parseInt(this.maxwidth || 0), | 91 'width': parseInt(this.maxwidth || 0), |
88 'height': parseInt(this.maxheight || 0) | 92 'height': parseInt(this.maxheight || 0) |
89 } | 93 } |
(...skipping 13 matching lines...) Expand all Loading... |
103 // one case. | 107 // one case. |
104 oldValue = oldValue || ''; | 108 oldValue = oldValue || ''; |
105 newValue = newValue || ''; | 109 newValue = newValue || ''; |
106 | 110 |
107 if (oldValue === newValue) | 111 if (oldValue === newValue) |
108 return; | 112 return; |
109 | 113 |
110 if (name == 'extension') { | 114 if (name == 'extension') { |
111 this.extensionId = newValue; | 115 this.extensionId = newValue; |
112 // Create new guest view if one hasn't been created for this element. | 116 // Create new guest view if one hasn't been created for this element. |
113 if (!this.instanceId && this.parseExtensionAttribute()) | 117 if (!this.guestInstanceId && this.parseExtensionAttribute()) |
114 this.init(); | 118 this.init(); |
115 // TODO(ericzeng): Implement navigation to another guest view if we want | 119 // TODO(ericzeng): Implement navigation to another guest view if we want |
116 // that functionality. | 120 // that functionality. |
117 } else if (AUTO_SIZE_ATTRIBUTES.hasOwnProperty(name) > -1) { | 121 } else if (AUTO_SIZE_ATTRIBUTES.hasOwnProperty(name) > -1) { |
118 this[name] = newValue; | 122 this[name] = newValue; |
119 this.resetSizeConstraintsIfInvalid(); | 123 this.resetSizeConstraintsIfInvalid(); |
120 | 124 |
121 if (!this.instanceId) | 125 if (!this.guestInstanceId) |
122 return; | 126 return; |
123 | 127 |
124 GuestViewInternal.setAutoSize(this.instanceId, { | 128 GuestViewInternal.setAutoSize(this.guestInstanceId, { |
125 'enableAutoSize': this.extensionoptionsNode.hasAttribute('autosize'), | 129 'enableAutoSize': this.extensionoptionsNode.hasAttribute('autosize'), |
126 'min': { | 130 'min': { |
127 'width': parseInt(this.minwidth || 0), | 131 'width': parseInt(this.minwidth || 0), |
128 'height': parseInt(this.minheight || 0) | 132 'height': parseInt(this.minheight || 0) |
129 }, | 133 }, |
130 'max': { | 134 'max': { |
131 'width': parseInt(this.maxwidth || 0), | 135 'width': parseInt(this.maxwidth || 0), |
132 'height': parseInt(this.maxheight || 0) | 136 'height': parseInt(this.maxheight || 0) |
133 } | 137 } |
134 }); | 138 }); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 280 |
277 var useCapture = true; | 281 var useCapture = true; |
278 window.addEventListener('readystatechange', function listener(event) { | 282 window.addEventListener('readystatechange', function listener(event) { |
279 if (document.readyState == 'loading') | 283 if (document.readyState == 'loading') |
280 return; | 284 return; |
281 | 285 |
282 registerBrowserPluginElement(); | 286 registerBrowserPluginElement(); |
283 registerExtensionOptionsElement(); | 287 registerExtensionOptionsElement(); |
284 window.removeEventListener(event.type, listener, useCapture); | 288 window.removeEventListener(event.type, listener, useCapture); |
285 }, useCapture); | 289 }, useCapture); |
OLD | NEW |