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

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: Fixed formatting 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.viewInstanceId = IdGenerator.GetNextId(); 17 this.viewInstanceId = IdGenerator.GetNextId();
18 } 18 }
19 19
20 AppViewInternal.prototype.getErrorNode = function() {
21 if (!this.errorNode) {
22 this.errorNode = document.createElement('div');
23 this.errorNode.innerText = 'Unable to connect to app.';
24 this.errorNode.style.position = 'absolute';
25 this.errorNode.style.left = '0px';
26 this.errorNode.style.top = '0px';
27 this.errorNode.style.width = '100%';
28 this.errorNode.style.height = '100%';
29 this.appviewNode.shadowRoot.appendChild(this.errorNode);
30 }
31 return this.errorNode;
32 };
33
20 AppViewInternal.prototype.createBrowserPluginNode = function() { 34 AppViewInternal.prototype.createBrowserPluginNode = function() {
21 // We create BrowserPlugin as a custom element in order to observe changes 35 // We create BrowserPlugin as a custom element in order to observe changes
22 // to attributes synchronously. 36 // to attributes synchronously.
23 var browserPluginNode = new AppViewInternal.BrowserPlugin(); 37 var browserPluginNode = new AppViewInternal.BrowserPlugin();
24 privates(browserPluginNode).internal = this; 38 privates(browserPluginNode).internal = this;
25 return browserPluginNode; 39 return browserPluginNode;
26 }; 40 };
27 41
28 AppViewInternal.prototype.connect = function(src, callback) { 42 AppViewInternal.prototype.connect = function(app, callback) {
29 var params = { 43 var params = {
44 'appId': app
30 }; 45 };
31 var self = this; 46 var self = this;
32 GuestViewInternal.createGuest( 47 GuestViewInternal.createGuest(
33 'appview', 48 'appview',
34 params, 49 params,
35 function(instanceId) { 50 function(instanceId) {
36 self.attachWindow(instanceId, src); 51 if (!instanceId) {
52 self.browserPluginNode.style.visibility = 'hidden';
53 var errorMsg = 'Unable to connect to app "' + app + '".';
54 window.console.warn(errorMsg);
55 self.getErrorNode().innerText = errorMsg;
56 if (callback) {
57 callback(false);
58 }
59 return;
60 }
61 self.attachWindow(instanceId);
37 if (callback) { 62 if (callback) {
38 callback(); 63 callback(true);
39 } 64 }
40 } 65 }
41 ); 66 );
42 }; 67 };
43 68
44 AppViewInternal.prototype.attachWindow = function(instanceId, src) { 69 AppViewInternal.prototype.attachWindow = function(instanceId) {
45 this.instanceId = instanceId; 70 this.instanceId = instanceId;
46 var params = { 71 var params = {
47 'instanceId': this.viewInstanceId, 72 'instanceId': this.viewInstanceId,
48 'src': src
49 }; 73 };
74 this.browserPluginNode.style.visibility = 'visible';
50 return this.browserPluginNode['-internal-attach'](instanceId, params); 75 return this.browserPluginNode['-internal-attach'](instanceId, params);
51 }; 76 };
52 77
53 function registerBrowserPluginElement() { 78 function registerBrowserPluginElement() {
54 var proto = Object.create(HTMLObjectElement.prototype); 79 var proto = Object.create(HTMLObjectElement.prototype);
55 80
56 proto.createdCallback = function() { 81 proto.createdCallback = function() {
57 this.setAttribute('type', 'application/browser-plugin'); 82 this.setAttribute('type', 'application/browser-plugin');
58 this.style.width = '100%'; 83 this.style.width = '100%';
59 this.style.height = '100%'; 84 this.style.height = '100%';
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 123
99 var useCapture = true; 124 var useCapture = true;
100 window.addEventListener('readystatechange', function listener(event) { 125 window.addEventListener('readystatechange', function listener(event) {
101 if (document.readyState == 'loading') 126 if (document.readyState == 'loading')
102 return; 127 return;
103 128
104 registerBrowserPluginElement(); 129 registerBrowserPluginElement();
105 registerAppViewElement(); 130 registerAppViewElement();
106 window.removeEventListener(event.type, listener, useCapture); 131 window.removeEventListener(event.type, listener, useCapture);
107 }, useCapture); 132 }, useCapture);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698