From f994d03624bf7e8ea8d1bb5b5065865fff7bf4a3 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 13 May 2015 17:59:08 +0200 Subject: [PATCH] Bug 1017758 - Use infallible getters for appId/isInBrowserElement/unknownAppId; r=bz --- docshell/base/nsDocShell.cpp | 12 +++--------- dom/base/nsDocument.cpp | 29 ++++++++++------------------ dom/base/nsGlobalWindow.cpp | 9 ++------- dom/storage/DOMStorageManager.cpp | 32 ++++++------------------------- 4 files changed, 21 insertions(+), 61 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 80969353ae4a..2e39f3bb51f8 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -6685,11 +6685,7 @@ 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) { @@ -6697,7 +6693,7 @@ nsDocShell::DoAppRedirectIfNeeded(nsIURI* aURI, do_GetService(APPS_SERVICE_CONTRACTID); NS_ASSERTION(appsService, "No AppsService available"); nsCOMPtr 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); @@ -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 appsService = diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 71a5ded0ea37..ea11a32d5c25 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -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"); @@ -2864,16 +2857,14 @@ nsDocument::InitCSP(nsIChannel* aChannel) if (appStatus != nsIPrincipal::APP_STATUS_NOT_INSTALLED) { nsCOMPtr 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; } } } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 70c44239860e..c4d6a25fb8bb 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -8438,13 +8438,8 @@ nsGlobalWindow::PostMessageMoz(JSContext* aCx, JS::Handle aMessage, nsCOMPtr 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. diff --git a/dom/storage/DOMStorageManager.cpp b/dom/storage/DOMStorageManager.cpp index cd103011c503..954cc53cd159 100644 --- a/dom/storage/DOMStorageManager.cpp +++ b/dom/storage/DOMStorageManager.cpp @@ -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; @@ -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;