Added IOService hooking API instead of allowing its override.

This commit is contained in:
Jacek Caban 2015-10-05 14:03:02 +02:00
parent 744e6dbc02
commit 112de6198f
4 changed files with 44 additions and 17 deletions

View File

@ -12,6 +12,7 @@ interface nsIFile;
interface nsIDOMNode;
interface nsIPrincipal;
interface nsILoadInfo;
interface nsIIOServiceHook;
/**
* nsIIOService provides a set of network utility functions. This interface
@ -235,8 +236,7 @@ interface nsIIOService : nsISupports
*/
ACString extractScheme(in AUTF8String urlString);
nsILoadInfo newLoadInfo(in nsIPrincipal aLoadingPrincipal,in nsIPrincipal aTriggeringPrincipal,
in nsIDOMNode aLoadingNode, in unsigned long aSecurityFlags, in unsigned long aContentPolicyType);
void setHook(in nsIIOServiceHook hook);
};
[scriptable, uuid(4ac296a0-ca1b-44f4-8787-117a88cb70fb)]
@ -294,3 +294,13 @@ interface nsIIOServiceInternal : nsISupports
*/
void NotifyWakeup();
};
[builtinclass, uuid(d13c21ca-7329-45a5-8912-9d2e2fef1231)]
interface nsIIOServiceHook : nsISupports
{
nsIChannel newChannel(in nsIURI aURI, in nsILoadInfo aLoadInfo);
nsIProtocolHandler getProtocolHandler(in nsIProtocolHandler aHandler);
nsIURI newURI(in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI);
boolean protocolHasFlags(in nsIURI aURI, in unsigned long aFlag);
boolean URIChainHasFlags(in nsIURI aURI, in unsigned long aFlags);
};

View File

@ -79,6 +79,8 @@ using mozilla::net::CaptivePortalService;
#define MAX_RECURSION_COUNT 50
#define NS_SUCCESS_DEFAULT_ACTION NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_NETWORK, 66)
nsIOService* gIOService = nullptr;
static bool gHasWarnedUploadChannel2;
@ -544,6 +546,8 @@ nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result)
result);
if (NS_FAILED(rv))
return NS_ERROR_UNKNOWN_PROTOCOL;
if (mHook)
return mHook->GetProtocolHandler(*result, result);
return rv;
}
@ -588,6 +592,12 @@ nsIOService::NewURI(const nsACString &aSpec, const char *aCharset, nsIURI *aBase
{
NS_ASSERTION(NS_IsMainThread(), "wrong thread");
if (mHook) {
nsresult rv = mHook->NewURI(aSpec, aCharset, aBaseURI, result);
if (rv != NS_SUCCESS_DEFAULT_ACTION)
return rv;
}
static uint32_t recursionCount = 0;
if (recursionCount >= MAX_RECURSION_COUNT)
return NS_ERROR_MALFORMED_URI;
@ -696,6 +706,12 @@ nsIOService::NewChannelFromURIWithProxyFlagsInternal(nsIURI* aURI,
nsresult rv;
NS_ENSURE_ARG_POINTER(aURI);
if (mHook) {
rv = mHook->NewChannel(aURI, aLoadInfo, result);
if (rv != NS_SUCCESS_DEFAULT_ACTION)
return rv;
}
nsAutoCString scheme;
rv = aURI->GetScheme(scheme);
if (NS_FAILED(rv))
@ -1513,6 +1529,12 @@ nsIOService::ProtocolHasFlags(nsIURI *uri,
{
NS_ENSURE_ARG(uri);
if(mHook) {
nsresult rv = mHook->ProtocolHasFlags(uri, flags, result);
if(rv != NS_SUCCESS_DEFAULT_ACTION)
return rv;
}
*result = false;
nsAutoCString scheme;
nsresult rv = uri->GetScheme(scheme);
@ -1535,6 +1557,12 @@ nsIOService::URIChainHasFlags(nsIURI *uri,
uint32_t flags,
bool *result)
{
if(mHook) {
nsresult rv = mHook->URIChainHasFlags(uri, flags, result);
if(rv != NS_SUCCESS_DEFAULT_ACTION)
return rv;
}
nsresult rv = ProtocolHasFlags(uri, flags, result);
NS_ENSURE_SUCCESS(rv, rv);
@ -2039,15 +2067,8 @@ nsIOService::IsAppOffline(uint32_t aAppId, bool* aResult)
}
NS_IMETHODIMP
nsIOService::NewLoadInfo(nsIPrincipal *aLoadingPrincipal, nsIPrincipal *aTriggeringPrincipal,
nsIDOMNode *aLoadingNode, uint32_t aSecurityFlags, uint32_t aContentPolicyType, nsILoadInfo **_retval)
nsIOService::SetHook(nsIIOServiceHook *aHook)
{
nsCOMPtr<nsINode> loadingNode(do_QueryInterface(aLoadingNode));
nsCOMPtr<nsILoadInfo> loadInfo = new mozilla::LoadInfo(aLoadingPrincipal,
aTriggeringPrincipal,
loadingNode,
aSecurityFlags,
aContentPolicyType);
loadInfo.forget(_retval);
mHook = aHook;
return NS_OK;
}

View File

@ -160,6 +160,8 @@ private:
nsCOMPtr<nsINetworkLinkService> mNetworkLinkService;
bool mNetworkLinkServiceInitialized;
nsCOMPtr<nsIIOServiceHook> mHook;
// Cached protocol handlers
nsWeakPtr mWeakHandler[NS_N(gScheme)];

View File

@ -81,12 +81,6 @@ MOZ_ALWAYS_INLINE nsresult
net_EnsureIOService(nsIIOService **ios, nsCOMPtr<nsIIOService> &grip)
{
nsresult rv = NS_OK;
#ifdef WINE_GECKO_SRC
if (*ios) {
(*ios)->Release();
*ios = nullptr;
}
#endif
if (!*ios) {
grip = do_GetIOService(&rv);
*ios = grip;