Skip to content

Commit

Permalink
Bug 1017758 - Use infallible getters for appId/isInBrowserElement/unk…
Browse files Browse the repository at this point in the history
…nownAppId; r=bz
  • Loading branch information
Ms2ger committed May 13, 2015
1 parent 5b94fb1 commit 274bba7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 61 deletions.
12 changes: 3 additions & 9 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6685,19 +6685,15 @@ nsDocShell::DoAppRedirectIfNeeded(nsIURI* aURI,
nsIDocShellLoadInfo* aLoadInfo,
bool aFirstParty)
{
uint32_t appId;
nsresult rv = GetAppId(&appId);
if (NS_FAILED(rv)) {
return false;
}
uint32_t appId = nsIDocShell::GetAppId();

if (appId != nsIScriptSecurityManager::NO_APP_ID &&
appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
nsCOMPtr<nsIAppsService> appsService =
do_GetService(APPS_SERVICE_CONTRACTID);
NS_ASSERTION(appsService, "No AppsService available");
nsCOMPtr<nsIURI> redirect;
rv = appsService->GetRedirect(appId, aURI, getter_AddRefs(redirect));
nsresult rv = appsService->GetRedirect(appId, aURI, getter_AddRefs(redirect));
if (NS_SUCCEEDED(rv) && redirect) {
rv = LoadURI(redirect, aLoadInfo, nsIWebNavigation::LOAD_FLAGS_NONE,
aFirstParty);
Expand Down Expand Up @@ -13845,9 +13841,7 @@ nsDocShell::GetAppId(uint32_t* aAppId)
NS_IMETHODIMP
nsDocShell::GetAppManifestURL(nsAString& aAppManifestURL)
{
uint32_t appId;
GetAppId(&appId);

uint32_t appId = nsIDocShell::GetAppId();
if (appId != nsIScriptSecurityManager::NO_APP_ID &&
appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
nsCOMPtr<nsIAppsService> appsService =
Expand Down
29 changes: 10 additions & 19 deletions dom/base/nsDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2655,15 +2655,8 @@ nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
}
#endif

#ifdef DEBUG
{
uint32_t appId;
nsresult rv = NodePrincipal()->GetAppId(&appId);
NS_ENSURE_SUCCESS(rv, rv);
MOZ_ASSERT(appId != nsIScriptSecurityManager::UNKNOWN_APP_ID,
"Document should never have UNKNOWN_APP_ID");
}
#endif
MOZ_ASSERT(NodePrincipal()->GetAppId() != nsIScriptSecurityManager::UNKNOWN_APP_ID,
"Document should never have UNKNOWN_APP_ID");

MOZ_ASSERT(GetReadyStateEnum() == nsIDocument::READYSTATE_UNINITIALIZED,
"Bad readyState");
Expand Down Expand Up @@ -2864,16 +2857,14 @@ nsDocument::InitCSP(nsIChannel* aChannel)
if (appStatus != nsIPrincipal::APP_STATUS_NOT_INSTALLED) {
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
if (appsService) {
uint32_t appId = 0;
if (NS_SUCCEEDED(principal->GetAppId(&appId))) {
appsService->GetManifestCSPByLocalId(appId, appManifestCSP);
if (!appManifestCSP.IsEmpty()) {
applyAppManifestCSP = true;
}
appsService->GetDefaultCSPByLocalId(appId, appDefaultCSP);
if (!appDefaultCSP.IsEmpty()) {
applyAppDefaultCSP = true;
}
uint32_t appId = principal->GetAppId();
appsService->GetManifestCSPByLocalId(appId, appManifestCSP);
if (!appManifestCSP.IsEmpty()) {
applyAppManifestCSP = true;
}
appsService->GetDefaultCSPByLocalId(appId, appDefaultCSP);
if (!appDefaultCSP.IsEmpty()) {
applyAppDefaultCSP = true;
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions dom/base/nsGlobalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8438,13 +8438,8 @@ nsGlobalWindow::PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
nsCOMPtr<nsIPrincipal> principal = nsContentUtils::SubjectPrincipal();
MOZ_ASSERT(principal);

uint32_t appId;
if (NS_WARN_IF(NS_FAILED(principal->GetAppId(&appId))))
return;

bool isInBrowser;
if (NS_WARN_IF(NS_FAILED(principal->GetIsInBrowserElement(&isInBrowser))))
return;
uint32_t appId = principal->GetAppId();
bool isInBrowser = principal->GetIsInBrowserElement();

// Create a nsIPrincipal inheriting the app/browser attributes from the
// caller.
Expand Down
32 changes: 6 additions & 26 deletions dom/storage/DOMStorageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,9 @@ CreateScopeKey(nsIPrincipal* aPrincipal,
key.Append(nsPrintfCString(":%d", port));
}

bool unknownAppId;
rv = aPrincipal->GetUnknownAppId(&unknownAppId);
NS_ENSURE_SUCCESS(rv, rv);

if (!unknownAppId) {
uint32_t appId;
rv = aPrincipal->GetAppId(&appId);
NS_ENSURE_SUCCESS(rv, rv);

bool isInBrowserElement;
rv = aPrincipal->GetIsInBrowserElement(&isInBrowserElement);
NS_ENSURE_SUCCESS(rv, rv);

if (!aPrincipal->GetUnknownAppId()) {
uint32_t appId = aPrincipal->GetAppId();
bool isInBrowserElement = aPrincipal->GetIsInBrowserElement();
if (appId == nsIScriptSecurityManager::NO_APP_ID && !isInBrowserElement) {
aKey.Assign(key);
return NS_OK;
Expand Down Expand Up @@ -221,19 +211,9 @@ CreateQuotaDBKey(nsIPrincipal* aPrincipal,

CreateReversedDomain(eTLDplusOne, subdomainsDBKey);

bool unknownAppId;
rv = aPrincipal->GetUnknownAppId(&unknownAppId);
NS_ENSURE_SUCCESS(rv, rv);

if (!unknownAppId) {
uint32_t appId;
rv = aPrincipal->GetAppId(&appId);
NS_ENSURE_SUCCESS(rv, rv);

bool isInBrowserElement;
rv = aPrincipal->GetIsInBrowserElement(&isInBrowserElement);
NS_ENSURE_SUCCESS(rv, rv);

if (!aPrincipal->GetUnknownAppId()) {
uint32_t appId = aPrincipal->GetAppId();
bool isInBrowserElement = aPrincipal->GetIsInBrowserElement();
if (appId == nsIScriptSecurityManager::NO_APP_ID && !isInBrowserElement) {
aKey.Assign(subdomainsDBKey);
return NS_OK;
Expand Down

0 comments on commit 274bba7

Please sign in to comment.