Bug 1702240. Change nsDocShell's notification of keyword-search pass a string rather than an engine. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D130336
This commit is contained in:
Evgenia Kotovich 2021-11-17 09:28:06 +00:00
Родитель a62c197b64
Коммит 5264bfd45a
3 изменённых файлов: 19 добавлений и 18 удалений

Просмотреть файл

@ -1124,7 +1124,9 @@ BrowserGlue.prototype = {
// URI that it's been asked to load into a keyword search.
let engine = null;
try {
engine = subject.QueryInterface(Ci.nsISearchEngine);
engine = Services.search.getEngineByName(
subject.QueryInterface(Ci.nsISupportsString).data
);
} catch (ex) {
Cu.reportError(ex);
}

Просмотреть файл

@ -146,6 +146,7 @@
#include "nsIScriptSecurityManager.h"
#include "nsIScrollableFrame.h"
#include "nsIScrollObserver.h"
#include "nsISupportsPrimitives.h"
#include "nsISecureBrowserUI.h"
#include "nsISeekableStream.h"
#include "nsISelectionDisplay.h"
@ -203,7 +204,6 @@
#include "nsEscape.h"
#include "nsFocusManager.h"
#include "nsGlobalWindow.h"
#include "nsISearchService.h"
#include "nsJSEnvironment.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
@ -13231,20 +13231,19 @@ void nsDocShell::MaybeNotifyKeywordSearchLoading(const nsString& aProvider,
if (aProvider.IsEmpty()) {
return;
}
nsresult rv;
nsCOMPtr<nsISupportsString> isupportsString =
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
NS_ENSURE_SUCCESS_VOID(rv);
nsCOMPtr<nsISearchService> searchSvc =
do_GetService("@mozilla.org/browser/search-service;1");
if (searchSvc) {
nsCOMPtr<nsISearchEngine> searchEngine;
searchSvc->GetEngineByName(aProvider, getter_AddRefs(searchEngine));
if (searchEngine) {
nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService();
if (obsSvc) {
// Note that "keyword-search" refers to a search via the url
// bar, not a bookmarks keyword search.
obsSvc->NotifyObservers(searchEngine, "keyword-search", aKeyword.get());
}
}
rv = isupportsString->SetData(aProvider);
NS_ENSURE_SUCCESS_VOID(rv);
nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService();
if (obsSvc) {
// Note that "keyword-search" refers to a search via the url
// bar, not a bookmarks keyword search.
obsSvc->NotifyObservers(isupportsString, "keyword-search", aKeyword.get());
}
}

Просмотреть файл

@ -46,9 +46,9 @@ add_task(async function() {
let [subject, data] = await TestUtils.topicObserved("keyword-search");
let engine = Services.search.defaultEngine;
Assert.ok(engine, "Have default search engine.");
Assert.equal(engine, subject, "Notification subject is engine.");
let engine = subject.QueryInterface(Ci.nsISupportsString).data;
Assert.equal(engine, kSearchEngineID, "Should be the search engine id");
Assert.equal(data, "firefox", "Notification data is search term.");
gBrowser.removeTab(tab);