Files
tubestation/toolkit/components/search/nsSidebar.js
Dave Townsend bb7ee9f2fb Bug 1068186: Update window.sidebar and window.external APIs to support e10s. r=felipe
Moves nsSidebar.js to toolkit and makes it just pass messages to chrome for each
API call. MainProcessSingleton listens for those messages and passes the call
along to the search service.
Combines the validation code into the same function and takes the opportunity to
support relative URLs too.
Adds a bunch of tests for these web APIs.

Also fixes:
Bug 518929: Implement window.external APIs in core code
Bug 530847: Remove Fennec's nsISidebar implementation once that code is moved into the core
Bug 517720: Adding a search engine using relative URIs is not supported
2015-02-02 12:15:26 -08:00

64 lines
2.3 KiB
JavaScript

/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const { interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
// File extension for Sherlock search plugin description files
const SHERLOCK_FILE_EXT_REGEXP = /\.src$/i;
function nsSidebar() {
}
nsSidebar.prototype = {
init: function(window) {
this.window = window;
this.mm = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIContentFrameMessageManager);
},
// The suggestedTitle and suggestedCategory parameters are ignored, but remain
// for backward compatibility.
addSearchEngine: function(engineURL, iconURL, suggestedTitle, suggestedCategory) {
let dataType = SHERLOCK_FILE_EXT_REGEXP.test(engineURL) ?
Ci.nsISearchEngine.DATA_TEXT :
Ci.nsISearchEngine.DATA_XML;
this.mm.sendAsyncMessage("Search:AddEngine", {
pageURL: this.window.document.documentURIObject.spec,
engineURL,
type: dataType,
iconURL
});
},
// This function exists largely to implement window.external.AddSearchProvider(),
// to match other browsers' APIs. The capitalization, although nonstandard here,
// is therefore important.
AddSearchProvider: function(engineURL) {
this.mm.sendAsyncMessage("Search:AddEngine", {
pageURL: this.window.document.documentURIObject.spec,
engineURL,
type: Ci.nsISearchEngine.DATA_XML
});
},
// This function exists to implement window.external.IsSearchProviderInstalled(),
// for compatibility with other browsers. The function has been deprecated
// and so will not be implemented.
IsSearchProviderInstalled: function(engineURL) {
return 0;
},
classID: Components.ID("{22117140-9c6e-11d3-aaf1-00805f8a4905}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
Ci.nsIDOMGlobalPropertyInitializer])
}
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsSidebar]);