Skip to content

Commit

Permalink
Bug 1319045 - Get rid of nsPrincipal::GetOriginFromURI, r=qdot
Browse files Browse the repository at this point in the history
  • Loading branch information
bakulf committed Nov 22, 2016
1 parent e727c44 commit dd1d53b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
14 changes: 4 additions & 10 deletions caps/nsPrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ nsPrincipal::GetScriptLocation(nsACString &aStr)
return mCodebase->GetSpec(aStr);
}

/* static */ nsresult
nsPrincipal::GetOriginForURI(nsIURI* aURI, nsACString& aOrigin)
nsresult
nsPrincipal::GetOriginInternal(nsACString& aOrigin)
{
if (!aURI) {
if (!mCodebase) {
return NS_ERROR_FAILURE;
}

nsCOMPtr<nsIURI> origin = NS_GetInnermostURI(aURI);
nsCOMPtr<nsIURI> origin = NS_GetInnermostURI(mCodebase);
if (!origin) {
return NS_ERROR_FAILURE;
}
Expand Down Expand Up @@ -178,12 +178,6 @@ nsPrincipal::GetOriginForURI(nsIURI* aURI, nsACString& aOrigin)
return NS_OK;
}

nsresult
nsPrincipal::GetOriginInternal(nsACString& aOrigin)
{
return GetOriginForURI(mCodebase, aOrigin);
}

bool
nsPrincipal::SubsumesInternal(nsIPrincipal* aOther,
BasePrincipal::DocumentDomainConsideration aConsideration)
Expand Down
5 changes: 0 additions & 5 deletions caps/nsPrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class nsPrincipal final : public mozilla::BasePrincipal
virtual nsresult GetScriptLocation(nsACString& aStr) override;
void SetURI(nsIURI* aURI);

/**
* Computes the puny-encoded origin of aURI.
*/
static nsresult GetOriginForURI(nsIURI* aURI, nsACString& aOrigin);

/**
* Called at startup to setup static data, e.g. about:config pref-observers.
*/
Expand Down
19 changes: 14 additions & 5 deletions dom/media/MediaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2079,8 +2079,14 @@ if (privileged) {
(uint32_t) GetUserMediaSecurityState::Other);
}

nsCString origin;
rv = nsPrincipal::GetOriginForURI(docURI, origin);
nsCOMPtr<nsIPrincipal> principal =
nsGlobalWindow::Cast(aWindow)->GetPrincipal();
if (NS_WARN_IF(!principal)) {
return NS_ERROR_FAILURE;
}

nsAutoCString origin;
rv = principal->GetOrigin(origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
Expand Down Expand Up @@ -2236,7 +2242,6 @@ if (privileged) {
StreamListeners* listeners = AddWindowID(windowID);

// Create a disabled listener to act as a placeholder
nsIPrincipal* principal = aWindow->GetExtantDoc()->NodePrincipal();
RefPtr<GetUserMediaCallbackMediaStreamListener> listener =
new GetUserMediaCallbackMediaStreamListener(mMediaThread, windowID,
MakePrincipalHandle(principal));
Expand Down Expand Up @@ -2492,8 +2497,12 @@ MediaManager::EnumerateDevicesImpl(uint64_t aWindowId,
// 3. Anonymize the raw list with the origin-key.

bool privateBrowsing = IsPrivateBrowsing(window);
nsCString origin;
nsPrincipal::GetOriginForURI(window->GetDocumentURI(), origin);
nsCOMPtr<nsIPrincipal> principal =
nsGlobalWindow::Cast(window)->GetPrincipal();
MOZ_ASSERT(principal);

nsAutoCString origin;
principal->GetOrigin(origin);

bool persist = IsActivelyCapturingOrHasAPermission(aWindowId);

Expand Down

0 comments on commit dd1d53b

Please sign in to comment.