| 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 GuestViewInternal = | 8 var GuestViewInternal = |
| 9 require('binding').Binding.create('guestViewInternal').generate(); | 9 require('binding').Binding.create('guestViewInternal').generate(); |
| 10 var GuestViewInternalNatives = requireNative('guest_view_internal'); | 10 var GuestViewInternalNatives = requireNative('guest_view_internal'); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Map of possible errors for each action. For each action, the errors are | 75 // Map of possible errors for each action. For each action, the errors are |
| 76 // listed for states in the order: GUEST_STATE_START, GUEST_STATE_CREATED, | 76 // listed for states in the order: GUEST_STATE_START, GUEST_STATE_CREATED, |
| 77 // GUEST_STATE_ATTACHED. | 77 // GUEST_STATE_ATTACHED. |
| 78 var errors = { | 78 var errors = { |
| 79 'attach': [ERROR_MSG_NOT_CREATED, null, ERROR_MSG_ALREADY_ATTACHED], | 79 'attach': [ERROR_MSG_NOT_CREATED, null, ERROR_MSG_ALREADY_ATTACHED], |
| 80 'create': [null, ERROR_MSG_ALREADY_CREATED, ERROR_MSG_ALREADY_CREATED], | 80 'create': [null, ERROR_MSG_ALREADY_CREATED, ERROR_MSG_ALREADY_CREATED], |
| 81 'destroy': [null, null, null], | 81 'destroy': [null, null, null], |
| 82 'detach': [ERROR_MSG_NOT_ATTACHED, ERROR_MSG_NOT_ATTACHED, null], | 82 'detach': [ERROR_MSG_NOT_ATTACHED, ERROR_MSG_NOT_ATTACHED, null], |
| 83 'setAutoSize': [ERROR_MSG_NOT_CREATED, null, null] | 83 'setSize': [ERROR_MSG_NOT_CREATED, null, null] |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 // Check that the proposed action is a real action. | 86 // Check that the proposed action is a real action. |
| 87 if (errors[action] == undefined) { | 87 if (errors[action] == undefined) { |
| 88 window.console.error(errorPrefix + ERROR_MSG_INVALID_ACTION); | 88 window.console.error(errorPrefix + ERROR_MSG_INVALID_ACTION); |
| 89 return false; | 89 return false; |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Report the error if the proposed action is found to be invalid for the | 92 // Report the error if the proposed action is found to be invalid for the |
| 93 // current state. | 93 // current state. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 205 |
| 206 GuestViewInternalNatives.DetachGuest( | 206 GuestViewInternalNatives.DetachGuest( |
| 207 this.internalInstanceId, | 207 this.internalInstanceId, |
| 208 this.handleCallback.bind(this, callback)); | 208 this.handleCallback.bind(this, callback)); |
| 209 | 209 |
| 210 this.contentWindow = null; | 210 this.contentWindow = null; |
| 211 this.internalInstanceId = 0; | 211 this.internalInstanceId = 0; |
| 212 this.state = GUEST_STATE_CREATED; | 212 this.state = GUEST_STATE_CREATED; |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 // Internal implementation of setAutoSize(). | 215 // Internal implementation of setSize(). |
| 216 GuestViewImpl.prototype.setAutoSizeImpl = function(autoSizeParams, callback) { | 216 GuestViewImpl.prototype.setSizeImpl = function(sizeParams, callback) { |
| 217 // Check the current state. | 217 // Check the current state. |
| 218 if (!this.checkState('setAutoSize')) { | 218 if (!this.checkState('setSize')) { |
| 219 this.handleCallback(callback); | 219 this.handleCallback(callback); |
| 220 return; | 220 return; |
| 221 } | 221 } |
| 222 | 222 |
| 223 GuestViewInternal.setAutoSize(this.id, autoSizeParams, | 223 GuestViewInternal.setSize(this.id, sizeParams, |
| 224 this.handleCallback.bind(this, callback)); | 224 this.handleCallback.bind(this, callback)); |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 // The exposed interface to a guestview. Exposes in its API the functions | 227 // The exposed interface to a guestview. Exposes in its API the functions |
| 228 // attach(), create(), destroy(), and getId(). All other implementation details | 228 // attach(), create(), destroy(), and getId(). All other implementation details |
| 229 // are hidden. | 229 // are hidden. |
| 230 function GuestView(viewType, guestInstanceId) { | 230 function GuestView(viewType, guestInstanceId) { |
| 231 privates(this).internal = new GuestViewImpl(viewType, guestInstanceId); | 231 privates(this).internal = new GuestViewImpl(viewType, guestInstanceId); |
| 232 } | 232 } |
| 233 | 233 |
| 234 // Attaches the guestview to the container with ID |internalInstanceId|. | 234 // Attaches the guestview to the container with ID |internalInstanceId|. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 258 | 258 |
| 259 // Detaches the guestview from its container. | 259 // Detaches the guestview from its container. |
| 260 // Note: This is not currently used. | 260 // Note: This is not currently used. |
| 261 GuestView.prototype.detach = function(callback) { | 261 GuestView.prototype.detach = function(callback) { |
| 262 var internal = privates(this).internal; | 262 var internal = privates(this).internal; |
| 263 internal.actionQueue.push(internal.detachImpl.bind(internal, callback)); | 263 internal.actionQueue.push(internal.detachImpl.bind(internal, callback)); |
| 264 internal.performNextAction(); | 264 internal.performNextAction(); |
| 265 }; | 265 }; |
| 266 | 266 |
| 267 // Adjusts the guestview's sizing parameters. | 267 // Adjusts the guestview's sizing parameters. |
| 268 GuestView.prototype.setAutoSize = function(autoSizeParams, callback) { | 268 GuestView.prototype.setSize = function(sizeParams, callback) { |
| 269 var internal = privates(this).internal; | 269 var internal = privates(this).internal; |
| 270 internal.actionQueue.push(internal.setAutoSizeImpl.bind( | 270 internal.actionQueue.push(internal.setSizeImpl.bind( |
| 271 internal, autoSizeParams, callback)); | 271 internal, sizeParams, callback)); |
| 272 internal.performNextAction(); | 272 internal.performNextAction(); |
| 273 }; | 273 }; |
| 274 | 274 |
| 275 // Returns the contentWindow for this guestview. | 275 // Returns the contentWindow for this guestview. |
| 276 GuestView.prototype.getContentWindow = function() { | 276 GuestView.prototype.getContentWindow = function() { |
| 277 var internal = privates(this).internal; | 277 var internal = privates(this).internal; |
| 278 return internal.contentWindow; | 278 return internal.contentWindow; |
| 279 }; | 279 }; |
| 280 | 280 |
| 281 // Returns the ID for this guestview. | 281 // Returns the ID for this guestview. |
| 282 GuestView.prototype.getId = function() { | 282 GuestView.prototype.getId = function() { |
| 283 var internal = privates(this).internal; | 283 var internal = privates(this).internal; |
| 284 return internal.id; | 284 return internal.id; |
| 285 }; | 285 }; |
| 286 | 286 |
| 287 // Exports | 287 // Exports |
| 288 exports.GuestView = GuestView; | 288 exports.GuestView = GuestView; |
| OLD | NEW |