bug 600244 - Some cleanups in search and sidebar code found by SeaMonkey's OpenSearch work, r=gavin

This commit is contained in:
Robert Kaiser 2011-05-23 22:14:21 +02:00
parent 1fc2b406e5
commit da07d8c5a7
2 changed files with 17 additions and 47 deletions

View File

@ -3346,7 +3346,7 @@ const BrowserSearch = {
var win = getTopWin();
if (win) {
// If there's an open browser window, it should handle this command
win.focus()
win.focus();
win.BrowserSearch.webSearch();
} else {
// If there are no open browser windows, open a new one
@ -3356,7 +3356,7 @@ const BrowserSearch = {
Services.obs.removeObserver(observer, "browser-delayed-startup-finished");
}
}
win = window.openDialog("chrome://browser/content/", "_blank",
win = window.openDialog(getBrowserURL(), "_blank",
"chrome,all,dialog=no", "about:blank");
Services.obs.addObserver(observer, "browser-delayed-startup-finished", false);
}

View File

@ -41,6 +41,7 @@
#
# ***** END LICENSE BLOCK *****
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
const DEBUG = false; /* set to false to suppress debug messages */
@ -56,15 +57,6 @@ const SHERLOCK_FILE_EXT_REGEXP = /\.src$/i;
function nsSidebar()
{
const PROMPTSERVICE_CONTRACTID = "@mozilla.org/embedcomp/prompt-service;1";
const nsIPromptService = Components.interfaces.nsIPromptService;
this.promptService =
Components.classes[PROMPTSERVICE_CONTRACTID].getService(nsIPromptService);
const SEARCHSERVICE_CONTRACTID = "@mozilla.org/browser/search-service;1";
const nsIBrowserSearchService = Components.interfaces.nsIBrowserSearchService;
this.searchService =
Components.classes[SEARCHSERVICE_CONTRACTID].getService(nsIBrowserSearchService);
}
nsSidebar.prototype.classID = SIDEBAR_CID;
@ -102,20 +94,15 @@ function(aTitle, aContentURL, aCustomizeURL)
nsSidebar.prototype.addPanelInternal =
function (aTitle, aContentURL, aCustomizeURL, aPersist)
{
var WINMEDSVC = Components.classes['@mozilla.org/appshell/window-mediator;1']
.getService(Components.interfaces.nsIWindowMediator);
// XXX Bug 620418: We shouldn't do this anymore. Instead, we should find the
// global object for our caller and use it.
var win = WINMEDSVC.getMostRecentWindow( "navigator:browser" );
var win = Services.wm.getMostRecentWindow("navigator:browser");
if (!sidebarURLSecurityCheck(aContentURL))
return;
var uri = null;
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
try {
uri = ioService.newURI(aContentURL, null, null);
uri = Services.io.newURI(aContentURL, null, null);
}
catch(ex) { return; }
@ -141,7 +128,7 @@ function (engineURL, iconURL)
if (!isWeb.test(engineURL))
throw "Unsupported search engine URL";
if (iconURL && !isWeb.test(iconURL))
throw "Unsupported search icon URL.";
}
@ -149,19 +136,17 @@ function (engineURL, iconURL)
{
debug(ex);
Components.utils.reportError("Invalid argument passed to window.sidebar.addSearchEngine: " + ex);
var searchBundle = srGetStrBundle("chrome://global/locale/search/search.properties");
var brandBundle = srGetStrBundle("chrome://branding/locale/brand.properties");
var searchBundle = Services.strings.createBundle("chrome://global/locale/search/search.properties");
var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
var brandName = brandBundle.GetStringFromName("brandShortName");
var title = searchBundle.GetStringFromName("error_invalid_engine_title");
var msg = searchBundle.formatStringFromName("error_invalid_engine_msg",
[brandName], 1);
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].
getService(Components.interfaces.nsIWindowWatcher);
ww.getNewPrompter(null).alert(title, msg);
Services.ww.getNewPrompter(null).alert(title, msg);
return false;
}
return true;
}
@ -185,7 +170,7 @@ function (engineURL, iconURL, suggestedTitle, suggestedCategory)
else
dataType = Components.interfaces.nsISearchEngine.DATA_XML;
this.searchService.addEngine(engineURL, dataType, iconURL, true);
Services.search.addEngine(engineURL, dataType, iconURL, true);
}
// This function exists largely to implement window.external.AddSearchProvider(),
@ -198,23 +183,21 @@ function (aDescriptionURL)
// page since we don't have easy access to the active document. Most search
// engines will override this with an icon specified in the OpenSearch
// description anyway.
var WINMEDSVC = Components.classes['@mozilla.org/appshell/window-mediator;1']
.getService(Components.interfaces.nsIWindowMediator);
var win = WINMEDSVC.getMostRecentWindow("navigator:browser");
var browser = win.document.getElementById("content");
var win = Services.wm.getMostRecentWindow("navigator:browser");
var browser = win.gBrowser;
var iconURL = "";
// Use documentURIObject in the check for shouldLoadFavIcon so that we
// do the right thing with about:-style error pages. Bug 453442
if (browser.shouldLoadFavIcon(browser.selectedBrowser
.contentDocument
.documentURIObject))
iconURL = win.gBrowser.getIcon();
iconURL = browser.getIcon();
if (!this.validateSearchEngine(aDescriptionURL, iconURL))
return;
const typeXML = Components.interfaces.nsISearchEngine.DATA_XML;
this.searchService.addEngine(aDescriptionURL, typeXML, iconURL, true);
Services.search.addEngine(aDescriptionURL, typeXML, iconURL, true);
}
// This function exists to implement window.external.IsSearchProviderInstalled(),
@ -265,16 +248,3 @@ if (DEBUG)
debug = function (s) { dump("-*- sidebar component: " + s + "\n"); }
else
debug = function (s) {}
// String bundle service
var gStrBundleService = null;
function srGetStrBundle(path)
{
if (!gStrBundleService)
gStrBundleService =
Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
return gStrBundleService.createBundle(path);
}