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

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

Issue 353013007: Implement <appview> skeleton. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@app_view_skeleton
Patch Set: Fixed PermissionsTest unit test 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
(Empty)
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
3 // found in the LICENSE file.
4
5 var DocumentNatives = requireNative('document_natives');
6 var GuestViewInternal =
7 require('binding').Binding.create('guestViewInternal').generate();
8 var IdGenerator = requireNative('id_generator');
9
10 function AppViewInternal(appviewNode) {
11 privates(appviewNode).internal = this;
12 this.appviewNode = appviewNode;
13
14 this.browserPluginNode = this.createBrowserPluginNode();
15 var shadowRoot = this.appviewNode.createShadowRoot();
16 shadowRoot.appendChild(this.browserPluginNode);
17 this.viewInstanceId = IdGenerator.GetNextId();
18 }
19
20 AppViewInternal.prototype.createBrowserPluginNode = function() {
21 // We create BrowserPlugin as a custom element in order to observe changes
22 // to attributes synchronously.
23 var browserPluginNode = new AppViewInternal.BrowserPlugin();
24 privates(browserPluginNode).internal = this;
25 return browserPluginNode;
26 };
27
28 AppViewInternal.prototype.connect = function(src, callback) {
29 var params = {
30 };
31 var self = this;
32 GuestViewInternal.createGuest(
33 'appview',
34 params,
35 function(instanceId) {
36 self.attachWindow(instanceId, src);
37 if (callback) {
38 callback();
39 }
40 }
41 );
42 };
43
44 AppViewInternal.prototype.attachWindow = function(instanceId, src) {
45 this.instanceId = instanceId;
46 var params = {
47 'instanceId': this.viewInstanceId,
48 'src': src
49 };
50 return this.browserPluginNode['-internal-attach'](instanceId, params);
51 };
52
53 function registerBrowserPluginElement() {
54 var proto = Object.create(HTMLObjectElement.prototype);
55
56 proto.createdCallback = function() {
57 this.setAttribute('type', 'application/browser-plugin');
58 this.style.width = '100%';
59 this.style.height = '100%';
60 };
61
62 proto.attachedCallback = function() {
63 // Load the plugin immediately.
64 var unused = this.nonExistentAttribute;
65 };
66
67 AppViewInternal.BrowserPlugin =
68 DocumentNatives.RegisterElement('appplugin', {extends: 'object',
69 prototype: proto});
70
71 delete proto.createdCallback;
72 delete proto.attachedCallback;
73 delete proto.detachedCallback;
74 delete proto.attributeChangedCallback;
75 }
76
77 function registerAppViewElement() {
78 var proto = Object.create(HTMLElement.prototype);
79
80 proto.createdCallback = function() {
81 new AppViewInternal(this);
82 };
83
84 proto.connect = function() {
85 var internal = privates(this).internal;
86 $Function.apply(internal.connect, internal, arguments);
87 }
88 window.AppView =
89 DocumentNatives.RegisterElement('appview', {prototype: proto});
90
91 // Delete the callbacks so developers cannot call them and produce unexpected
92 // behavior.
93 delete proto.createdCallback;
94 delete proto.attachedCallback;
95 delete proto.detachedCallback;
96 delete proto.attributeChangedCallback;
97 }
98
99 var useCapture = true;
100 window.addEventListener('readystatechange', function listener(event) {
101 if (document.readyState == 'loading')
102 return;
103
104 registerBrowserPluginElement();
105 registerAppViewElement();
106 window.removeEventListener(event.type, listener, useCapture);
107 }, useCapture);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698