Commit 09ff23c2 authored by Nika Layzell's avatar Nika Layzell
Browse files

Bug 1337056 - Part 3: Send down http[s] and ftp permissions as they are...

Bug 1337056 - Part 3: Send down http[s] and ftp permissions as they are needed. Send down other permissions at startup, r=baku

MozReview-Commit-ID: CUKPvFp6zpF
parent ba95fb3f
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
@@ -1330,6 +1330,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();

@@ -5052,6 +5056,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)
+11 −0
Original line number Diff line number Diff line
@@ -640,6 +640,8 @@ public:
  // 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;

@@ -780,6 +782,13 @@ private:
  // 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,
@@ -1223,6 +1232,8 @@ private:
  // 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;
+8 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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;
+9 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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(),
+7 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include "SerializedLoadContext.h"
#include "nsIContentPolicy.h"
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/dom/ContentParent.h"

using namespace mozilla::ipc;

@@ -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);