Bug 605079 - "Search engines are not added in the list via nsISidebar" [r=mark.finkle]
--- a/mobile/components/MobileComponents.manifest
+++ b/mobile/components/MobileComponents.manifest
@@ -19,16 +19,17 @@ component {ef0f7a87-c1ee-45a8-8d67-26f58
contract @mozilla.org/browser/directory-provider;1 {ef0f7a87-c1ee-45a8-8d67-26f586e46a4b}
category xpcom-directory-providers browser-directory-provider @mozilla.org/browser/directory-provider;1
# Sidebar.js
component {22117140-9c6e-11d3-aaf1-00805f8a4905} Sidebar.js
contract @mozilla.org/sidebar;1 {22117140-9c6e-11d3-aaf1-00805f8a4905}
category JavaScript-global-property sidebar @mozilla.org/sidebar;1
category JavaScript-global-property external @mozilla.org/sidebar;1
+category wakeup-request Sidebar @mozilla.org/sidebar;1,nsISidebarExternal,getService,Sidebar:AddSearchProvider
# SessionStore.js
component {8c1f07d6-cba3-4226-a315-8bd43d67d032} SessionStore.js
contract @mozilla.org/browser/sessionstore;1 {8c1f07d6-cba3-4226-a315-8bd43d67d032}
category app-startup SessionStore service,@mozilla.org/browser/sessionstore;1
# BrowserStartup.js
component {1d542abc-c88b-4636-a4ef-075b49806317} BrowserStartup.js
--- a/mobile/components/Sidebar.js
+++ b/mobile/components/Sidebar.js
@@ -1,9 +1,8 @@
-# -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
@@ -38,22 +37,48 @@
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
const Ci = Components.interfaces;
+const Cc = Components.classes;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
function Sidebar() {
+ // Depending on if we are in the parent or child, prepare to remote
+ // certain calls
+ var appInfo = Cc["@mozilla.org/xre/app-info;1"];
+ if (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
+ // Parent process
+
+ this.inContentProcess = false;
+
+ // Used for wakeups service. FIXME: clean up with bug 593407
+ this.wrappedJSObject = this;
+
+ // Setup listener for child messages. We don't need to call
+ // addMessageListener as the wakeup service will do that for us.
+ this.receiveMessage = function(aMessage) {
+ switch (aMessage.name) {
+ case "Sidebar:AddSearchProvider":
+ this.AddSearchProvider(aMessage.json.descriptionURL);
+ }
+ };
+ } else {
+ // Child process
+
+ this.inContentProcess = true;
+ this.messageManager = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
+ }
}
Sidebar.prototype = {
// =========================== utility code ===========================
_validateSearchEngine: function validateSearchEngine(engineURL, iconURL) {
try {
// Make sure we're using HTTP, HTTPS, or FTP.
if (! /^(https?|ftp):\/\//i.test(engineURL))
@@ -117,17 +142,23 @@ Sidebar.prototype = {
// =========================== nsISidebarExternal ===========================
// This function exists to implement window.external.AddSearchProvider(),
// to match other browsers' APIs. The capitalization, although nonstandard here,
// is therefore important.
AddSearchProvider: function AddSearchProvider(aDescriptionURL) {
if (!this._validateSearchEngine(aDescriptionURL, ""))
return;
-
+
+ if (this.inContentProcess) {
+ this.messageManager.sendAsyncMessage("Sidebar:AddSearchProvider",
+ { descriptionURL: aDescriptionURL });
+ return;
+ }
+
const typeXML = Ci.nsISearchEngine.DATA_XML;
Services.search.addEngine(aDescriptionURL, typeXML, "", true);
},
// This function exists to implement window.external.IsSearchProviderInstalled(),
// for compatibility with other browsers. It will return an integer value
// indicating whether the given engine is installed for the current user.
// However, it is currently stubbed out due to security/privacy concerns