/
Credential.cpp
86 lines (74 loc) · 2.25 KB
/
Credential.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "Credential.h"
#include "mozilla/dom/CredentialContainerBinding.h"
#include "mozilla/dom/FetchBinding.h"
#include "mozilla/dom/RequestBinding.h"
#include "nsFormData.h"
#include "nsIDOMLocation.h"
#include "nsIIOService.h"
#include "nsIURI.h"
#include "nsNetUtil.h"
#include "mozilla/dom/Fetch.h"
namespace mozilla {
namespace dom {
// Only needed for refcounted objects.
// NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Credential)
NS_IMPL_CYCLE_COLLECTION(Credential, mGlobal)
NS_IMPL_CYCLE_COLLECTING_ADDREF(Credential)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Credential)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Credential)
//NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
Credential::Credential()
{
}
Credential::~Credential()
{
}
Credential::Credential(nsIGlobalObject* aGlobal, const CredentialData& data)
{
mGlobal = aGlobal;
if (data.mId.WasPassed()) {
mId = data.mId.Value();
} else {
// FIXME throw if not passed???
}
}
static bool isInherentlyInsecure(nsIDOMLocation* aLocation)
{
DOMString protocol;
nsresult rv = aLocation->GetProtocol(protocol);
NS_ENSURE_SUCCESS(rv, false);
nsString pString = protocol.AsAString();
return pString.EqualsLiteral("http");
}
static bool isInherentlyInsecure(nsCOMPtr<nsIURI> aUri)
{
nsAutoCString schemeStr;
nsresult rv = aUri->GetScheme(schemeStr);
NS_ENSURE_SUCCESS(rv, false);
return (!(StringBeginsWith(schemeStr, NS_LITERAL_CSTRING("http")) &&
(schemeStr.Length() == 4)));
}
already_AddRefed<Credential>
Credential::Constructor(const GlobalObject& aGlobal,
const CredentialData& data, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
MOZ_ASSERT(global, "expected a DOM window");
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
nsIDOMLocation* location;
nsresult rv = window->GetLocation(&location);
NS_ENSURE_SUCCESS(rv, nullptr);
if (isInherentlyInsecure(location)) {
NS_WARNING("Do not use Credential on inherently insecure pages");
}
nsRefPtr<Credential> ret = new Credential(global, data);
return ret.forget();
}
static bool originMismatch(nsCOMPtr<nsIURI> uri) {
// FIXME
return false;
}
} // namespace dom
} // namespace mozilla