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 }); | |
49 }; | |
50 | |
51 function registerBrowserPluginElement() { | |
not at google - send to devlin
2014/07/08 19:17:25
fady is there some reuse we can do with appview, p
Fady Samuel
2014/07/08 19:23:57
Perhaps. It's not yet clear how much code reuse th
| |
52 var proto = Object.create(HTMLObjectElement.prototype); | |
53 | |
54 proto.createdCallback = function() { | |
55 this.setAttribute('type', 'application/browser-plugin'); | |
56 this.style.width = '100%'; | |
57 this.style.height = '100%'; | |
58 }; | |
59 | |
60 proto.attachedCallback = function() { | |
61 // Load the plugin immediately. | |
62 var unused = this.nonExistentAttribute; | |
not at google - send to devlin
2014/07/08 19:17:25
how does this imply loading the plugin automatical
Fady Samuel
2014/07/08 19:23:57
I don't actually know. This was added by Dominic C
| |
63 }; | |
64 | |
65 ExtensionOptionsInternal.BrowserPlugin = | |
not at google - send to devlin
2014/07/08 19:17:25
why do you need to assign this?
Fady Samuel
2014/07/08 19:23:57
So we can easily create this type of BrowserPlugin
not at google - send to devlin
2014/07/08 19:41:16
I see. yeah that would be better, or we can just s
| |
66 DocumentNatives.RegisterElement("extensionoptionsplugin", | |
67 {extends: 'object', prototype: proto}); | |
68 delete proto.createdCallback; | |
69 delete proto.attachedCallback; | |
70 } | |
71 | |
72 function registerExtensionOptionsElement() { | |
73 var proto = Object.create(HTMLElement.prototype); | |
74 | |
75 proto.createdCallback = function() { | |
76 new ExtensionOptionsInternal(this); | |
77 } | |
not at google - send to devlin
2014/07/08 19:41:16
semicolon
| |
78 | |
79 // Forward proto.foo* method calls to ExtensionOptionsInternal.foo*. | |
80 for (var i = 0; methods[i]; ++i) { | |
not at google - send to devlin
2014/07/08 19:41:16
where is |methods| defined?
Fady Samuel
2014/07/10 15:32:48
This code doesn't apply yet. Delete this entire bl
| |
81 var createHandler = function(m) { | |
82 return function(var_args) { | |
83 var internal = privates(this).internal; | |
not at google - send to devlin
2014/07/08 19:41:16
I'd rather we be explicit rather than using "inter
| |
84 return $Function.apply(internal[m], internal, arguments); | |
85 }; | |
86 }; | |
87 proto[methods[i]] = createHandler(methods[i]); | |
88 } | |
89 | |
90 window.ExtensionOptions = | |
91 DocumentNatives.RegisterElement('extensionoptions', {prototype: proto}); | |
not at google - send to devlin
2014/07/08 19:17:25
why do you need to assign this to window?
Fady Samuel
2014/07/08 19:23:57
This permits the following:
var eo = new Extensio
not at google - send to devlin
2014/07/08 19:41:16
ah right. can you do the same thing with document.
Fady Samuel
2014/07/10 15:32:48
document.createElement also works.
| |
92 | |
93 // Delete the callbacks so developers cannot call them and produce unexpected | |
94 // behavior. | |
not at google - send to devlin
2014/07/08 19:17:25
is this standard custom element practice?
Fady Samuel
2014/07/08 19:23:57
Yes, we should delete all callbacks. See web_view.
| |
95 delete proto.createdCallback; | |
96 } | |
97 | |
98 var useCapture = true; | |
99 window.addEventListener('readystatechange', function listener(event) { | |
100 if (document.readyState == 'loading') | |
101 return; | |
102 | |
103 registerBrowserPluginElement(); | |
104 registerExtensionOptionsElement(); | |
105 window.removeEventListener(event.type, listener, useCapture); | |
106 }, useCapture); | |
OLD | NEW |