OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 var DocumentNatives = requireNative('document_natives'); | |
6 var GuestViewInternal = | |
7 require('binding').Binding.create('guestViewInternal').generate(); | |
8 var IdGenerator = requireNative('id_generator'); | |
9 | |
10 /** | |
11 * @constructor | |
12 */ | |
13 function AppViewInternal(appviewNode) { | |
14 privates(appviewNode).internal = this; | |
15 this.appviewNode = appviewNode; | |
16 | |
17 this.browserPluginNode = this.createBrowserPluginNode(); | |
18 var shadowRoot = this.appviewNode.createShadowRoot(); | |
19 shadowRoot.appendChild(this.browserPluginNode); | |
20 this.viewInstanceId = IdGenerator.GetNextId(); | |
21 } | |
22 | |
23 /** | |
24 * @private | |
lazyboy
2014/06/27 04:14:02
Let's not add @private annotations, I'm trying to
Fady Samuel
2014/06/27 16:11:00
Done.
| |
25 */ | |
26 AppViewInternal.prototype.createBrowserPluginNode = function() { | |
27 // We create BrowserPlugin as a custom element in order to observe changes | |
28 // to attributes synchronously. | |
29 var browserPluginNode = new AppViewInternal.BrowserPlugin(); | |
30 privates(browserPluginNode).internal = this; | |
31 return browserPluginNode; | |
32 }; | |
33 | |
34 /** | |
35 * @private | |
36 */ | |
37 AppViewInternal.prototype.connect = function(src, callback) { | |
38 var params = { | |
39 }; | |
40 var self = this; | |
41 GuestViewInternal.createGuest( | |
42 'appview', | |
43 params, | |
44 function(instanceId) { | |
45 self.attachWindow(instanceId, src); | |
46 if (callback) { | |
47 callback(); | |
48 } | |
49 } | |
50 ); | |
51 }; | |
52 | |
53 /** @private */ | |
54 AppViewInternal.prototype.attachWindow = function(instanceId, src) { | |
55 this.instanceId = instanceId; | |
56 var params = { | |
57 'instanceId': this.viewInstanceId, | |
58 'src': src | |
59 }; | |
60 return this.browserPluginNode['-internal-attach'](instanceId, params); | |
61 }; | |
62 | |
63 // Registers browser plugin <object> custom element. | |
64 function registerBrowserPluginElement() { | |
65 var proto = Object.create(HTMLObjectElement.prototype); | |
66 | |
67 proto.createdCallback = function() { | |
68 this.setAttribute('type', 'application/browser-plugin'); | |
69 this.style.width = '100%'; | |
70 this.style.height = '100%'; | |
71 }; | |
72 | |
73 proto.attachedCallback = function() { | |
74 // Load the plugin immediately. | |
75 var unused = this.nonExistentAttribute; | |
76 }; | |
77 | |
78 AppViewInternal.BrowserPlugin = | |
79 DocumentNatives.RegisterElement('app-plugin', {extends: 'object', | |
80 prototype: proto}); | |
81 | |
82 delete proto.createdCallback; | |
83 delete proto.attachedCallback; | |
84 delete proto.detachedCallback; | |
85 delete proto.attributeChangedCallback; | |
86 } | |
87 | |
88 // Registers <appview> custom element. | |
89 function registerAppViewElement() { | |
90 var proto = Object.create(HTMLElement.prototype); | |
91 | |
92 proto.createdCallback = function() { | |
93 new AppViewInternal(this); | |
94 }; | |
95 | |
96 proto.connect = function() { | |
97 var internal = privates(this).internal; | |
98 $Function.apply(internal.connect, internal, arguments); | |
99 } | |
100 window.AppView = | |
101 DocumentNatives.RegisterElement('appview', {prototype: proto}); | |
102 | |
103 // Delete the callbacks so developers cannot call them and produce unexpected | |
104 // behavior. | |
105 delete proto.createdCallback; | |
106 delete proto.attachedCallback; | |
107 delete proto.detachedCallback; | |
108 delete proto.attributeChangedCallback; | |
109 } | |
110 | |
111 var useCapture = true; | |
112 window.addEventListener('readystatechange', function listener(event) { | |
113 if (document.readyState == 'loading') | |
114 return; | |
115 | |
116 registerBrowserPluginElement(); | |
117 registerAppViewElement(); | |
118 window.removeEventListener(event.type, listener, useCapture); | |
119 }, useCapture); | |
OLD | NEW |