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 // This module implements a wrapper for a guestview that manages its | 5 // This module implements a wrapper for a guestview that manages its |
6 // creation, attaching, and destruction. | 6 // creation, attaching, and destruction. |
7 | 7 |
8 var CreateEvent = require('guestViewEvents').CreateEvent; | 8 var CreateEvent = require('guestViewEvents').CreateEvent; |
9 var EventBindings = require('event_bindings'); | 9 var EventBindings = require('event_bindings'); |
10 var GuestViewInternal = | 10 var GuestViewInternal = |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 | 132 |
133 // Internal implementation of attach(). | 133 // Internal implementation of attach(). |
134 GuestViewImpl.prototype.attachImpl = function( | 134 GuestViewImpl.prototype.attachImpl = function( |
135 internalInstanceId, viewInstanceId, attachParams, callback) { | 135 internalInstanceId, viewInstanceId, attachParams, callback) { |
136 // Check the current state. | 136 // Check the current state. |
137 if (!this.checkState('attach')) { | 137 if (!this.checkState('attach')) { |
138 this.handleCallback(callback); | 138 this.handleCallback(callback); |
139 return; | 139 return; |
140 } | 140 } |
141 | 141 |
142 var isSitePerProcess = GuestViewInternalNatives.IsSitePerProcess(); | |
142 // Callback wrapper function to store the contentWindow from the attachGuest() | 143 // Callback wrapper function to store the contentWindow from the attachGuest() |
143 // callback, handle potential attaching failure, register an automatic detach, | 144 // callback, handle potential attaching failure, register an automatic detach, |
144 // and advance the queue. | 145 // and advance the queue. |
145 var callbackWrapper = function(callback, contentWindow) { | 146 var callbackWrapper = function(callback, contentWindow) { |
146 // Check if attaching failed. | 147 // Check if attaching failed. |
148 if (isSitePerProcess) { | |
149 contentWindow = this.guestView.browserPluginElement.contentWindow; | |
Fady Samuel
2015/05/26 16:42:15
Why are you using browserPluginElement for sitePer
| |
150 } | |
151 | |
147 if (!contentWindow) { | 152 if (!contentWindow) { |
148 this.state = GUEST_STATE_CREATED; | 153 this.state = GUEST_STATE_CREATED; |
149 this.internalInstanceId = 0; | 154 this.internalInstanceId = 0; |
150 } else { | 155 } else { |
151 // Only update the contentWindow if attaching is successful. | 156 // Only update the contentWindow if attaching is successful. |
152 this.contentWindow = contentWindow; | 157 this.contentWindow = contentWindow; |
153 } | 158 } |
154 | 159 |
155 this.handleCallback(callback); | 160 this.handleCallback(callback); |
156 }; | 161 }; |
157 | 162 |
158 attachParams['instanceId'] = viewInstanceId; | 163 attachParams['instanceId'] = viewInstanceId; |
159 GuestViewInternalNatives.AttachGuest(internalInstanceId, | 164 if (isSitePerProcess) { |
160 this.id, | 165 var contentWindow = this.guestView.browserPluginElement.contentWindow; |
161 attachParams, | 166 GuestViewInternalNatives.AttachIframeGuest( |
162 callbackWrapper.bind(this, callback)); | 167 internalInstanceId, this.id, attachParams, contentWindow, |
168 callbackWrapper.bind(this, callback)); | |
169 } else { | |
170 GuestViewInternalNatives.AttachGuest(internalInstanceId, | |
171 this.id, | |
172 attachParams, | |
173 callbackWrapper.bind(this, callback)); | |
174 } | |
163 | 175 |
164 this.internalInstanceId = internalInstanceId; | 176 this.internalInstanceId = internalInstanceId; |
165 this.state = GUEST_STATE_ATTACHED; | 177 this.state = GUEST_STATE_ATTACHED; |
166 | 178 |
167 // Detach automatically when the container is destroyed. | 179 // Detach automatically when the container is destroyed. |
168 GuestViewInternalNatives.RegisterDestructionCallback(internalInstanceId, | 180 GuestViewInternalNatives.RegisterDestructionCallback(internalInstanceId, |
169 function() { | 181 function() { |
170 if (this.state != GUEST_STATE_ATTACHED || | 182 if (this.state != GUEST_STATE_ATTACHED || |
171 this.internalInstanceId != internalInstanceId) { | 183 this.internalInstanceId != internalInstanceId) { |
172 return; | 184 return; |
173 } | 185 } |
174 | 186 |
175 this.internalInstanceId = 0; | 187 this.internalInstanceId = 0; |
176 this.state = GUEST_STATE_CREATED; | 188 this.state = GUEST_STATE_CREATED; |
177 }.bind(this)); | 189 }.bind(this)); |
178 }; | 190 }; |
179 | 191 |
180 // Internal implementation of create(). | 192 // Internal implementation of create(). |
181 GuestViewImpl.prototype.createImpl = function(createParams, callback) { | 193 GuestViewImpl.prototype.createImpl = function(createParams, callback) { |
182 // Check the current state. | 194 // Check the current state. |
183 if (!this.checkState('create')) { | 195 if (!this.checkState('create')) { |
184 this.handleCallback(callback); | 196 this.handleCallback(callback); |
185 return; | 197 return; |
186 } | 198 } |
187 | 199 |
200 var isSitePerProcess = GuestViewInternalNatives.IsSitePerProcess(); | |
188 // Callback wrapper function to store the guestInstanceId from the | 201 // Callback wrapper function to store the guestInstanceId from the |
189 // createGuest() callback, handle potential creation failure, and advance the | 202 // createGuest() callback, handle potential creation failure, and advance the |
190 // queue. | 203 // queue. |
191 var callbackWrapper = function(callback, guestInfo) { | 204 var callbackWrapper = function(callback, guestInfo) { |
192 this.id = guestInfo.id; | 205 this.id = guestInfo.id; |
193 this.contentWindow = | 206 if (!isSitePerProcess) { |
194 GuestViewInternalNatives.GetContentWindow(guestInfo.contentWindowId); | 207 this.contentWindow = |
208 GuestViewInternalNatives.GetContentWindow(guestInfo.contentWindowId); | |
209 } | |
195 | 210 |
196 // Check if creation failed. | 211 // Check if creation failed. |
197 if (this.id === 0) { | 212 if (this.id === 0) { |
198 this.state = GUEST_STATE_START; | 213 this.state = GUEST_STATE_START; |
199 this.contentWindow = null; | 214 this.contentWindow = null; |
200 } | 215 } |
201 | 216 |
202 ResizeEvent.addListener(this.callOnResize, {instanceId: this.id}); | 217 ResizeEvent.addListener(this.callOnResize, {instanceId: this.id}); |
203 this.handleCallback(callback); | 218 this.handleCallback(callback); |
204 }; | 219 }; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 this.handleCallback.bind(this, callback)); | 285 this.handleCallback.bind(this, callback)); |
271 }; | 286 }; |
272 | 287 |
273 // The exposed interface to a guestview. Exposes in its API the functions | 288 // The exposed interface to a guestview. Exposes in its API the functions |
274 // attach(), create(), destroy(), and getId(). All other implementation details | 289 // attach(), create(), destroy(), and getId(). All other implementation details |
275 // are hidden. | 290 // are hidden. |
276 function GuestView(viewType, guestInstanceId) { | 291 function GuestView(viewType, guestInstanceId) { |
277 privates(this).internal = new GuestViewImpl(this, viewType, guestInstanceId); | 292 privates(this).internal = new GuestViewImpl(this, viewType, guestInstanceId); |
278 } | 293 } |
279 | 294 |
295 GuestView.prototype.setBrowserPluginElement = function(browserPluginElement) { | |
296 this.browserPluginElement = browserPluginElement; | |
297 } | |
298 | |
280 // Attaches the guestview to the container with ID |internalInstanceId|. | 299 // Attaches the guestview to the container with ID |internalInstanceId|. |
281 GuestView.prototype.attach = function( | 300 GuestView.prototype.attach = function( |
282 internalInstanceId, viewInstanceId, attachParams, callback) { | 301 internalInstanceId, viewInstanceId, attachParams, callback) { |
283 var internal = privates(this).internal; | 302 var internal = privates(this).internal; |
284 internal.actionQueue.push(internal.attachImpl.bind( | 303 internal.actionQueue.push(internal.attachImpl.bind( |
285 internal, internalInstanceId, viewInstanceId, attachParams, callback)); | 304 internal, internalInstanceId, viewInstanceId, attachParams, callback)); |
286 internal.performNextAction(); | 305 internal.performNextAction(); |
287 }; | 306 }; |
288 | 307 |
289 // Creates the guestview. | 308 // Creates the guestview. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 }; | 344 }; |
326 | 345 |
327 // Returns the ID for this guestview. | 346 // Returns the ID for this guestview. |
328 GuestView.prototype.getId = function() { | 347 GuestView.prototype.getId = function() { |
329 var internal = privates(this).internal; | 348 var internal = privates(this).internal; |
330 return internal.id; | 349 return internal.id; |
331 }; | 350 }; |
332 | 351 |
333 // Exports | 352 // Exports |
334 exports.GuestView = GuestView; | 353 exports.GuestView = GuestView; |
OLD | NEW |