diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-04 17:20:24 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-12 08:15:25 +0000 |
commit | 8fa0776f1f79e91fc9c0b9c1ba11a0a29c05196b (patch) | |
tree | 788d8d7549712682703a0310ca4a0f0860d4802b /chromium/components/sessions | |
parent | 606d85f2a5386472314d39923da28c70c60dc8e7 (diff) | |
download | qtwebengine-chromium-8fa0776f1f79e91fc9c0b9c1ba11a0a29c05196b.tar.gz |
BASELINE: Update Chromium to 98.0.4758.90
Change-Id: Ib7c41539bf8a8e0376bd639f27d68294de90f3c8
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/sessions')
27 files changed, 221 insertions, 54 deletions
diff --git a/chromium/components/sessions/content/content_live_tab.h b/chromium/components/sessions/content/content_live_tab.h index 89b90c73c30..0a4859af429 100644 --- a/chromium/components/sessions/content/content_live_tab.h +++ b/chromium/components/sessions/content/content_live_tab.h @@ -5,7 +5,7 @@ #ifndef COMPONENTS_SESSIONS_CONTENT_CONTENT_LIVE_TAB_H_ #define COMPONENTS_SESSIONS_CONTENT_CONTENT_LIVE_TAB_H_ -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/supports_user_data.h" #include "components/sessions/content/content_serialized_navigation_builder.h" #include "components/sessions/core/live_tab.h" @@ -59,7 +59,7 @@ class SESSIONS_EXPORT ContentLiveTab return web_contents_->GetController(); } - content::WebContents* web_contents_; + raw_ptr<content::WebContents> web_contents_; }; } // namespace sessions diff --git a/chromium/components/sessions/content/content_serialized_navigation_builder_unittest.cc b/chromium/components/sessions/content/content_serialized_navigation_builder_unittest.cc index 177b9c25373..38b26fdbfcc 100644 --- a/chromium/components/sessions/content/content_serialized_navigation_builder_unittest.cc +++ b/chromium/components/sessions/content/content_serialized_navigation_builder_unittest.cc @@ -282,7 +282,7 @@ TEST_F(ContentSerializedNavigationBuilderTest, ToNavigationEntries) { content::BrowserTaskEnvironment test_environment; content::TestBrowserContext browser_context; - // Make a NavigationEntries, serialize it twice into a vector. + // Make a NavigationEntry and serialize it twice into a vector. const std::unique_ptr<content::NavigationEntry> entry( MakeNavigationEntryForTest()); std::vector<SerializedNavigationEntry> navigations; @@ -300,17 +300,76 @@ TEST_F(ContentSerializedNavigationBuilderTest, ToNavigationEntries) { ASSERT_EQ(entry->GetURL(), restored_entries[1]->GetURL()); // Because the state of the two SerializedNavigationEntries was identical - // (specifcally, their item sequence numbers), the root FrameNavigationEntries - // for the two restored entries should be de-duplicated and shared. The url - // is stored on the root FrameNavigationEntry, so because they are shared, - // calling SetURL() on one of the restored entries should update the url on - // both. + // (specifically, their item sequence numbers), the root + // FrameNavigationEntries for the two restored entries should be de-duplicated + // and shared. The url is stored on the root FrameNavigationEntry, so because + // they are shared, calling SetURL() on one of the restored entries should + // update the url on both. GURL new_url("http://www.url.com#ToNavigationEntries"); restored_entries[0]->SetURL(new_url); EXPECT_EQ(new_url, restored_entries[0]->GetURL()); EXPECT_EQ(new_url, restored_entries[1]->GetURL()); } +// Test that we can restore FrameNavigationEntries with matching item sequence +// numbers and unique names but different URLs, as these may be found in +// serialized sessions from builds prior to r894383. +// See https://crbug.com/1275257. +TEST_F(ContentSerializedNavigationBuilderTest, DeduplicateEntriesByURL) { + content::BrowserTaskEnvironment test_environment; + content::TestBrowserContext browser_context; + + // Make a NavigationEntry and serialize it several times into a vector. + // Change the URL but not item sequence number for the last two entries, to + // simulate a replaceState that was serialized from a build prior to r894383. + const std::unique_ptr<content::NavigationEntry> entry( + MakeNavigationEntryForTest()); + GURL url1("http://www.url.com/page1"); + entry->SetURL(url1); + std::vector<SerializedNavigationEntry> navigations; + navigations.push_back( + ContentSerializedNavigationBuilder::FromNavigationEntry(0, entry.get())); + navigations.push_back( + ContentSerializedNavigationBuilder::FromNavigationEntry(1, entry.get())); + GURL url2("http://www.url.com/page2"); + entry->SetURL(url2); + navigations.push_back( + ContentSerializedNavigationBuilder::FromNavigationEntry(2, entry.get())); + navigations.push_back( + ContentSerializedNavigationBuilder::FromNavigationEntry(3, entry.get())); + + // Deserialize them via ToNavigationEntries(). + std::vector<std::unique_ptr<content::NavigationEntry>> restored_entries = + ContentSerializedNavigationBuilder::ToNavigationEntries(navigations, + &browser_context); + ASSERT_EQ(restored_entries.size(), 4ul); + ASSERT_EQ(url1, restored_entries[0]->GetURL()); + ASSERT_EQ(url1, restored_entries[1]->GetURL()); + ASSERT_EQ(url2, restored_entries[2]->GetURL()); + ASSERT_EQ(url2, restored_entries[3]->GetURL()); + + // The root FrameNavigationEntries for the first two restored entries should + // have been de-duplicated and shared, so changing the URL of one of them + // should change the other, but not the third and fourth entries (which had a + // different URL and thus aren't shared). + GURL url3("http://www.url.com/page3"); + restored_entries[0]->SetURL(url3); + EXPECT_EQ(url3, restored_entries[0]->GetURL()); + EXPECT_EQ(url3, restored_entries[1]->GetURL()); + EXPECT_EQ(url2, restored_entries[2]->GetURL()); + EXPECT_EQ(url2, restored_entries[3]->GetURL()); + + // The third and fourth entries should have a shared FrameNavigationEntry as + // well, such that updating one affects the other but not the first and second + // entries. + GURL url4("http://www.url.com/page4"); + restored_entries[3]->SetURL(url4); + EXPECT_EQ(url3, restored_entries[0]->GetURL()); + EXPECT_EQ(url3, restored_entries[1]->GetURL()); + EXPECT_EQ(url4, restored_entries[2]->GetURL()); + EXPECT_EQ(url4, restored_entries[3]->GetURL()); +} + TEST_F(ContentSerializedNavigationBuilderTest, SetPasswordState) { std::unique_ptr<content::NavigationEntry> entry( content::NavigationEntry::Create()); diff --git a/chromium/components/sessions/content/content_serialized_navigation_driver.h b/chromium/components/sessions/content/content_serialized_navigation_driver.h index c3d07185d57..e8bc1d0c756 100644 --- a/chromium/components/sessions/content/content_serialized_navigation_driver.h +++ b/chromium/components/sessions/content/content_serialized_navigation_driver.h @@ -9,7 +9,6 @@ #include <memory> #include <string> -#include "base/macros.h" #include "components/sessions/content/extended_info_handler.h" #include "components/sessions/core/serialized_navigation_driver.h" #include "components/sessions/core/sessions_export.h" diff --git a/chromium/components/sessions/content/content_test_helper.h b/chromium/components/sessions/content/content_test_helper.h index 0c9fc04031f..72682577b63 100644 --- a/chromium/components/sessions/content/content_test_helper.h +++ b/chromium/components/sessions/content/content_test_helper.h @@ -7,7 +7,6 @@ #include <string> -#include "base/macros.h" #include "components/sessions/core/serialized_navigation_entry.h" namespace sessions { diff --git a/chromium/components/sessions/content/session_tab_helper.cc b/chromium/components/sessions/content/session_tab_helper.cc index c479614fda2..a1ad7931c83 100644 --- a/chromium/components/sessions/content/session_tab_helper.cc +++ b/chromium/components/sessions/content/session_tab_helper.cc @@ -22,6 +22,7 @@ namespace sessions { SessionTabHelper::SessionTabHelper(content::WebContents* contents, DelegateLookup lookup) : content::WebContentsObserver(contents), + content::WebContentsUserData<SessionTabHelper>(*contents), delegate_lookup_(std::move(lookup)), session_id_(SessionID::NewUnique()), window_id_(SessionID::InvalidValue()) {} diff --git a/chromium/components/sessions/content/session_tab_helper.h b/chromium/components/sessions/content/session_tab_helper.h index c5d7baf7c11..ca14a1b082c 100644 --- a/chromium/components/sessions/content/session_tab_helper.h +++ b/chromium/components/sessions/content/session_tab_helper.h @@ -6,7 +6,6 @@ #define COMPONENTS_SESSIONS_CONTENT_SESSION_TAB_HELPER_H_ #include "base/callback.h" -#include "base/macros.h" #include "components/sessions/core/session_id.h" #include "components/sessions/core/sessions_export.h" #include "content/public/browser/web_contents_observer.h" diff --git a/chromium/components/sessions/core/command_storage_backend.cc b/chromium/components/sessions/core/command_storage_backend.cc index 8242c43db12..b7b1347fd57 100644 --- a/chromium/components/sessions/core/command_storage_backend.cc +++ b/chromium/components/sessions/core/command_storage_backend.cc @@ -673,8 +673,8 @@ std::unique_ptr<base::File> CommandStorageBackend::OpenAndWriteHeader( DCHECK(!path.empty()); std::unique_ptr<base::File> file = std::make_unique<base::File>( path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | - base::File::FLAG_EXCLUSIVE_WRITE | - base::File::FLAG_EXCLUSIVE_READ); + base::File::FLAG_WIN_EXCLUSIVE_WRITE | + base::File::FLAG_WIN_EXCLUSIVE_READ); if (!file->IsValid()) return nullptr; FileHeader header; diff --git a/chromium/components/sessions/core/command_storage_manager.h b/chromium/components/sessions/core/command_storage_manager.h index 94c1c2b1a66..6a31b46fca4 100644 --- a/chromium/components/sessions/core/command_storage_manager.h +++ b/chromium/components/sessions/core/command_storage_manager.h @@ -12,9 +12,10 @@ #include "base/callback.h" #include "base/files/file_path.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "components/sessions/core/sessions_export.h" namespace sessions { @@ -153,7 +154,7 @@ class SESSIONS_EXPORT CommandStorageManager { // The number of commands sent to the backend before doing a reset. int commands_since_reset_ = 0; - CommandStorageManagerDelegate* delegate_; + raw_ptr<CommandStorageManagerDelegate> delegate_; // TaskRunner all backend tasks are run on. This is a SequencedTaskRunner as // all tasks *must* be processed in the order they are scheduled. diff --git a/chromium/components/sessions/core/command_storage_manager_test_helper.h b/chromium/components/sessions/core/command_storage_manager_test_helper.h index 1c342bcac37..c0fda553770 100644 --- a/chromium/components/sessions/core/command_storage_manager_test_helper.h +++ b/chromium/components/sessions/core/command_storage_manager_test_helper.h @@ -10,7 +10,7 @@ #include "base/callback.h" #include "base/location.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" namespace sessions { class SessionCommand; @@ -47,7 +47,7 @@ class CommandStorageManagerTestHelper { void ForceAppendCommandsToFailForTesting(); private: - CommandStorageManager* command_storage_manager_; + raw_ptr<CommandStorageManager> command_storage_manager_; }; } // namespace sessions diff --git a/chromium/components/sessions/core/live_tab_context.h b/chromium/components/sessions/core/live_tab_context.h index fd5f3a7b6e1..fff5e758563 100644 --- a/chromium/components/sessions/core/live_tab_context.h +++ b/chromium/components/sessions/core/live_tab_context.h @@ -5,6 +5,7 @@ #ifndef COMPONENTS_SESSIONS_CORE_LIVE_TAB_CONTEXT_H_ #define COMPONENTS_SESSIONS_CORE_LIVE_TAB_CONTEXT_H_ +#include <map> #include <string> #include <vector> @@ -41,13 +42,16 @@ class SESSIONS_EXPORT LiveTabContext { virtual std::string GetUserTitle() const = 0; virtual LiveTab* GetLiveTabAt(int index) const = 0; virtual LiveTab* GetActiveLiveTab() const = 0; - virtual bool IsTabPinned(int index) const = 0; + virtual std::map<std::string, std::string> GetExtraDataForTab( + int index) const = 0; + virtual std::map<std::string, std::string> GetExtraDataForWindow() const = 0; virtual absl::optional<tab_groups::TabGroupId> GetTabGroupForTab( int index) const = 0; // Should not be called for |group| unless GetTabGroupForTab() returned // |group|. virtual const tab_groups::TabGroupVisualData* GetVisualDataForGroup( const tab_groups::TabGroupId& group) const = 0; + virtual bool IsTabPinned(int index) const = 0; // Update |group|'s metadata. Should only be called for |group| if a tab has // been restored in |group| via AddRestoredTab() or ReplaceRestoredTab(). virtual void SetVisualDataForGroup( @@ -73,6 +77,7 @@ class SESSIONS_EXPORT LiveTabContext { bool pin, const PlatformSpecificTabData* tab_platform_data, const sessions::SerializedUserAgentOverride& user_agent_override, + const std::map<std::string, std::string>& extra_data, const SessionID* tab_id) = 0; // Note: |tab_platform_data| may be null (e.g., if restoring from last session @@ -84,7 +89,8 @@ class SESSIONS_EXPORT LiveTabContext { int selected_navigation, const std::string& extension_app_id, const PlatformSpecificTabData* tab_platform_data, - const sessions::SerializedUserAgentOverride& user_agent_override) = 0; + const sessions::SerializedUserAgentOverride& user_agent_override, + const std::map<std::string, std::string>& extra_data) = 0; virtual void CloseTab() = 0; protected: diff --git a/chromium/components/sessions/core/serialized_navigation_entry.cc b/chromium/components/sessions/core/serialized_navigation_entry.cc index 21305940756..ebbbf2e8ae6 100644 --- a/chromium/components/sessions/core/serialized_navigation_entry.cc +++ b/chromium/components/sessions/core/serialized_navigation_entry.cc @@ -7,7 +7,7 @@ #include <stddef.h> #include <utility> -#include "base/macros.h" +#include "base/ignore_result.h" #include "base/pickle.h" #include "base/trace_event/memory_usage_estimator.h" #include "components/sessions/core/serialized_navigation_driver.h" diff --git a/chromium/components/sessions/core/serialized_navigation_entry_test_helper.h b/chromium/components/sessions/core/serialized_navigation_entry_test_helper.h index f97e2f7c68d..b6f58d4080b 100644 --- a/chromium/components/sessions/core/serialized_navigation_entry_test_helper.h +++ b/chromium/components/sessions/core/serialized_navigation_entry_test_helper.h @@ -9,7 +9,6 @@ #include <string> -#include "base/macros.h" #include "base/time/time.h" #include "components/sessions/core/serialized_navigation_entry.h" #include "ui/base/page_transition_types.h" diff --git a/chromium/components/sessions/core/session_command.h b/chromium/components/sessions/core/session_command.h index ec5349840bb..2d70cead35e 100644 --- a/chromium/components/sessions/core/session_command.h +++ b/chromium/components/sessions/core/session_command.h @@ -11,7 +11,6 @@ #include <memory> #include <string> -#include "base/macros.h" #include "base/strings/string_piece.h" #include "components/sessions/core/sessions_export.h" diff --git a/chromium/components/sessions/core/session_id_generator.h b/chromium/components/sessions/core/session_id_generator.h index 594c7612fb7..80a427447c5 100644 --- a/chromium/components/sessions/core/session_id_generator.h +++ b/chromium/components/sessions/core/session_id_generator.h @@ -6,7 +6,7 @@ #define COMPONENTS_SESSIONS_CORE_SESSION_ID_GENERATOR_H_ #include "base/callback.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/singleton.h" #include "base/sequence_checker.h" #include "components/sessions/core/session_id.h" @@ -53,7 +53,7 @@ class SESSIONS_EXPORT SessionIdGenerator { void IncrementValueBy(int increment); SEQUENCE_CHECKER(sequence_checker_); - PrefService* local_state_; + raw_ptr<PrefService> local_state_; SessionID::id_type last_value_; // Used to override the random number generator for tests. diff --git a/chromium/components/sessions/core/session_id_generator_unittest.cc b/chromium/components/sessions/core/session_id_generator_unittest.cc index 1f5aa3708a2..0456d00a947 100644 --- a/chromium/components/sessions/core/session_id_generator_unittest.cc +++ b/chromium/components/sessions/core/session_id_generator_unittest.cc @@ -6,7 +6,6 @@ #include <limits> -#include "base/macros.h" #include "base/test/mock_callback.h" #include "components/prefs/testing_pref_service.h" #include "testing/gmock/include/gmock/gmock.h" diff --git a/chromium/components/sessions/core/session_service_commands.cc b/chromium/components/sessions/core/session_service_commands.cc index d1f675abcbb..bda93c0a8dd 100644 --- a/chromium/components/sessions/core/session_service_commands.cc +++ b/chromium/components/sessions/core/session_service_commands.cc @@ -7,18 +7,34 @@ #include <stdint.h> #include <string.h> +#include <map> #include <utility> #include <vector> #include "base/containers/flat_set.h" #include "base/guid.h" +#include "base/ignore_result.h" #include "base/logging.h" #include "base/memory/ptr_util.h" #include "base/pickle.h" #include "base/token.h" +#include "base/values.h" #include "components/sessions/core/base_session_service_commands.h" #include "components/tab_groups/tab_group_color.h" +namespace { + +bool ReadSessionIdFromPickle(base::PickleIterator* iterator, SessionID* id) { + SessionID::id_type value; + if (!iterator->ReadInt(&value)) { + return false; + } + *id = SessionID::FromSerializedValue(value); + return true; +} + +} // namespace + namespace sessions { // Identifier for commands written to file. @@ -69,6 +85,8 @@ static const SessionCommand::id_type kCommandSetTabData = 30; static const SessionCommand::id_type kCommandSetWindowUserTitle = 31; static const SessionCommand::id_type kCommandSetWindowVisibleOnAllWorkspaces = 32; +static const SessionCommand::id_type kCommandAddTabExtraData = 33; +static const SessionCommand::id_type kCommandAddWindowExtraData = 34; // ID 255 is used by CommandStorageBackend. namespace { @@ -838,6 +856,40 @@ bool CreateTabsAndWindows( break; } + case kCommandAddTabExtraData: { + std::unique_ptr<base::Pickle> pickle(command->PayloadAsPickle()); + base::PickleIterator it(*pickle); + + SessionID tab_id = SessionID::InvalidValue(); + std::string key; + std::string data; + if (!ReadSessionIdFromPickle(&it, &tab_id) || !it.ReadString(&key) || + !it.ReadString(&data)) { + DVLOG(1) << "Failed reading command " << command->id(); + return true; + } + + GetTab(tab_id, tabs)->extra_data[key] = std::move(data); + break; + } + + case kCommandAddWindowExtraData: { + std::unique_ptr<base::Pickle> pickle(command->PayloadAsPickle()); + base::PickleIterator it(*pickle); + + SessionID window_id = SessionID::InvalidValue(); + std::string key; + std::string data; + if (!ReadSessionIdFromPickle(&it, &window_id) || !it.ReadString(&key) || + !it.ReadString(&data)) { + DVLOG(1) << "Failed reading command " << command->id(); + return true; + } + + GetWindow(window_id, windows)->extra_data[key] = std::move(data); + break; + } + case kCommandSetWindowUserTitle: { SessionID window_id = SessionID::InvalidValue(); std::string title; @@ -1095,6 +1147,34 @@ std::unique_ptr<SessionCommand> CreateSetTabDataCommand( return std::make_unique<SessionCommand>(kCommandSetTabData, pickle); } +std::unique_ptr<SessionCommand> CreateAddExtraDataCommand( + SessionCommand::id_type command, + const SessionID& session_id, + const std::string& key, + const std::string& data) { + base::Pickle pickle; + pickle.WriteInt(session_id.id()); + pickle.WriteString(key); + pickle.WriteString(data); + + return std::make_unique<SessionCommand>(command, pickle); +} + +std::unique_ptr<SessionCommand> CreateAddTabExtraDataCommand( + const SessionID& tab_id, + const std::string& key, + const std::string& data) { + return CreateAddExtraDataCommand(kCommandAddTabExtraData, tab_id, key, data); +} + +std::unique_ptr<SessionCommand> CreateAddWindowExtraDataCommand( + const SessionID& window_id, + const std::string& key, + const std::string& data) { + return CreateAddExtraDataCommand(kCommandAddWindowExtraData, window_id, key, + data); +} + bool ReplacePendingCommand(CommandStorageManager* command_storage_manager, std::unique_ptr<SessionCommand>* command) { // We optimize page navigations, which can happen quite frequently and diff --git a/chromium/components/sessions/core/session_service_commands.h b/chromium/components/sessions/core/session_service_commands.h index 0aeaf8b201f..5011dcb7d50 100644 --- a/chromium/components/sessions/core/session_service_commands.h +++ b/chromium/components/sessions/core/session_service_commands.h @@ -101,6 +101,16 @@ SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateSetTabDataCommand( const SessionID& tab_id, const std::map<std::string, std::string>& data); +SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateAddTabExtraDataCommand( + const SessionID& tab_id, + const std::string& key, + const std::string& data); + +SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateAddWindowExtraDataCommand( + const SessionID& window_id, + const std::string& key, + const std::string& data); + // Searches for a pending command using |command_storage_manager| that can be // replaced with |command|. If one is found, pending command is removed, the // command is added to the pending commands (taken ownership) and true is diff --git a/chromium/components/sessions/core/session_types.h b/chromium/components/sessions/core/session_types.h index 8406afad2c9..5faff74a6f1 100644 --- a/chromium/components/sessions/core/session_types.h +++ b/chromium/components/sessions/core/session_types.h @@ -6,11 +6,11 @@ #define COMPONENTS_SESSIONS_CORE_SESSION_TYPES_H_ #include <algorithm> +#include <map> #include <memory> #include <string> #include <vector> -#include "base/macros.h" #include "base/time/time.h" #include "base/token.h" #include "build/chromeos_buildflags.h" @@ -107,6 +107,9 @@ struct SESSIONS_EXPORT SessionTab { // Data associated with the tab by the embedder. std::map<std::string, std::string> data; + + // Extra data associated with the tab. + std::map<std::string, std::string> extra_data; }; // SessionTabGroup ----------------------------------------------------------- @@ -202,6 +205,9 @@ struct SESSIONS_EXPORT SessionWindow { // The user-configured title for this window, may be empty. std::string user_title; + + // Extra data associated with the window. + std::map<std::string, std::string> extra_data; }; } // namespace sessions diff --git a/chromium/components/sessions/core/tab_restore_service.h b/chromium/components/sessions/core/tab_restore_service.h index 128c2f6db26..89f1a706278 100644 --- a/chromium/components/sessions/core/tab_restore_service.h +++ b/chromium/components/sessions/core/tab_restore_service.h @@ -80,6 +80,9 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService { // creation. base::Time timestamp; + // Used for storing arbitrary key/value pairs. + std::map<std::string, std::string> extra_data; + // Estimates memory usage. By default returns 0. virtual size_t EstimateMemoryUsage() const; diff --git a/chromium/components/sessions/core/tab_restore_service_client.h b/chromium/components/sessions/core/tab_restore_service_client.h index 0d8322b9db6..a6480f21195 100644 --- a/chromium/components/sessions/core/tab_restore_service_client.h +++ b/chromium/components/sessions/core/tab_restore_service_client.h @@ -5,6 +5,7 @@ #ifndef COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_CLIENT_H_ #define COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_CLIENT_H_ +#include <map> #include <memory> #include "base/callback.h" @@ -49,7 +50,8 @@ class SESSIONS_EXPORT TabRestoreServiceClient { const gfx::Rect& bounds, ui::WindowShowState show_state, const std::string& workspace, - const std::string& user_title) = 0; + const std::string& user_title, + const std::map<std::string, std::string>& extra_data) = 0; // Returns the LiveTabContext instance that is associated with // |tab|, or null if there is no such instance. diff --git a/chromium/components/sessions/core/tab_restore_service_helper.cc b/chromium/components/sessions/core/tab_restore_service_helper.cc index 84a7a49069d..62ac841dfb0 100644 --- a/chromium/components/sessions/core/tab_restore_service_helper.cc +++ b/chromium/components/sessions/core/tab_restore_service_helper.cc @@ -9,6 +9,7 @@ #include <algorithm> #include <iterator> +#include <map> #include <memory> #include <string> #include <utility> @@ -24,6 +25,7 @@ #include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/memory_usage_estimator.h" #include "base/trace_event/process_memory_dump.h" +#include "base/values.h" #include "components/dom_distiller/core/url_constants.h" #include "components/sessions/core/live_tab.h" #include "components/sessions/core/live_tab_context.h" @@ -109,7 +111,7 @@ absl::optional<SessionID> TabRestoreServiceHelper::CreateHistoricalTab( return absl::nullopt; } - // Save the Window as well as the Tab if this is the last tab of an appp + // Save the Window as well as the Tab if this is the last tab of an app // browser to ensure the tab will reopen in the correct app window. if (context && context->GetTabCount() == 1 && !context->GetAppName().empty()) { @@ -138,6 +140,7 @@ void TabRestoreServiceHelper::BrowserClosing(LiveTabContext* context) { window->show_state = context->GetRestoredState(); window->workspace = context->GetWorkspace(); window->user_title = context->GetUserTitle(); + window->extra_data = context->GetExtraDataForWindow(); base::flat_set<tab_groups::TabGroupId> seen_groups; for (int tab_index = 0; tab_index < context->GetTabCount(); ++tab_index) { @@ -432,7 +435,7 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById( if (entry_id_matches_restore_id) { context = client_->CreateLiveTabContext( window.app_name, window.bounds, window.show_state, window.workspace, - window.user_title); + window.user_title, window.extra_data); base::flat_map<tab_groups::TabGroupId, tab_groups::TabGroupId> new_group_ids; @@ -465,7 +468,8 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById( tab.current_navigation_index, tab.extension_app_id, new_group, tab.group_visual_data.value_or(tab_groups::TabGroupVisualData()), static_cast<int>(tab_i) == window.selected_tab_index, tab.pinned, - tab.platform_data.get(), tab.user_agent_override, nullptr); + tab.platform_data.get(), tab.user_agent_override, tab.extra_data, + nullptr); if (restored_tab) { client_->OnTabRestored( tab.navigations.at(tab.current_navigation_index).virtual_url()); @@ -771,14 +775,12 @@ void TabRestoreServiceHelper::PopulateTab(Tab* tab, } if (actual_entry_count != max_entry_count) tab->navigations.resize(static_cast<int>(actual_entry_count)); + tab->timestamp = TimeNow(); tab->current_navigation_index = current_navigation_index; tab->tabstrip_index = index; - tab->extension_app_id = client_->GetExtensionAppIDForTab(live_tab); - tab->user_agent_override = live_tab->GetUserAgentOverride(); - tab->platform_data = live_tab->GetPlatformSpecificTabData(); // Delegate may be NULL during unit tests. @@ -793,6 +795,7 @@ void TabRestoreServiceHelper::PopulateTab(Tab* tab, ->GetVisualDataForGroup( tab->group.value())} : absl::nullopt; + tab->extra_data = context->GetExtraDataForTab(tab->tabstrip_index); } } @@ -805,7 +808,8 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTab( if (disposition == WindowOpenDisposition::CURRENT_TAB && context) { restored_tab = context->ReplaceRestoredTab( tab.navigations, absl::nullopt, tab.current_navigation_index, - tab.extension_app_id, tab.platform_data.get(), tab.user_agent_override); + tab.extension_app_id, tab.platform_data.get(), tab.user_agent_override, + tab.extra_data); } else { // We only respect the tab's original browser if there's no disposition. if (disposition == WindowOpenDisposition::UNKNOWN) { @@ -833,9 +837,9 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTab( if (context && disposition != WindowOpenDisposition::NEW_WINDOW) { tab_index = tab.tabstrip_index; } else { - context = client_->CreateLiveTabContext(std::string(), gfx::Rect(), - ui::SHOW_STATE_NORMAL, - std::string(), std::string()); + context = client_->CreateLiveTabContext( + std::string(), gfx::Rect(), ui::SHOW_STATE_NORMAL, std::string(), + std::string(), std::map<std::string, std::string>()); if (tab.browser_id) UpdateTabBrowserIDs(tab.browser_id, context->GetSessionID()); } @@ -852,8 +856,10 @@ LiveTabContext* TabRestoreServiceHelper::RestoreTab( tab.extension_app_id, tab.group, tab.group_visual_data.value_or(tab_groups::TabGroupVisualData()), disposition != WindowOpenDisposition::NEW_BACKGROUND_TAB, tab.pinned, - tab.platform_data.get(), tab.user_agent_override, &tab.id); + tab.platform_data.get(), tab.user_agent_override, tab.extra_data, + &tab.id); } + client_->OnTabRestored( tab.navigations.at(tab.current_navigation_index).virtual_url()); if (live_tab) diff --git a/chromium/components/sessions/core/tab_restore_service_helper.h b/chromium/components/sessions/core/tab_restore_service_helper.h index 09cd6bcbfa7..3b514aefdb4 100644 --- a/chromium/components/sessions/core/tab_restore_service_helper.h +++ b/chromium/components/sessions/core/tab_restore_service_helper.h @@ -8,7 +8,7 @@ #include <set> #include <vector> -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/observer_list.h" #include "base/time/time.h" #include "base/trace_event/memory_dump_provider.h" @@ -201,11 +201,11 @@ class SESSIONS_EXPORT TabRestoreServiceHelper // Gets the current time. This uses the time_factory_ if there is one. base::Time TimeNow() const; - TabRestoreService* const tab_restore_service_; + const raw_ptr<TabRestoreService> tab_restore_service_; - Observer* observer_; + raw_ptr<Observer> observer_; - TabRestoreServiceClient* client_; + raw_ptr<TabRestoreServiceClient> client_; // Set of entries. They are ordered from most to least recent. Entries entries_; @@ -226,7 +226,7 @@ class SESSIONS_EXPORT TabRestoreServiceHelper // creating historical tabs for them. std::set<tab_groups::TabGroupId> closing_groups_; - TimeFactory* const time_factory_; + const raw_ptr<TimeFactory> time_factory_; }; } // namespace sessions diff --git a/chromium/components/sessions/core/tab_restore_service_impl.cc b/chromium/components/sessions/core/tab_restore_service_impl.cc index 7142d9ed40a..e894c1475e3 100644 --- a/chromium/components/sessions/core/tab_restore_service_impl.cc +++ b/chromium/components/sessions/core/tab_restore_service_impl.cc @@ -16,7 +16,7 @@ #include "base/compiler_specific.h" #include "base/files/file_path.h" #include "base/files/file_util.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/notreached.h" @@ -352,12 +352,12 @@ CreateWindowEntryFromCommand(const SessionCommand* command, fields.window_width == 0 && fields.window_height == 0)) { window->bounds.SetRect(fields.window_x, fields.window_y, fields.window_width, fields.window_height); - // |show_state| was converted from window->show_state earlier during - // validation. - window->show_state = show_state; - window->workspace = std::move(fields.workspace); } + // |show_state| was converted from window->show_state earlier during + // validation. + window->show_state = show_state; + window->workspace = std::move(fields.workspace); return window; } @@ -550,11 +550,11 @@ class TabRestoreServiceImpl::PersistenceDelegate private: // The associated client. - TabRestoreServiceClient* client_; + raw_ptr<TabRestoreServiceClient> client_; std::unique_ptr<CommandStorageManager> command_storage_manager_; - TabRestoreServiceHelper* tab_restore_service_helper_; + raw_ptr<TabRestoreServiceHelper> tab_restore_service_helper_; // The number of entries to write. int entries_to_write_; @@ -1331,6 +1331,7 @@ bool TabRestoreServiceImpl::PersistenceDelegate::ConvertSessionWindowToWindow( tab.navigations.swap(i->navigations); tab.current_navigation_index = i->current_navigation_index; tab.extension_app_id = i->extension_app_id; + tab.extra_data = std::move(i->extra_data); tab.timestamp = base::Time(); } @@ -1341,6 +1342,7 @@ bool TabRestoreServiceImpl::PersistenceDelegate::ConvertSessionWindowToWindow( window->selected_tab_index = std::min(session_window->selected_tab_index, static_cast<int>(window->tabs.size() - 1)); + window->extra_data = std::move(session_window->extra_data); window->timestamp = base::Time(); window->bounds = session_window->bounds; window->show_state = session_window->show_state; diff --git a/chromium/components/sessions/core/tab_restore_service_impl.h b/chromium/components/sessions/core/tab_restore_service_impl.h index 93438a85096..23978a0a21b 100644 --- a/chromium/components/sessions/core/tab_restore_service_impl.h +++ b/chromium/components/sessions/core/tab_restore_service_impl.h @@ -9,7 +9,6 @@ #include <vector> #include "base/compiler_specific.h" -#include "base/macros.h" #include "components/prefs/pref_change_registrar.h" #include "components/sessions/core/sessions_export.h" #include "components/sessions/core/tab_restore_service.h" diff --git a/chromium/components/sessions/ios/ios_restore_live_tab.h b/chromium/components/sessions/ios/ios_restore_live_tab.h index ffbb20ae60f..0a8c400989f 100644 --- a/chromium/components/sessions/ios/ios_restore_live_tab.h +++ b/chromium/components/sessions/ios/ios_restore_live_tab.h @@ -5,7 +5,6 @@ #ifndef COMPONENTS_SESSIONS_IOS_IOS_RESTORE_LIVE_TAB_H_ #define COMPONENTS_SESSIONS_IOS_IOS_RESTORE_LIVE_TAB_H_ -#include "base/macros.h" #include "base/supports_user_data.h" #include "components/sessions/ios/ios_live_tab.h" diff --git a/chromium/components/sessions/ios/ios_restore_live_tab.mm b/chromium/components/sessions/ios/ios_restore_live_tab.mm index cc4dedb57dc..4590c91f655 100644 --- a/chromium/components/sessions/ios/ios_restore_live_tab.mm +++ b/chromium/components/sessions/ios/ios_restore_live_tab.mm @@ -33,7 +33,7 @@ int RestoreIOSLiveTab::GetPendingEntryIndex() { sessions::SerializedNavigationEntry RestoreIOSLiveTab::GetEntryAtIndex( int index) { - NSArray* item_storages = session_.itemStorages; + NSArray<CRWNavigationItemStorage*>* item_storages = session_.itemStorages; CRWNavigationItemStorage* item = item_storages[index]; return sessions::IOSSerializedNavigationBuilder::FromNavigationStorageItem( index, item); diff --git a/chromium/components/sessions/ios/ios_webstate_live_tab.h b/chromium/components/sessions/ios/ios_webstate_live_tab.h index c4a73aa7772..7b8b913636d 100644 --- a/chromium/components/sessions/ios/ios_webstate_live_tab.h +++ b/chromium/components/sessions/ios/ios_webstate_live_tab.h @@ -5,7 +5,6 @@ #ifndef COMPONENTS_SESSIONS_IOS_IOS_WEBSTATE_LIVE_TAB_H_ #define COMPONENTS_SESSIONS_IOS_IOS_WEBSTATE_LIVE_TAB_H_ -#include "base/macros.h" #include "base/supports_user_data.h" #include "components/sessions/ios/ios_live_tab.h" #include "components/sessions/ios/ios_serialized_navigation_builder.h" |