From 22e6962ade112630b8921f4921d1b43c22564df1 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Thu, 11 Sep 2014 14:50:55 +0100 Subject: [PATCH] Bug 1057166 - move FHR reporting out of docshell and fix test to work in e10s, r=bz --- browser/base/content/browser.js | 2 +- docshell/base/nsDefaultURIFixup.cpp | 107 +++++++++--------- docshell/base/nsDefaultURIFixup.h | 6 +- docshell/base/nsDocShell.cpp | 68 ++++++++++- docshell/base/nsDocShell.h | 3 + docshell/base/nsIURIFixup.idl | 19 +++- docshell/test/browser/browser.ini | 1 - .../browser/browser_search_notification.js | 21 ++++ .../test/unit/test_nsDefaultURIFixup_info.js | 2 +- dom/ipc/ContentParent.cpp | 37 +++++- dom/ipc/ContentParent.h | 7 +- dom/ipc/PContent.ipdl | 4 +- dom/ipc/moz.build | 3 + 13 files changed, 206 insertions(+), 74 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 127327b17f1e..055f9140209b 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -694,7 +694,7 @@ function gKeywordURIFixup({ target: browser, data: fixupInfo }) { // whether the original input would be vaguely interpretable as a URL, // so figure that out first. let alternativeURI = deserializeURI(fixupInfo.fixedURI); - if (!fixupInfo.fixupUsedKeyword || !alternativeURI || !alternativeURI.host) { + if (!fixupInfo.keywordProviderName || !alternativeURI || !alternativeURI.host) { return; } diff --git a/docshell/base/nsDefaultURIFixup.cpp b/docshell/base/nsDefaultURIFixup.cpp index e1e28a7202cd..f7e15f10f6c0 100644 --- a/docshell/base/nsDefaultURIFixup.cpp +++ b/docshell/base/nsDefaultURIFixup.cpp @@ -300,20 +300,16 @@ nsDefaultURIFixup::GetFixupURIInfo(const nsACString& aStringURI, uint32_t aFixup ioService->GetProtocolHandler(scheme.get(), getter_AddRefs(ourHandler)); extHandler = do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"default"); - nsCOMPtr uri; if (ourHandler != extHandler || !PossiblyHostPortUrl(uriString)) { // Just try to create an URL out of it - rv = NS_NewURI(getter_AddRefs(uri), uriString, nullptr); - if (NS_SUCCEEDED(rv)) { - info->mFixedURI = uri; - } + rv = NS_NewURI(getter_AddRefs(info->mFixedURI), uriString, nullptr); - if (!uri && rv != NS_ERROR_MALFORMED_URI) { + if (!info->mFixedURI && rv != NS_ERROR_MALFORMED_URI) { return rv; } } - if (uri && ourHandler == extHandler && sFixupKeywords && + if (info->mFixedURI && ourHandler == extHandler && sFixupKeywords && (aFixupFlags & FIXUP_FLAG_FIX_SCHEME_TYPOS)) { nsCOMPtr extProtService = do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID); @@ -328,18 +324,17 @@ nsDefaultURIFixup::GetFixupURIInfo(const nsACString& aStringURI, uint32_t aFixup // It's more likely the user wants to search, and so we // chuck this over to their preferred search provider instead: if (!handlerExists) { - nsresult rv = KeywordToURI(uriString, aPostData, getter_AddRefs(uri)); - if (NS_SUCCEEDED(rv) && uri) { - info->mFixupUsedKeyword = true; - } + TryKeywordFixupForURIInfo(uriString, info, aPostData); } } } - if (uri) { - if (aFixupFlags & FIXUP_FLAGS_MAKE_ALTERNATE_URI) - info->mFixupCreatedAlternateURI = MakeAlternateURI(uri); - info->mPreferredURI = uri; + if (info->mFixedURI) { + if (!info->mPreferredURI) { + if (aFixupFlags & FIXUP_FLAGS_MAKE_ALTERNATE_URI) + info->mFixupCreatedAlternateURI = MakeAlternateURI(info->mFixedURI); + info->mPreferredURI = info->mFixedURI; + } return NS_OK; } @@ -415,12 +410,7 @@ nsDefaultURIFixup::GetFixupURIInfo(const nsACString& aStringURI, uint32_t aFixup // If we still haven't been able to construct a valid URI, try to force a // keyword match. This catches search strings with '.' or ':' in them. if (sFixupKeywords && (aFixupFlags & FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP)) { - rv = KeywordToURI(aStringURI, aPostData, getter_AddRefs(info->mPreferredURI)); - if (NS_SUCCEEDED(rv) && info->mPreferredURI) - { - info->mFixupUsedKeyword = true; - return NS_OK; - } + rv = TryKeywordFixupForURIInfo(aStringURI, info, aPostData); } return rv; @@ -428,9 +418,11 @@ nsDefaultURIFixup::GetFixupURIInfo(const nsACString& aStringURI, uint32_t aFixup NS_IMETHODIMP nsDefaultURIFixup::KeywordToURI(const nsACString& aKeyword, nsIInputStream **aPostData, - nsIURI **aURI) + nsIURIFixupInfo **aInfo) { - *aURI = nullptr; + nsRefPtr info = new nsDefaultURIFixupInfo(aKeyword); + NS_ADDREF(*aInfo = info); + if (aPostData) { *aPostData = nullptr; } @@ -451,10 +443,14 @@ NS_IMETHODIMP nsDefaultURIFixup::KeywordToURI(const nsACString& aKeyword, ipc::OptionalInputStreamParams postData; ipc::OptionalURIParams uri; - if (!contentChild->SendKeywordToURI(keyword, &postData, &uri)) { + nsAutoString providerName; + if (!contentChild->SendKeywordToURI(keyword, &providerName, &postData, &uri)) { return NS_ERROR_FAILURE; } + CopyUTF8toUTF16(keyword, info->mKeywordAsSent); + info->mKeywordProviderName = providerName; + if (aPostData) { nsTArray fds; nsCOMPtr temp = DeserializeInputStream(postData, fds); @@ -464,7 +460,7 @@ NS_IMETHODIMP nsDefaultURIFixup::KeywordToURI(const nsACString& aKeyword, } nsCOMPtr temp = DeserializeURI(uri); - temp.forget(aURI); + info->mPreferredURI = temp.forget(); return NS_OK; } @@ -486,7 +482,8 @@ NS_IMETHODIMP nsDefaultURIFixup::KeywordToURI(const nsACString& aKeyword, responseType.Assign(mozKeywordSearch); } - defaultEngine->GetSubmission(NS_ConvertUTF8toUTF16(keyword), + NS_ConvertUTF8toUTF16 keywordW(keyword); + defaultEngine->GetSubmission(keywordW, responseType, NS_LITERAL_STRING("keyword"), getter_AddRefs(submission)); @@ -504,21 +501,9 @@ NS_IMETHODIMP nsDefaultURIFixup::KeywordToURI(const nsACString& aKeyword, return NS_ERROR_FAILURE; } - // This notification is meant for Firefox Health Report so it - // can increment counts from the search engine. The assumption - // here is that this keyword/submission will eventually result - // in a search. Since we only generate a URI here, there is the - // possibility we'll increment the counter without actually - // incurring a search. A robust solution would involve currying - // the search engine's name through various function calls. - nsCOMPtr obsSvc = mozilla::services::GetObserverService(); - if (obsSvc) { - // Note that "keyword-search" refers to a search via the url - // bar, not a bookmarks keyword search. - obsSvc->NotifyObservers(defaultEngine, "keyword-search", NS_ConvertUTF8toUTF16(keyword).get()); - } - - return submission->GetUri(aURI); + defaultEngine->GetName(info->mKeywordProviderName); + info->mKeywordAsSent = keywordW; + return submission->GetUri(getter_AddRefs(info->mPreferredURI)); } } } @@ -528,6 +513,22 @@ NS_IMETHODIMP nsDefaultURIFixup::KeywordToURI(const nsACString& aKeyword, return NS_ERROR_NOT_AVAILABLE; } +// Helper to deal with passing around uri fixup stuff +nsresult +nsDefaultURIFixup::TryKeywordFixupForURIInfo(const nsACString & aURIString, + nsDefaultURIFixupInfo* aFixupInfo, + nsIInputStream **aPostData) +{ + nsCOMPtr keywordInfo; + nsresult rv = KeywordToURI(aURIString, aPostData, getter_AddRefs(keywordInfo)); + if (NS_SUCCEEDED(rv)) { + keywordInfo->GetKeywordProviderName(aFixupInfo->mKeywordProviderName); + keywordInfo->GetKeywordAsSent(aFixupInfo->mKeywordAsSent); + keywordInfo->GetPreferredURI(getter_AddRefs(aFixupInfo->mPreferredURI)); + } + return rv; +} + bool nsDefaultURIFixup::MakeAlternateURI(nsIURI *aURI) { if (!Preferences::GetRootBranch()) @@ -1073,11 +1074,7 @@ void nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString, (isValidAsciiHost && isValidHost && !hasAsciiAlpha && host.EqualsIgnoreCase(asciiHost.get()))) { - rv = KeywordToURI(aFixupInfo->mOriginalInput, aPostData, - getter_AddRefs(aFixupInfo->mPreferredURI)); - if (NS_SUCCEEDED(rv) && aFixupInfo->mPreferredURI) { - aFixupInfo->mFixupUsedKeyword = true; - } + rv = TryKeywordFixupForURIInfo(aFixupInfo->mOriginalInput, aFixupInfo, aPostData); } // ... or if there is no question mark or colon, and there is either no // dot, or exactly 1 and it is the first or last character of the input: @@ -1091,11 +1088,7 @@ void nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString, // If we get here, we don't have a valid URI, or we did but the // host is not whitelisted, so we do a keyword search *anyway*: - rv = KeywordToURI(aFixupInfo->mOriginalInput, aPostData, - getter_AddRefs(aFixupInfo->mPreferredURI)); - if (NS_SUCCEEDED(rv) && aFixupInfo->mPreferredURI) { - aFixupInfo->mFixupUsedKeyword = true; - } + rv = TryKeywordFixupForURIInfo(aFixupInfo->mOriginalInput, aFixupInfo, aPostData); } } @@ -1134,7 +1127,6 @@ nsresult NS_NewURIFixup(nsIURIFixup **aURIFixup) NS_IMPL_ISUPPORTS(nsDefaultURIFixupInfo, nsIURIFixupInfo) nsDefaultURIFixupInfo::nsDefaultURIFixupInfo(const nsACString& aOriginalInput): - mFixupUsedKeyword(false), mFixupChangedProtocol(false), mFixupCreatedAlternateURI(false) { @@ -1178,9 +1170,16 @@ nsDefaultURIFixupInfo::GetFixedURI(nsIURI** aFixedURI) } NS_IMETHODIMP -nsDefaultURIFixupInfo::GetFixupUsedKeyword(bool* aOut) +nsDefaultURIFixupInfo::GetKeywordProviderName(nsAString& aOut) { - *aOut = mFixupUsedKeyword; + aOut = mKeywordProviderName; + return NS_OK; +} + +NS_IMETHODIMP +nsDefaultURIFixupInfo::GetKeywordAsSent(nsAString& aOut) +{ + aOut = mKeywordAsSent; return NS_OK; } diff --git a/docshell/base/nsDefaultURIFixup.h b/docshell/base/nsDefaultURIFixup.h index 1088349ff595..3b93fa9f81f0 100644 --- a/docshell/base/nsDefaultURIFixup.h +++ b/docshell/base/nsDefaultURIFixup.h @@ -33,6 +33,9 @@ private: void KeywordURIFixup(const nsACString &aStringURI, nsDefaultURIFixupInfo* aFixupInfo, nsIInputStream** aPostData); + nsresult TryKeywordFixupForURIInfo(const nsACString &aStringURI, + nsDefaultURIFixupInfo* aFixupInfo, + nsIInputStream** aPostData); bool PossiblyByteExpandedFileName(const nsAString& aIn); bool PossiblyHostPortUrl(const nsACString& aUrl); bool MakeAlternateURI(nsIURI *aURI); @@ -58,9 +61,10 @@ private: nsCOMPtr mConsumer; nsCOMPtr mPreferredURI; nsCOMPtr mFixedURI; - bool mFixupUsedKeyword; bool mFixupChangedProtocol; bool mFixupCreatedAlternateURI; + nsString mKeywordProviderName; + nsString mKeywordAsSent; nsAutoCString mOriginalInput; }; #endif diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index c9bf3d9ab205..f9647455116a 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -201,6 +201,10 @@ #include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/URLSearchParams.h" +#ifdef MOZ_TOOLKIT_SEARCH +#include "nsIBrowserSearchService.h" +#endif + static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); #if defined(DEBUG_bryner) || defined(DEBUG_chb) @@ -4583,6 +4587,7 @@ nsDocShell::LoadURIWithBase(const char16_t * aURI, aLoadFlags &= ~LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP; } + nsCOMPtr fixupInfo; if (sURIFixup) { // Call the fixup object. This will clobber the rv from NS_NewURI // above, but that's fine with us. Note that we need to do this even @@ -4596,7 +4601,6 @@ nsDocShell::LoadURIWithBase(const char16_t * aURI, fixupFlags |= nsIURIFixup::FIXUP_FLAG_FIX_SCHEME_TYPOS; } nsCOMPtr fixupStream; - nsCOMPtr fixupInfo; rv = sURIFixup->GetFixupURIInfo(uriString, fixupFlags, getter_AddRefs(fixupStream), getter_AddRefs(fixupInfo)); @@ -4607,7 +4611,7 @@ nsDocShell::LoadURIWithBase(const char16_t * aURI, } if (fixupStream) { - // CreateFixupURI only returns a post data stream if it succeeded + // GetFixupURIInfo only returns a post data stream if it succeeded // and changed the URI, in which case we should override the // passed-in post data. postStream = fixupStream; @@ -4666,6 +4670,13 @@ nsDocShell::LoadURIWithBase(const char16_t * aURI, loadInfo->SetHeadersStream(aHeaderStream); loadInfo->SetBaseURI(aBaseURI); + if (fixupInfo) { + nsAutoString searchProvider, keyword; + fixupInfo->GetKeywordProviderName(searchProvider); + fixupInfo->GetKeywordAsSent(keyword); + MaybeNotifyKeywordSearchLoading(searchProvider, keyword); + } + rv = LoadURI(uri, loadInfo, extraFlags, true); // Save URI string in case it's needed later when @@ -7382,6 +7393,7 @@ nsDocShell::EndPageLoad(nsIWebProgress * aProgress, // // First try keyword fixup // + nsAutoString keywordProviderName, keywordAsSent; if (aStatus == NS_ERROR_UNKNOWN_HOST && mAllowKeywordFixup) { bool keywordsEnabled = Preferences::GetBool("keyword.enabled", false); @@ -7412,11 +7424,12 @@ nsDocShell::EndPageLoad(nsIWebProgress * aProgress, } if (keywordsEnabled && (kNotFound == dotLoc)) { + nsCOMPtr info; // only send non-qualified hosts to the keyword server if (!mOriginalUriString.IsEmpty()) { sURIFixup->KeywordToURI(mOriginalUriString, getter_AddRefs(newPostData), - getter_AddRefs(newURI)); + getter_AddRefs(info)); } else { // @@ -7438,13 +7451,19 @@ nsDocShell::EndPageLoad(nsIWebProgress * aProgress, NS_SUCCEEDED(idnSrv->ConvertACEtoUTF8(host, utf8Host))) { sURIFixup->KeywordToURI(utf8Host, getter_AddRefs(newPostData), - getter_AddRefs(newURI)); + getter_AddRefs(info)); } else { sURIFixup->KeywordToURI(host, getter_AddRefs(newPostData), - getter_AddRefs(newURI)); + getter_AddRefs(info)); } } + + info->GetPreferredURI(getter_AddRefs(newURI)); + if (newURI) { + info->GetKeywordAsSent(keywordAsSent); + info->GetKeywordProviderName(keywordProviderName); + } } // end keywordsEnabled } @@ -7477,6 +7496,8 @@ nsDocShell::EndPageLoad(nsIWebProgress * aProgress, if (doCreateAlternate) { newURI = nullptr; newPostData = nullptr; + keywordProviderName.Truncate(); + keywordAsSent.Truncate(); sURIFixup->CreateFixupURI(oldSpec, nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI, getter_AddRefs(newPostData), @@ -7497,6 +7518,10 @@ nsDocShell::EndPageLoad(nsIWebProgress * aProgress, newURI->GetSpec(newSpec); NS_ConvertUTF8toUTF16 newSpecW(newSpec); + // This notification is meant for Firefox Health Report so it + // can increment counts from the search engine + MaybeNotifyKeywordSearchLoading(keywordProviderName, keywordAsSent); + return LoadURI(newSpecW.get(), // URI string LOAD_FLAGS_NONE, // Load flags nullptr, // Referring URI @@ -13508,3 +13533,36 @@ nsDocShell::GetURLSearchParams() { return mURLSearchParams; } + +void +nsDocShell::MaybeNotifyKeywordSearchLoading(const nsString &aProvider, + const nsString &aKeyword) { + + if (aProvider.IsEmpty()) { + return; + } + + if (XRE_GetProcessType() == GeckoProcessType_Content) { + dom::ContentChild* contentChild = dom::ContentChild::GetSingleton(); + if (contentChild) { + contentChild->SendNotifyKeywordSearchLoading(aProvider, aKeyword); + } + return; + } + +#ifdef MOZ_TOOLKIT_SEARCH + nsCOMPtr searchSvc = do_GetService("@mozilla.org/browser/search-service;1"); + if (searchSvc) { + nsCOMPtr searchEngine; + searchSvc->GetEngineByName(aProvider, getter_AddRefs(searchEngine)); + if (searchEngine) { + nsCOMPtr obsSvc = mozilla::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()); + } + } + } +#endif +} diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index e7e2513826dc..eda8f2215584 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -978,6 +978,9 @@ private: nsIDocShellTreeItem* aOriginalRequestor, nsIDocShellTreeItem** _retval); + // Notify consumers of a search being loaded through the observer service: + void MaybeNotifyKeywordSearchLoading(const nsString &aProvider, const nsString &aKeyword); + #ifdef DEBUG // We're counting the number of |nsDocShells| to help find leaks static unsigned long gNumberOfDocShells; diff --git a/docshell/base/nsIURIFixup.idl b/docshell/base/nsIURIFixup.idl index 7384f8c99d83..53ec55106a19 100644 --- a/docshell/base/nsIURIFixup.idl +++ b/docshell/base/nsIURIFixup.idl @@ -12,7 +12,7 @@ interface nsIInputStream; /** * Interface indicating what we found/corrected when fixing up a URI */ -[scriptable, uuid(62aac1e0-3da8-4920-bd1b-a54fc2e2eb24)] +[scriptable, uuid(4819f183-b532-4932-ac09-b309cd853be7)] interface nsIURIFixupInfo : nsISupports { /** @@ -36,9 +36,16 @@ interface nsIURIFixupInfo : nsISupports readonly attribute nsIURI fixedURI; /** - * Whether the preferred option ended up using a keyword search. + * The name of the keyword search provider used to provide a keyword search; + * empty string if no keyword search was done. */ - readonly attribute boolean fixupUsedKeyword; + readonly attribute AString keywordProviderName; + + /** + * The keyword as used for the search (post trimming etc.) + * empty string if no keyword search was done. + */ + readonly attribute AString keywordAsSent; /** * Whether we changed the protocol instead of using one from the input as-is. @@ -63,7 +70,7 @@ interface nsIURIFixupInfo : nsISupports /** * Interface implemented by objects capable of fixing up strings into URIs */ -[scriptable, uuid(49298f2b-3630-4874-aecc-522300a7fead)] +[scriptable, uuid(d2a78abe-e678-4103-9bcc-dd1377460c44)] interface nsIURIFixup : nsISupports { /** No fixup flags. */ @@ -146,7 +153,7 @@ interface nsIURIFixup : nsISupports * @throws NS_ERROR_FAILURE if the resulting URI requires submission of POST * data and aPostData is null. */ - nsIURI keywordToURI(in AUTF8String aKeyword, - [optional] out nsIInputStream aPostData); + nsIURIFixupInfo keywordToURI(in AUTF8String aKeyword, + [optional] out nsIInputStream aPostData); }; diff --git a/docshell/test/browser/browser.ini b/docshell/test/browser/browser.ini index b0c14ec1234e..0d213e52d834 100644 --- a/docshell/test/browser/browser.ini +++ b/docshell/test/browser/browser.ini @@ -95,7 +95,6 @@ skip-if = e10s # Bug ?????? - event handler checks event.target is the content d [browser_onbeforeunload_navigation.js] skip-if = e10s [browser_search_notification.js] -skip-if = e10s [browser_timelineMarkers-01.js] [browser_timelineMarkers-02.js] skip-if = e10s diff --git a/docshell/test/browser/browser_search_notification.js b/docshell/test/browser/browser_search_notification.js index 2dcb4fcbe5b5..b0a4571e589d 100644 --- a/docshell/test/browser/browser_search_notification.js +++ b/docshell/test/browser/browser_search_notification.js @@ -4,6 +4,27 @@ function test() { waitForExplicitFinish(); + const kSearchEngineID = "test_urifixup_search_engine"; + const kSearchEngineURL = "http://localhost/?search={searchTerms}"; + Services.search.addEngineWithDetails(kSearchEngineID, "", "", "", "get", + kSearchEngineURL); + + let oldDefaultEngine = Services.search.defaultEngine; + Services.search.defaultEngine = Services.search.getEngineByName(kSearchEngineID); + + let selectedName = Services.search.defaultEngine.name; + is(selectedName, kSearchEngineID, "Check fake search engine is selected"); + + registerCleanupFunction(function() { + if (oldDefaultEngine) { + Services.search.defaultEngine = oldDefaultEngine; + } + let engine = Services.search.getEngineByName(kSearchEngineID); + if (engine) { + Services.search.removeEngine(engine); + } + }); + let tab = gBrowser.addTab(); gBrowser.selectedTab = tab; diff --git a/docshell/test/unit/test_nsDefaultURIFixup_info.js b/docshell/test/unit/test_nsDefaultURIFixup_info.js index 439ae4501a9d..83b3c3d192fd 100644 --- a/docshell/test/unit/test_nsDefaultURIFixup_info.js +++ b/docshell/test/unit/test_nsDefaultURIFixup_info.js @@ -530,7 +530,7 @@ function run_test() { // Check booleans on input: let couldDoKeywordLookup = flags & urifixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP; - do_check_eq(info.fixupUsedKeyword, couldDoKeywordLookup && expectKeywordLookup); + do_check_eq(!!info.keywordProviderName, couldDoKeywordLookup && expectKeywordLookup); do_check_eq(info.fixupChangedProtocol, expectProtocolChange); do_check_eq(info.fixupCreatedAlternateURI, makeAlternativeURI && alternativeURI != null); diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 4b38a0ba065e..46a524ed0182 100755 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -187,6 +187,10 @@ using namespace mozilla::system; #include "mozilla/Sandbox.h" #endif +#ifdef MOZ_TOOLKIT_SEARCH +#include "nsIBrowserSearchService.h" +#endif + static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID); static const char* sClipboardTextFlavors[] = { kUnicodeMime }; @@ -3826,7 +3830,9 @@ ContentParent::RecvSetFakeVolumeState(const nsString& fsName, const int32_t& fsS } bool -ContentParent::RecvKeywordToURI(const nsCString& aKeyword, OptionalInputStreamParams* aPostData, +ContentParent::RecvKeywordToURI(const nsCString& aKeyword, + nsString* aProviderName, + OptionalInputStreamParams* aPostData, OptionalURIParams* aURI) { nsCOMPtr fixup = do_GetService(NS_URIFIXUP_CONTRACTID); @@ -3835,20 +3841,45 @@ ContentParent::RecvKeywordToURI(const nsCString& aKeyword, OptionalInputStreamPa } nsCOMPtr postData; - nsCOMPtr uri; + nsCOMPtr info; + if (NS_FAILED(fixup->KeywordToURI(aKeyword, getter_AddRefs(postData), - getter_AddRefs(uri)))) { + getter_AddRefs(info)))) { return true; } + info->GetKeywordProviderName(*aProviderName); nsTArray fds; SerializeInputStream(postData, *aPostData, fds); MOZ_ASSERT(fds.IsEmpty()); + nsCOMPtr uri; + info->GetPreferredURI(getter_AddRefs(uri)); SerializeURI(uri, *aURI); return true; } +bool +ContentParent::RecvNotifyKeywordSearchLoading(const nsString &aProvider, + const nsString &aKeyword) { +#ifdef MOZ_TOOLKIT_SEARCH + nsCOMPtr searchSvc = do_GetService("@mozilla.org/browser/search-service;1"); + if (searchSvc) { + nsCOMPtr searchEngine; + searchSvc->GetEngineByName(aProvider, getter_AddRefs(searchEngine)); + if (searchEngine) { + nsCOMPtr obsSvc = mozilla::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()); + } + } + } +#endif + return true; +} + bool ContentParent::ShouldContinueFromReplyTimeout() { diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index e59035b41a3f..b43cba00ba27 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -627,9 +627,14 @@ private: virtual bool RecvSetFakeVolumeState(const nsString& fsName, const int32_t& fsState) MOZ_OVERRIDE; - virtual bool RecvKeywordToURI(const nsCString& aKeyword, OptionalInputStreamParams* aPostData, + virtual bool RecvKeywordToURI(const nsCString& aKeyword, + nsString* aProviderName, + OptionalInputStreamParams* aPostData, OptionalURIParams* aURI) MOZ_OVERRIDE; + virtual bool RecvNotifyKeywordSearchLoading(const nsString &aProvider, + const nsString &aKeyword) MOZ_OVERRIDE; + virtual void ProcessingError(Result what) MOZ_OVERRIDE; virtual bool RecvAllocateLayerTreeId(uint64_t* aId) MOZ_OVERRIDE; diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index deb3e87721dd..2819a3f77d4a 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -680,7 +680,9 @@ parent: async SetFakeVolumeState(nsString fsName, int32_t fsState); sync KeywordToURI(nsCString keyword) - returns (OptionalInputStreamParams postData, OptionalURIParams uri); + returns (nsString providerName, OptionalInputStreamParams postData, OptionalURIParams uri); + + sync NotifyKeywordSearchLoading(nsString providerName, nsString keyword); // Tell the compositor to allocate a layer tree id for nested remote mozbrowsers. sync AllocateLayerTreeId() diff --git a/dom/ipc/moz.build b/dom/ipc/moz.build index 49218e171c93..89bdf6984382 100644 --- a/dom/ipc/moz.build +++ b/dom/ipc/moz.build @@ -126,6 +126,9 @@ DEFINES['BIN_SUFFIX'] = '"%s"' % CONFIG['BIN_SUFFIX'] if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gonk', 'qt'): DEFINES['MOZ_ENABLE_FREETYPE'] = True +if CONFIG['MOZ_TOOLKIT_SEARCH']: + DEFINES['MOZ_TOOLKIT_SEARCH'] = True + for var in ('MOZ_PERMISSIONS', 'MOZ_CHILD_PERMISSIONS'): if CONFIG[var]: DEFINES[var] = True