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 // 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 EventBindings = require('event_bindings'); | 8 var EventBindings = require('event_bindings'); |
| 9 var GuestViewInternal = | 9 var GuestViewInternal = |
| 10 require('binding').Binding.create('guestViewInternal').generate(); | 10 require('binding').Binding.create('guestViewInternal').generate(); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 // Check the current state. | 139 // Check the current state. |
| 140 if (!this.checkState('attach')) { | 140 if (!this.checkState('attach')) { |
| 141 this.handleCallback(callback); | 141 this.handleCallback(callback); |
| 142 return; | 142 return; |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Callback wrapper function to store the contentWindow from the attachGuest() | 145 // Callback wrapper function to store the contentWindow from the attachGuest() |
| 146 // callback, handle potential attaching failure, register an automatic detach, | 146 // callback, handle potential attaching failure, register an automatic detach, |
| 147 // and advance the queue. | 147 // and advance the queue. |
| 148 var callbackWrapper = function(callback, contentWindow) { | 148 var callbackWrapper = function(callback, contentWindow) { |
| 149 this.contentWindow = contentWindow; | 149 this.contentWindow = contentWindow; |
|
lfg
2015/03/04 19:10:20
Since the contentWindow is already assigned in cre
Fady Samuel
2015/03/05 20:56:23
No, not all GuestView types get a contentWindow on
| |
| 150 | 150 |
| 151 // Check if attaching failed. | 151 // Check if attaching failed. |
| 152 if (this.contentWindow === null) { | 152 if (this.contentWindow === null) { |
| 153 this.state = GUEST_STATE_CREATED; | 153 this.state = GUEST_STATE_CREATED; |
| 154 } else { | 154 } else { |
| 155 // Detach automatically when the container is destroyed. | 155 // Detach automatically when the container is destroyed. |
| 156 GuestViewInternalNatives.RegisterDestructionCallback(internalInstanceId, | 156 GuestViewInternalNatives.RegisterDestructionCallback(internalInstanceId, |
| 157 function() { | 157 function() { |
| 158 if (this.state == GUEST_STATE_ATTACHED) { | 158 if (this.state == GUEST_STATE_ATTACHED) { |
| 159 this.contentWindow = null; | |
| 160 this.internalInstanceId = 0; | 159 this.internalInstanceId = 0; |
| 161 this.state = GUEST_STATE_CREATED; | 160 this.state = GUEST_STATE_CREATED; |
| 162 } | 161 } |
| 163 }.bind(this)); | 162 }.bind(this)); |
| 164 } | 163 } |
| 165 | 164 |
| 166 this.handleCallback(callback); | 165 this.handleCallback(callback); |
| 167 }; | 166 }; |
| 168 | 167 |
| 169 attachParams['instanceId'] = viewInstanceId; | 168 attachParams['instanceId'] = viewInstanceId; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 180 GuestViewImpl.prototype.createImpl = function(createParams, callback) { | 179 GuestViewImpl.prototype.createImpl = function(createParams, callback) { |
| 181 // Check the current state. | 180 // Check the current state. |
| 182 if (!this.checkState('create')) { | 181 if (!this.checkState('create')) { |
| 183 this.handleCallback(callback); | 182 this.handleCallback(callback); |
| 184 return; | 183 return; |
| 185 } | 184 } |
| 186 | 185 |
| 187 // Callback wrapper function to store the guestInstanceId from the | 186 // Callback wrapper function to store the guestInstanceId from the |
| 188 // createGuest() callback, handle potential creation failure, and advance the | 187 // createGuest() callback, handle potential creation failure, and advance the |
| 189 // queue. | 188 // queue. |
| 190 var callbackWrapper = function(callback, guestInstanceId) { | 189 var callbackWrapper = function(callback, guestInfo) { |
| 191 this.id = guestInstanceId; | 190 this.id = guestInfo.id; |
| 191 this.contentWindow = | |
| 192 GuestViewInternalNatives.GetContentWindow(guestInfo.contentWindowId); | |
|
lfg
2015/03/04 19:10:20
This is ok, but I think it would it be nicer to pa
Fady Samuel
2015/03/05 20:56:23
I'll do that in a separate patch. I don't want to
| |
| 192 | 193 |
| 193 // Check if creation failed. | 194 // Check if creation failed. |
| 194 if (this.id === 0) { | 195 if (this.id === 0) { |
| 195 this.state = GUEST_STATE_START; | 196 this.state = GUEST_STATE_START; |
| 197 this.contentWindow = null; | |
| 196 } | 198 } |
| 197 | 199 |
| 198 ResizeEvent.addListener(this.callOnResize, {instanceId: this.id}); | 200 ResizeEvent.addListener(this.callOnResize, {instanceId: this.id}); |
| 199 this.handleCallback(callback); | 201 this.handleCallback(callback); |
| 200 }; | 202 }; |
| 201 | 203 |
| 202 GuestViewInternal.createGuest(this.viewType, | 204 GuestViewInternal.createGuest(this.viewType, |
| 203 createParams, | 205 createParams, |
| 204 callbackWrapper.bind(this, callback)); | 206 callbackWrapper.bind(this, callback)); |
| 205 | 207 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 // Check the current state. | 245 // Check the current state. |
| 244 if (!this.checkState('detach')) { | 246 if (!this.checkState('detach')) { |
| 245 this.handleCallback(callback); | 247 this.handleCallback(callback); |
| 246 return; | 248 return; |
| 247 } | 249 } |
| 248 | 250 |
| 249 GuestViewInternalNatives.DetachGuest( | 251 GuestViewInternalNatives.DetachGuest( |
| 250 this.internalInstanceId, | 252 this.internalInstanceId, |
| 251 this.handleCallback.bind(this, callback)); | 253 this.handleCallback.bind(this, callback)); |
| 252 | 254 |
| 253 this.contentWindow = null; | |
| 254 this.internalInstanceId = 0; | 255 this.internalInstanceId = 0; |
| 255 this.state = GUEST_STATE_CREATED; | 256 this.state = GUEST_STATE_CREATED; |
| 256 }; | 257 }; |
| 257 | 258 |
| 258 // Internal implementation of setSize(). | 259 // Internal implementation of setSize(). |
| 259 GuestViewImpl.prototype.setSizeImpl = function(sizeParams, callback) { | 260 GuestViewImpl.prototype.setSizeImpl = function(sizeParams, callback) { |
| 260 // Check the current state. | 261 // Check the current state. |
| 261 if (!this.checkState('setSize')) { | 262 if (!this.checkState('setSize')) { |
| 262 this.handleCallback(callback); | 263 this.handleCallback(callback); |
| 263 return; | 264 return; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 }; | 323 }; |
| 323 | 324 |
| 324 // Returns the ID for this guestview. | 325 // Returns the ID for this guestview. |
| 325 GuestView.prototype.getId = function() { | 326 GuestView.prototype.getId = function() { |
| 326 var internal = privates(this).internal; | 327 var internal = privates(this).internal; |
| 327 return internal.id; | 328 return internal.id; |
| 328 }; | 329 }; |
| 329 | 330 |
| 330 // Exports | 331 // Exports |
| 331 exports.GuestView = GuestView; | 332 exports.GuestView = GuestView; |
| OLD | NEW |