mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Backed out changeset a99817b61d70 (bug 1306248) for crashed @nsContentUtils::SubjectPrincipal
CLOSED TREE
This commit is contained in:
parent
1f9a415918
commit
2afc902dd2
@ -10577,18 +10577,16 @@ nsGlobalWindow::GetSessionStorage(ErrorResult& aError)
|
||||
}
|
||||
|
||||
DOMStorage*
|
||||
nsGlobalWindow::GetLocalStorage(const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aError)
|
||||
nsGlobalWindow::GetLocalStorage(ErrorResult& aError)
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(IsInnerWindow());
|
||||
MOZ_ASSERT(aSubjectPrincipal.isSome());
|
||||
|
||||
if (!Preferences::GetBool(kStorageEnabled)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!mLocalStorage) {
|
||||
if (!DOMStorage::CanUseStorage(AsInner(), aSubjectPrincipal)) {
|
||||
if (!DOMStorage::CanUseStorage(AsInner())) {
|
||||
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
@ -11537,9 +11535,8 @@ nsGlobalWindow::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
// Clone the storage event included in the observer notification. We want
|
||||
// to dispatch clones rather than the original event.
|
||||
ErrorResult error;
|
||||
RefPtr<StorageEvent> newEvent =
|
||||
CloneStorageEvent(eventType, event, nsContentUtils::SubjectPrincipal(),
|
||||
error);
|
||||
RefPtr<StorageEvent> newEvent = CloneStorageEvent(eventType,
|
||||
event, error);
|
||||
if (error.Failed()) {
|
||||
return error.StealNSResult();
|
||||
}
|
||||
@ -11638,11 +11635,9 @@ nsGlobalWindow::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
already_AddRefed<StorageEvent>
|
||||
nsGlobalWindow::CloneStorageEvent(const nsAString& aType,
|
||||
const RefPtr<StorageEvent>& aEvent,
|
||||
nsIPrincipal* aSubjectPrincipal,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(IsInnerWindow());
|
||||
MOZ_ASSERT(aSubjectPrincipal);
|
||||
|
||||
StorageEventInit dict;
|
||||
|
||||
@ -11658,7 +11653,7 @@ nsGlobalWindow::CloneStorageEvent(const nsAString& aType,
|
||||
|
||||
RefPtr<DOMStorage> storage;
|
||||
if (storageArea->GetType() == DOMStorage::LocalStorage) {
|
||||
storage = GetLocalStorage(Some(aSubjectPrincipal), aRv);
|
||||
storage = GetLocalStorage(aRv);
|
||||
} else {
|
||||
MOZ_ASSERT(storageArea->GetType() == DOMStorage::SessionStorage);
|
||||
storage = GetSessionStorage(aRv);
|
||||
|
@ -1044,9 +1044,7 @@ public:
|
||||
void Btoa(const nsAString& aBinaryData, nsAString& aAsciiBase64String,
|
||||
mozilla::ErrorResult& aError);
|
||||
mozilla::dom::DOMStorage* GetSessionStorage(mozilla::ErrorResult& aError);
|
||||
mozilla::dom::DOMStorage*
|
||||
GetLocalStorage(const mozilla::Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
mozilla::ErrorResult& aError);
|
||||
mozilla::dom::DOMStorage* GetLocalStorage(mozilla::ErrorResult& aError);
|
||||
mozilla::dom::Selection* GetSelectionOuter();
|
||||
mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aError);
|
||||
already_AddRefed<nsISelection> GetSelection() override;
|
||||
@ -1671,7 +1669,6 @@ protected:
|
||||
already_AddRefed<mozilla::dom::StorageEvent>
|
||||
CloneStorageEvent(const nsAString& aType,
|
||||
const RefPtr<mozilla::dom::StorageEvent>& aEvent,
|
||||
nsIPrincipal* aSubjectPrincipal,
|
||||
mozilla::ErrorResult& aRv);
|
||||
|
||||
public:
|
||||
|
@ -67,12 +67,9 @@ DOMStorage::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
}
|
||||
|
||||
uint32_t
|
||||
DOMStorage::GetLength(const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv)
|
||||
DOMStorage::GetLength(ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(aSubjectPrincipal.isSome());
|
||||
|
||||
if (!CanUseStorage(nullptr, aSubjectPrincipal, this)) {
|
||||
if (!CanUseStorage(nullptr, this)) {
|
||||
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return 0;
|
||||
}
|
||||
@ -83,13 +80,9 @@ DOMStorage::GetLength(const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
}
|
||||
|
||||
void
|
||||
DOMStorage::Key(uint32_t aIndex, nsAString& aResult,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv)
|
||||
DOMStorage::Key(uint32_t aIndex, nsAString& aResult, ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(aSubjectPrincipal.isSome());
|
||||
|
||||
if (!CanUseStorage(nullptr, aSubjectPrincipal, this)) {
|
||||
if (!CanUseStorage(nullptr, this)) {
|
||||
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return;
|
||||
}
|
||||
@ -98,13 +91,9 @@ DOMStorage::Key(uint32_t aIndex, nsAString& aResult,
|
||||
}
|
||||
|
||||
void
|
||||
DOMStorage::GetItem(const nsAString& aKey, nsAString& aResult,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv)
|
||||
DOMStorage::GetItem(const nsAString& aKey, nsAString& aResult, ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(aSubjectPrincipal.isSome());
|
||||
|
||||
if (!CanUseStorage(nullptr, aSubjectPrincipal, this)) {
|
||||
if (!CanUseStorage(nullptr, this)) {
|
||||
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return;
|
||||
}
|
||||
@ -114,12 +103,9 @@ DOMStorage::GetItem(const nsAString& aKey, nsAString& aResult,
|
||||
|
||||
void
|
||||
DOMStorage::SetItem(const nsAString& aKey, const nsAString& aData,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(aSubjectPrincipal.isSome());
|
||||
|
||||
if (!CanUseStorage(nullptr, aSubjectPrincipal, this)) {
|
||||
if (!CanUseStorage(nullptr, this)) {
|
||||
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return;
|
||||
}
|
||||
@ -143,13 +129,9 @@ DOMStorage::SetItem(const nsAString& aKey, const nsAString& aData,
|
||||
}
|
||||
|
||||
void
|
||||
DOMStorage::RemoveItem(const nsAString& aKey,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv)
|
||||
DOMStorage::RemoveItem(const nsAString& aKey, ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(aSubjectPrincipal.isSome());
|
||||
|
||||
if (!CanUseStorage(nullptr, aSubjectPrincipal, this)) {
|
||||
if (!CanUseStorage(nullptr, this)) {
|
||||
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return;
|
||||
}
|
||||
@ -166,12 +148,9 @@ DOMStorage::RemoveItem(const nsAString& aKey,
|
||||
}
|
||||
|
||||
void
|
||||
DOMStorage::Clear(const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv)
|
||||
DOMStorage::Clear(ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(aSubjectPrincipal.isSome());
|
||||
|
||||
if (!CanUseStorage(nullptr, aSubjectPrincipal, this)) {
|
||||
if (!CanUseStorage(nullptr, this)) {
|
||||
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return;
|
||||
}
|
||||
@ -247,12 +226,8 @@ static const char kStorageEnabled[] = "dom.storage.enabled";
|
||||
|
||||
// static, public
|
||||
bool
|
||||
DOMStorage::CanUseStorage(nsPIDOMWindowInner* aWindow,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
DOMStorage* aStorage)
|
||||
DOMStorage::CanUseStorage(nsPIDOMWindowInner* aWindow, DOMStorage* aStorage)
|
||||
{
|
||||
MOZ_ASSERT(aSubjectPrincipal.isSome());
|
||||
|
||||
// This method is responsible for correct setting of mIsSessionOnly.
|
||||
|
||||
if (!mozilla::Preferences::GetBool(kStorageEnabled)) {
|
||||
@ -273,7 +248,9 @@ DOMStorage::CanUseStorage(nsPIDOMWindowInner* aWindow,
|
||||
if (aStorage) {
|
||||
aStorage->mIsSessionOnly = access <= nsContentUtils::StorageAccess::eSessionScoped;
|
||||
|
||||
return aStorage->CanAccess(aSubjectPrincipal.value());
|
||||
nsCOMPtr<nsIPrincipal> subjectPrincipal =
|
||||
nsContentUtils::SubjectPrincipal();
|
||||
return aStorage->CanAccess(subjectPrincipal);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -321,8 +298,7 @@ DOMStorage::CanAccess(nsIPrincipal* aPrincipal)
|
||||
void
|
||||
DOMStorage::GetSupportedNames(nsTArray<nsString>& aKeys)
|
||||
{
|
||||
if (!CanUseStorage(nullptr, Some(nsContentUtils::SubjectPrincipal()),
|
||||
this)) {
|
||||
if (!CanUseStorage(nullptr, this)) {
|
||||
// return just an empty array
|
||||
aKeys.Clear();
|
||||
return;
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "nsIDOMStorage.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsWeakReference.h"
|
||||
@ -70,53 +69,40 @@ public:
|
||||
return mWindow;
|
||||
}
|
||||
|
||||
uint32_t GetLength(const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv);
|
||||
uint32_t GetLength(ErrorResult& aRv);
|
||||
|
||||
void Key(uint32_t aIndex, nsAString& aResult,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv);
|
||||
void Key(uint32_t aIndex, nsAString& aResult, ErrorResult& aRv);
|
||||
|
||||
void GetItem(const nsAString& aKey, nsAString& aResult,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv);
|
||||
void GetItem(const nsAString& aKey, nsAString& aResult, ErrorResult& aRv);
|
||||
|
||||
void GetSupportedNames(nsTArray<nsString>& aKeys);
|
||||
|
||||
void NamedGetter(const nsAString& aKey, bool& aFound, nsAString& aResult,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
GetItem(aKey, aResult, aSubjectPrincipal, aRv);
|
||||
GetItem(aKey, aResult, aRv);
|
||||
aFound = !aResult.IsVoid();
|
||||
}
|
||||
|
||||
void SetItem(const nsAString& aKey, const nsAString& aValue,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void NamedSetter(const nsAString& aKey, const nsAString& aValue,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
SetItem(aKey, aValue, aSubjectPrincipal, aRv);
|
||||
SetItem(aKey, aValue, aRv);
|
||||
}
|
||||
|
||||
void RemoveItem(const nsAString& aKey,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv);
|
||||
void RemoveItem(const nsAString& aKey, ErrorResult& aRv);
|
||||
|
||||
void NamedDeleter(const nsAString& aKey, bool& aFound,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv)
|
||||
void NamedDeleter(const nsAString& aKey, bool& aFound, ErrorResult& aRv)
|
||||
{
|
||||
RemoveItem(aKey, aSubjectPrincipal, aRv);
|
||||
RemoveItem(aKey, aRv);
|
||||
|
||||
aFound = !aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION);
|
||||
}
|
||||
|
||||
void Clear(const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
ErrorResult& aRv);
|
||||
void Clear(ErrorResult& aRv);
|
||||
|
||||
// The method checks whether the caller can use a storage.
|
||||
// CanUseStorage is called before any DOM initiated operation
|
||||
@ -126,7 +112,6 @@ public:
|
||||
// state determination are complex and share the code (comes hand in
|
||||
// hand together).
|
||||
static bool CanUseStorage(nsPIDOMWindowInner* aWindow,
|
||||
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
||||
DOMStorage* aStorage = nullptr);
|
||||
|
||||
bool IsPrivate() const;
|
||||
|
@ -12,22 +12,22 @@
|
||||
*/
|
||||
|
||||
interface Storage {
|
||||
[Throws, NeedsSubjectPrincipal]
|
||||
[Throws]
|
||||
readonly attribute unsigned long length;
|
||||
|
||||
[Throws, NeedsSubjectPrincipal]
|
||||
[Throws]
|
||||
DOMString? key(unsigned long index);
|
||||
|
||||
[Throws, NeedsSubjectPrincipal]
|
||||
[Throws]
|
||||
getter DOMString? getItem(DOMString key);
|
||||
|
||||
[Throws, NeedsSubjectPrincipal]
|
||||
[Throws]
|
||||
setter creator void setItem(DOMString key, DOMString value);
|
||||
|
||||
[Throws, NeedsSubjectPrincipal]
|
||||
[Throws]
|
||||
deleter void removeItem(DOMString key);
|
||||
|
||||
[Throws, NeedsSubjectPrincipal]
|
||||
[Throws]
|
||||
void clear();
|
||||
|
||||
[ChromeOnly]
|
||||
|
@ -129,7 +129,7 @@ Window implements WindowSessionStorage;
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/
|
||||
[NoInterfaceObject]
|
||||
interface WindowLocalStorage {
|
||||
[Throws, NeedsSubjectPrincipal] readonly attribute Storage? localStorage;
|
||||
[Throws] readonly attribute Storage? localStorage;
|
||||
};
|
||||
Window implements WindowLocalStorage;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user