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

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

Issue 354483004: Implement <appview> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@app_view_skeleton
Patch Set: Added tests 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 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 AppViewInternal(appviewNode) {
11 privates(appviewNode).internal = this; 11 privates(appviewNode).internal = this;
12 this.appviewNode = appviewNode; 12 this.appviewNode = appviewNode;
13 13
14 this.browserPluginNode = this.createBrowserPluginNode(); 14 this.browserPluginNode = this.createBrowserPluginNode();
15 var shadowRoot = this.appviewNode.createShadowRoot(); 15 var shadowRoot = this.appviewNode.createShadowRoot();
16 shadowRoot.appendChild(this.browserPluginNode); 16 shadowRoot.appendChild(this.browserPluginNode);
17 this.errorNode = document.createElement('div');
lazyboy 2014/07/07 21:34:44 Can we lazily create this error node when we actua
Fady Samuel 2014/07/08 15:47:09 Done.
18 this.errorNode.innerText = 'Unable to connect to app.';
19 this.errorNode.style.display = 'absolute';
20 this.errorNode.style.left = '0px';
21 this.errorNode.style.top = '0px';
22 this.errorNode.style.width = '100%';
23 this.errorNode.style.height = '100%';
24
25 shadowRoot.appendChild(this.errorNode);
26
17 this.viewInstanceId = IdGenerator.GetNextId(); 27 this.viewInstanceId = IdGenerator.GetNextId();
18 } 28 }
19 29
20 AppViewInternal.prototype.createBrowserPluginNode = function() { 30 AppViewInternal.prototype.createBrowserPluginNode = function() {
21 // We create BrowserPlugin as a custom element in order to observe changes 31 // We create BrowserPlugin as a custom element in order to observe changes
22 // to attributes synchronously. 32 // to attributes synchronously.
23 var browserPluginNode = new AppViewInternal.BrowserPlugin(); 33 var browserPluginNode = new AppViewInternal.BrowserPlugin();
24 privates(browserPluginNode).internal = this; 34 privates(browserPluginNode).internal = this;
25 return browserPluginNode; 35 return browserPluginNode;
26 }; 36 };
27 37
28 AppViewInternal.prototype.connect = function(src, callback) { 38 AppViewInternal.prototype.connect = function(app, callback) {
29 var params = { 39 var params = {
40 'appId': app
30 }; 41 };
31 var self = this; 42 var self = this;
32 GuestViewInternal.createGuest( 43 GuestViewInternal.createGuest(
33 'appview', 44 'appview',
34 params, 45 params,
35 function(instanceId) { 46 function(instanceId) {
36 self.attachWindow(instanceId, src); 47 if (!instanceId) {
48 self.browserPluginNode.style.visibility = 'hidden';
49 var errorMsg = 'Unable to connect to app "' + app + '".';
50 window.console.warn(errorMsg);
51 self.errorNode.innerText = errorMsg;
52 if (callback) {
53 callback(false);
54 }
55 return;
56 }
57 self.attachWindow(instanceId);
37 if (callback) { 58 if (callback) {
38 callback(); 59 callback(true);
39 } 60 }
40 } 61 }
41 ); 62 );
42 }; 63 };
43 64
44 AppViewInternal.prototype.attachWindow = function(instanceId, src) { 65 AppViewInternal.prototype.attachWindow = function(instanceId) {
45 this.instanceId = instanceId; 66 this.instanceId = instanceId;
46 var params = { 67 var params = {
47 'instanceId': this.viewInstanceId, 68 'instanceId': this.viewInstanceId,
48 'src': src
49 }; 69 };
70 this.browserPluginNode.style.visibility = 'visible';
50 return this.browserPluginNode['-internal-attach'](instanceId, params); 71 return this.browserPluginNode['-internal-attach'](instanceId, params);
lazyboy 2014/07/07 21:34:44 You need to add the code for display:none handling
Fady Samuel 2014/07/08 15:47:09 This is not currently necessary because <appview>
51 }; 72 };
52 73
53 function registerBrowserPluginElement() { 74 function registerBrowserPluginElement() {
54 var proto = Object.create(HTMLObjectElement.prototype); 75 var proto = Object.create(HTMLObjectElement.prototype);
55 76
56 proto.createdCallback = function() { 77 proto.createdCallback = function() {
57 this.setAttribute('type', 'application/browser-plugin'); 78 this.setAttribute('type', 'application/browser-plugin');
58 this.style.width = '100%'; 79 this.style.width = '100%';
59 this.style.height = '100%'; 80 this.style.height = '100%';
81 this.style.position = 'absolute';
lazyboy 2014/07/07 21:34:44 I'm not totally sure why you'd need this? position
Fady Samuel 2014/07/08 15:47:09 So that the errorNode can overlap the BrowserPlugi
82 this.style.left = '0px';
83 this.style.top = '0px';
60 }; 84 };
61 85
62 proto.attachedCallback = function() { 86 proto.attachedCallback = function() {
63 // Load the plugin immediately. 87 // Load the plugin immediately.
64 var unused = this.nonExistentAttribute; 88 var unused = this.nonExistentAttribute;
65 }; 89 };
66 90
67 AppViewInternal.BrowserPlugin = 91 AppViewInternal.BrowserPlugin =
68 DocumentNatives.RegisterElement('appplugin', {extends: 'object', 92 DocumentNatives.RegisterElement('appplugin', {extends: 'object',
69 prototype: proto}); 93 prototype: proto});
(...skipping 28 matching lines...) Expand all
98 122
99 var useCapture = true; 123 var useCapture = true;
100 window.addEventListener('readystatechange', function listener(event) { 124 window.addEventListener('readystatechange', function listener(event) {
101 if (document.readyState == 'loading') 125 if (document.readyState == 'loading')
102 return; 126 return;
103 127
104 registerBrowserPluginElement(); 128 registerBrowserPluginElement();
105 registerAppViewElement(); 129 registerAppViewElement();
106 window.removeEventListener(event.type, listener, useCapture); 130 window.removeEventListener(event.type, listener, useCapture);
107 }, useCapture); 131 }, useCapture);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698