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 var DocumentNatives = requireNative('document_natives'); | 5 var DocumentNatives = requireNative('document_natives'); |
6 var GuestView = require('guestView').GuestView; | 6 var GuestView = require('guestView').GuestView; |
7 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; | 7 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; |
8 var IdGenerator = requireNative('id_generator'); | 8 var IdGenerator = requireNative('id_generator'); |
9 | 9 |
10 function AppViewImpl(appviewElement) { | 10 function AppViewImpl(appviewElement) { |
11 GuestViewContainer.call(this, appviewElement, 'appview'); | 11 GuestViewContainer.call(this, appviewElement, 'appview'); |
| 12 |
| 13 this.app = ''; |
| 14 this.data = ''; |
12 } | 15 } |
13 | 16 |
14 AppViewImpl.prototype.__proto__ = GuestViewContainer.prototype; | 17 AppViewImpl.prototype.__proto__ = GuestViewContainer.prototype; |
15 | 18 |
16 AppViewImpl.VIEW_TYPE = 'AppView'; | 19 AppViewImpl.VIEW_TYPE = 'AppView'; |
17 | 20 |
18 // Add extra functionality to |this.element|. | 21 // Add extra functionality to |this.element|. |
19 AppViewImpl.setupElement = function(proto) { | 22 AppViewImpl.setupElement = function(proto) { |
20 var apiMethods = [ | 23 var apiMethods = [ |
21 'connect' | 24 'connect' |
(...skipping 10 matching lines...) Expand all Loading... |
32 this.errorNode.style.position = 'absolute'; | 35 this.errorNode.style.position = 'absolute'; |
33 this.errorNode.style.left = '0px'; | 36 this.errorNode.style.left = '0px'; |
34 this.errorNode.style.top = '0px'; | 37 this.errorNode.style.top = '0px'; |
35 this.errorNode.style.width = '100%'; | 38 this.errorNode.style.width = '100%'; |
36 this.errorNode.style.height = '100%'; | 39 this.errorNode.style.height = '100%'; |
37 this.element.shadowRoot.appendChild(this.errorNode); | 40 this.element.shadowRoot.appendChild(this.errorNode); |
38 } | 41 } |
39 return this.errorNode; | 42 return this.errorNode; |
40 }; | 43 }; |
41 | 44 |
| 45 AppViewImpl.prototype.buildContainerParams = function() { |
| 46 return { |
| 47 'appId': this.app, |
| 48 'data': this.data || {} |
| 49 }; |
| 50 }; |
| 51 |
42 AppViewImpl.prototype.connect = function(app, data, callback) { | 52 AppViewImpl.prototype.connect = function(app, data, callback) { |
43 if (!this.elementAttached) { | 53 if (!this.elementAttached) { |
44 if (callback) { | 54 if (callback) { |
45 callback(false); | 55 callback(false); |
46 } | 56 } |
47 return; | 57 return; |
48 } | 58 } |
49 var createParams = { | 59 |
50 'appId': app, | 60 this.app = app; |
51 'data': data || {} | 61 this.data = data; |
52 }; | |
53 | 62 |
54 this.guest.destroy(); | 63 this.guest.destroy(); |
55 this.guest.create(createParams, function() { | 64 this.guest.create(this.buildParams(), function() { |
56 if (!this.guest.getId()) { | 65 if (!this.guest.getId()) { |
57 var errorMsg = 'Unable to connect to app "' + app + '".'; | 66 var errorMsg = 'Unable to connect to app "' + app + '".'; |
58 window.console.warn(errorMsg); | 67 window.console.warn(errorMsg); |
59 this.getErrorNode().innerText = errorMsg; | 68 this.getErrorNode().innerText = errorMsg; |
60 if (callback) { | 69 if (callback) { |
61 callback(false); | 70 callback(false); |
62 } | 71 } |
63 return; | 72 return; |
64 } | 73 } |
65 this.attachWindow(); | 74 this.attachWindow(); |
66 if (callback) { | 75 if (callback) { |
67 callback(true); | 76 callback(true); |
68 } | 77 } |
69 }.bind(this)); | 78 }.bind(this)); |
70 }; | 79 }; |
71 | 80 |
72 GuestViewContainer.registerElement(AppViewImpl); | 81 GuestViewContainer.registerElement(AppViewImpl); |
OLD | NEW |