Bug 1184607 P7.7 Allow new Response() to be used in xpcshell tests. r=ehsan

This commit is contained in:
Ben Kelly 2015-08-31 14:26:30 -07:00
parent ba103561d2
commit 3e155da886
3 changed files with 25 additions and 5 deletions

View File

@ -6,6 +6,7 @@
#include "mozilla/dom/ChannelInfo.h"
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "nsIChannel.h"
#include "nsIDocument.h"
#include "nsIHttpChannel.h"
@ -68,6 +69,20 @@ ChannelInfo::InitFromChannel(nsIChannel* aChannel)
mInited = true;
}
void
ChannelInfo::InitFromChromeGlobal(nsIGlobalObject* aGlobal)
{
MOZ_ASSERT(!mInited, "Cannot initialize the object twice");
MOZ_ASSERT(aGlobal);
MOZ_RELEASE_ASSERT(
nsContentUtils::IsSystemPrincipal(aGlobal->PrincipalOrNull()));
mSecurityInfo.Truncate();
mRedirected = false;
mInited = true;
}
void
ChannelInfo::InitFromIPCChannelInfo(const ipc::IPCChannelInfo& aChannelInfo)
{

View File

@ -12,6 +12,7 @@
class nsIChannel;
class nsIDocument;
class nsIGlobalObject;
class nsIURI;
namespace mozilla {
@ -69,6 +70,7 @@ public:
void InitFromDocument(nsIDocument* aDoc);
void InitFromChannel(nsIChannel* aChannel);
void InitFromChromeGlobal(nsIGlobalObject* aGlobal);
void InitFromIPCChannelInfo(const IPCChannelInfo& aChannelInfo);
// This restores every possible information stored from a previous channel

View File

@ -162,12 +162,15 @@ Response::Constructor(const GlobalObject& aGlobal,
// Grab a valid channel info from the global so this response is 'valid' for
// interception.
if (NS_IsMainThread()) {
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global);
MOZ_ASSERT(window);
nsIDocument* doc = window->GetExtantDoc();
MOZ_ASSERT(doc);
ChannelInfo info;
info.InitFromDocument(doc);
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global);
if (window) {
nsIDocument* doc = window->GetExtantDoc();
MOZ_ASSERT(doc);
info.InitFromDocument(doc);
} else {
info.InitFromChromeGlobal(global);
}
internalResponse->InitChannelInfo(info);
} else {
workers::WorkerPrivate* worker = workers::GetCurrentThreadWorkerPrivate();