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

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

Issue 926083002: Decouple web_view.js from attribute internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ignore_mutation
Patch Set: Rebased Created 5 years, 10 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
« no previous file with comments | « extensions/renderer/resources/guest_view/web_view.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 attributes of the <webview> tag. 5 // This module implements the attributes of the <webview> tag.
6 6
7 var GuestViewInternal = 7 var GuestViewInternal =
8 require('binding').Binding.create('guestViewInternal').generate(); 8 require('binding').Binding.create('guestViewInternal').generate();
9 var WebViewImpl = require('webView').WebViewImpl; 9 var WebViewImpl = require('webView').WebViewImpl;
10 var WebViewConstants = require('webViewConstants').WebViewConstants; 10 var WebViewConstants = require('webViewConstants').WebViewConstants;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 if (this.ignoreMutation) { 57 if (this.ignoreMutation) {
58 return; 58 return;
59 } 59 }
60 60
61 this.handleMutation(oldValue, newValue); 61 this.handleMutation(oldValue, newValue);
62 }; 62 };
63 63
64 // Called when a change that isn't ignored occurs to the attribute's value. 64 // Called when a change that isn't ignored occurs to the attribute's value.
65 WebViewAttribute.prototype.handleMutation = function(oldValue, newValue) {}; 65 WebViewAttribute.prototype.handleMutation = function(oldValue, newValue) {};
66 66
67 // Called when the <webview> element is detached from the DOM tree.
68 WebViewAttribute.prototype.reset = function() {};
69
67 // An attribute that is treated as a Boolean. 70 // An attribute that is treated as a Boolean.
68 function BooleanAttribute(name, webViewImpl) { 71 function BooleanAttribute(name, webViewImpl) {
69 WebViewAttribute.call(this, name, webViewImpl); 72 WebViewAttribute.call(this, name, webViewImpl);
70 } 73 }
71 74
72 BooleanAttribute.prototype.__proto__ = WebViewAttribute.prototype; 75 BooleanAttribute.prototype.__proto__ = WebViewAttribute.prototype;
73 76
74 BooleanAttribute.prototype.getValue = function() { 77 BooleanAttribute.prototype.getValue = function() {
75 return this.webViewImpl.element.hasAttribute(this.name); 78 return this.webViewImpl.element.hasAttribute(this.name);
76 }; 79 };
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 this, WebViewConstants.ATTRIBUTE_PARTITION, webViewImpl); 172 this, WebViewConstants.ATTRIBUTE_PARTITION, webViewImpl);
170 this.validPartitionId = true; 173 this.validPartitionId = true;
171 } 174 }
172 175
173 PartitionAttribute.prototype.__proto__ = WebViewAttribute.prototype; 176 PartitionAttribute.prototype.__proto__ = WebViewAttribute.prototype;
174 177
175 PartitionAttribute.prototype.handleMutation = function(oldValue, newValue) { 178 PartitionAttribute.prototype.handleMutation = function(oldValue, newValue) {
176 newValue = newValue || ''; 179 newValue = newValue || '';
177 180
178 // The partition cannot change if the webview has already navigated. 181 // The partition cannot change if the webview has already navigated.
179 if (!this.webViewImpl.beforeFirstNavigation) { 182 if (!this.webViewImpl.attributes[
183 WebViewConstants.ATTRIBUTE_SRC].beforeFirstNavigation) {
180 window.console.error(WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED); 184 window.console.error(WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED);
181 this.setValueIgnoreMutation(oldValue); 185 this.setValueIgnoreMutation(oldValue);
182 return; 186 return;
183 } 187 }
184 if (newValue == 'persist:') { 188 if (newValue == 'persist:') {
185 this.validPartitionId = false; 189 this.validPartitionId = false;
186 window.console.error( 190 window.console.error(
187 WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE); 191 WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE);
188 } 192 }
189 }; 193 };
190 194
195 PartitionAttribute.prototype.reset = function() {
196 this.validPartitionId = true;
197 };
198
191 // Attribute that handles the location and navigation of the webview. 199 // Attribute that handles the location and navigation of the webview.
192 function SrcAttribute(webViewImpl) { 200 function SrcAttribute(webViewImpl) {
193 WebViewAttribute.call(this, WebViewConstants.ATTRIBUTE_SRC, webViewImpl); 201 WebViewAttribute.call(this, WebViewConstants.ATTRIBUTE_SRC, webViewImpl);
194 this.setupMutationObserver(); 202 this.setupMutationObserver();
203 this.beforeFirstNavigation = true;
195 } 204 }
196 205
197 SrcAttribute.prototype.__proto__ = WebViewAttribute.prototype; 206 SrcAttribute.prototype.__proto__ = WebViewAttribute.prototype;
198 207
199 SrcAttribute.prototype.setValueIgnoreMutation = function(value) { 208 SrcAttribute.prototype.setValueIgnoreMutation = function(value) {
200 // takeRecords() is needed to clear queued up src mutations. Without it, it is 209 // takeRecords() is needed to clear queued up src mutations. Without it, it is
201 // possible for this change to get picked up asyncronously by src's mutation 210 // possible for this change to get picked up asyncronously by src's mutation
202 // observer |observer|, and then get handled even though we do not want to 211 // observer |observer|, and then get handled even though we do not want to
203 // handle this mutation. 212 // handle this mutation.
204 this.observer.takeRecords(); 213 this.observer.takeRecords();
205 this.ignoreMutation = true; 214 this.ignoreMutation = true;
206 this.webViewImpl.element.setAttribute(this.name, value || ''); 215 this.webViewImpl.element.setAttribute(this.name, value || '');
207 this.ignoreMutation = false; 216 this.ignoreMutation = false;
208 } 217 }
209 218
210 SrcAttribute.prototype.handleMutation = function(oldValue, newValue) { 219 SrcAttribute.prototype.handleMutation = function(oldValue, newValue) {
211 // Once we have navigated, we don't allow clearing the src attribute. 220 // Once we have navigated, we don't allow clearing the src attribute.
212 // Once <webview> enters a navigated state, it cannot return to a 221 // Once <webview> enters a navigated state, it cannot return to a
213 // placeholder state. 222 // placeholder state.
214 if (!newValue && oldValue) { 223 if (!newValue && oldValue) {
215 // src attribute changes normally initiate a navigation. We suppress 224 // src attribute changes normally initiate a navigation. We suppress
216 // the next src attribute handler call to avoid reloading the page 225 // the next src attribute handler call to avoid reloading the page
217 // on every guest-initiated navigation. 226 // on every guest-initiated navigation.
218 this.setValueIgnoreMutation(oldValue); 227 this.setValueIgnoreMutation(oldValue);
219 return; 228 return;
220 } 229 }
221 this.parse(); 230 this.parse();
222 }; 231 };
223 232
233 SrcAttribute.prototype.reset = function() {
234 this.beforeFirstNavigation = true;
235 };
236
224 // The purpose of this mutation observer is to catch assignment to the src 237 // The purpose of this mutation observer is to catch assignment to the src
225 // attribute without any changes to its value. This is useful in the case 238 // attribute without any changes to its value. This is useful in the case
226 // where the webview guest has crashed and navigating to the same address 239 // where the webview guest has crashed and navigating to the same address
227 // spawns off a new process. 240 // spawns off a new process.
228 SrcAttribute.prototype.setupMutationObserver = 241 SrcAttribute.prototype.setupMutationObserver =
229 function() { 242 function() {
230 this.observer = new MutationObserver(function(mutations) { 243 this.observer = new MutationObserver(function(mutations) {
231 $Array.forEach(mutations, function(mutation) { 244 $Array.forEach(mutations, function(mutation) {
232 var oldValue = mutation.oldValue; 245 var oldValue = mutation.oldValue;
233 var newValue = this.getValue(); 246 var newValue = this.getValue();
(...skipping 13 matching lines...) Expand all
247 260
248 SrcAttribute.prototype.parse = function() { 261 SrcAttribute.prototype.parse = function() {
249 if (!this.webViewImpl.elementAttached || 262 if (!this.webViewImpl.elementAttached ||
250 !this.webViewImpl.attributes[ 263 !this.webViewImpl.attributes[
251 WebViewConstants.ATTRIBUTE_PARTITION].validPartitionId || 264 WebViewConstants.ATTRIBUTE_PARTITION].validPartitionId ||
252 !this.getValue()) { 265 !this.getValue()) {
253 return; 266 return;
254 } 267 }
255 268
256 if (!this.webViewImpl.guest.getId()) { 269 if (!this.webViewImpl.guest.getId()) {
257 if (this.webViewImpl.beforeFirstNavigation) { 270 if (this.beforeFirstNavigation) {
258 this.webViewImpl.beforeFirstNavigation = false; 271 this.beforeFirstNavigation = false;
259 this.webViewImpl.createGuest(); 272 this.webViewImpl.createGuest();
260 } 273 }
261 return; 274 return;
262 } 275 }
263 276
264 // Navigate to |src|. 277 // Navigate to |src|.
265 WebViewInternal.navigate(this.webViewImpl.guest.getId(), this.getValue()); 278 WebViewInternal.navigate(this.webViewImpl.guest.getId(), this.getValue());
266 }; 279 };
267 280
268 // ----------------------------------------------------------------------------- 281 // -----------------------------------------------------------------------------
(...skipping 15 matching lines...) Expand all
284 297
285 var autosizeAttributes = [WebViewConstants.ATTRIBUTE_MAXHEIGHT, 298 var autosizeAttributes = [WebViewConstants.ATTRIBUTE_MAXHEIGHT,
286 WebViewConstants.ATTRIBUTE_MAXWIDTH, 299 WebViewConstants.ATTRIBUTE_MAXWIDTH,
287 WebViewConstants.ATTRIBUTE_MINHEIGHT, 300 WebViewConstants.ATTRIBUTE_MINHEIGHT,
288 WebViewConstants.ATTRIBUTE_MINWIDTH]; 301 WebViewConstants.ATTRIBUTE_MINWIDTH];
289 for (var i = 0; autosizeAttributes[i]; ++i) { 302 for (var i = 0; autosizeAttributes[i]; ++i) {
290 this.attributes[autosizeAttributes[i]] = 303 this.attributes[autosizeAttributes[i]] =
291 new AutosizeDimensionAttribute(autosizeAttributes[i], this); 304 new AutosizeDimensionAttribute(autosizeAttributes[i], this);
292 } 305 }
293 }; 306 };
OLDNEW
« no previous file with comments | « extensions/renderer/resources/guest_view/web_view.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698