Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: chrome/renderer/resources/extensions/extension_options.js

Issue 378783002: Initial implementation of the <extensionoptions> GuestView tag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix problems with attaching guest view, add extension function dispatcher Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var DocumentNatives = requireNative('document_natives'); 5 var DocumentNatives = requireNative('document_natives');
6 var GuestViewInternal = 6 var GuestViewInternal =
7 require('binding').Binding.create('guestViewInternal').generate(); 7 require('binding').Binding.create('guestViewInternal').generate();
8 var IdGenerator = requireNative('id_generator'); 8 var IdGenerator = requireNative('id_generator');
9 9
10 function AppViewInternal(appviewNode) { 10 function ExtensionOptionsInternal(extensionoptionsNode) {
11 privates(appviewNode).internal = this; 11 privates(extensionoptionsNode).internal = this;
12 this.appviewNode = appviewNode; 12 this.extensionoptionsNode = extensionoptionsNode;
13 13
14 this.browserPluginNode = this.createBrowserPluginNode(); 14 this.browserPluginNode = this.createBrowserPluginNode();
15 var shadowRoot = this.appviewNode.createShadowRoot(); 15 var shadowRoot = this.extensionoptionsNode.createShadowRoot();
16 shadowRoot.appendChild(this.browserPluginNode); 16 shadowRoot.appendChild(this.browserPluginNode);
17 this.viewInstanceId = IdGenerator.GetNextId(); 17 this.viewInstanceId = IdGenerator.GetNextId();
18
19 if (this.parseExtensionAttribute()) {
20 this.createGuest();
21 }
18 } 22 }
19 23
20 AppViewInternal.prototype.createBrowserPluginNode = function() { 24 ExtensionOptionsInternal.prototype.createBrowserPluginNode = function() {
21 // We create BrowserPlugin as a custom element in order to observe changes 25 var browserPluginNode = new ExtensionOptionsInternal.BrowserPlugin();
22 // to attributes synchronously.
23 var browserPluginNode = new AppViewInternal.BrowserPlugin();
24 privates(browserPluginNode).internal = this; 26 privates(browserPluginNode).internal = this;
25 return browserPluginNode; 27 return browserPluginNode;
26 }; 28 }
27 29
28 AppViewInternal.prototype.connect = function(src, callback) { 30 ExtensionOptionsInternal.prototype.parseExtensionAttribute = function() {
31 if (this.extensionoptionsNode.hasAttribute('extension')) {
32 this.extensionId = this.extensionoptionsNode.getAttribute('extension');
33 return true;
34 }
35 return false;
36 }
37
38 ExtensionOptionsInternal.prototype.createGuest = function() {
29 var params = { 39 var params = {
40 'extensionId': this.extensionId,
30 }; 41 };
31 var self = this; 42 var self = this;
32 GuestViewInternal.createGuest( 43 GuestViewInternal.createGuest(
33 'appview', 44 'extensionoptions',
34 params, 45 params,
35 function(instanceId) { 46 function(instanceId) {
36 self.attachWindow(instanceId, src); 47 self.instanceId = instanceId;
37 if (callback) { 48 self.attachWindow(instanceId);
38 callback(); 49 });
39 }
40 }
41 );
42 }; 50 };
43 51
44 AppViewInternal.prototype.attachWindow = function(instanceId, src) { 52 ExtensionOptionsInternal.prototype.attachWindow = function(instanceId) {
45 this.instanceId = instanceId; 53 this.instanceId = instanceId;
46 var params = { 54 var params = {
47 'instanceId': this.viewInstanceId, 55 'instanceId': this.viewInstanceId,
48 'src': src 56 }
49 };
50 return this.browserPluginNode['-internal-attach'](instanceId, params); 57 return this.browserPluginNode['-internal-attach'](instanceId, params);
51 }; 58 }
52 59
53 function registerBrowserPluginElement() { 60 function registerBrowserPluginElement() {
54 var proto = Object.create(HTMLObjectElement.prototype); 61 var proto = Object.create(HTMLObjectElement.prototype);
55 62
56 proto.createdCallback = function() { 63 proto.createdCallback = function() {
57 this.setAttribute('type', 'application/browser-plugin'); 64 this.setAttribute('type', 'application/browser-plugin');
58 this.style.width = '100%'; 65 this.style.width = '100%';
59 this.style.height = '100%'; 66 this.style.height = '100%';
60 }; 67 };
61 68
62 proto.attachedCallback = function() { 69 proto.attachedCallback = function() {
63 // Load the plugin immediately. 70 // Load the plugin immediately.
64 var unused = this.nonExistentAttribute; 71 var unused = this.nonExistentAttribute;
65 }; 72 };
66 73
67 AppViewInternal.BrowserPlugin = 74 ExtensionOptionsInternal.BrowserPlugin =
68 DocumentNatives.RegisterElement('appplugin', {extends: 'object', 75 DocumentNatives.RegisterElement("extensionoptionsplugin",
69 prototype: proto}); 76 {extends: 'object', prototype: proto});
70
71 delete proto.createdCallback; 77 delete proto.createdCallback;
72 delete proto.attachedCallback; 78 delete proto.attachedCallback;
73 delete proto.detachedCallback;
74 delete proto.attributeChangedCallback;
Fady Samuel 2014/07/11 21:08:05 You want to delete these callbacks too.
ericzeng 2014/07/12 00:10:05 Done.
75 } 79 }
76 80
77 function registerAppViewElement() { 81 function registerExtensionOptionsElement() {
78 var proto = Object.create(HTMLElement.prototype); 82 var proto = Object.create(HTMLElement.prototype);
79 83
80 proto.createdCallback = function() { 84 proto.createdCallback = function() {
81 new AppViewInternal(this); 85 new ExtensionOptionsInternal(this);
82 }; 86 }
83 87
84 proto.connect = function() { 88 window.ExtensionOptions =
85 var internal = privates(this).internal; 89 DocumentNatives.RegisterElement('extensionoptions', {prototype: proto});
86 $Function.apply(internal.connect, internal, arguments);
87 }
88 window.AppView =
89 DocumentNatives.RegisterElement('appview', {prototype: proto});
90 90
91 // Delete the callbacks so developers cannot call them and produce unexpected 91 // Delete the callbacks so developers cannot call them and produce unexpected
92 // behavior. 92 // behavior.
93 delete proto.createdCallback; 93 delete proto.createdCallback;
94 delete proto.attachedCallback;
95 delete proto.detachedCallback;
96 delete proto.attributeChangedCallback;
Fady Samuel 2014/07/11 21:08:05 You want to delete these callbacks too.
ericzeng 2014/07/12 00:10:05 Done.
97 } 94 }
98 95
99 var useCapture = true; 96 var useCapture = true;
100 window.addEventListener('readystatechange', function listener(event) { 97 window.addEventListener('readystatechange', function listener(event) {
101 if (document.readyState == 'loading') 98 if (document.readyState == 'loading')
102 return; 99 return;
103 100
104 registerBrowserPluginElement(); 101 registerBrowserPluginElement();
105 registerAppViewElement(); 102 registerExtensionOptionsElement();
106 window.removeEventListener(event.type, listener, useCapture); 103 window.removeEventListener(event.type, listener, useCapture);
107 }, useCapture); 104 }, useCapture);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698