Bug 1379345 - Transmit permissions for view-source URIs, r=ehsan

This commit is contained in:
Michael Layzell 2017-08-18 12:36:50 -04:00 коммит произвёл Ehsan Akhgari
Родитель 3f20e1f6cd
Коммит 4f71ca4422
8 изменённых файлов: 47 добавлений и 10 удалений

Просмотреть файл

@ -5135,7 +5135,17 @@ ContentParent::AboutToLoadHttpFtpWyciwygDocumentForChild(nsIChannel* aChannel)
MOZ_ASSERT(aChannel);
nsresult rv;
if (!aChannel->IsDocument()) {
bool isDocument = aChannel->IsDocument();
if (!isDocument) {
// We may be looking at a nsIHttpChannel which has isMainDocumentChannel set
// (e.g. the internal http channel for a view-source: load.).
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
rv = httpChannel->GetIsMainDocumentChannel(&isDocument);
NS_ENSURE_SUCCESS(rv, rv);
}
}
if (!isDocument) {
return NS_OK;
}
@ -5155,9 +5165,7 @@ ContentParent::AboutToLoadHttpFtpWyciwygDocumentForChild(nsIChannel* aChannel)
nsLoadFlags newLoadFlags;
aChannel->GetLoadFlags(&newLoadFlags);
bool isDocument = false;
aChannel->GetIsDocument(&isDocument);
if (newLoadFlags & nsIRequest::LOAD_DOCUMENT_NEEDS_COOKIE && isDocument) {
if (newLoadFlags & nsIRequest::LOAD_DOCUMENT_NEEDS_COOKIE) {
UpdateCookieStatus(aChannel);
}

Просмотреть файл

@ -7,3 +7,4 @@
# nsPermissionManager::PermissionKey::CreateFromPrincipal. Because of this, it
# is only run in e10s opt builds.
skip-if = debug || !e10s
[browser_permmgr_viewsrc.js]

Просмотреть файл

@ -0,0 +1,19 @@
add_task(async function() {
// Add a permission for example.com, start a new content process, and make
// sure that the permission has been sent down.
Services.perms.add(Services.io.newURI("http://example.com"),
"viewsourceTestingPerm",
Services.perms.ALLOW_ACTION);
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser,
"view-source:http://example.com",
/* waitForLoad */ true,
/* waitForStateStop */ false,
/* forceNewProcess */ true);
await ContentTask.spawn(tab.linkedBrowser, null, async function() {
is(Services.perms.testPermission(Services.io.newURI("http://example.com"),
"viewsourceTestingPerm"),
Services.perms.ALLOW_ACTION);
});
await BrowserTestUtils.removeTab(tab);
});

Просмотреть файл

@ -150,6 +150,7 @@ struct HttpChannelOpenArgs
TimeStamp dispatchFetchEventEnd;
TimeStamp handleFetchEventStart;
TimeStamp handleFetchEventEnd;
bool forceMainDocumentChannel;
};
struct HttpChannelConnectArgs

Просмотреть файл

@ -438,7 +438,6 @@ HttpBaseChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
}
mLoadFlags = aLoadFlags;
mForceMainDocumentChannel = (aLoadFlags & LOAD_DOCUMENT_URI);
return NS_OK;
}
@ -2171,7 +2170,7 @@ NS_IMETHODIMP
HttpBaseChannel::GetIsMainDocumentChannel(bool* aValue)
{
NS_ENSURE_ARG_POINTER(aValue);
*aValue = mForceMainDocumentChannel || (mLoadFlags & LOAD_DOCUMENT_URI);
*aValue = IsNavigation();
return NS_OK;
}
@ -2963,7 +2962,7 @@ HttpBaseChannel::GetURIPrincipal()
bool
HttpBaseChannel::IsNavigation()
{
return mForceMainDocumentChannel;
return mForceMainDocumentChannel || (mLoadFlags & LOAD_DOCUMENT_URI);
}
bool

Просмотреть файл

@ -2613,6 +2613,8 @@ HttpChannelChild::ContinueAsyncOpen()
openArgs.handleFetchEventStart() = mHandleFetchEventStart;
openArgs.handleFetchEventEnd() = mHandleFetchEventEnd;
openArgs.forceMainDocumentChannel() = mForceMainDocumentChannel;
// This must happen before the constructor message is sent. Otherwise messages
// from the parent could arrive quickly and be delivered to the wrong event
// target.

Просмотреть файл

@ -149,7 +149,8 @@ HttpChannelParent::Init(const HttpChannelCreationArgs& aArgs)
a.dispatchFetchEventStart(),
a.dispatchFetchEventEnd(),
a.handleFetchEventStart(),
a.handleFetchEventEnd());
a.handleFetchEventEnd(),
a.forceMainDocumentChannel());
}
case HttpChannelCreationArgs::THttpChannelConnectArgs:
{
@ -478,7 +479,8 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI,
const TimeStamp& aDispatchFetchEventStart,
const TimeStamp& aDispatchFetchEventEnd,
const TimeStamp& aHandleFetchEventStart,
const TimeStamp& aHandleFetchEventEnd)
const TimeStamp& aHandleFetchEventEnd,
const bool& aForceMainDocumentChannel)
{
nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
if (!uri) {
@ -555,6 +557,10 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI,
if (aLoadFlags != nsIRequest::LOAD_NORMAL)
httpChannel->SetLoadFlags(aLoadFlags);
if (aForceMainDocumentChannel) {
httpChannel->SetIsMainDocumentChannel(true);
}
for (uint32_t i = 0; i < requestHeaders.Length(); i++) {
if (requestHeaders[i].mEmpty) {
httpChannel->SetEmptyRequestHeader(requestHeaders[i].mHeader);

Просмотреть файл

@ -172,7 +172,8 @@ protected:
const TimeStamp& aDispatchFetchEventStart,
const TimeStamp& aDispatchFetchEventEnd,
const TimeStamp& aHandleFetchEventStart,
const TimeStamp& aHandleFetchEventEnd);
const TimeStamp& aHandleFetchEventEnd,
const bool& aForceMainDocumentChannel);
virtual mozilla::ipc::IPCResult RecvSetPriority(const int16_t& priority) override;
virtual mozilla::ipc::IPCResult RecvSetClassOfService(const uint32_t& cos) override;