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

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

Issue 856563002: Added the infrastructure for surfaceProxy.onResize() and SurfaceView.onResize() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 EventBindings = require('event_bindings');
9 var GuestView = require('guestView').GuestView; 10 var GuestView = require('guestView').GuestView;
11 var GuestViewInternalNatives = requireNative('guest_view_internal');
10 var IdGenerator = requireNative('id_generator'); 12 var IdGenerator = requireNative('id_generator');
11 13
12 function GuestViewContainer(element, viewType) { 14 function GuestViewContainer(element, viewType) {
13 privates(element).internal = this; 15 privates(element).internal = this;
14 this.element = element; 16 this.element = element;
15 this.elementAttached = false; 17 this.elementAttached = false;
16 this.guest = new GuestView(viewType); 18 this.guest = new GuestView(viewType);
17 this.viewInstanceId = IdGenerator.GetNextId(); 19 this.viewInstanceId = IdGenerator.GetNextId();
18 this.viewType = viewType; 20 this.viewType = viewType;
19 21
20 privates(this).browserPluginElement = this.createBrowserPluginElement(); 22 privates(this).browserPluginElement = this.createBrowserPluginElement();
21 this.setupFocusPropagation(); 23 this.setupFocusPropagation();
22 24
23 var shadowRoot = this.element.createShadowRoot(); 25 var shadowRoot = this.element.createShadowRoot();
24 shadowRoot.appendChild(privates(this).browserPluginElement); 26 shadowRoot.appendChild(privates(this).browserPluginElement);
27
28 this.setupResizeEvents();
25 } 29 }
26 30
27 // Forward public API methods from |proto| to their internal implementations. 31 // Forward public API methods from |proto| to their internal implementations.
28 GuestViewContainer.forwardApiMethods = function(proto, apiMethods) { 32 GuestViewContainer.forwardApiMethods = function(proto, apiMethods) {
29 var createProtoHandler = function(m) { 33 var createProtoHandler = function(m) {
30 return function(var_args) { 34 return function(var_args) {
31 var internal = privates(this).internal; 35 var internal = privates(this).internal;
32 return $Function.apply(internal[m], internal, arguments); 36 return $Function.apply(internal[m], internal, arguments);
33 }; 37 };
34 }; 38 };
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 this.element.addEventListener('focus', function(e) { 78 this.element.addEventListener('focus', function(e) {
75 // Focus the BrowserPlugin when the GuestViewContainer takes focus. 79 // Focus the BrowserPlugin when the GuestViewContainer takes focus.
76 privates(this).browserPluginElement.focus(); 80 privates(this).browserPluginElement.focus();
77 }.bind(this)); 81 }.bind(this));
78 this.element.addEventListener('blur', function(e) { 82 this.element.addEventListener('blur', function(e) {
79 // Blur the BrowserPlugin when the GuestViewContainer loses focus. 83 // Blur the BrowserPlugin when the GuestViewContainer loses focus.
80 privates(this).browserPluginElement.blur(); 84 privates(this).browserPluginElement.blur();
81 }.bind(this)); 85 }.bind(this));
82 }; 86 };
83 87
88 GuestViewContainer.prototype.setupResizeEvents = function() {
89 // Track when the guest resizes using the onResize event.
90 var CreateEvent = function(name) {
91 var eventOpts = {supportsListeners: true, supportsFilters: true};
92 return new EventBindings.Event(name, undefined, eventOpts);
93 };
94 var resizeEvent = CreateEvent('guestViewInternal.onResize');
Fady Samuel 2015/01/15 21:40:12 Remove this for now? This doesn't seem to do anyth
paulmeyer 2015/01/19 23:45:35 Moved to guest_view.js, as discussed offline.
95 resizeEvent.addListener(function(e) {
96 this.onGuestResize(e.oldWidth, e.oldHeight, e.newWidth, e.newHeight);
97 }.bind(this), {instanceId: this.viewInstanceId});
98
99 // Track when the element resizes using the element resize callback.
100 GuestViewInternalNatives.RegisterElementResizeCallback(
101 this.internalInstanceId, this.onElementResize.bind(this));
102 };
103
84 GuestViewContainer.prototype.attachWindow = function() { 104 GuestViewContainer.prototype.attachWindow = function() {
85 if (!this.internalInstanceId) { 105 if (!this.internalInstanceId) {
86 return true; 106 return true;
87 } 107 }
88 108
89 this.guest.attach(this.internalInstanceId, 109 this.guest.attach(this.internalInstanceId,
90 this.viewInstanceId, 110 this.viewInstanceId,
91 this.buildAttachParams()); 111 this.buildAttachParams());
92 return true; 112 return true;
93 }; 113 };
(...skipping 13 matching lines...) Expand all
107 } 127 }
108 }; 128 };
109 129
110 // Implemented by the specific view type, if needed. 130 // Implemented by the specific view type, if needed.
111 GuestViewContainer.prototype.buildAttachParams = function() { return {}; }; 131 GuestViewContainer.prototype.buildAttachParams = function() { return {}; };
112 GuestViewContainer.prototype.handleAttributeMutation = function() {}; 132 GuestViewContainer.prototype.handleAttributeMutation = function() {};
113 GuestViewContainer.prototype.onElementAttached = function() {}; 133 GuestViewContainer.prototype.onElementAttached = function() {};
114 GuestViewContainer.prototype.onElementDetached = function() { 134 GuestViewContainer.prototype.onElementDetached = function() {
115 this.guest.destroy(); 135 this.guest.destroy();
116 }; 136 };
137 GuestViewContainer.prototype.onElementResize = function(oldWidth, oldHeight,
138 newWidth, newHeight) {};
139 GuestViewContainer.prototype.onGuestResize = function(oldWidth, oldHeight,
140 newWidth, newHeight) {};
117 141
118 // Registers the browser plugin <object> custom element. |viewType| is the 142 // Registers the browser plugin <object> custom element. |viewType| is the
119 // name of the specific guestview container (e.g. 'webview'). 143 // name of the specific guestview container (e.g. 'webview').
120 function registerBrowserPluginElement(viewType) { 144 function registerBrowserPluginElement(viewType) {
121 var proto = Object.create(HTMLObjectElement.prototype); 145 var proto = Object.create(HTMLObjectElement.prototype);
122 146
123 proto.createdCallback = function() { 147 proto.createdCallback = function() {
124 this.setAttribute('type', 'application/browser-plugin'); 148 this.setAttribute('type', 'application/browser-plugin');
125 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); 149 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId());
126 this.style.width = '100%'; 150 this.style.width = '100%';
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // Delete the callbacks so developers cannot call them and produce unexpected 224 // Delete the callbacks so developers cannot call them and produce unexpected
201 // behavior. 225 // behavior.
202 delete proto.createdCallback; 226 delete proto.createdCallback;
203 delete proto.attachedCallback; 227 delete proto.attachedCallback;
204 delete proto.detachedCallback; 228 delete proto.detachedCallback;
205 delete proto.attributeChangedCallback; 229 delete proto.attributeChangedCallback;
206 } 230 }
207 231
208 // Exports. 232 // Exports.
209 exports.GuestViewContainer = GuestViewContainer; 233 exports.GuestViewContainer = GuestViewContainer;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698