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

Side by Side Diff: extensions/renderer/resources/guest_view/guest_view_container.js

Issue 845363004: <webview>, <appview> and <extensionoptions> can run in a detached state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SurfaceView fix Created 5 years, 11 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 // This module implements the shared functionality for different guestview 5 // This module implements the shared functionality for different guestview
6 // containers, such as web_view, app_view, etc. 6 // containers, such as web_view, app_view, etc.
7 7
8 var DocumentNatives = requireNative('document_natives'); 8 var DocumentNatives = requireNative('document_natives');
9 var GuestView = require('guestView').GuestView; 9 var GuestView = require('guestView').GuestView;
10 var IdGenerator = requireNative('id_generator'); 10 var IdGenerator = requireNative('id_generator');
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 this.element.addEventListener('focus', function(e) { 74 this.element.addEventListener('focus', function(e) {
75 // Focus the BrowserPlugin when the GuestViewContainer takes focus. 75 // Focus the BrowserPlugin when the GuestViewContainer takes focus.
76 privates(this).browserPluginElement.focus(); 76 privates(this).browserPluginElement.focus();
77 }.bind(this)); 77 }.bind(this));
78 this.element.addEventListener('blur', function(e) { 78 this.element.addEventListener('blur', function(e) {
79 // Blur the BrowserPlugin when the GuestViewContainer loses focus. 79 // Blur the BrowserPlugin when the GuestViewContainer loses focus.
80 privates(this).browserPluginElement.blur(); 80 privates(this).browserPluginElement.blur();
81 }.bind(this)); 81 }.bind(this));
82 }; 82 };
83 83
84 GuestViewContainer.prototype.attach = function() {
85 // Augment the attach parameters with the element size, so that the guestview
86 // can fit the element initially.
87 var attachParams = this.buildAttachParams();
88 attachParams['elementWidth'] = parseInt(this.element.offsetWidth);
89 attachParams['elementHeight'] = parseInt(this.element.offsetHeight);
90
91 this.guest.attach(this.internalInstanceId, this.viewInstanceId, attachParams);
92 };
93
94 GuestViewContainer.prototype.attachWindow = function() { 84 GuestViewContainer.prototype.attachWindow = function() {
95 if (!this.internalInstanceId) { 85 if (!this.internalInstanceId) {
96 return true; 86 return true;
97 } 87 }
98 88
99 this.attach(); 89 this.guest.attach(this.internalInstanceId,
90 this.viewInstanceId,
91 this.buildParams());
100 return true; 92 return true;
101 }; 93 };
102 94
103 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = 95 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation =
104 function(name, oldValue, newValue) { 96 function(name, oldValue, newValue) {
105 if (name == 'internalinstanceid' && !oldValue && !!newValue) { 97 if (name == 'internalinstanceid' && !oldValue && !!newValue) {
106 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); 98 privates(this).browserPluginElement.removeAttribute('internalinstanceid');
107 this.internalInstanceId = parseInt(newValue); 99 this.internalInstanceId = parseInt(newValue);
108 100
109 if (!this.guest.getId()) { 101 if (!this.guest.getId()) {
110 return; 102 return;
111 } 103 }
112 this.attach(); 104 this.guest.attach(this.internalInstanceId,
105 this.viewInstanceId,
106 this.buildParams());
113 } 107 }
114 }; 108 };
115 109
110 GuestViewContainer.prototype.buildParams = function() {
111 var params = this.buildContainerParams();
112 params['instanceId'] = this.viewInstanceId;
113 params['elementWidth'] = parseInt(this.element.offsetWidth);
114 params['elementHeight'] = parseInt(this.element.offsetHeight);
115 return params;
116 };
117
116 // Implemented by the specific view type, if needed. 118 // Implemented by the specific view type, if needed.
117 GuestViewContainer.prototype.buildAttachParams = function() { return {}; }; 119 GuestViewContainer.prototype.buildContainerParams = function() { return {}; };
118 GuestViewContainer.prototype.handleAttributeMutation = function() {}; 120 GuestViewContainer.prototype.handleAttributeMutation = function() {};
119 GuestViewContainer.prototype.onElementAttached = function() {}; 121 GuestViewContainer.prototype.onElementAttached = function() {};
120 GuestViewContainer.prototype.onElementDetached = function() { 122 GuestViewContainer.prototype.onElementDetached = function() {
121 this.guest.destroy(); 123 this.guest.destroy();
122 }; 124 };
123 125
124 // Registers the browser plugin <object> custom element. |viewType| is the 126 // Registers the browser plugin <object> custom element. |viewType| is the
125 // name of the specific guestview container (e.g. 'webview'). 127 // name of the specific guestview container (e.g. 'webview').
126 function registerBrowserPluginElement(viewType) { 128 function registerBrowserPluginElement(viewType) {
127 var proto = Object.create(HTMLObjectElement.prototype); 129 var proto = Object.create(HTMLObjectElement.prototype);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 184 }
183 internal.handleAttributeMutation(name, oldValue, newValue); 185 internal.handleAttributeMutation(name, oldValue, newValue);
184 }; 186 };
185 187
186 proto.detachedCallback = function() { 188 proto.detachedCallback = function() {
187 var internal = privates(this).internal; 189 var internal = privates(this).internal;
188 if (!internal) { 190 if (!internal) {
189 return; 191 return;
190 } 192 }
191 internal.elementAttached = false; 193 internal.elementAttached = false;
194 internal.internalInstanceId = 0;
192 internal.onElementDetached(); 195 internal.onElementDetached();
193 }; 196 };
194 197
195 // Let the specific view type add extra functionality to its custom element 198 // Let the specific view type add extra functionality to its custom element
196 // through |proto|. 199 // through |proto|.
197 if (guestViewContainerType.setupElement) { 200 if (guestViewContainerType.setupElement) {
198 guestViewContainerType.setupElement(proto); 201 guestViewContainerType.setupElement(proto);
199 } 202 }
200 203
201 window[guestViewContainerType.VIEW_TYPE] = 204 window[guestViewContainerType.VIEW_TYPE] =
202 DocumentNatives.RegisterElement( 205 DocumentNatives.RegisterElement(
203 guestViewContainerType.VIEW_TYPE.toLowerCase(), 206 guestViewContainerType.VIEW_TYPE.toLowerCase(),
204 {prototype: proto}); 207 {prototype: proto});
205 208
206 // Delete the callbacks so developers cannot call them and produce unexpected 209 // Delete the callbacks so developers cannot call them and produce unexpected
207 // behavior. 210 // behavior.
208 delete proto.createdCallback; 211 delete proto.createdCallback;
209 delete proto.attachedCallback; 212 delete proto.attachedCallback;
210 delete proto.detachedCallback; 213 delete proto.detachedCallback;
211 delete proto.attributeChangedCallback; 214 delete proto.attributeChangedCallback;
212 } 215 }
213 216
214 // Exports. 217 // Exports.
215 exports.GuestViewContainer = GuestViewContainer; 218 exports.GuestViewContainer = GuestViewContainer;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698