Bug 1199049 - Part 10: Use Necko-level CORS preflights in sendBeacon; r=jdm

This commit is contained in:
Ehsan Akhgari 2015-08-27 18:09:17 -04:00
Родитель 8c79cf1c17
Коммит b64a770b94
1 изменённых файлов: 16 добавлений и 9 удалений

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

@ -68,6 +68,7 @@
#include "nsComponentManagerUtils.h"
#include "nsIStringStream.h"
#include "nsIHttpChannel.h"
#include "nsIHttpChannelInternal.h"
#include "TimeManager.h"
#include "DeviceStorage.h"
#include "nsIDOMNavigatorSystemMessages.h"
@ -1322,18 +1323,24 @@ Navigator::SendBeacon(const nsAString& aUrl,
nsCOMPtr<nsIInterfaceRequestor> soc = nsContentUtils::SameOriginChecker();
channel->SetNotificationCallbacks(soc);
nsCOMPtr<nsIChannel> preflightChannel;
nsCOMPtr<nsIHttpChannelInternal> internalChannel =
do_QueryInterface(channel);
if (!internalChannel) {
aRv.Throw(NS_ERROR_FAILURE);
return false;
}
nsTArray<nsCString> unsafeHeaders;
unsafeHeaders.AppendElement(NS_LITERAL_CSTRING("Content-Type"));
rv = NS_StartCORSPreflight(channel,
beaconListener,
doc->NodePrincipal(),
true,
unsafeHeaders,
getter_AddRefs(preflightChannel));
} else {
rv = channel->AsyncOpen2(beaconListener);
rv = internalChannel->SetCorsPreflightParameters(unsafeHeaders,
true,
doc->NodePrincipal());
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(rv);
return false;
}
}
rv = channel->AsyncOpen2(beaconListener);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return false;