Skip to content

Commit

Permalink
Fix localStorage support in 1p-ES mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
goodov committed May 31, 2021
1 parent 81e19f1 commit bdb8d79
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#define BRAVE_CACHED_STORAGE_AREA_ENSURE_LOADED \
if (remote_area_.is_bound() && !remote_area_.is_connected()) { \
ResetConnection(); \
registered_disconnect_handler_ = false; \
} \
\
if (!registered_disconnect_handler_ && remote_area_.is_bound() && \
remote_area_.is_connected()) { \
remote_area_.set_disconnect_handler( \
base::BindOnce([](CachedStorageArea* area) { area->map_.reset(); }, \
base::Unretained(this))); \
registered_disconnect_handler_ = true; \
}

#include "../../../../../../../third_party/blink/renderer/modules/storage/cached_storage_area.cc"

#undef BRAVE_CACHED_STORAGE_AREA_ENSURE_LOADED
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_MODULES_STORAGE_CACHED_STORAGE_AREA_H_
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_MODULES_STORAGE_CACHED_STORAGE_AREA_H_

#define pending_mutations_by_key_ \
pending_mutations_by_key_; \
bool registered_disconnect_handler_ = false

#include "../../../../../../../third_party/blink/renderer/modules/storage/cached_storage_area.h"

#undef pending_mutations_by_key_

#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_MODULES_STORAGE_CACHED_STORAGE_AREA_H_
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,8 @@ StorageArea* BraveDOMWindowStorage::ephemeralLocalStorage() {
if (!namespaces)
return nullptr;

auto* controller = StorageController::GetInstance();
controller->ClearAreasIfNeeded();
auto storage_area = base::MakeRefCounted<CachedStorageArea>(
CachedStorageArea::AreaType::kSessionStorage, window->GetSecurityOrigin(),
controller->TaskRunner(), namespaces->local_storage());
auto storage_area =
namespaces->local_storage()->GetCachedArea(window->GetSecurityOrigin());

// Ephemeral localStorage never persists stored data, which is also how
// sessionStorage works. Due to this, when opening up a new ephemeral
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/third_party/blink/renderer/modules/storage/cached_storage_area.cc b/third_party/blink/renderer/modules/storage/cached_storage_area.cc
index 9a3840e551985c7072e160fb950e606703a1d2aa..30b032269d4f2bfccc1d10c525f5265993945b17 100644
--- a/third_party/blink/renderer/modules/storage/cached_storage_area.cc
+++ b/third_party/blink/renderer/modules/storage/cached_storage_area.cc
@@ -556,6 +556,7 @@ void CachedStorageArea::MaybeApplyNonLocalMutationForKey(
}

void CachedStorageArea::EnsureLoaded() {
+ BRAVE_CACHED_STORAGE_AREA_ENSURE_LOADED
if (map_)
return;

0 comments on commit bdb8d79

Please sign in to comment.