Bug 1649879 - Don't create nsIURIFixupInfo in content process nsDocShellLoadState construction. r=kmag
Rather than constructing an nsIURIFixupInfo from the IPC call return valuess, and then immediately querying the same data, this just use the results directly. It also moves the firing of "keyword-uri-fixup" observers to the parent process side. As far as I can tell, the only consumer was URIFixupChild, which was also forwarding them to the parent process. Differential Revision: https://phabricator.services.mozilla.com/D81944
This commit is contained in:
@@ -212,7 +212,8 @@ nsresult nsDocShellLoadState::CreateFromLoadURIOptions(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIURIFixupInfo> fixupInfo;
|
nsAutoString searchProvider, keyword;
|
||||||
|
bool didFixup = false;
|
||||||
if (fixup) {
|
if (fixup) {
|
||||||
uint32_t fixupFlags;
|
uint32_t fixupFlags;
|
||||||
if (NS_FAILED(sURIFixup->WebNavigationFlagsToFixupFlags(
|
if (NS_FAILED(sURIFixup->WebNavigationFlagsToFixupFlags(
|
||||||
@@ -230,41 +231,47 @@ nsresult nsDocShellLoadState::CreateFromLoadURIOptions(
|
|||||||
fixupFlags |= nsIURIFixup::FIXUP_FLAG_PRIVATE_CONTEXT;
|
fixupFlags |= nsIURIFixup::FIXUP_FLAG_PRIVATE_CONTEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIInputStream> fixupStream;
|
RefPtr<nsIInputStream> fixupStream;
|
||||||
if (XRE_IsContentProcess()) {
|
if (XRE_IsContentProcess()) {
|
||||||
dom::ContentChild* contentChild = dom::ContentChild::GetSingleton();
|
dom::ContentChild* contentChild = dom::ContentChild::GetSingleton();
|
||||||
if (contentChild) {
|
if (contentChild) {
|
||||||
RefPtr<nsIInputStream> postData;
|
RefPtr<nsIURI> preferredURI;
|
||||||
RefPtr<nsIURI> fixedURI, preferredURI;
|
|
||||||
nsAutoString providerName;
|
|
||||||
nsAutoCString stringURI(uriString);
|
|
||||||
// TODO (Bug 1375244): This synchronous IPC messaging should be changed.
|
// TODO (Bug 1375244): This synchronous IPC messaging should be changed.
|
||||||
if (contentChild->SendGetFixupURIInfo(stringURI, fixupFlags,
|
if (contentChild->SendGetFixupURIInfo(
|
||||||
&providerName, &postData,
|
PromiseFlatString(aURI), fixupFlags,
|
||||||
&fixedURI, &preferredURI)) {
|
loadFlags &
|
||||||
|
nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP,
|
||||||
|
&searchProvider, &fixupStream, &preferredURI)) {
|
||||||
if (preferredURI) {
|
if (preferredURI) {
|
||||||
fixupInfo =
|
didFixup = true;
|
||||||
do_CreateInstance("@mozilla.org/docshell/uri-fixup-info;1");
|
rv = NS_OK;
|
||||||
if (fixupInfo) {
|
uri = preferredURI;
|
||||||
fixupInfo->SetKeywordProviderName(providerName);
|
|
||||||
fixupStream = postData;
|
|
||||||
fixupInfo->SetFixedURI(fixedURI);
|
|
||||||
fixupInfo->SetPreferredURI(preferredURI);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
nsCOMPtr<nsIURIFixupInfo> fixupInfo;
|
||||||
sURIFixup->GetFixupURIInfo(uriString, fixupFlags,
|
sURIFixup->GetFixupURIInfo(uriString, fixupFlags,
|
||||||
getter_AddRefs(fixupStream),
|
getter_AddRefs(fixupStream),
|
||||||
getter_AddRefs(fixupInfo));
|
getter_AddRefs(fixupInfo));
|
||||||
}
|
if (fixupInfo) {
|
||||||
|
// We could fix the uri, clear NS_ERROR_MALFORMED_URI.
|
||||||
|
rv = NS_OK;
|
||||||
|
fixupInfo->GetPreferredURI(getter_AddRefs(uri));
|
||||||
|
fixupInfo->SetConsumer(aBrowsingContext);
|
||||||
|
fixupInfo->GetKeywordProviderName(searchProvider);
|
||||||
|
fixupInfo->GetKeywordAsSent(keyword);
|
||||||
|
didFixup = true;
|
||||||
|
|
||||||
if (fixupInfo) {
|
if (fixupInfo &&
|
||||||
// We could fix the uri, clear NS_ERROR_MALFORMED_URI.
|
loadFlags & nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) {
|
||||||
rv = NS_OK;
|
nsCOMPtr<nsIObserverService> serv = services::GetObserverService();
|
||||||
fixupInfo->GetPreferredURI(getter_AddRefs(uri));
|
if (serv) {
|
||||||
fixupInfo->SetConsumer(aBrowsingContext);
|
serv->NotifyObservers(fixupInfo, "keyword-uri-fixup",
|
||||||
|
PromiseFlatString(aURI).get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fixupStream) {
|
if (fixupStream) {
|
||||||
@@ -273,15 +280,6 @@ nsresult nsDocShellLoadState::CreateFromLoadURIOptions(
|
|||||||
// passed-in post data.
|
// passed-in post data.
|
||||||
postData = fixupStream;
|
postData = fixupStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fixupInfo &&
|
|
||||||
loadFlags & nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) {
|
|
||||||
nsCOMPtr<nsIObserverService> serv = services::GetObserverService();
|
|
||||||
if (serv) {
|
|
||||||
serv->NotifyObservers(fixupInfo, "keyword-uri-fixup",
|
|
||||||
PromiseFlatString(aURI).get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rv == NS_ERROR_MALFORMED_URI) {
|
if (rv == NS_ERROR_MALFORMED_URI) {
|
||||||
@@ -348,10 +346,7 @@ nsresult nsDocShellLoadState::CreateFromLoadURIOptions(
|
|||||||
loadState->SetCancelContentJSEpoch(aLoadURIOptions.mCancelContentJSEpoch);
|
loadState->SetCancelContentJSEpoch(aLoadURIOptions.mCancelContentJSEpoch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fixupInfo) {
|
if (didFixup) {
|
||||||
nsAutoString searchProvider, keyword;
|
|
||||||
fixupInfo->GetKeywordProviderName(searchProvider);
|
|
||||||
fixupInfo->GetKeywordAsSent(keyword);
|
|
||||||
nsDocShell::MaybeNotifyKeywordSearchLoading(searchProvider, keyword);
|
nsDocShell::MaybeNotifyKeywordSearchLoading(searchProvider, keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4472,28 +4472,41 @@ mozilla::ipc::IPCResult ContentParent::RecvKeywordToURI(
|
|||||||
}
|
}
|
||||||
|
|
||||||
mozilla::ipc::IPCResult ContentParent::RecvGetFixupURIInfo(
|
mozilla::ipc::IPCResult ContentParent::RecvGetFixupURIInfo(
|
||||||
const nsCString& aURIString, const uint32_t& aFixupFlags,
|
const nsString& aURIString, const uint32_t& aFixupFlags,
|
||||||
nsString* aProviderName, RefPtr<nsIInputStream>* aPostData,
|
bool aAllowThirdPartyFixup, nsString* aProviderName,
|
||||||
RefPtr<nsIURI>* aFixedURI, RefPtr<nsIURI>* aPreferredURI) {
|
RefPtr<nsIInputStream>* aPostData, RefPtr<nsIURI>* aPreferredURI) {
|
||||||
*aPostData = nullptr;
|
*aPostData = nullptr;
|
||||||
*aFixedURI = nullptr;
|
|
||||||
*aPreferredURI = nullptr;
|
*aPreferredURI = nullptr;
|
||||||
nsCOMPtr<nsIURIFixup> fixup = components::URIFixup::Service();
|
nsCOMPtr<nsIURIFixup> fixup = components::URIFixup::Service();
|
||||||
if (!fixup) {
|
if (!fixup) {
|
||||||
return IPC_OK();
|
return IPC_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_ConvertUTF16toUTF8 uriString(aURIString);
|
||||||
|
// Cleanup the empty spaces that might be on each end.
|
||||||
|
uriString.Trim(" ");
|
||||||
|
// Eliminate embedded newlines, which single-line text fields now allow:
|
||||||
|
uriString.StripCRLF();
|
||||||
|
|
||||||
nsCOMPtr<nsIURIFixupInfo> info;
|
nsCOMPtr<nsIURIFixupInfo> info;
|
||||||
if (NS_FAILED(fixup->GetFixupURIInfo(aURIString, aFixupFlags,
|
if (NS_FAILED(fixup->GetFixupURIInfo(uriString, aFixupFlags,
|
||||||
getter_AddRefs(*aPostData),
|
getter_AddRefs(*aPostData),
|
||||||
getter_AddRefs(info)))) {
|
getter_AddRefs(info)))) {
|
||||||
return IPC_OK();
|
return IPC_OK();
|
||||||
}
|
}
|
||||||
info->GetKeywordProviderName(*aProviderName);
|
info->GetKeywordProviderName(*aProviderName);
|
||||||
nsCOMPtr<nsIURI> uri;
|
nsCOMPtr<nsIURI> uri;
|
||||||
info->GetFixedURI(getter_AddRefs(uri));
|
|
||||||
*aFixedURI = uri;
|
|
||||||
info->GetPreferredURI(getter_AddRefs(uri));
|
info->GetPreferredURI(getter_AddRefs(uri));
|
||||||
*aPreferredURI = uri;
|
*aPreferredURI = uri;
|
||||||
|
|
||||||
|
if (aAllowThirdPartyFixup) {
|
||||||
|
nsCOMPtr<nsIObserverService> serv = services::GetObserverService();
|
||||||
|
if (serv) {
|
||||||
|
serv->NotifyObservers(info, "keyword-uri-fixup",
|
||||||
|
PromiseFlatString(aURIString).get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return IPC_OK();
|
return IPC_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1093,11 +1093,11 @@ class ContentParent final
|
|||||||
RefPtr<nsIInputStream>* aPostData,
|
RefPtr<nsIInputStream>* aPostData,
|
||||||
RefPtr<nsIURI>* aURI);
|
RefPtr<nsIURI>* aURI);
|
||||||
|
|
||||||
mozilla::ipc::IPCResult RecvGetFixupURIInfo(const nsCString& aURIString,
|
mozilla::ipc::IPCResult RecvGetFixupURIInfo(const nsString& aURIString,
|
||||||
const uint32_t& aFixupFlags,
|
const uint32_t& aFixupFlags,
|
||||||
|
bool aAllowThirdPartyFixup,
|
||||||
nsString* aProviderName,
|
nsString* aProviderName,
|
||||||
RefPtr<nsIInputStream>* aPostData,
|
RefPtr<nsIInputStream>* aPostData,
|
||||||
RefPtr<nsIURI>* aFixedURI,
|
|
||||||
RefPtr<nsIURI>* aPreferredURI);
|
RefPtr<nsIURI>* aPreferredURI);
|
||||||
|
|
||||||
mozilla::ipc::IPCResult RecvNotifyKeywordSearchLoading(
|
mozilla::ipc::IPCResult RecvNotifyKeywordSearchLoading(
|
||||||
|
|||||||
@@ -1109,8 +1109,8 @@ parent:
|
|||||||
|
|
||||||
sync KeywordToURI(nsCString keyword, bool isPrivateContext)
|
sync KeywordToURI(nsCString keyword, bool isPrivateContext)
|
||||||
returns (nsString providerName, nsIInputStream postData, nsIURI uri);
|
returns (nsString providerName, nsIInputStream postData, nsIURI uri);
|
||||||
sync GetFixupURIInfo(nsCString uriString, uint32_t fixupflags)
|
sync GetFixupURIInfo(nsString uriString, uint32_t fixupflags, bool aAllowThirdPartyFixup)
|
||||||
returns (nsString providerName, nsIInputStream postData, nsIURI fixedURI, nsIURI preferredURI);
|
returns (nsString providerName, nsIInputStream postData, nsIURI preferredURI);
|
||||||
|
|
||||||
sync NotifyKeywordSearchLoading(nsString providerName, nsString keyword);
|
sync NotifyKeywordSearchLoading(nsString providerName, nsString keyword);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user