OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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 function ExtensionOptionsInternal(extensionoptionsNode) { | |
11 privates(extensionoptionsNode).internal = this; | |
12 this.extensionoptionsNode = extensionoptionsNode; | |
13 | |
14 this.browserPluginNode = this.createBrowserPluginNode(); | |
15 var shadowRoot = this.extensionoptionsNode.createShadowRoot(); | |
16 shadowRoot.appendChild(this.browserPluginNode); | |
17 this.viewInstanceId = IdGenerator.GetNextId(); | |
18 | |
19 if (parseExtensionAttribute()) { | |
20 this.allocateInstanceId(); | |
21 } | |
22 } | |
23 | |
24 ExtensionOptionsInternal.prototype.createBrowserPluginNode = function() { | |
25 var browserPluginNode = new ExtensionOptionsInternal.BrowserPlugin(); | |
26 privates(browserPluginNode).internal = this; | |
27 return browserPluginNode; | |
28 } | |
29 | |
30 ExtensionOptionsInternal.prototype.parseExtensionAttribute = function() { | |
31 if (this.extensionoptionsNode.hasAttribute('extension')) { | |
32 this.extension = this.extensionoptionsNode.getAttribute('extension'); | |
33 return true; | |
34 } | |
35 return false; | |
36 } | |
37 | |
38 ExtensionOptionsInternal.prototype.allocateInstanceId = function() { | |
39 var params = { | |
40 'extensionId': this.extension, | |
41 }; | |
42 var self = this; | |
43 GuestViewInternal.createGuest( | |
44 'extensionoptions', | |
45 params, | |
46 function(instanceId) { | |
47 self.instanceId = instanceId; | |
48 // TODO(lazyboy): Make sure this.autoNavigate_ stuff correctly updated | |
49 // |self.src| at this point. | |
50 self.attachWindowAndSetUpEvents(self.instanceId, self.src); | |
Fady Samuel
2014/07/08 14:23:40
This code doesn't do anything...
ericzeng
2014/07/08 18:10:48
Oops, done
| |
51 }); | |
not at google - send to devlin
2014/07/08 19:17:25
FYI a nice pattern (perhaps appview doesn't do thi
| |
52 }; | |
53 | |
54 function registerBrowserPluginElement() { | |
55 var proto = Object.create(HTMLObjectElement.prototype); | |
56 | |
57 proto.createdCallback = function() { | |
58 this.setAttribute('type', 'application/browser-plugin'); | |
59 this.style.width = '100%'; | |
60 this.style.height = '100%'; | |
61 }; | |
62 | |
63 proto.attachedCallback = function() { | |
64 // Load the plugin immediately. | |
65 var unused = this.nonExistentAttribute; | |
66 }; | |
67 | |
68 ExtensionOptionsInternal.BrowserPlugin = | |
69 DocumentNatives.RegisterElement("extensionoptionsplugin", | |
70 {extends: 'object', prototype: proto}); | |
71 delete proto.createdCallback; | |
72 delete proto.attachedCallback; | |
73 } | |
74 | |
75 function registerExtensionOptionsElement() { | |
76 var proto = Object.create(HTMLElement.prototype); | |
77 | |
78 proto.createdCallback = function() { | |
79 new ExtensionOptionsInternal(this); | |
80 } | |
81 | |
82 // Forward proto.foo* method calls to ExtensionOptionsInternal.foo*. | |
83 for (var i = 0; methods[i]; ++i) { | |
84 var createHandler = function(m) { | |
85 return function(var_args) { | |
86 var internal = privates(this).internal; | |
87 return $Function.apply(internal[m], internal, arguments); | |
88 }; | |
89 }; | |
90 proto[methods[i]] = createHandler(methods[i]); | |
91 } | |
92 | |
93 window.ExtensionOptions = | |
94 DocumentNatives.RegisterElement('extensionoptions', {prototype: proto}); | |
95 | |
96 // Delete the callbacks so developers cannot call them and produce unexpected | |
97 // behavior. | |
98 delete proto.createdCallback; | |
99 } | |
100 | |
101 var useCapture = true; | |
102 window.addEventListener('readystatechange', function listener(event) { | |
103 if (document.readyState == 'loading') | |
104 return; | |
105 | |
106 registerBrowserPluginElement(); | |
107 registerExtensionOptionsElement(); | |
108 window.removeEventListener(event.type, listener, useCapture); | |
109 }, useCapture); | |
OLD | NEW |