Skip to content

Commit

Permalink
Bug 1337056 - Part 3: Send down http[s] and ftp permissions as they a…
Browse files Browse the repository at this point in the history
…re needed. Send down other permissions at startup, r=baku

MozReview-Commit-ID: CUKPvFp6zpF
  • Loading branch information
mystor committed Mar 14, 2017
1 parent e7fb4ee commit d861bbc
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
60 changes: 60 additions & 0 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,10 @@ ContentParent::Init()
}
#endif

// Ensure that the default set of permissions are avaliable in the content
// process before we try to load any URIs in it.
EnsurePermissionsByKey(EmptyCString());

RefPtr<GeckoMediaPluginServiceParent> gmps(GeckoMediaPluginServiceParent::GetSingleton());
gmps->UpdateContentProcessGMPCapabilities();

Expand Down Expand Up @@ -4986,6 +4990,62 @@ ContentParent::ForceTabPaint(TabParent* aTabParent, uint64_t aLayerObserverEpoch
ProcessHangMonitor::ForcePaint(mHangMonitorActor, aTabParent, aLayerObserverEpoch);
}

nsresult
ContentParent::TransmitPermissionsFor(nsIChannel* aChannel)
{
MOZ_ASSERT(aChannel);
#ifdef MOZ_PERMISSIONS
// If the LOAD_DOCUMENT_URI load flag is not set, we don't need to send down
// permissions, as we won't create a document from this channel.
nsLoadFlags loadFlags;
nsresult rv = aChannel->GetLoadFlags(&loadFlags);
NS_ENSURE_SUCCESS(rv, rv);
if (!(loadFlags & nsIChannel::LOAD_DOCUMENT_URI)) {
return NS_OK;
}

// Get the principal for the channel result, so that we can get the permission
// key for the document which will be created from this response.
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
if (NS_WARN_IF(!ssm)) {
return NS_ERROR_FAILURE;
}

nsCOMPtr<nsIPrincipal> principal;
rv = ssm->GetChannelResultPrincipal(aChannel, getter_AddRefs(principal));
NS_ENSURE_SUCCESS(rv, rv);

// Create the key, and send it down to the content process.
nsAutoCString key;
nsPermissionManager::GetKeyForPrincipal(principal, key);
EnsurePermissionsByKey(key);
#endif

return NS_OK;
}

void
ContentParent::EnsurePermissionsByKey(const nsCString& aKey)
{
#ifdef MOZ_PERMISSIONS
if (mActivePermissionKeys.Contains(aKey)) {
return;
}
mActivePermissionKeys.PutEntry(aKey);

nsCOMPtr<nsIPermissionManager> permManager =
services::GetPermissionManager();

nsTArray<IPC::Permission> perms;
nsresult rv = permManager->GetPermissionsWithKey(aKey, perms);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}

Unused << SendSetPermissionsWithKey(aKey, perms);
#endif
}

mozilla::ipc::IPCResult
ContentParent::RecvAccumulateChildHistograms(
InfallibleTArray<Accumulation>&& aAccumulations)
Expand Down
11 changes: 11 additions & 0 deletions dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ class ContentParent final : public PContentParent
// Use the PHangMonitor channel to ask the child to repaint a tab.
void ForceTabPaint(TabParent* aTabParent, uint64_t aLayerObserverEpoch);

nsresult TransmitPermissionsFor(nsIChannel* aChannel);

protected:
void OnChannelConnected(int32_t pid) override;

Expand Down Expand Up @@ -763,6 +765,13 @@ class ContentParent final : public PContentParent
// Start the force-kill timer on shutdown.
void StartForceKillTimer();

// Ensure that the permissions for the giben Permission key are set in the
// content process.
//
// See nsIPermissionManager::GetPermissionsForKey for more information on
// these keys.
void EnsurePermissionsByKey(const nsCString& aKey);

static void ForceKillTimerCallback(nsITimer* aTimer, void* aClosure);

static bool AllocateLayerTreeId(ContentParent* aContent,
Expand Down Expand Up @@ -1206,6 +1215,8 @@ class ContentParent final : public PContentParent
// GetFilesHelper can be aborted by receiving RecvDeleteGetFilesRequest.
nsRefPtrHashtable<nsIDHashKey, GetFilesHelper> mGetFilesPendingRequests;

nsTHashtable<nsCStringHashKey> mActivePermissionKeys;

nsTArray<nsCString> mBlobURLs;
#ifdef MOZ_CRASHREPORTER
UniquePtr<mozilla::ipc::CrashReporterHost> mCrashReporter;
Expand Down
8 changes: 8 additions & 0 deletions netwerk/protocol/ftp/FTPChannelParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "nsIContentPolicy.h"
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/dom/ContentParent.h"

using namespace mozilla::dom;
using namespace mozilla::ipc;
Expand Down Expand Up @@ -457,6 +458,13 @@ FTPChannelParent::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
MOZ_ASSERT(chan);
NS_ENSURE_TRUE(chan, NS_ERROR_UNEXPECTED);

// Send down any permissions which are relevant to this URL if we are
// performing a document load.
PContentParent* pcp = Manager()->Manager();
DebugOnly<nsresult> rv =
static_cast<ContentParent*>(pcp)->TransmitPermissionsFor(chan);
MOZ_ASSERT(NS_SUCCEEDED(rv));

int64_t contentLength;
chan->GetContentLength(&contentLength);
nsCString contentType;
Expand Down
10 changes: 9 additions & 1 deletion netwerk/protocol/http/HttpChannelParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "nsStringStream.h"
#include "nsQueryObject.h"
#include "nsIURIClassifier.h"
#include "mozilla/dom/ContentParent.h"

using mozilla::BasePrincipal;
using namespace mozilla::dom;
Expand Down Expand Up @@ -1126,6 +1127,13 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
MOZ_ASSERT(mChannel == chan,
"HttpChannelParent getting OnStartRequest from a different nsHttpChannel instance");

// Send down any permissions which are relevant to this URL if we are
// performing a document load.
PContentParent* pcp = Manager()->Manager();
nsresult rv =
static_cast<ContentParent*>(pcp)->TransmitPermissionsFor(chan);
MOZ_ASSERT(NS_SUCCEEDED(rv));

nsHttpResponseHead *responseHead = chan->GetResponseHead();
nsHttpRequestHead *requestHead = chan->GetRequestHead();
bool isFromCache = false;
Expand Down Expand Up @@ -1192,7 +1200,7 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)

// !!! We need to lock headers and please don't forget to unlock them !!!
requestHead->Enter();
nsresult rv = NS_OK;
rv = NS_OK;
if (mIPCClosed ||
!SendOnStartRequest(channelStatus,
responseHead ? *responseHead : nsHttpResponseHead(),
Expand Down
7 changes: 7 additions & 0 deletions netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "SerializedLoadContext.h"
#include "nsIContentPolicy.h"
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/dom/ContentParent.h"

using namespace mozilla::ipc;

Expand Down Expand Up @@ -320,6 +321,12 @@ WyciwygChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext
nsCOMPtr<nsIWyciwygChannel> chan = do_QueryInterface(aRequest, &rv);
NS_ENSURE_SUCCESS(rv, rv);

// Send down any permissions which are relevant to this URL if we are
// performing a document load.
PContentParent* pcp = Manager()->Manager();
rv = static_cast<ContentParent*>(pcp)->TransmitPermissionsFor(chan);
MOZ_ASSERT(NS_SUCCEEDED(rv));

nsresult status;
chan->GetStatus(&status);

Expand Down

0 comments on commit d861bbc

Please sign in to comment.