Chromium Code Reviews| Index: chrome/renderer/resources/extensions/extension_options.js |
| diff --git a/chrome/renderer/resources/extensions/extension_options.js b/chrome/renderer/resources/extensions/extension_options.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..95cb8d6154da5a5e18a161ccee284a1bb89e06b8 |
| --- /dev/null |
| +++ b/chrome/renderer/resources/extensions/extension_options.js |
| @@ -0,0 +1,106 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +var DocumentNatives = requireNative('document_natives'); |
| +var GuestViewInternal = |
| + require('binding').Binding.create('guestViewInternal').generate(); |
| +var IdGenerator = requireNative('id_generator'); |
| + |
| +function ExtensionOptionsInternal(extensionoptionsNode) { |
| + privates(extensionoptionsNode).internal = this; |
| + this.extensionoptionsNode = extensionoptionsNode; |
| + |
| + this.browserPluginNode = this.createBrowserPluginNode(); |
| + var shadowRoot = this.extensionoptionsNode.createShadowRoot(); |
| + shadowRoot.appendChild(this.browserPluginNode); |
| + this.viewInstanceId = IdGenerator.GetNextId(); |
| + |
| + if (parseExtensionAttribute()) { |
| + this.allocateInstanceId(); |
| + } |
| +} |
| + |
| +ExtensionOptionsInternal.prototype.createBrowserPluginNode = function() { |
| + var browserPluginNode = new ExtensionOptionsInternal.BrowserPlugin(); |
| + privates(browserPluginNode).internal = this; |
| + return browserPluginNode; |
| +} |
| + |
| +ExtensionOptionsInternal.prototype.parseExtensionAttribute = function() { |
| + if (this.extensionoptionsNode.hasAttribute('extension')) { |
| + this.extension = this.extensionoptionsNode.getAttribute('extension'); |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +ExtensionOptionsInternal.prototype.allocateInstanceId = function() { |
| + var params = { |
| + 'extensionId': this.extension, |
| + }; |
| + var self = this; |
| + GuestViewInternal.createGuest( |
| + 'extensionoptions', |
| + params, |
| + function(instanceId) { |
| + self.instanceId = instanceId; |
| + }); |
| +}; |
| + |
| +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
|
| + var proto = Object.create(HTMLObjectElement.prototype); |
| + |
| + proto.createdCallback = function() { |
| + this.setAttribute('type', 'application/browser-plugin'); |
| + this.style.width = '100%'; |
| + this.style.height = '100%'; |
| + }; |
| + |
| + proto.attachedCallback = function() { |
| + // Load the plugin immediately. |
| + 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
|
| + }; |
| + |
| + 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
|
| + DocumentNatives.RegisterElement("extensionoptionsplugin", |
| + {extends: 'object', prototype: proto}); |
| + delete proto.createdCallback; |
| + delete proto.attachedCallback; |
| +} |
| + |
| +function registerExtensionOptionsElement() { |
| + var proto = Object.create(HTMLElement.prototype); |
| + |
| + proto.createdCallback = function() { |
| + new ExtensionOptionsInternal(this); |
| + } |
|
not at google - send to devlin
2014/07/08 19:41:16
semicolon
|
| + |
| + // Forward proto.foo* method calls to ExtensionOptionsInternal.foo*. |
| + 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
|
| + var createHandler = function(m) { |
| + return function(var_args) { |
| + 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
|
| + return $Function.apply(internal[m], internal, arguments); |
| + }; |
| + }; |
| + proto[methods[i]] = createHandler(methods[i]); |
| + } |
| + |
| + window.ExtensionOptions = |
| + 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.
|
| + |
| + // Delete the callbacks so developers cannot call them and produce unexpected |
| + // 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.
|
| + delete proto.createdCallback; |
| +} |
| + |
| +var useCapture = true; |
| +window.addEventListener('readystatechange', function listener(event) { |
| + if (document.readyState == 'loading') |
| + return; |
| + |
| + registerBrowserPluginElement(); |
| + registerExtensionOptionsElement(); |
| + window.removeEventListener(event.type, listener, useCapture); |
| +}, useCapture); |