Bug 1312954 - Part 9: Updating speculativeConnect to speculativeConnect2 for the search service. r?Gijs
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -490,17 +490,19 @@
// received focus, ignore the next focus event.
this._ignoreFocus = (document.activeElement == this._textbox.inputField);
]]></handler>
<handler event="focus">
<![CDATA[
// Speculatively connect to the current engine's search URI (and
// suggest URI, if different) to reduce request latency
- this.currentEngine.speculativeConnect({window});
+ this.currentEngine.speculativeConnect({window,
+ originAttributes: gBrowser.contentPrincipal
+ .originAttributes});
if (this._ignoreFocus) {
// This window has been re-focused, don't show the suggestions
this._ignoreFocus = false;
return;
}
// Don't open the suggestions if there is no text in the textbox.
--- a/browser/modules/ContentSearch.jsm
+++ b/browser/modules/ContentSearch.jsm
@@ -450,16 +450,17 @@ this.ContentSearch = {
_onMessageSpeculativeConnect(msg, engineName) {
let engine = Services.search.getEngineByName(engineName);
if (!engine) {
throw new Error("Unknown engine name: " + engineName);
}
if (msg.target.contentWindow) {
engine.speculativeConnect({
window: msg.target.contentWindow,
+ originAttributes: msg.target.contentPrincipal.originAttributes
});
}
},
_onObserve: Task.async(function* (data) {
if (data === "engine-current") {
let engine = yield this._currentEngineObj();
this._broadcast("CurrentEngine", engine);
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -6099,17 +6099,18 @@ var SearchEngines = {
engine: suggestEngine,
template: suggestTemplate,
enabled: Services.prefs.getBoolPref(this.PREF_SUGGEST_ENABLED),
prompted: Services.prefs.getBoolPref(this.PREF_SUGGEST_PROMPTED)
}
});
// Send a speculative connection to the default engine.
- Services.search.defaultEngine.speculativeConnect({window: window});
+ Services.search.defaultEngine.speculativeConnect({ window: window,
+ originAttributes: {} });
},
// Helper method to extract the engine name from a JSON. Simplifies the observe function.
_extractEngineFromJSON: function _extractEngineFromJSON(aData) {
let data = JSON.parse(aData);
return Services.search.getEngineByName(data.engine);
},
--- a/netwerk/base/nsIBrowserSearchService.idl
+++ b/netwerk/base/nsIBrowserSearchService.idl
@@ -104,16 +104,17 @@ interface nsISearchEngine : nsISupports
/**
* Opens a speculative connection to the engine's search URI
* (and suggest URI, if different) to reduce request latency
*
* @param options
* An object that must contain the following fields:
* {window} the content window for the window performing the search
+ * {originAttributes} the originAttributes for performing the search
*
* @throws NS_ERROR_INVALID_ARG if options is omitted or lacks required
* elemeents
*/
void speculativeConnect(in jsval options);
/**
* An optional shortcut alias for the engine.
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -2553,16 +2553,17 @@ Engine.prototype = {
/**
* Opens a speculative connection to the engine's search URI
* (and suggest URI, if different) to reduce request latency
*
* @param options
* An object that must contain the following fields:
* {window} the content window for the window performing the search
+ * {originAttributes} the originAttributes for performing the search
*
* @throws NS_ERROR_INVALID_ARG if options is omitted or lacks required
* elemeents
*/
speculativeConnect: function SRCH_ENG_speculativeConnect(options) {
if (!options || !options.window) {
Cu.reportError("invalid options arg passed to nsISearchEngine.speculativeConnect");
throw Cr.NS_ERROR_INVALID_ARG;
@@ -2571,22 +2572,36 @@ Engine.prototype = {
Services.io.QueryInterface(Components.interfaces.nsISpeculativeConnect);
let searchURI = this.getSubmission("dummy").uri;
let callbacks = options.window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsILoadContext);
- connector.speculativeConnect(searchURI, callbacks);
+ // Using the codebase principal which is constructed by the search URI
+ // and given originAttributes. If originAttributes are not given, we
+ // fallback to use the docShell's originAttributes.
+ let attrs = options.originAttributes;
+
+ if (!attrs) {
+ attrs = options.window.document
+ .docShell
+ .getOriginAttributes();
+ }
+
+ let principal = Services.scriptSecurityManager
+ .createCodebasePrincipal(searchURI, attrs);
+
+ connector.speculativeConnect2(searchURI, principal, callbacks);
if (this.supportsResponseType(URLTYPE_SUGGEST_JSON)) {
let suggestURI = this.getSubmission("dummy", URLTYPE_SUGGEST_JSON).uri;
if (suggestURI.prePath != searchURI.prePath)
- connector.speculativeConnect(suggestURI, callbacks);
+ connector.speculativeConnect2(suggestURI, principal, callbacks);
}
},
};
// nsISearchSubmission
function Submission(aURI, aPostData = null) {
this._uri = aURI;
this._postData = aPostData;