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..f6d5cf031b84fb1dfd99015bb3cd215f8ae1474a |
| --- /dev/null |
| +++ b/chrome/renderer/resources/extensions/extension_options.js |
| @@ -0,0 +1,109 @@ |
| +// 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; |
| + // TODO(lazyboy): Make sure this.autoNavigate_ stuff correctly updated |
| + // |self.src| at this point. |
| + 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
|
| + }); |
|
not at google - send to devlin
2014/07/08 19:17:25
FYI a nice pattern (perhaps appview doesn't do thi
|
| +}; |
| + |
| +function registerBrowserPluginElement() { |
| + 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; |
| + }; |
| + |
| + ExtensionOptionsInternal.BrowserPlugin = |
| + 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); |
| + } |
| + |
| + // Forward proto.foo* method calls to ExtensionOptionsInternal.foo*. |
| + for (var i = 0; methods[i]; ++i) { |
| + var createHandler = function(m) { |
| + return function(var_args) { |
| + var internal = privates(this).internal; |
| + return $Function.apply(internal[m], internal, arguments); |
| + }; |
| + }; |
| + proto[methods[i]] = createHandler(methods[i]); |
| + } |
| + |
| + window.ExtensionOptions = |
| + DocumentNatives.RegisterElement('extensionoptions', {prototype: proto}); |
| + |
| + // Delete the callbacks so developers cannot call them and produce unexpected |
| + // behavior. |
| + 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); |