Skip to content

Commit

Permalink
Bug 1379786, part 2 - Use nsContentUtils::GetSystemPrincipal in vario…
Browse files Browse the repository at this point in the history
…us places. r=mrbkap

MozReview-Commit-ID: KPXAqKeX4gI

--HG--
extra : rebase_source : 44fd734e7c5bbaba48bb25b882acc74cf0b81fb5
  • Loading branch information
amccreight committed Jul 10, 2017
1 parent 5de8ffc commit cf00cf9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 59 deletions.
15 changes: 3 additions & 12 deletions chrome/nsChromeProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "nsChromeProtocolHandler.h"
#include "nsChromeRegistry.h"
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "nsThreadUtils.h"
#include "nsIChannel.h"
#include "nsIChromeRegistry.h"
Expand Down Expand Up @@ -186,18 +187,8 @@ nsChromeProtocolHandler::NewChannel2(nsIURI* aURI,
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
nsAutoCString path;
rv = url->GetPath(path);
if (StringBeginsWith(path, NS_LITERAL_CSTRING("/content/")))
{
nsCOMPtr<nsIScriptSecurityManager> securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;

nsCOMPtr<nsIPrincipal> principal;
rv = securityManager->GetSystemPrincipal(getter_AddRefs(principal));
if (NS_FAILED(rv)) return rv;

nsCOMPtr<nsISupports> owner = do_QueryInterface(principal);
result->SetOwner(owner);
if (StringBeginsWith(path, NS_LITERAL_CSTRING("/content/"))) {
result->SetOwner(nsContentUtils::GetSystemPrincipal());
}

// XXX Removed dependency-tracking code from here, because we're not
Expand Down
10 changes: 1 addition & 9 deletions dom/base/test/gtest/TestNativeXMLHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ TEST(NativeXMLHttpRequest, Test)
NS_NAMED_LITERAL_CSTRING(testURL, TEST_URL);
const nsAString& empty = EmptyString();

nsCOMPtr<nsIScriptSecurityManager> secman =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
ASSERT_TRUE(NS_SUCCEEDED(rv)) << "Couldn't get script security manager";

nsCOMPtr<nsIPrincipal> systemPrincipal;
rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
ASSERT_TRUE(NS_SUCCEEDED(rv)) << "Couldn't get system principal";

rv = xhr->Init(systemPrincipal, nullptr, nullptr, nullptr);
rv = xhr->Init(nsContentUtils::GetSystemPrincipal(), nullptr, nullptr, nullptr);
ASSERT_TRUE(NS_SUCCEEDED(rv)) << "Couldn't initialize the XHR";

rv = xhr->Open(getString, testURL, false, empty, empty);
Expand Down
19 changes: 2 additions & 17 deletions media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "MediaStreamGraphImpl.h"

#include "nsContentUtils.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsIURI.h"
Expand Down Expand Up @@ -341,26 +342,10 @@ PeerConnectionMedia::InitProxy()
return NS_ERROR_FAILURE;
}

nsCOMPtr<nsIScriptSecurityManager> secMan(
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
if (NS_FAILED(rv)) {
CSFLogError(logTag, "%s: Failed to get IOService: %d",
__FUNCTION__, (int)rv);
CSFLogError(logTag, "%s: Failed to get securityManager: %d", __FUNCTION__, (int)rv);
return NS_ERROR_FAILURE;
}

nsCOMPtr<nsIPrincipal> systemPrincipal;
rv = secMan->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
if (NS_FAILED(rv)) {
CSFLogError(logTag, "%s: Failed to get systemPrincipal: %d", __FUNCTION__, (int)rv);
return NS_ERROR_FAILURE;
}

nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel),
fakeHttpsLocation,
systemPrincipal,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER);

Expand Down
8 changes: 2 additions & 6 deletions netwerk/base/nsIOService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1854,14 +1854,10 @@ nsIOService::SpeculativeConnectInternal(nsIURI *aURI,

NS_ASSERTION(aPrincipal, "We expect passing a principal here.");

// If the principal is given, we use this prinicpal directly. Otherwise,
// If the principal is given, we use this principal directly. Otherwise,
// we fallback to use the system principal.
if (!aPrincipal) {
nsCOMPtr<nsIScriptSecurityManager> secMan(
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
rv = secMan->GetSystemPrincipal(getter_AddRefs(loadingPrincipal));
NS_ENSURE_SUCCESS(rv, rv);
loadingPrincipal = nsContentUtils::GetSystemPrincipal();
}

// dummy channel used to create a TCP connection.
Expand Down
10 changes: 2 additions & 8 deletions netwerk/base/nsProtocolProxyService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "nsIScriptSecurityManager.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsContentUtils.h"
#include "nsThreadUtils.h"
#include "nsQueryObject.h"
#include "nsSOCKSIOLayer.h"
Expand Down Expand Up @@ -1415,19 +1416,12 @@ nsProtocolProxyService::AsyncResolve(nsISupports *channelOrURI, uint32_t flags,
return NS_ERROR_NO_INTERFACE;
}

nsCOMPtr<nsIScriptSecurityManager> secMan(
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrincipal> systemPrincipal;
rv = secMan->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
NS_ENSURE_SUCCESS(rv, rv);

// creating a temporary channel from the URI which is not
// used to perform any network loads, hence its safe to
// use systemPrincipal as the loadingPrincipal.
rv = NS_NewChannel(getter_AddRefs(channel),
uri,
systemPrincipal,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER);
NS_ENSURE_SUCCESS(rv, rv);
Expand Down
9 changes: 2 additions & 7 deletions netwerk/test/TestUDPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "nsINetAddr.h"
#include "nsIScriptSecurityManager.h"
#include "nsITimer.h"
#include "nsContentUtils.h"
#include "mozilla/net/DNS.h"
#include "prerror.h"

Expand Down Expand Up @@ -258,13 +259,7 @@ TEST(TestUDPSocket, TestUDPSocketMain)
// Create UDPServerListener to process UDP packets
RefPtr<UDPServerListener> serverListener = new UDPServerListener(waiter);

nsCOMPtr<nsIScriptSecurityManager> secman =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
ASSERT_TRUE(NS_SUCCEEDED(rv));

nsCOMPtr<nsIPrincipal> systemPrincipal;
rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
ASSERT_TRUE(NS_SUCCEEDED(rv));
nsCOMPtr<nsIPrincipal> systemPrincipal = nsContentUtils::GetSystemPrincipal();

// Bind server socket to 0.0.0.0
rv = server->Init(0, false, systemPrincipal, true, 0);
Expand Down

0 comments on commit cf00cf9

Please sign in to comment.