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

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

Issue 954543002: <webview>: Fix SrcAttribute and Cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 | « no previous file | extensions/renderer/resources/guest_view/web_view_attributes.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 WebView (<webview>) as a custom element that wraps a 5 // This module implements WebView (<webview>) as a custom element that wraps a
6 // BrowserPlugin object element. The object element is hidden within 6 // BrowserPlugin object element. The object element is hidden within
7 // the shadow DOM of the WebView element. 7 // the shadow DOM of the WebView element.
8 8
9 var DocumentNatives = requireNative('document_natives'); 9 var DocumentNatives = requireNative('document_natives');
10 var GuestView = require('guestView').GuestView; 10 var GuestView = require('guestView').GuestView;
11 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; 11 var GuestViewContainer = require('guestViewContainer').GuestViewContainer;
12 var WebViewConstants = require('webViewConstants').WebViewConstants; 12 var WebViewConstants = require('webViewConstants').WebViewConstants;
13 var WebViewEvents = require('webViewEvents').WebViewEvents; 13 var WebViewEvents = require('webViewEvents').WebViewEvents;
14 var WebViewInternal = require('webViewInternal').WebViewInternal; 14 var WebViewInternal = require('webViewInternal').WebViewInternal;
15 15
16 // Represents the internal state of <webview>. 16 // Represents the internal state of <webview>.
17 function WebViewImpl(webviewElement) { 17 function WebViewImpl(webviewElement) {
18 GuestViewContainer.call(this, webviewElement, 'webview'); 18 GuestViewContainer.call(this, webviewElement, 'webview');
19 19
20 this.setupWebViewAttributes(); 20 this.setupWebViewAttributes();
21 this.setupElementProperties(); 21 this.setupElementProperties();
22 22
23 // on* Event handlers.
24 this.on = {};
25 new WebViewEvents(this, this.viewInstanceId); 23 new WebViewEvents(this, this.viewInstanceId);
26 } 24 }
27 25
28 WebViewImpl.prototype.__proto__ = GuestViewContainer.prototype; 26 WebViewImpl.prototype.__proto__ = GuestViewContainer.prototype;
29 27
30 WebViewImpl.VIEW_TYPE = 'WebView'; 28 WebViewImpl.VIEW_TYPE = 'WebView';
31 29
32 // Add extra functionality to |this.element|. 30 // Add extra functionality to |this.element|.
33 WebViewImpl.setupElement = function(proto) { 31 WebViewImpl.setupElement = function(proto) {
34 // Public-facing API methods. 32 // Public-facing API methods.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 147 }
150 }; 148 };
151 149
152 WebViewImpl.prototype.createGuest = function() { 150 WebViewImpl.prototype.createGuest = function() {
153 this.guest.create(this.buildParams(), function() { 151 this.guest.create(this.buildParams(), function() {
154 this.attachWindow(); 152 this.attachWindow();
155 }.bind(this)); 153 }.bind(this));
156 }; 154 };
157 155
158 WebViewImpl.prototype.onFrameNameChanged = function(name) { 156 WebViewImpl.prototype.onFrameNameChanged = function(name) {
159 name = name || ''; 157 this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValueIgnoreMutation(name);
160 if (name === '') {
161 this.element.removeAttribute(WebViewConstants.ATTRIBUTE_NAME);
162 } else {
163 this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValue(name);
164 }
165 }; 158 };
166 159
167 WebViewImpl.prototype.dispatchEvent = function(webViewEvent) { 160 WebViewImpl.prototype.dispatchEvent = function(webViewEvent) {
168 return this.element.dispatchEvent(webViewEvent); 161 return this.element.dispatchEvent(webViewEvent);
169 }; 162 };
170 163
171 // Adds an 'on<event>' property on the webview, which can be used to set/unset
172 // an event handler.
173 WebViewImpl.prototype.setupEventProperty = function(eventName) {
174 var propertyName = 'on' + eventName.toLowerCase();
175 Object.defineProperty(this.element, propertyName, {
176 get: function() {
177 return this.on[propertyName];
178 }.bind(this),
179 set: function(value) {
180 if (this.on[propertyName])
181 this.element.removeEventListener(eventName, this.on[propertyName]);
182 this.on[propertyName] = value;
183 if (value)
184 this.element.addEventListener(eventName, value);
185 }.bind(this),
186 enumerable: true
187 });
188 };
189
190 // Updates state upon loadcommit. 164 // Updates state upon loadcommit.
191 WebViewImpl.prototype.onLoadCommit = function( 165 WebViewImpl.prototype.onLoadCommit = function(
192 baseUrlForDataUrl, currentEntryIndex, entryCount, 166 baseUrlForDataUrl, currentEntryIndex, entryCount,
193 processId, url, isTopLevel) { 167 processId, url, isTopLevel) {
194 this.baseUrlForDataUrl = baseUrlForDataUrl; 168 this.baseUrlForDataUrl = baseUrlForDataUrl;
195 this.currentEntryIndex = currentEntryIndex; 169 this.currentEntryIndex = currentEntryIndex;
196 this.entryCount = entryCount; 170 this.entryCount = entryCount;
197 this.processId = processId; 171 this.processId = processId;
198 var oldValue = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); 172 if (isTopLevel) {
199 var newValue = url;
200 if (isTopLevel && (oldValue != newValue)) {
201 // Touching the src attribute triggers a navigation. To avoid 173 // Touching the src attribute triggers a navigation. To avoid
202 // triggering a page reload on every guest-initiated navigation, 174 // triggering a page reload on every guest-initiated navigation,
203 // we do not handle this mutation. 175 // we do not handle this mutation.
204 this.attributes[WebViewConstants.ATTRIBUTE_SRC].setValueIgnoreMutation( 176 this.attributes[
205 newValue); 177 WebViewConstants.ATTRIBUTE_SRC].setValueIgnoreMutation(url);
206 } 178 }
207 }; 179 };
208 180
209 WebViewImpl.prototype.onAttach = function(storagePartitionId) { 181 WebViewImpl.prototype.onAttach = function(storagePartitionId) {
210 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].setValue( 182 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].setValueIgnoreMutation(
211 storagePartitionId); 183 storagePartitionId);
212 }; 184 };
213 185
214 WebViewImpl.prototype.buildContainerParams = function() { 186 WebViewImpl.prototype.buildContainerParams = function() {
215 var params = { 'userAgentOverride': this.userAgentOverride }; 187 var params = { 'userAgentOverride': this.userAgentOverride };
216 for (var i in this.attributes) { 188 for (var i in this.attributes) {
217 params[i] = this.attributes[i].getValue(); 189 params[i] = this.attributes[i].getValue();
218 } 190 }
219 return params; 191 return params;
220 }; 192 };
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 WebViewImpl.prototype.setupExperimentalContextMenus = function() {}; 231 WebViewImpl.prototype.setupExperimentalContextMenus = function() {};
260 WebViewImpl.prototype.maybeSetupExperimentalChromeWebViewEvents = 232 WebViewImpl.prototype.maybeSetupExperimentalChromeWebViewEvents =
261 function(request) { 233 function(request) {
262 return request; 234 return request;
263 }; 235 };
264 236
265 GuestViewContainer.registerElement(WebViewImpl); 237 GuestViewContainer.registerElement(WebViewImpl);
266 238
267 // Exports. 239 // Exports.
268 exports.WebViewImpl = WebViewImpl; 240 exports.WebViewImpl = WebViewImpl;
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/resources/guest_view/web_view_attributes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698