| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 this.contentWindow = contentWindow; | 146 this.contentWindow = contentWindow; |
| 147 | 147 |
| 148 // Check if attaching failed. | 148 // Check if attaching failed. |
| 149 if (this.contentWindow === null) { | 149 if (this.contentWindow === null) { |
| 150 this.state = GUEST_STATE_CREATED; | 150 this.state = GUEST_STATE_CREATED; |
| 151 } else { | 151 } else { |
| 152 // Detach automatically when the container is destroyed. | 152 // Detach automatically when the container is destroyed. |
| 153 GuestViewInternalNatives.RegisterDestructionCallback(internalInstanceId, | 153 GuestViewInternalNatives.RegisterDestructionCallback(internalInstanceId, |
| 154 function() { | 154 function() { |
| 155 if (this.state == GUEST_STATE_ATTACHED) { | 155 if (this.state == GUEST_STATE_ATTACHED) { |
| 156 this.contentWindow = null; | |
| 157 this.internalInstanceId = 0; | 156 this.internalInstanceId = 0; |
| 158 this.state = GUEST_STATE_CREATED; | 157 this.state = GUEST_STATE_CREATED; |
| 159 } | 158 } |
| 160 }.bind(this)); | 159 }.bind(this)); |
| 161 } | 160 } |
| 162 | 161 |
| 163 this.handleCallback(callback); | 162 this.handleCallback(callback); |
| 164 }; | 163 }; |
| 165 | 164 |
| 166 attachParams['instanceId'] = viewInstanceId; | 165 attachParams['instanceId'] = viewInstanceId; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 177 GuestViewImpl.prototype.createImpl = function(createParams, callback) { | 176 GuestViewImpl.prototype.createImpl = function(createParams, callback) { |
| 178 // Check the current state. | 177 // Check the current state. |
| 179 if (!this.checkState('create')) { | 178 if (!this.checkState('create')) { |
| 180 this.handleCallback(callback); | 179 this.handleCallback(callback); |
| 181 return; | 180 return; |
| 182 } | 181 } |
| 183 | 182 |
| 184 // Callback wrapper function to store the guestInstanceId from the | 183 // Callback wrapper function to store the guestInstanceId from the |
| 185 // createGuest() callback, handle potential creation failure, and advance the | 184 // createGuest() callback, handle potential creation failure, and advance the |
| 186 // queue. | 185 // queue. |
| 187 var callbackWrapper = function(callback, guestInstanceId) { | 186 var callbackWrapper = function(callback, guestInfo) { |
| 188 this.id = guestInstanceId; | 187 this.id = guestInfo.id; |
| 188 this.contentWindow = |
| 189 GuestViewInternalNatives.GetContentWindow(guestInfo.contentWindowId); |
| 189 | 190 |
| 190 // Check if creation failed. | 191 // Check if creation failed. |
| 191 if (this.id === 0) { | 192 if (this.id === 0) { |
| 192 this.state = GUEST_STATE_START; | 193 this.state = GUEST_STATE_START; |
| 194 this.contentWindow = null; |
| 193 } | 195 } |
| 194 | 196 |
| 195 ResizeEvent.addListener(this.callOnResize, {instanceId: this.id}); | 197 ResizeEvent.addListener(this.callOnResize, {instanceId: this.id}); |
| 196 this.handleCallback(callback); | 198 this.handleCallback(callback); |
| 197 }; | 199 }; |
| 198 | 200 |
| 199 GuestViewInternal.createGuest(this.viewType, | 201 GuestViewInternal.createGuest(this.viewType, |
| 200 createParams, | 202 createParams, |
| 201 callbackWrapper.bind(this, callback)); | 203 callbackWrapper.bind(this, callback)); |
| 202 | 204 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // Check the current state. | 242 // Check the current state. |
| 241 if (!this.checkState('detach')) { | 243 if (!this.checkState('detach')) { |
| 242 this.handleCallback(callback); | 244 this.handleCallback(callback); |
| 243 return; | 245 return; |
| 244 } | 246 } |
| 245 | 247 |
| 246 GuestViewInternalNatives.DetachGuest( | 248 GuestViewInternalNatives.DetachGuest( |
| 247 this.internalInstanceId, | 249 this.internalInstanceId, |
| 248 this.handleCallback.bind(this, callback)); | 250 this.handleCallback.bind(this, callback)); |
| 249 | 251 |
| 250 this.contentWindow = null; | |
| 251 this.internalInstanceId = 0; | 252 this.internalInstanceId = 0; |
| 252 this.state = GUEST_STATE_CREATED; | 253 this.state = GUEST_STATE_CREATED; |
| 253 }; | 254 }; |
| 254 | 255 |
| 255 // Internal implementation of setSize(). | 256 // Internal implementation of setSize(). |
| 256 GuestViewImpl.prototype.setSizeImpl = function(sizeParams, callback) { | 257 GuestViewImpl.prototype.setSizeImpl = function(sizeParams, callback) { |
| 257 // Check the current state. | 258 // Check the current state. |
| 258 if (!this.checkState('setSize')) { | 259 if (!this.checkState('setSize')) { |
| 259 this.handleCallback(callback); | 260 this.handleCallback(callback); |
| 260 return; | 261 return; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 }; | 320 }; |
| 320 | 321 |
| 321 // Returns the ID for this guestview. | 322 // Returns the ID for this guestview. |
| 322 GuestView.prototype.getId = function() { | 323 GuestView.prototype.getId = function() { |
| 323 var internal = privates(this).internal; | 324 var internal = privates(this).internal; |
| 324 return internal.id; | 325 return internal.id; |
| 325 }; | 326 }; |
| 326 | 327 |
| 327 // Exports | 328 // Exports |
| 328 exports.GuestView = GuestView; | 329 exports.GuestView = GuestView; |
| OLD | NEW |