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 var guestViewInternalNatives = requireNative('guest_view_internal'); |
9 | 10 |
10 function AppViewInternal(appviewNode) { | 11 function AppViewInternal(appviewNode) { |
11 privates(appviewNode).internal = this; | 12 privates(appviewNode).internal = this; |
12 this.appviewNode = appviewNode; | 13 this.appviewNode = appviewNode; |
13 | 14 |
14 this.browserPluginNode = this.createBrowserPluginNode(); | 15 this.browserPluginNode = this.createBrowserPluginNode(); |
15 var shadowRoot = this.appviewNode.createShadowRoot(); | 16 var shadowRoot = this.appviewNode.createShadowRoot(); |
16 shadowRoot.appendChild(this.browserPluginNode); | 17 shadowRoot.appendChild(this.browserPluginNode); |
17 this.viewInstanceId = IdGenerator.GetNextId(); | 18 this.viewInstanceId = IdGenerator.GetNextId(); |
18 } | 19 } |
(...skipping 21 matching lines...) Expand all Loading... |
40 }; | 41 }; |
41 | 42 |
42 AppViewInternal.prototype.connect = function(app, callback) { | 43 AppViewInternal.prototype.connect = function(app, callback) { |
43 var params = { | 44 var params = { |
44 'appId': app | 45 'appId': app |
45 }; | 46 }; |
46 var self = this; | 47 var self = this; |
47 GuestViewInternal.createGuest( | 48 GuestViewInternal.createGuest( |
48 'appview', | 49 'appview', |
49 params, | 50 params, |
50 function(instanceId) { | 51 function(guestInstanceId) { |
51 if (!instanceId) { | 52 if (!guestInstanceId) { |
52 self.browserPluginNode.style.visibility = 'hidden'; | 53 this.browserPluginNode.style.visibility = 'hidden'; |
53 var errorMsg = 'Unable to connect to app "' + app + '".'; | 54 var errorMsg = 'Unable to connect to app "' + app + '".'; |
54 window.console.warn(errorMsg); | 55 window.console.warn(errorMsg); |
55 self.getErrorNode().innerText = errorMsg; | 56 this.getErrorNode().innerText = errorMsg; |
56 if (callback) { | 57 if (callback) { |
57 callback(false); | 58 callback(false); |
58 } | 59 } |
59 return; | 60 return; |
60 } | 61 } |
61 self.attachWindow(instanceId); | 62 this.attachWindow(guestInstanceId); |
62 if (callback) { | 63 if (callback) { |
63 callback(true); | 64 callback(true); |
64 } | 65 } |
65 } | 66 }.bind(this) |
66 ); | 67 ); |
67 }; | 68 }; |
68 | 69 |
69 AppViewInternal.prototype.attachWindow = function(instanceId) { | 70 AppViewInternal.prototype.attachWindow = function(guestInstanceId) { |
70 this.instanceId = instanceId; | 71 this.guestInstanceId = guestInstanceId; |
71 var params = { | 72 var params = { |
72 'instanceId': this.viewInstanceId, | 73 'instanceId': this.viewInstanceId, |
73 }; | 74 }; |
74 this.browserPluginNode.style.visibility = 'visible'; | 75 this.browserPluginNode.style.visibility = 'visible'; |
75 return this.browserPluginNode['-internal-attach'](instanceId, params); | 76 return guestViewInternalNatives.AttachGuest( |
| 77 parseInt(this.browserPluginNode.getAttribute('internalinstanceid')), |
| 78 guestInstanceId, |
| 79 params); |
76 }; | 80 }; |
77 | 81 |
78 function registerBrowserPluginElement() { | 82 function registerBrowserPluginElement() { |
79 var proto = Object.create(HTMLObjectElement.prototype); | 83 var proto = Object.create(HTMLObjectElement.prototype); |
80 | 84 |
81 proto.createdCallback = function() { | 85 proto.createdCallback = function() { |
82 this.setAttribute('type', 'application/browser-plugin'); | 86 this.setAttribute('type', 'application/browser-plugin'); |
83 this.style.width = '100%'; | 87 this.style.width = '100%'; |
84 this.style.height = '100%'; | 88 this.style.height = '100%'; |
85 }; | 89 }; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 127 |
124 var useCapture = true; | 128 var useCapture = true; |
125 window.addEventListener('readystatechange', function listener(event) { | 129 window.addEventListener('readystatechange', function listener(event) { |
126 if (document.readyState == 'loading') | 130 if (document.readyState == 'loading') |
127 return; | 131 return; |
128 | 132 |
129 registerBrowserPluginElement(); | 133 registerBrowserPluginElement(); |
130 registerAppViewElement(); | 134 registerAppViewElement(); |
131 window.removeEventListener(event.type, listener, useCapture); | 135 window.removeEventListener(event.type, listener, useCapture); |
132 }, useCapture); | 136 }, useCapture); |
OLD | NEW |