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 GuestViewInternal = | 6 var GuestViewInternal = |
7 require('binding').Binding.create('guestViewInternal').generate(); | 7 require('binding').Binding.create('guestViewInternal').generate(); |
8 var IdGenerator = requireNative('id_generator'); | 8 var IdGenerator = requireNative('id_generator'); |
9 | 9 |
10 function AppViewInternal(appviewNode) { | 10 function AppViewInternal(appviewNode) { |
11 privates(appviewNode).internal = this; | 11 privates(appviewNode).internal = this; |
12 this.appviewNode = appviewNode; | 12 this.appviewNode = appviewNode; |
13 | 13 |
14 this.browserPluginNode = this.createBrowserPluginNode(); | 14 this.browserPluginNode = this.createBrowserPluginNode(); |
15 var shadowRoot = this.appviewNode.createShadowRoot(); | 15 this.shadowRoot = this.appviewNode.createShadowRoot(); |
lazyboy
2014/07/08 18:24:34
It isn't necessary to store the reference, this ca
Fady Samuel
2014/07/08 20:23:46
Done.
| |
16 shadowRoot.appendChild(this.browserPluginNode); | 16 this.shadowRoot.appendChild(this.browserPluginNode); |
17 this.viewInstanceId = IdGenerator.GetNextId(); | 17 this.viewInstanceId = IdGenerator.GetNextId(); |
18 } | 18 } |
19 | 19 |
20 AppViewInternal.prototype.getErrorNode = function() { | |
21 if (!this.errorNode) { | |
22 this.errorNode = document.createElement('div'); | |
23 this.errorNode.innerText = 'Unable to connect to app.'; | |
24 this.errorNode.style.display = 'absolute'; | |
25 this.errorNode.style.left = '0px'; | |
26 this.errorNode.style.top = '0px'; | |
27 this.errorNode.style.width = '100%'; | |
28 this.errorNode.style.height = '100%'; | |
29 this.shadowRoot.appendChild(this.errorNode); | |
30 } | |
31 return this.errorNode; | |
32 }; | |
33 | |
20 AppViewInternal.prototype.createBrowserPluginNode = function() { | 34 AppViewInternal.prototype.createBrowserPluginNode = function() { |
21 // We create BrowserPlugin as a custom element in order to observe changes | 35 // We create BrowserPlugin as a custom element in order to observe changes |
22 // to attributes synchronously. | 36 // to attributes synchronously. |
23 var browserPluginNode = new AppViewInternal.BrowserPlugin(); | 37 var browserPluginNode = new AppViewInternal.BrowserPlugin(); |
24 privates(browserPluginNode).internal = this; | 38 privates(browserPluginNode).internal = this; |
25 return browserPluginNode; | 39 return browserPluginNode; |
26 }; | 40 }; |
27 | 41 |
28 AppViewInternal.prototype.connect = function(src, callback) { | 42 AppViewInternal.prototype.connect = function(app, callback) { |
29 var params = { | 43 var params = { |
44 'appId': app | |
30 }; | 45 }; |
31 var self = this; | 46 var self = this; |
32 GuestViewInternal.createGuest( | 47 GuestViewInternal.createGuest( |
33 'appview', | 48 'appview', |
34 params, | 49 params, |
35 function(instanceId) { | 50 function(instanceId) { |
36 self.attachWindow(instanceId, src); | 51 if (!instanceId) { |
52 self.browserPluginNode.style.visibility = 'hidden'; | |
53 var errorMsg = 'Unable to connect to app "' + app + '".'; | |
54 window.console.warn(errorMsg); | |
55 self.getErrorNode().innerText = errorMsg; | |
56 if (callback) { | |
57 callback(false); | |
58 } | |
59 return; | |
60 } | |
61 self.attachWindow(instanceId); | |
37 if (callback) { | 62 if (callback) { |
38 callback(); | 63 callback(true); |
39 } | 64 } |
40 } | 65 } |
41 ); | 66 ); |
42 }; | 67 }; |
43 | 68 |
44 AppViewInternal.prototype.attachWindow = function(instanceId, src) { | 69 AppViewInternal.prototype.attachWindow = function(instanceId) { |
45 this.instanceId = instanceId; | 70 this.instanceId = instanceId; |
46 var params = { | 71 var params = { |
47 'instanceId': this.viewInstanceId, | 72 'instanceId': this.viewInstanceId, |
48 'src': src | |
49 }; | 73 }; |
74 this.browserPluginNode.style.visibility = 'visible'; | |
50 return this.browserPluginNode['-internal-attach'](instanceId, params); | 75 return this.browserPluginNode['-internal-attach'](instanceId, params); |
51 }; | 76 }; |
52 | 77 |
53 function registerBrowserPluginElement() { | 78 function registerBrowserPluginElement() { |
54 var proto = Object.create(HTMLObjectElement.prototype); | 79 var proto = Object.create(HTMLObjectElement.prototype); |
55 | 80 |
56 proto.createdCallback = function() { | 81 proto.createdCallback = function() { |
57 this.setAttribute('type', 'application/browser-plugin'); | 82 this.setAttribute('type', 'application/browser-plugin'); |
58 this.style.width = '100%'; | 83 this.style.width = '100%'; |
59 this.style.height = '100%'; | 84 this.style.height = '100%'; |
85 this.style.position = 'absolute'; | |
lazyboy
2014/07/08 18:24:33
Both the original plugin node and error node shoul
Fady Samuel
2014/07/08 20:23:46
Done.
| |
86 this.style.left = '0px'; | |
87 this.style.top = '0px'; | |
60 }; | 88 }; |
61 | 89 |
62 proto.attachedCallback = function() { | 90 proto.attachedCallback = function() { |
63 // Load the plugin immediately. | 91 // Load the plugin immediately. |
64 var unused = this.nonExistentAttribute; | 92 var unused = this.nonExistentAttribute; |
65 }; | 93 }; |
66 | 94 |
67 AppViewInternal.BrowserPlugin = | 95 AppViewInternal.BrowserPlugin = |
68 DocumentNatives.RegisterElement('appplugin', {extends: 'object', | 96 DocumentNatives.RegisterElement('appplugin', {extends: 'object', |
69 prototype: proto}); | 97 prototype: proto}); |
(...skipping 28 matching lines...) Expand all Loading... | |
98 | 126 |
99 var useCapture = true; | 127 var useCapture = true; |
100 window.addEventListener('readystatechange', function listener(event) { | 128 window.addEventListener('readystatechange', function listener(event) { |
101 if (document.readyState == 'loading') | 129 if (document.readyState == 'loading') |
102 return; | 130 return; |
103 | 131 |
104 registerBrowserPluginElement(); | 132 registerBrowserPluginElement(); |
105 registerAppViewElement(); | 133 registerAppViewElement(); |
106 window.removeEventListener(event.type, listener, useCapture); | 134 window.removeEventListener(event.type, listener, useCapture); |
107 }, useCapture); | 135 }, useCapture); |
OLD | NEW |