Skip to content

Truly independent web browser

LibWebView+Hub+UI/Qt: Keep local file access in history snapshots

Andreas Kling00be148e9a6b
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index ab08ab924e6..fdfc3c78361 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -981,7 +981,7 @@ void CanonicalTraversable::reconstruct_the_history_to_step(i32 step)
ErrorOr<URL::URL> CanonicalTraversable::restore_session_history_from_ui_snapshot(SessionHistorySnapshot snapshot)
{
- TRY(m_session_history.restore_from_ui_snapshot(move(snapshot.entries), move(snapshot.used_steps), snapshot.current_used_step_index, [] { return Application::the().allocate_ui_process_cross_process_id(); }));
+ TRY(m_session_history.restore_from_ui_snapshot(move(snapshot.entries), move(snapshot.used_steps), snapshot.current_used_step_index, [] { return Application::the().allocate_ui_process_cross_process_id(); }, snapshot.document_states_holding_local_file_content));
session_history_changed();
return m_session_history.current_entry().url;
diff --git a/Libraries/LibWebView/SessionHistory.cpp b/Libraries/LibWebView/SessionHistory.cpp
index 4f25d06f829..10e8aad95b2 100644
--- a/Libraries/LibWebView/SessionHistory.cpp
+++ b/Libraries/LibWebView/SessionHistory.cpp
@@ -249,7 +249,16 @@ static void assign_fresh_ids_to_restored_entries(Vector<Web::HTML::SessionHistor
}
}
-ErrorOr<void> TraversableSessionHistory::restore_from_ui_snapshot(Vector<Web::HTML::SessionHistoryEntryDescriptor> entries, Vector<i32> used_steps, size_t current_used_step_index, Function<Web::HTML::CrossProcessId()> allocate_cross_process_id)
+static void for_each_document_state(Vector<NonnullRefPtr<CanonicalSessionHistoryEntry>> const& entries, Function<void(CanonicalDocumentState&)> const& callback)
+{
+ for (auto const& entry : entries) {
+ callback(*entry->document_state);
+ for (auto const& nested_history : entry->document_state->nested_histories)
+ for_each_document_state(nested_history.entries, callback);
+ }
+}
+
+ErrorOr<void> TraversableSessionHistory::restore_from_ui_snapshot(Vector<Web::HTML::SessionHistoryEntryDescriptor> entries, Vector<i32> used_steps, size_t current_used_step_index, Function<Web::HTML::CrossProcessId()> allocate_cross_process_id, Vector<Web::HTML::CrossProcessId> const& document_states_holding_local_file_content)
{
TRY(validate_snapshot_is_restorable(entries, used_steps, current_used_step_index));
@@ -257,6 +266,18 @@ ErrorOr<void> TraversableSessionHistory::restore_from_ui_snapshot(Vector<Web::HT
assign_fresh_ids_to_restored_entries(entries, allocate_cross_process_id, assigned_ids);
m_entries = TRY(entries_from_descriptors(entries));
m_current_session_history_step = used_steps[current_used_step_index];
+
+ HashTable<Web::HTML::CrossProcessId> restored_ids_holding_local_file_content;
+ for (auto id : document_states_holding_local_file_content) {
+ if (auto restored_id = assigned_ids.get(id); restored_id.has_value())
+ restored_ids_holding_local_file_content.set(*restored_id);
+ }
+ if (!restored_ids_holding_local_file_content.is_empty()) {
+ for_each_document_state(m_entries, [&](CanonicalDocumentState& document_state) {
+ if (restored_ids_holding_local_file_content.contains(document_state.id))
+ document_state.held_local_file_content = true;
+ });
+ }
return {};
}
@@ -394,6 +415,17 @@ size_t TraversableSessionHistory::current_used_step_index() const
return used_steps().find_first_index(get_the_used_step(m_current_session_history_step).value()).value();
}
+Vector<Web::HTML::CrossProcessId> TraversableSessionHistory::document_states_holding_local_file_content() const
+{
+ Vector<Web::HTML::CrossProcessId> ids;
+ HashTable<Web::HTML::CrossProcessId> seen_ids;
+ for_each_document_state(m_entries, [&](CanonicalDocumentState& document_state) {
+ if (document_state.held_local_file_content && seen_ids.set(document_state.id) == HashSetResult::InsertedNewEntry)
+ ids.append(document_state.id);
+ });
+ return ids;
+}
+
Vector<Web::HTML::SessionHistoryEntryDescriptor> TraversableSessionHistory::entries() const
{
Vector<Web::HTML::SessionHistoryEntryDescriptor> entries;
diff --git a/Libraries/LibWebView/SessionHistory.h b/Libraries/LibWebView/SessionHistory.h
index 89d236896ef..42767ade660 100644
--- a/Libraries/LibWebView/SessionHistory.h
+++ b/Libraries/LibWebView/SessionHistory.h
@@ -46,7 +46,7 @@ public:
size_t current_top_level_entry_index() const;
bool initialize_for_testing(Vector<Web::HTML::SessionHistoryEntryDescriptor>, Vector<i32> used_steps, size_t current_used_step_index);
- [[nodiscard]] ErrorOr<void> restore_from_ui_snapshot(Vector<Web::HTML::SessionHistoryEntryDescriptor> entries, Vector<i32> used_steps, size_t current_used_step_index, Function<Web::HTML::CrossProcessId()> allocate_cross_process_id);
+ [[nodiscard]] ErrorOr<void> restore_from_ui_snapshot(Vector<Web::HTML::SessionHistoryEntryDescriptor> entries, Vector<i32> used_steps, size_t current_used_step_index, Function<Web::HTML::CrossProcessId()> allocate_cross_process_id, Vector<Web::HTML::CrossProcessId> const& document_states_holding_local_file_content = {});
Optional<i32> append_nested_history(CanonicalNavigable const& parent_navigable, CanonicalDocumentState& parent_document_state, Web::HTML::CrossProcessId child_navigable_id, NonnullRefPtr<CanonicalSessionHistoryEntry> history_entry);
bool remove_nested_history(CanonicalNavigable const& parent_navigable, Web::HTML::CrossProcessId parent_document_state_id, Web::HTML::CrossProcessId child_navigable_id);
void clear_the_forward_session_history();
@@ -58,6 +58,7 @@ public:
bool replace_session_history_entry(CanonicalNavigable const&, CanonicalSessionHistoryEntry const& entry_to_replace, NonnullRefPtr<CanonicalSessionHistoryEntry>);
void update_directive_state_value(Web::HTML::CrossProcessId, Optional<String>);
Vector<Web::HTML::SessionHistoryEntryDescriptor> entries() const;
+ Vector<Web::HTML::CrossProcessId> document_states_holding_local_file_content() const;
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#getting-all-used-history-steps
Vector<i32> used_steps() const;
@@ -94,6 +95,10 @@ struct SessionHistorySnapshot {
Vector<Web::HTML::SessionHistoryEntryDescriptor> entries;
Vector<i32> used_steps;
size_t current_used_step_index { 0 };
+ // NB: The browser populated local file content for these document states, so it reads the file an entry of one
+ // names when a history step populates it again. Only the browser holds this: a renderer reports entries, but
+ // not this.
+ Vector<Web::HTML::CrossProcessId> document_states_holding_local_file_content;
};
WEBVIEW_API ErrorOr<void> validate_snapshot_is_restorable(Vector<Web::HTML::SessionHistoryEntryDescriptor> const& entries, Vector<i32> const& used_steps, size_t current_used_step_index);
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 148e417ec72..be015946143 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -4242,6 +4242,7 @@ SessionHistorySnapshot ViewImplementation::session_history_snapshot() const
.entries = session_history.entries(),
.used_steps = session_history.used_steps(),
.current_used_step_index = session_history.current_used_step_index(),
+ .document_states_holding_local_file_content = session_history.document_states_holding_local_file_content(),
};
}
diff --git a/Services/Hub/HubClient.ipc b/Services/Hub/HubClient.ipc
index ca893434de4..0cbf8b90dbe 100644
--- a/Services/Hub/HubClient.ipc
+++ b/Services/Hub/HubClient.ipc
@@ -187,6 +187,7 @@ struct WebView::SessionHistorySnapshot {
Vector<Web::HTML::SessionHistoryEntryDescriptor> entries;
Vector<i32> used_steps;
size_t current_used_step_index;
+ Vector<Web::HTML::CrossProcessId> document_states_holding_local_file_content;
}
// A language the tab's page can be translated into, perhaps after a download.
diff --git a/Tests/LibWebView/TestSessionHistory.cpp b/Tests/LibWebView/TestSessionHistory.cpp
index a7e7c291a20..88389682ab1 100644
--- a/Tests/LibWebView/TestSessionHistory.cpp
+++ b/Tests/LibWebView/TestSessionHistory.cpp
@@ -1111,6 +1111,25 @@ TEST_CASE(restore_from_ui_snapshot_preserves_shared_document_state_identity)
EXPECT_EQ(first_id, second_id);
}
+// The browser reads the local file an entry names for a history step only when it populated local file content for the
+// entry's document state, so a restored document state keeps that under its new identity.
+TEST_CASE(restore_from_ui_snapshot_keeps_which_document_states_held_local_file_content)
+{
+ WebView::TraversableSessionHistory history { initial_history_entry() };
+
+ auto result = history.restore_from_ui_snapshot({
+ entry(0, "file:///tmp/a.html"sv, 1, "main"sv),
+ entry(1, "https://a.example/"sv, 2, "main"sv),
+ },
+ { 0, 1 }, 1, allocate_test_ui_process_document_state_id, { test_document_state_id(1), test_document_state_id(7) });
+
+ EXPECT(!result.is_error());
+ auto const& file_document_state = *history.entry_at(0)->document_state;
+ EXPECT(file_document_state.held_local_file_content);
+ EXPECT(!history.entry_at(1)->document_state->held_local_file_content);
+ EXPECT(history.document_states_holding_local_file_content() == Vector<Web::HTML::CrossProcessId> { file_document_state.id });
+}
+
TEST_CASE(restore_from_ui_snapshot_rejects_structurally_invalid_snapshots)
{
auto restore = [](Vector<Web::HTML::SessionHistoryEntryDescriptor> entries, Vector<i32> used_steps, size_t current_used_step_index) {
diff --git a/Tests/UI/Qt/TestSessionHistorySnapshotStorage.cpp b/Tests/UI/Qt/TestSessionHistorySnapshotStorage.cpp
index 01abf58cacf..a21afa586ec 100644
--- a/Tests/UI/Qt/TestSessionHistorySnapshotStorage.cpp
+++ b/Tests/UI/Qt/TestSessionHistorySnapshotStorage.cpp
@@ -354,7 +354,7 @@ static void insert_minimal_entry(Database::Database& database, SessionHistorySna
static_cast<i64>(0), absent_text, absent_text, absent_text, absent_port, absent_text,
static_cast<i64>(0), absent_text, static_cast<i64>(0),
static_cast<i64>(0), absent_text,
- absent_text, String {}, ever_populated, false, false);
+ absent_text, String {}, ever_populated, false, false, false);
}
static i32 count_tab_rows(Database::Database& database, StringView table, i64 tab_id)
@@ -545,6 +545,35 @@ TEST_CASE(snapshot_round_trips_flat_entries)
EXPECT_EQ(loaded.entries[1].document_state.initiator_origin->domain()->serialize(), "b.example"_string);
}
+// The document states the browser populated local file content for survive a round trip, including in nested
+// histories, and a document state that several entries share is named once.
+TEST_CASE(snapshot_round_trip_preserves_document_states_holding_local_file_content)
+{
+ auto database = make_database();
+ auto statements = prepare_snapshot_tables(*database);
+
+ insert_tab_row(*database, 43);
+
+ auto parent = make_entry(0, "file:///tmp/parent.html"sv, 1, 0x11, 0x22, "keyA"sv, "idA"sv, {});
+ parent.document_state.nested_histories.append({
+ .id = Web::HTML::CrossProcessId { .namespace_id = 1, .local_id = 9 },
+ .entries = { make_entry(0, "file:///tmp/child.html"sv, 3, 0x33, 0x44, "keyC"sv, "idC"sv, {}) },
+ });
+
+ WebView::SessionHistorySnapshot snapshot;
+ snapshot.entries.append(move(parent));
+ snapshot.entries.append(make_entry(1, "https://a.example/"sv, 2, 0x55, 0x66, "keyB"sv, "idB"sv, {}));
+ snapshot.entries.append(make_entry(2, "file:///tmp/parent.html#again"sv, 1, 0x77, 0x88, "keyD"sv, "idD"sv, {}));
+ snapshot.used_steps = { 0, 1, 2 };
+ snapshot.current_used_step_index = 2;
+ snapshot.document_states_holding_local_file_content = { snapshot.entries[0].document_state.id, snapshot.entries[0].document_state.nested_histories[0].entries[0].document_state.id };
+
+ TRY_OR_FAIL(store_session_history_snapshot(*database, statements, 43, snapshot));
+
+ auto loaded = TRY_OR_FAIL(load_session_history_snapshot(*database, statements, 43, 2));
+ EXPECT(loaded.document_states_holding_local_file_content == snapshot.document_states_holding_local_file_content);
+}
+
// A database from before the user_agent_initiated column gains it with every entry saved there as No.
TEST_CASE(snapshot_entries_saved_before_the_user_agent_initiated_column_load_as_no)
{
@@ -565,6 +594,7 @@ TEST_CASE(snapshot_entries_saved_before_the_user_agent_initiated_column_load_as_
// Take the database back to the baseline schema, keeping the entry's row.
TRY_OR_FAIL(database->execute_raw(R"#(
+ ALTER TABLE SessionEntries DROP COLUMN held_local_file_content;
DROP TABLE SessionUpgradeInsecureNavigations;
ALTER TABLE SessionPolicyContainers DROP COLUMN insecure_requests_policy;
ALTER TABLE Sessions DROP COLUMN maximized;
@@ -585,7 +615,7 @@ TEST_CASE(snapshot_entries_saved_before_the_user_agent_initiated_column_load_as_
)#"sv));
auto migrated_statements = prepare_snapshot_tables(*database);
- EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 10u });
+ EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 11u });
auto loaded = TRY_OR_FAIL(load_session_history_snapshot(*database, migrated_statements, 42, 0));
EXPECT_EQ(loaded.entries.size(), 1uz);
@@ -614,6 +644,7 @@ TEST_CASE(snapshot_policy_containers_saved_before_the_insecure_requests_policy_l
// Take the database back to the schema before the insecure requests policy, keeping the container's row.
TRY_OR_FAIL(database->execute_raw(R"#(
+ ALTER TABLE SessionEntries DROP COLUMN held_local_file_content;
DROP TABLE SessionUpgradeInsecureNavigations;
ALTER TABLE SessionPolicyContainers DROP COLUMN insecure_requests_policy;
ALTER TABLE SessionLifecycle DROP COLUMN restart;
@@ -621,7 +652,7 @@ TEST_CASE(snapshot_policy_containers_saved_before_the_insecure_requests_policy_l
)#"sv));
auto migrated_statements = prepare_snapshot_tables(*database);
- EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 10u });
+ EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 11u });
auto loaded = TRY_OR_FAIL(load_session_history_snapshot(*database, migrated_statements, 27, 0));
auto const* container = loaded.entries[0].document_state.history_policy_container.get_pointer<Web::HTML::SerializedPolicyContainer>();
diff --git a/Tests/UI/Qt/TestSessionStore.cpp b/Tests/UI/Qt/TestSessionStore.cpp
index b45dea36586..aa8c6200bf3 100644
--- a/Tests/UI/Qt/TestSessionStore.cpp
+++ b/Tests/UI/Qt/TestSessionStore.cpp
@@ -79,6 +79,7 @@ static SessionTabId open_tab(SessionStore& store, SessionWindowId window, String
// Takes the schema back to SESSIONS_SCHEMA_DOCUMENT_POLICY_VERSION, so every migration after it runs again.
static void rewind_sessions_schema_to_version_4(Database::Database& database)
{
+ MUST(database.execute_raw("ALTER TABLE SessionEntries DROP COLUMN held_local_file_content;"sv));
MUST(database.execute_raw("DROP TABLE SessionUpgradeInsecureNavigations;"sv));
MUST(database.execute_raw("ALTER TABLE SessionPolicyContainers DROP COLUMN insecure_requests_policy;"sv));
MUST(database.execute_raw("ALTER TABLE Sessions DROP COLUMN maximized;"sv));
@@ -110,7 +111,7 @@ TEST_CASE(fresh_database_migrates_to_the_latest_schema)
for (auto table : { "Sessions"sv, "SessionTabs"sv, "SessionUsedSteps"sv, "SessionHistories"sv, "SessionNestedHistories"sv, "SessionEntries"sv, "SessionUpgradeInsecureNavigations"sv })
EXPECT(TRY_OR_FAIL(database->table_exists(table)));
- EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 10u });
+ EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 11u });
}
TEST_CASE(deleting_a_session_cascades_through_its_tabs)
@@ -157,7 +158,7 @@ TEST_CASE(version_4_database_migrates_to_the_latest_schema)
rewind_sessions_schema_to_version_4(*database);
EXPECT_EQ(TRY_OR_FAIL(SessionStore::migrate_schema(*database)), Database::MigrationOutcome::Success);
- EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 10u });
+ EXPECT_EQ(TRY_OR_FAIL(database->schema_version("Sessions"sv)), Optional<u32> { 11u });
EXPECT(TRY_OR_FAIL(database->table_exists("SessionUpgradeInsecureNavigations"sv)));
EXPECT_EQ(select_i64(*database, "SELECT pinned FROM SessionTabs WHERE id = 2;"_string), 0);
EXPECT_EQ(select_i64(*database, "SELECT COUNT(*) FROM Sessions WHERE id = 1 AND width IS NULL;"_string), 1);
@@ -224,6 +225,23 @@ TEST_CASE(a_changed_user_agent_initiated_flag_alone_flushes)
EXPECT_EQ(select_i64(*database, "SELECT COUNT(*) FROM SessionEntries WHERE user_agent_initiated = 1;"_string), 1);
}
+TEST_CASE(a_changed_set_of_document_states_holding_local_file_content_alone_replaces_a_pending_push)
+{
+ auto database = create_session_database();
+ auto store = TRY_OR_FAIL(SessionStore::create(*database));
+
+ auto tab = TRY_OR_FAIL(store->tab_opened({ .window_id = {}, .initial_url = parse_url("about:blank"sv), .insertion_index = {}, .is_active = SessionStore::IsActive::No }));
+
+ auto snapshot = make_snapshot({ "file:///tmp/a.html"sv });
+ store->update_tab_state({ .tab_id = tab, .history = snapshot, .url = parse_url("file:///tmp/a.html"sv) });
+
+ // The set is the only difference from the pending push, which it still replaces.
+ snapshot.document_states_holding_local_file_content.append(snapshot.entries[0].document_state.id);
+ store->update_tab_state({ .tab_id = tab, .history = snapshot, .url = parse_url("file:///tmp/a.html"sv) });
+ store->flush_dirty_state();
+ EXPECT_EQ(select_i64(*database, "SELECT COUNT(*) FROM SessionEntries WHERE held_local_file_content = 1;"_string), 1);
+}
+
TEST_CASE(a_changed_insecure_requests_policy_alone_replaces_a_pending_push)
{
auto database = create_session_database();
diff --git a/UI/Qt/SessionHistorySnapshotStorage.cpp b/UI/Qt/SessionHistorySnapshotStorage.cpp
index 431723f03c4..9c9d7459b04 100644
--- a/UI/Qt/SessionHistorySnapshotStorage.cpp
+++ b/UI/Qt/SessionHistorySnapshotStorage.cpp
@@ -583,7 +583,8 @@ ErrorOr<SessionHistorySnapshotStatements> prepare_session_history_snapshot_state
initiator_origin_kind, initiator_origin_nonce, initiator_origin_scheme,
initiator_origin_host, initiator_origin_port, initiator_origin_domain,
referrer_kind, referrer_url, referrer_policy, resource_kind, resource_string,
- about_base_url, navigable_target_name, ever_populated, reload_pending, user_agent_initiated)
+ about_base_url, navigable_target_name, ever_populated, reload_pending, user_agent_initiated,
+ held_local_file_content)
VALUES (
:history_id, :entry_ordinal, :step, :url, :document_state_namespace_id, :document_state_local_id,
:classic_state, :navigation_state,
@@ -594,7 +595,8 @@ ErrorOr<SessionHistorySnapshotStatements> prepare_session_history_snapshot_state
:initiator_origin_kind, :initiator_origin_nonce, :initiator_origin_scheme,
:initiator_origin_host, :initiator_origin_port, :initiator_origin_domain,
:referrer_kind, :referrer_url, :referrer_policy, :resource_kind, :resource_string,
- :about_base_url, :navigable_target_name, :ever_populated, :reload_pending, :user_agent_initiated);
+ :about_base_url, :navigable_target_name, :ever_populated, :reload_pending, :user_agent_initiated,
+ :held_local_file_content);
)#"sv)),
.insert_used_step = TRY(database.prepare_statement(
"INSERT INTO SessionUsedSteps (tab_id, step_ordinal, step) VALUES (:tab_id, :step_ordinal, :step);"sv)),
@@ -646,7 +648,8 @@ ErrorOr<SessionHistorySnapshotStatements> prepare_session_history_snapshot_state
initiator_origin_kind, initiator_origin_nonce, initiator_origin_scheme,
initiator_origin_host, initiator_origin_port, initiator_origin_domain,
referrer_kind, referrer_url, referrer_policy, resource_kind, resource_string,
- about_base_url, navigable_target_name, ever_populated, reload_pending, user_agent_initiated
+ about_base_url, navigable_target_name, ever_populated, reload_pending, user_agent_initiated,
+ held_local_file_content
FROM SessionEntries
INNER JOIN SessionHistories ON SessionEntries.history_id = SessionHistories.id
WHERE SessionHistories.tab_id = :tab_id;
@@ -840,7 +843,7 @@ ErrorOr<void> validate_session_history_snapshot_storable(WebView::SessionHistory
return WebView::validate_snapshot_is_restorable(snapshot.entries, snapshot.used_steps, snapshot.current_used_step_index);
}
-static ErrorOr<void> store_history_entries(Database::Database& database, SessionHistorySnapshotStatements const& statements, i64 tab_id, i64 history_id, Vector<Web::HTML::SessionHistoryEntryDescriptor> const& entries)
+static ErrorOr<void> store_history_entries(Database::Database& database, SessionHistorySnapshotStatements const& statements, i64 tab_id, i64 history_id, Vector<Web::HTML::SessionHistoryEntryDescriptor> const& entries, HashTable<Web::HTML::CrossProcessId> const& document_states_holding_local_file_content)
{
i64 entry_ordinal = 0;
for (auto const& entry : entries) {
@@ -891,6 +894,7 @@ static ErrorOr<void> store_history_entries(Database::Database& database, Session
TRY(bind("ever_populated"sv, document_state.ever_populated));
TRY(bind("reload_pending"sv, document_state.reload_pending));
TRY(bind("user_agent_initiated"sv, document_state.user_agent_initiated == Web::HTML::UserAgentInitiated::Yes));
+ TRY(bind("held_local_file_content"sv, document_states_holding_local_file_content.contains(document_state.id)));
return {};
}));
++entry_ordinal;
@@ -916,7 +920,7 @@ static ErrorOr<void> store_history_entries(Database::Database& database, Session
TRY(bind("child_history_id"sv, child_history_id));
return {};
}));
- TRY(store_history_entries(database, statements, tab_id, child_history_id, nested_history.entries));
+ TRY(store_history_entries(database, statements, tab_id, child_history_id, nested_history.entries, document_states_holding_local_file_content));
++nested_ordinal;
}
++entry_ordinal;
@@ -943,7 +947,10 @@ ErrorOr<void> store_session_history_snapshot(Database::Database& database, Sessi
auto root_history_id = TRY(insert_row_returning_id(database, statements.insert_history, [&](auto& bind) -> ErrorOr<void> {
return bind("tab_id"sv, tab_id);
}));
- TRY(store_history_entries(database, statements, tab_id, root_history_id, snapshot.entries));
+ HashTable<Web::HTML::CrossProcessId> document_states_holding_local_file_content;
+ for (auto id : snapshot.document_states_holding_local_file_content)
+ document_states_holding_local_file_content.set(id);
+ TRY(store_history_entries(database, statements, tab_id, root_history_id, snapshot.entries, document_states_holding_local_file_content));
return {};
}
@@ -977,6 +984,7 @@ struct EntryRow {
bool ever_populated { false };
bool reload_pending { false };
bool user_agent_initiated { false };
+ bool held_local_file_content { false };
};
struct PolicyContainerRow {
@@ -1332,6 +1340,8 @@ struct HistoryTreeLoadState {
HashMap<i64, Vector<NestedHistoryLinkRow>> links_by_parent;
HashMap<i64, HashMap<i64, Web::HTML::SerializedPolicyContainer>> containers_by_history;
HashTable<i64> unvisited_histories;
+ Vector<Web::HTML::CrossProcessId> document_states_holding_local_file_content;
+ HashTable<Web::HTML::CrossProcessId> seen_document_states_holding_local_file_content;
};
}
@@ -1352,7 +1362,11 @@ static ErrorOr<Vector<Web::HTML::SessionHistoryEntryDescriptor>> load_history_en
entries.ensure_capacity(entry_rows.size());
for (auto& row : entry_rows) {
auto container = containers.take(row.entry_ordinal);
+ auto held_local_file_content = row.held_local_file_content;
entries.unchecked_append(TRY(build_entry(move(row), move(container))));
+ auto document_state_id = entries.last().document_state.id;
+ if (held_local_file_content && state.seen_document_states_holding_local_file_content.set(document_state_id) == HashSetResult::InsertedNewEntry)
+ state.document_states_holding_local_file_content.append(document_state_id);
}
if (!containers.is_empty())
return Error::from_string_literal("Session history policy container references a missing entry");
@@ -1456,6 +1470,7 @@ ErrorOr<WebView::SessionHistorySnapshot> load_session_history_snapshot(Database:
row.ever_populated = TRY(result_row.read_bool("ever_populated"sv));
row.reload_pending = TRY(result_row.read_bool("reload_pending"sv));
row.user_agent_initiated = TRY(result_row.read_bool("user_agent_initiated"sv));
+ row.held_local_file_content = TRY(result_row.read_bool("held_local_file_content"sv));
return row;
}));
@@ -1513,6 +1528,7 @@ ErrorOr<WebView::SessionHistorySnapshot> load_session_history_snapshot(Database:
return Error::from_string_literal("Session history snapshot lacks a unique root history");
snapshot.entries = TRY(load_history_entry_tree(state, *root_history_id, 0));
+ snapshot.document_states_holding_local_file_content = move(state.document_states_holding_local_file_content);
if (!state.unvisited_histories.is_empty())
return Error::from_string_literal("Session history has an unreachable nested history");
}
diff --git a/UI/Qt/SessionStore.cpp b/UI/Qt/SessionStore.cpp
index fee58073216..76099112b3f 100644
--- a/UI/Qt/SessionStore.cpp
+++ b/UI/Qt/SessionStore.cpp
@@ -28,6 +28,7 @@ static constexpr u32 SESSIONS_SCHEMA_LAUNCH_RESTORE_VERSION = 7u;
static constexpr u32 SESSIONS_SCHEMA_WINDOW_GEOMETRY_VERSION = 8u;
static constexpr u32 SESSIONS_SCHEMA_UPGRADE_INSECURE_REQUESTS_VERSION = 9u;
static constexpr u32 SESSIONS_SCHEMA_RESTART_VERSION = 10u;
+static constexpr u32 SESSIONS_SCHEMA_LOCAL_FILE_CONTENT_VERSION = 11u;
// After this many unclean exits in a row, launch restore stops, so a session that crashes the browser doesn't restore
// into the same crash every time.
@@ -298,6 +299,12 @@ ErrorOr<Database::MigrationOutcome> SessionStore::PersistedStorage::migrate_sche
ALTER TABLE SessionLifecycle ADD COLUMN restart INTEGER NOT NULL DEFAULT 0;
)#"sv,
},
+ {
+ .version = SESSIONS_SCHEMA_LOCAL_FILE_CONTENT_VERSION,
+ .sql = R"#(
+ ALTER TABLE SessionEntries ADD COLUMN held_local_file_content INTEGER NOT NULL DEFAULT 0;
+ )#"sv,
+ },
});
return database.migrate("Sessions"sv, migrations, mode);
@@ -1535,6 +1542,10 @@ static bool snapshots_match(Optional<WebView::SessionHistorySnapshot> const& a,
return true;
if (a->current_used_step_index != b->current_used_step_index || a->used_steps != b->used_steps)
return false;
+ auto const& a_held = a->document_states_holding_local_file_content;
+ auto const& b_held = b->document_states_holding_local_file_content;
+ if (a_held.size() != b_held.size() || !all_of(a_held, [&](auto id) { return b_held.contains_slow(id); }))
+ return false;
return session_history_entry_descriptors_match(a->entries, b->entries);
}