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