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

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

Issue 1165773004: Extract the element implementation logic to function mods in <webview>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@qui
Patch Set: fix comments Created 5 years, 6 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 GuestViewInternalNatives = requireNative('guest_view_internal'); 10 var GuestViewInternalNatives = requireNative('guest_view_internal');
11 var IdGenerator = requireNative('id_generator'); 11 var IdGenerator = requireNative('id_generator');
12 12
13 function GuestViewContainer(element, viewType) { 13 function GuestViewContainer(element, viewType) {
14 privates(element).internal = this; 14 privates(element).internal = this;
15 this.attributes = {}; 15 this.attributes = {};
16 this.element = element; 16 this.element = element;
17 this.elementAttached = false; 17 this.elementAttached = false;
18 this.viewInstanceId = IdGenerator.GetNextId(); 18 this.viewInstanceId = IdGenerator.GetNextId();
19 this.viewType = viewType; 19 this.viewType = viewType;
20 20
21 this.setupGuestProperty(); 21 this.setupGuestProperty();
22 this.guest = new GuestView(viewType); 22 this.guest = new GuestView(viewType);
23 this.setupAttributes(); 23 this.setupAttributes();
24 24
25 privates(this).browserPluginElement = this.createBrowserPluginElement(); 25 privates(this).internalElement = this.createInternalElement$();
26 this.setupFocusPropagation(); 26 this.setupFocusPropagation();
27 var shadowRoot = this.element.createShadowRoot(); 27 var shadowRoot = this.element.createShadowRoot();
28 shadowRoot.appendChild(privates(this).browserPluginElement); 28 shadowRoot.appendChild(privates(this).internalElement);
29 29
30 GuestViewInternalNatives.RegisterView(this.viewInstanceId, this); 30 GuestViewInternalNatives.RegisterView(this.viewInstanceId, this);
31 } 31 }
32 32
33 // Forward public API methods from |proto| to their internal implementations. 33 // Forward public API methods from |proto| to their internal implementations.
34 GuestViewContainer.forwardApiMethods = function(proto, apiMethods) { 34 GuestViewContainer.forwardApiMethods = function(proto, apiMethods) {
35 var createProtoHandler = function(m) { 35 var createProtoHandler = function(m) {
36 return function(var_args) { 36 return function(var_args) {
37 var internal = privates(this).internal; 37 var internal = privates(this).internal;
38 return $Function.apply(internal[m], internal, arguments); 38 return $Function.apply(internal[m], internal, arguments);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 contentResizeEvent.oldHeight = e.oldHeight; 77 contentResizeEvent.oldHeight = e.oldHeight;
78 contentResizeEvent.newWidth = e.newWidth; 78 contentResizeEvent.newWidth = e.newWidth;
79 contentResizeEvent.newHeight = e.newHeight; 79 contentResizeEvent.newHeight = e.newHeight;
80 this.dispatchEvent(contentResizeEvent); 80 this.dispatchEvent(contentResizeEvent);
81 }.bind(this); 81 }.bind(this);
82 }.bind(this), 82 }.bind(this),
83 enumerable: true 83 enumerable: true
84 }); 84 });
85 }; 85 };
86 86
87 GuestViewContainer.prototype.createBrowserPluginElement = function() { 87 GuestViewContainer.prototype.createInternalElement$ = function() {
88 // We create BrowserPlugin as a custom element in order to observe changes 88 // We create BrowserPlugin as a custom element in order to observe changes
89 // to attributes synchronously. 89 // to attributes synchronously.
90 var browserPluginElement = 90 var browserPluginElement =
91 new GuestViewContainer[this.viewType + 'BrowserPlugin'](); 91 new GuestViewContainer[this.viewType + 'BrowserPlugin']();
92 privates(browserPluginElement).internal = this; 92 privates(browserPluginElement).internal = this;
93 return browserPluginElement; 93 return browserPluginElement;
94 }; 94 };
95 95
96 GuestViewContainer.prototype.setupFocusPropagation = function() { 96 GuestViewContainer.prototype.setupFocusPropagation = function() {
97 if (!this.element.hasAttribute('tabIndex')) { 97 if (!this.element.hasAttribute('tabIndex')) {
98 // GuestViewContainer needs a tabIndex in order to be focusable. 98 // GuestViewContainer needs a tabIndex in order to be focusable.
99 // TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute 99 // TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute
100 // to allow GuestViewContainer to be focusable. 100 // to allow GuestViewContainer to be focusable.
101 // See http://crbug.com/231664. 101 // See http://crbug.com/231664.
102 this.element.setAttribute('tabIndex', -1); 102 this.element.setAttribute('tabIndex', -1);
103 } 103 }
104 this.element.addEventListener('focus', this.weakWrapper(function(e) { 104 this.element.addEventListener('focus', this.weakWrapper(function(e) {
105 // Focus the BrowserPlugin when the GuestViewContainer takes focus. 105 // Focus the BrowserPlugin when the GuestViewContainer takes focus.
106 privates(this).browserPluginElement.focus(); 106 privates(this).internalElement.focus();
107 })); 107 }));
108 this.element.addEventListener('blur', this.weakWrapper(function(e) { 108 this.element.addEventListener('blur', this.weakWrapper(function(e) {
109 // Blur the BrowserPlugin when the GuestViewContainer loses focus. 109 // Blur the BrowserPlugin when the GuestViewContainer loses focus.
110 privates(this).browserPluginElement.blur(); 110 privates(this).internalElement.blur();
111 })); 111 }));
112 }; 112 };
113 113
114 GuestViewContainer.prototype.attachWindow = function() { 114 GuestViewContainer.prototype.attachWindow$ = function() {
115 if (!this.internalInstanceId) { 115 if (!this.internalInstanceId) {
116 return true; 116 return true;
117 } 117 }
118 118
119 this.guest.attach(this.internalInstanceId, 119 this.guest.attach(this.internalInstanceId,
120 this.viewInstanceId, 120 this.viewInstanceId,
121 this.buildParams()); 121 this.buildParams());
122 return true; 122 return true;
123 }; 123 };
124 124
125 GuestViewContainer.prototype.onInternalInstanceID = function(
Fady Samuel 2015/06/09 03:16:31 onInternalInstanceId
lazyboy 2015/06/09 18:48:22 Done.
126 internalInstanceId) {
127 this.internalInstanceId = internalInstanceId;
128
129 // Track when the element resizes using the element resize callback.
130 GuestViewInternalNatives.RegisterElementResizeCallback(
131 this.internalInstanceId, this.weakWrapper(this.onElementResize));
132
133 if (!this.guest.getId()) {
134 return;
135 }
136 this.guest.attach(this.internalInstanceId,
137 this.viewInstanceId,
138 this.buildParams());
139 };
140
125 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = 141 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation =
Fady Samuel 2015/06/09 03:16:31 nit: handleInternalElementAttributeMutation. Chan
lazyboy 2015/06/09 18:48:22 Done mostly except one local variable, where it he
126 function(name, oldValue, newValue) { 142 function(name, oldValue, newValue) {
127 if (name == 'internalinstanceid' && !oldValue && !!newValue) { 143 if (name == 'internalinstanceid' && !oldValue && !!newValue) {
128 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); 144 privates(this).internalElement.removeAttribute('internalinstanceid');
129 this.internalInstanceId = parseInt(newValue); 145 this.onInternalInstanceID(parseInt(newValue));
130
131 // Track when the element resizes using the element resize callback.
132 GuestViewInternalNatives.RegisterElementResizeCallback(
133 this.internalInstanceId, this.weakWrapper(this.onElementResize));
134
135 if (!this.guest.getId()) {
136 return;
137 }
138 this.guest.attach(this.internalInstanceId,
139 this.viewInstanceId,
140 this.buildParams());
141 } 146 }
142 }; 147 };
143 148
144 GuestViewContainer.prototype.onElementResize = function(newWidth, newHeight) { 149 GuestViewContainer.prototype.onElementResize = function(newWidth, newHeight) {
145 if (!this.guest.getId()) 150 if (!this.guest.getId())
146 return; 151 return;
147 this.guest.setSize({normal: {width: newWidth, height: newHeight}}); 152 this.guest.setSize({normal: {width: newWidth, height: newHeight}});
148 }; 153 };
149 154
150 GuestViewContainer.prototype.buildParams = function() { 155 GuestViewContainer.prototype.buildParams = function() {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // Delete the callbacks so developers cannot call them and produce unexpected 279 // Delete the callbacks so developers cannot call them and produce unexpected
275 // behavior. 280 // behavior.
276 delete proto.createdCallback; 281 delete proto.createdCallback;
277 delete proto.attachedCallback; 282 delete proto.attachedCallback;
278 delete proto.detachedCallback; 283 delete proto.detachedCallback;
279 delete proto.attributeChangedCallback; 284 delete proto.attributeChangedCallback;
280 } 285 }
281 286
282 // Exports. 287 // Exports.
283 exports.GuestViewContainer = GuestViewContainer; 288 exports.GuestViewContainer = GuestViewContainer;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698