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 f97867a78a2baf7867273dd1a7c1ffa47850a642..0f2464470f4bc681d2382f62255eab00a0e69bd4 100644 |
--- a/chrome/renderer/resources/extensions/web_view.js |
+++ b/chrome/renderer/resources/extensions/web_view.js |
@@ -14,6 +14,7 @@ var IdGenerator = requireNative('id_generator'); |
// something else. |
var WebView = require('webViewInternal').WebView; |
var WebViewEvents = require('webViewEvents').WebViewEvents; |
+var guestViewInternalNatives = requireNative('guest_view_internal'); |
var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; |
var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; |
@@ -21,8 +22,6 @@ var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; |
var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; |
var WEB_VIEW_ATTRIBUTE_PARTITION = 'partition'; |
-var PLUGIN_METHOD_ATTACH = '-internal-attach'; |
- |
var ERROR_MSG_ALREADY_NAVIGATED = |
'The object has already navigated, so its partition cannot be changed.'; |
var ERROR_MSG_INVALID_PARTITION_ATTRIBUTE = 'Invalid partition attribute.'; |
@@ -145,15 +144,16 @@ WebViewInternal.prototype.createBrowserPluginNode = function() { |
return browserPluginNode; |
}; |
-WebViewInternal.prototype.getInstanceId = function() { |
- return this.instanceId; |
+WebViewInternal.prototype.getGuestInstanceId = function() { |
+ return this.guestInstanceId; |
}; |
/** |
* Resets some state upon reattaching <webview> element to the DOM. |
*/ |
-WebViewInternal.prototype.resetUponReattachment = function() { |
- this.instanceId = undefined; |
+WebViewInternal.prototype.reset = function() { |
+ this.guestInstanceId = undefined; |
+ this.internalInstanceId = 0; |
this.beforeFirstNavigation = true; |
this.validPartitionId = true; |
this.partition.validPartitionId = true; |
@@ -223,10 +223,10 @@ WebViewInternal.prototype.canGoForward = function() { |
* @private |
*/ |
WebViewInternal.prototype.clearData = function() { |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
return; |
} |
- var args = $Array.concat([this.instanceId], $Array.slice(arguments)); |
+ var args = $Array.concat([this.guestInstanceId], $Array.slice(arguments)); |
$Function.apply(WebView.clearData, null, args); |
}; |
@@ -241,10 +241,10 @@ WebViewInternal.prototype.getProcessId = function() { |
* @private |
*/ |
WebViewInternal.prototype.go = function(relativeIndex) { |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
return; |
} |
- WebView.go(this.instanceId, relativeIndex); |
+ WebView.go(this.guestInstanceId, relativeIndex); |
}; |
/** |
@@ -258,30 +258,30 @@ WebViewInternal.prototype.print = function() { |
* @private |
*/ |
WebViewInternal.prototype.reload = function() { |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
return; |
} |
- WebView.reload(this.instanceId); |
+ WebView.reload(this.guestInstanceId); |
}; |
/** |
* @private |
*/ |
WebViewInternal.prototype.stop = function() { |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
return; |
} |
- WebView.stop(this.instanceId); |
+ WebView.stop(this.guestInstanceId); |
}; |
/** |
* @private |
*/ |
WebViewInternal.prototype.terminate = function() { |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
return; |
} |
- WebView.terminate(this.instanceId); |
+ WebView.terminate(this.guestInstanceId); |
}; |
/** |
@@ -290,7 +290,7 @@ WebViewInternal.prototype.terminate = function() { |
WebViewInternal.prototype.validateExecuteCodeCall = function() { |
var ERROR_MSG_CANNOT_INJECT_SCRIPT = '<webview>: ' + |
'Script cannot be injected into content until the page has loaded.'; |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
throw new Error(ERROR_MSG_CANNOT_INJECT_SCRIPT); |
} |
}; |
@@ -300,7 +300,7 @@ WebViewInternal.prototype.validateExecuteCodeCall = function() { |
*/ |
WebViewInternal.prototype.executeScript = function(var_args) { |
this.validateExecuteCodeCall(); |
- var args = $Array.concat([this.instanceId, this.src], |
+ var args = $Array.concat([this.guestInstanceId, this.src], |
$Array.slice(arguments)); |
$Function.apply(WebView.executeScript, null, args); |
}; |
@@ -310,7 +310,7 @@ WebViewInternal.prototype.executeScript = function(var_args) { |
*/ |
WebViewInternal.prototype.insertCSS = function(var_args) { |
this.validateExecuteCodeCall(); |
- var args = $Array.concat([this.instanceId, this.src], |
+ var args = $Array.concat([this.guestInstanceId, this.src], |
$Array.slice(arguments)); |
$Function.apply(WebView.insertCSS, null, args); |
}; |
@@ -456,10 +456,10 @@ WebViewInternal.prototype.handleWebviewAttributeMutation = |
return; |
} |
this.name = newValue; |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
return; |
} |
- WebView.setName(this.instanceId, newValue); |
+ WebView.setName(this.guestInstanceId, newValue); |
return; |
} else if (name == 'src') { |
// We treat null attribute (attribute removed) and the empty string as |
@@ -512,20 +512,21 @@ WebViewInternal.prototype.handleWebviewAttributeMutation = |
*/ |
WebViewInternal.prototype.handleBrowserPluginAttributeMutation = |
function(name, oldValue, newValue) { |
- if (name == 'internalbindings' && !oldValue && newValue) { |
- this.browserPluginNode.removeAttribute('internalbindings'); |
- |
- if (this.deferredAttachState) { |
- var self = this; |
- // A setTimeout is necessary for the binding to be initialized properly. |
+ if (name == 'internalinstanceid' && !oldValue && !!newValue) { |
+ this.browserPluginNode.removeAttribute('internalinstanceid'); |
+ this.internalInstanceId = 1 * newValue; |
+ if (this.deferredAttachState && !!this.guestInstanceId && |
+ this.guestInstanceId != 0) { |
window.setTimeout(function() { |
- if (self.hasBindings()) { |
- var params = self.buildAttachParams( |
- self.deferredAttachState.isNewWindow); |
- self.browserPluginNode[PLUGIN_METHOD_ATTACH](self.instanceId, params); |
- self.deferredAttachState = null; |
- } |
- }, 0); |
+ var isNewWindow = this.deferredAttachState ? |
+ this.deferredAttachState.isNewWindow : false; |
+ var params = this.buildAttachParams(isNewWindow); |
+ guestViewInternalNatives.AttachPlugin( |
+ this.guestInstanceId, |
+ this.internalInstanceId, |
+ params, |
+ this.browserPluginNode); |
+ }.bind(this), 0); |
} |
return; |
} |
@@ -605,10 +606,9 @@ WebViewInternal.prototype.onSizeChanged = function(newWidth, newHeight) { |
} |
}; |
-// Returns true if Browser Plugin bindings is available. |
-// Bindings are unavailable if <object> is not in the render tree. |
-WebViewInternal.prototype.hasBindings = function() { |
- return 'function' == typeof this.browserPluginNode[PLUGIN_METHOD_ATTACH]; |
+// Returns if <object> is in the render tree. |
+WebViewInternal.prototype.isPluginInRenderTree = function() { |
+ return !!this.internalInstanceId && this.internalInstanceId != 0; |
}; |
WebViewInternal.prototype.hasNavigated = function() { |
@@ -640,7 +640,7 @@ WebViewInternal.prototype.parseSrcAttribute = function(result) { |
} |
// Navigate to this.src. |
- WebView.navigate(this.instanceId, this.src); |
+ WebView.navigate(this.guestInstanceId, this.src); |
return true; |
}; |
@@ -653,7 +653,7 @@ WebViewInternal.prototype.parseAttributes = function() { |
}; |
WebViewInternal.prototype.hasGuestInstanceID = function() { |
- return this.instanceId != undefined; |
+ return this.guestInstanceId != undefined; |
}; |
WebViewInternal.prototype.allocateInstanceId = function() { |
@@ -667,10 +667,10 @@ WebViewInternal.prototype.allocateInstanceId = function() { |
GuestViewInternal.createGuest( |
'webview', |
params, |
- function(instanceId) { |
+ function(guestInstanceId) { |
// TODO(lazyboy): Make sure this.autoNavigate_ stuff correctly updated |
// |self.src| at this point. |
- self.attachWindow(instanceId, false); |
+ self.attachWindow(guestInstanceId, false); |
}); |
}; |
@@ -747,43 +747,43 @@ WebViewInternal.prototype.isUserAgentOverridden = function() { |
/** @private */ |
WebViewInternal.prototype.setUserAgentOverride = function(userAgentOverride) { |
this.userAgentOverride = userAgentOverride; |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
// If we are not attached yet, then we will pick up the user agent on |
// attachment. |
return; |
} |
- WebView.overrideUserAgent(this.instanceId, userAgentOverride); |
+ WebView.overrideUserAgent(this.guestInstanceId, userAgentOverride); |
}; |
/** @private */ |
WebViewInternal.prototype.find = function(search_text, options, callback) { |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
return; |
} |
- WebView.find(this.instanceId, search_text, options, callback); |
+ WebView.find(this.guestInstanceId, search_text, options, callback); |
}; |
/** @private */ |
WebViewInternal.prototype.stopFinding = function(action) { |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
return; |
} |
- WebView.stopFinding(this.instanceId, action); |
+ WebView.stopFinding(this.guestInstanceId, action); |
}; |
/** @private */ |
WebViewInternal.prototype.setZoom = function(zoomFactor, callback) { |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
return; |
} |
- WebView.setZoom(this.instanceId, zoomFactor, callback); |
+ WebView.setZoom(this.guestInstanceId, zoomFactor, callback); |
}; |
WebViewInternal.prototype.getZoom = function(callback) { |
- if (!this.instanceId) { |
+ if (!this.guestInstanceId) { |
return; |
} |
- WebView.getZoom(this.instanceId, callback); |
+ WebView.getZoom(this.guestInstanceId, callback); |
}; |
WebViewInternal.prototype.buildAttachParams = function(isNewWindow) { |
@@ -801,19 +801,20 @@ WebViewInternal.prototype.buildAttachParams = function(isNewWindow) { |
return params; |
}; |
-WebViewInternal.prototype.attachWindow = function(instanceId, isNewWindow) { |
- this.instanceId = instanceId; |
+WebViewInternal.prototype.attachWindow = function(guestInstanceId, |
+ isNewWindow) { |
+ this.guestInstanceId = guestInstanceId; |
var params = this.buildAttachParams(isNewWindow); |
- if (!this.hasBindings()) { |
- // No bindings means that the plugin isn't there (display: none), we defer |
- // attachWindow in this case. |
+ if (!this.isPluginInRenderTree()) { |
this.deferredAttachState = {isNewWindow: isNewWindow}; |
return false; |
} |
this.deferredAttachState = null; |
- return this.browserPluginNode[PLUGIN_METHOD_ATTACH](this.instanceId, params); |
+ return guestViewInternalNatives.AttachPlugin( |
+ this.guestInstanceId, this.internalInstanceId, params, |
+ this.browserPluginNode); |
}; |
// Registers browser plugin <object> custom element. |
@@ -872,6 +873,7 @@ function registerWebViewElement() { |
return; |
} |
internal.elementAttached = false; |
+ internal.reset(); |
}; |
proto.attachedCallback = function() { |
@@ -881,7 +883,6 @@ function registerWebViewElement() { |
} |
if (!internal.elementAttached) { |
internal.elementAttached = true; |
- internal.resetUponReattachment(); |
internal.parseAttributes(); |
} |
}; |
@@ -968,7 +969,7 @@ WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { |
// Setting |params| = undefined will show the context menu unmodified, hence |
// the 'contextmenu' API is disabled for stable channel. |
var params = undefined; |
- WebView.showContextMenu(this.instanceId, requestId, params); |
+ WebView.showContextMenu(this.guestInstanceId, requestId, params); |
}; |
/** |