Skip to content

Commit

Permalink
Bug 1264178 - Part 2: Change URL's getter function from PassByReferen…
Browse files Browse the repository at this point in the history
…ce to ReturnByReference. r=bkelly

--HG--
extra : rebase_source : d38a18c5856943b125d4a999091e4532a56934e2
  • Loading branch information
chihweitung committed Nov 7, 2016
1 parent a63de77 commit 8b030a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
23 changes: 8 additions & 15 deletions dom/fetch/InternalResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,37 +85,30 @@ class InternalResponse final
{
return Type() == ResponseType::Error;
}

// GetUrl should return last fetch URL in response's url list and null if
// response's url list is the empty list.
void
GetURL(nsCString& aURL) const
const nsCString&
GetURL() const
{
// Empty urlList when response is a synthetic response.
if (mURLList.IsEmpty()) {
aURL.Truncate();
return;
return EmptyCString();
}

aURL.Assign(mURLList.LastElement());
return mURLList.LastElement();
}

void
GetURLList(nsTArray<nsCString>& aURLList) const
{
aURLList.Assign(mURLList);
}

void
GetUnfilteredURL(nsCString& aURL) const
const nsCString&
GetUnfilteredURL() const
{
if (mWrappedResponse) {
return mWrappedResponse->GetURL(aURL);
return mWrappedResponse->GetURL();
}

return GetURL(aURL);
return GetURL();
}

void
GetUnfilteredURLList(nsTArray<nsCString>& aURLList) const
{
Expand Down
7 changes: 1 addition & 6 deletions dom/fetch/Response.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,16 @@ class Response final : public nsISupports
{
return mInternalResponse->Type();
}

void
GetUrl(nsAString& aUrl) const
{
nsCString url;
mInternalResponse->GetURL(url);
CopyUTF8toUTF16(url, aUrl);
CopyUTF8toUTF16(mInternalResponse->GetURL(), aUrl);
}

bool
Redirected() const
{
return mInternalResponse->IsRedirected();
}

uint16_t
Status() const
{
Expand Down
10 changes: 2 additions & 8 deletions dom/workers/ServiceWorkerEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,19 @@ class FinishResponse final : public Runnable

return rv;
}

bool CSPPermitsResponse(nsILoadInfo* aLoadInfo)
{
AssertIsOnMainThread();
MOZ_ASSERT(aLoadInfo);

nsresult rv;
nsCOMPtr<nsIURI> uri;
nsAutoCString url;
mInternalResponse->GetUnfilteredURL(url);
nsCString url = mInternalResponse->GetUnfilteredURL();
if (url.IsEmpty()) {
// Synthetic response. The buck stops at the worker script.
url = mScriptSpec;
}
rv = NS_NewURI(getter_AddRefs(uri), url, nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, false);

int16_t decision = nsIContentPolicy::ACCEPT;
rv = NS_CheckContentLoadPolicy(aLoadInfo->InternalContentPolicyType(), uri,
aLoadInfo->LoadingPrincipal(),
Expand Down Expand Up @@ -635,18 +631,16 @@ RespondWithHandler::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValu
if (NS_WARN_IF(!ir)) {
return;
}

// When an opaque response is encountered, we need the original channel's principal
// to reflect the final URL. Non-opaque responses are either same-origin or CORS-enabled
// cross-origin responses, which are treated as same-origin by consumers.
nsCString responseURL;
if (response->Type() == ResponseType::Opaque) {
ir->GetUnfilteredURL(responseURL);
responseURL = ir->GetUnfilteredURL();
if (NS_WARN_IF(responseURL.IsEmpty())) {
return;
}
}

nsAutoPtr<RespondWithClosure> closure(new RespondWithClosure(mInterceptedChannel,
mRegistration, ir,
worker->GetChannelInfo(),
Expand Down

0 comments on commit 8b030a7

Please sign in to comment.