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

Unified Diff: chrome/renderer/resources/extensions/web_view.js

Issue 291483010: <webview>: Move name attribute to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@newwindow_refactor
Patch Set: Addressed John's comments Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/web_view.js
diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js
index 3a8627c0cbe4c7cb67e3b306f2ef7888a99650d0..f00fb9b2e6a3440181199217b7d9d4a3e8bba2c3 100644
--- a/chrome/renderer/resources/extensions/web_view.js
+++ b/chrome/renderer/resources/extensions/web_view.js
@@ -26,7 +26,6 @@ var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth';
var WEB_VIEW_ATTRIBUTES = [
'allowtransparency',
'autosize',
- 'name',
'partition',
WEB_VIEW_ATTRIBUTE_MINHEIGHT,
WEB_VIEW_ATTRIBUTE_MINWIDTH,
@@ -53,6 +52,9 @@ var CreateEvent = function(name) {
// behavior can be canceled. If the default action associated with the event
// is prevented, then its dispatch function will return false in its event
// handler. The event must have a custom handler for this to be meaningful.
+
+var FrameNameChangedEvent = CreateEvent('webview.onFrameNameChanged');
+
var WEB_VIEW_EVENTS = {
'close': {
evt: CreateEvent('webview.onClose'),
@@ -387,6 +389,16 @@ WebViewInternal.prototype.setupWebviewNodeProperties = function() {
enumerable: true
});
+ Object.defineProperty(this.webviewNode, 'name', {
+ get: function() {
+ return self.name;
+ },
+ set: function(value) {
+ self.webviewNode.setAttribute('name', value);
+ },
+ enumerable: true
+ });
+
// We cannot use {writable: true} property descriptor because we want a
// dynamic getter value.
Object.defineProperty(this.webviewNode, 'contentWindow', {
@@ -446,7 +458,22 @@ WebViewInternal.prototype.handleWebviewAttributeMutation =
// a BrowserPlugin property will update the corresponding BrowserPlugin
// attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more
// details.
- if (name == 'src') {
+ if (name == 'name') {
+ // We treat null attribute (attribute removed) and the empty string as
+ // one case.
+ oldValue = oldValue || '';
+ newValue = newValue || '';
+
+ if (oldValue === newValue) {
+ return;
+ }
+ this.name = newValue;
+ if (!this.instanceId) {
+ return;
+ }
+ WebView.setName(this.instanceId, newValue);
+ return;
+ } else if (name == 'src') {
// We treat null attribute (attribute removed) and the empty string as
// one case.
oldValue = oldValue || '';
@@ -595,6 +622,21 @@ WebViewInternal.prototype.setupWebviewNodeEvents = function() {
/**
* @private
*/
+WebViewInternal.prototype.setupNameAttribute = function() {
+ var self = this;
+ FrameNameChangedEvent.addListener(function(event) {
+ self.name = event.name || '';
+ if (self.name === '') {
+ self.webviewNode.removeAttribute('name');
+ } else {
+ self.webviewNode.setAttribute('name', self.name);
+ }
+ }, {instanceId: self.instanceId});
+};
+
+/**
+ * @private
+ */
WebViewInternal.prototype.setupEvent = function(eventName, eventInfo) {
var self = this;
var webviewNode = this.webviewNode;
@@ -1024,17 +1066,20 @@ WebViewInternal.prototype.attachWindowAndSetUpEvents = function(instanceId) {
this.instanceId = instanceId;
var params = {
'api': 'webview',
- 'instanceId': this.viewInstanceId
+ 'instanceId': this.viewInstanceId,
+ 'name': this.name
};
if (this.userAgentOverride) {
params['userAgentOverride'] = this.userAgentOverride;
}
- this.browserPluginNode['-internal-attach'](this.instanceId, params);
-
+ this.setupNameAttribute();
var events = this.getEvents();
for (var eventName in events) {
this.setupEvent(eventName, events[eventName]);
}
+
+ this.browserPluginNode['-internal-attach'](this.instanceId, params);
+
return true;
};
« no previous file with comments | « chrome/renderer/chrome_render_view_observer.cc ('k') | content/browser/browser_plugin/browser_plugin_guest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698