Skip to content

Commit

Permalink
Bug 1284579 - Part 2: revise NS_ShouldCheckAppCache. r=valentin
Browse files Browse the repository at this point in the history
There's one redudant NS_ShouldCheckAppCache(nsIURI*, bool) is not used
anymore. Also we remove the extra usePrivateBrowsing argument, since we
can get this information from nsIPrincipal.
  • Loading branch information
allstarschh committed May 4, 2017
1 parent 339c476 commit 7652396
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 32 deletions.
4 changes: 2 additions & 2 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7571,7 +7571,7 @@ nsDocShell::OnRedirectStateChange(nsIChannel* aOldChannel,
secMan->GetDocShellCodebasePrincipal(newURI, this,
getter_AddRefs(principal));
appCacheChannel->SetChooseApplicationCache(
NS_ShouldCheckAppCache(principal, UsePrivateBrowsing()));
NS_ShouldCheckAppCache(principal));
}
}
}
Expand Down Expand Up @@ -11160,7 +11160,7 @@ nsDocShell::DoURILoad(nsIURI* aURI,
secMan->GetDocShellCodebasePrincipal(aURI, this,
getter_AddRefs(principal));
appCacheChannel->SetChooseApplicationCache(
NS_ShouldCheckAppCache(principal, UsePrivateBrowsing()));
NS_ShouldCheckAppCache(principal));
}
}
}
Expand Down
30 changes: 5 additions & 25 deletions netwerk/base/nsNetUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1656,9 +1656,11 @@ NS_HasBeenCrossOrigin(nsIChannel* aChannel, bool aReport)
}

bool
NS_ShouldCheckAppCache(nsIURI *aURI, bool usePrivateBrowsing)
NS_ShouldCheckAppCache(nsIPrincipal *aPrincipal)
{
if (usePrivateBrowsing) {
uint32_t privateBrowsingId = 0;
nsresult rv = aPrincipal->GetPrivateBrowsingId(&privateBrowsingId);
if (NS_SUCCEEDED(rv) && (privateBrowsingId > 0)) {
return false;
}

Expand All @@ -1669,29 +1671,7 @@ NS_ShouldCheckAppCache(nsIURI *aURI, bool usePrivateBrowsing)
}

bool allowed;
nsresult rv = offlineService->OfflineAppAllowedForURI(aURI,
nullptr,
&allowed);
return NS_SUCCEEDED(rv) && allowed;
}

bool
NS_ShouldCheckAppCache(nsIPrincipal *aPrincipal, bool usePrivateBrowsing)
{
if (usePrivateBrowsing) {
return false;
}

nsCOMPtr<nsIOfflineCacheUpdateService> offlineService =
do_GetService("@mozilla.org/offlinecacheupdate-service;1");
if (!offlineService) {
return false;
}

bool allowed;
nsresult rv = offlineService->OfflineAppAllowed(aPrincipal,
nullptr,
&allowed);
rv = offlineService->OfflineAppAllowed(aPrincipal, nullptr, &allowed);
return NS_SUCCEEDED(rv) && allowed;
}

Expand Down
6 changes: 2 additions & 4 deletions netwerk/base/nsNetUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,9 @@ bool NS_HasBeenCrossOrigin(nsIChannel* aChannel, bool aReport = false);
"about.ef2a7dd5-93bc-417f-a698-142c3116864f.mozilla"

/**
* Determines whether appcache should be checked for a given URI.
* Determines whether appcache should be checked for a given principal.
*/
bool NS_ShouldCheckAppCache(nsIURI *aURI, bool usePrivateBrowsing);

bool NS_ShouldCheckAppCache(nsIPrincipal *aPrincipal, bool usePrivateBrowsing);
bool NS_ShouldCheckAppCache(nsIPrincipal *aPrincipal);

/**
* Wraps an nsIAuthPrompt so that it can be used as an nsIAuthPrompt2. This
Expand Down
2 changes: 1 addition & 1 deletion netwerk/protocol/http/HttpChannelParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI,
bool chooseAppCache = false;
// This works because we've already called SetNotificationCallbacks and
// done mPBOverride logic by this point.
chooseAppCache = NS_ShouldCheckAppCache(principal, NS_UsePrivateBrowsing(mChannel));
chooseAppCache = NS_ShouldCheckAppCache(principal);

appCacheChan->SetChooseApplicationCache(chooseAppCache);
}
Expand Down

0 comments on commit 7652396

Please sign in to comment.