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