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 the SurfaceView prototype. | 5 // This module implements the SurfaceView prototype. |
6 | 6 |
7 var GuestView = require('guestView').GuestView; | 7 var GuestView = require('guestView').GuestView; |
8 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; | 8 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; |
9 | 9 |
10 function SurfaceViewImpl(surfaceviewElement) { | 10 function SurfaceViewImpl(surfaceviewElement) { |
11 GuestViewContainer.call(this, surfaceviewElement, 'surfaceview'); | 11 GuestViewContainer.call(this, surfaceviewElement, 'surfaceview'); |
12 } | 12 } |
13 | 13 |
14 SurfaceViewImpl.prototype.__proto__ = GuestViewContainer.prototype; | 14 SurfaceViewImpl.prototype.__proto__ = GuestViewContainer.prototype; |
15 | 15 |
16 SurfaceViewImpl.VIEW_TYPE = 'SurfaceView'; | 16 SurfaceViewImpl.VIEW_TYPE = 'SurfaceView'; |
17 | 17 |
18 // Add extra functionality to |this.element|. | 18 // Add extra functionality to |this.element|. |
19 SurfaceViewImpl.setupElement = function(proto) { | 19 SurfaceViewImpl.setupElement = function(proto) { |
20 var apiMethods = [ | 20 var apiMethods = [ |
21 'connect' | 21 'connect' |
22 ]; | 22 ]; |
23 | 23 |
24 // Forward proto.foo* method calls to SurfaceViewImpl.foo*. | 24 // Forward proto.foo* method calls to SurfaceViewImpl.foo*. |
25 GuestViewContainer.forwardApiMethods(proto, apiMethods); | 25 GuestViewContainer.forwardApiMethods(proto, apiMethods); |
26 } | 26 } |
27 | 27 |
| 28 SurfaceViewImpl.prototype.buildContainerParams = function() { |
| 29 return { 'url': this.url }; |
| 30 }; |
| 31 |
28 SurfaceViewImpl.prototype.connect = function(url, callback) { | 32 SurfaceViewImpl.prototype.connect = function(url, callback) { |
29 if (!this.elementAttached) { | 33 if (!this.elementAttached) { |
30 if (callback) { | 34 if (callback) { |
31 callback(false); | 35 callback(false); |
32 } | 36 } |
33 return; | 37 return; |
34 } | 38 } |
35 | 39 |
| 40 this.url = url; |
| 41 |
36 this.guest.destroy(); | 42 this.guest.destroy(); |
37 | 43 |
38 var createParams = { | 44 this.guest.create(this.buildParams(), function() { |
39 'url': url | |
40 }; | |
41 | |
42 this.guest.create(createParams, function() { | |
43 this.attachWindow(); | 45 this.attachWindow(); |
44 if (callback) { | 46 if (callback) { |
45 callback(true); | 47 callback(true); |
46 } | 48 } |
47 }.bind(this)); | 49 }.bind(this)); |
48 }; | 50 }; |
49 | 51 |
50 GuestViewContainer.registerElement(SurfaceViewImpl); | 52 GuestViewContainer.registerElement(SurfaceViewImpl); |
OLD | NEW |