summaryrefslogtreecommitdiff
path: root/chromium/components/sessions
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/components/sessions
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/sessions')
-rw-r--r--chromium/components/sessions/core/command_storage_backend.cc43
-rw-r--r--chromium/components/sessions/core/command_storage_backend.h3
-rw-r--r--chromium/components/sessions/core/command_storage_backend_unittest.cc16
-rw-r--r--chromium/components/sessions/core/session_service_commands.cc40
-rw-r--r--chromium/components/sessions/core/session_service_commands.h4
-rw-r--r--chromium/components/sessions/core/session_types.h3
6 files changed, 98 insertions, 11 deletions
diff --git a/chromium/components/sessions/core/command_storage_backend.cc b/chromium/components/sessions/core/command_storage_backend.cc
index 967b6d0e2ba..45dbc5f179b 100644
--- a/chromium/components/sessions/core/command_storage_backend.cc
+++ b/chromium/components/sessions/core/command_storage_backend.cc
@@ -58,6 +58,13 @@ class SessionFileReader {
file_ = std::make_unique<base::File>(
path, base::File::FLAG_OPEN | base::File::FLAG_READ);
}
+
+ // Returns true if the file has a valid header. A return value of false
+ // most likely means the file was not written by this code. This function
+ // is implicitly called by Read(), but may be called separately for checking
+ // if the file is valid.
+ bool HasValidHeader();
+
// Reads the contents of the file specified in the constructor, returning
// true on success, and filling up |commands| with commands.
bool Read(std::vector<std::unique_ptr<sessions::SessionCommand>>* commands);
@@ -107,24 +114,32 @@ class SessionFileReader {
// Count of the number of commands encountered.
int command_counter_ = 0;
+ bool did_check_header_ = false;
+
DISALLOW_COPY_AND_ASSIGN(SessionFileReader);
};
-bool SessionFileReader::Read(
- std::vector<std::unique_ptr<sessions::SessionCommand>>* commands) {
+bool SessionFileReader::HasValidHeader() {
+ // This function advances |file| and should only be called once.
+ DCHECK(!did_check_header_);
+ did_check_header_ = true;
+
if (!file_->IsValid())
return false;
FileHeader header;
- int read_count;
- read_count =
+ const int read_count =
file_->ReadAtCurrentPos(reinterpret_cast<char*>(&header), sizeof(header));
- if (read_count != sizeof(header) || header.signature != kFileSignature) {
- const bool encrypt = aead_.get() != nullptr;
- if ((encrypt && header.version != kEncryptedFileCurrentVersion) ||
- (!encrypt && header.version != kFileCurrentVersion)) {
- return false;
- }
- }
+ if (read_count != sizeof(header) || header.signature != kFileSignature)
+ return false;
+ const bool encrypt = aead_.get() != nullptr;
+ return (encrypt && header.version == kEncryptedFileCurrentVersion) ||
+ (!encrypt && header.version == kFileCurrentVersion);
+}
+
+bool SessionFileReader::Read(
+ std::vector<std::unique_ptr<sessions::SessionCommand>>* commands) {
+ if (!HasValidHeader())
+ return false;
std::vector<std::unique_ptr<sessions::SessionCommand>> read_commands;
for (std::unique_ptr<sessions::SessionCommand> command = ReadCommand();
@@ -263,6 +278,12 @@ CommandStorageBackend::CommandStorageBackend(
const base::FilePath& path)
: RefCountedDeleteOnSequence(owning_task_runner), path_(path) {}
+// static
+bool CommandStorageBackend::IsValidFile(const base::FilePath& path) {
+ SessionFileReader file_reader(path, {});
+ return file_reader.HasValidHeader();
+}
+
void CommandStorageBackend::AppendCommands(
std::vector<std::unique_ptr<sessions::SessionCommand>> commands,
bool truncate,
diff --git a/chromium/components/sessions/core/command_storage_backend.h b/chromium/components/sessions/core/command_storage_backend.h
index 8fb526fb137..8db65119ae0 100644
--- a/chromium/components/sessions/core/command_storage_backend.h
+++ b/chromium/components/sessions/core/command_storage_backend.h
@@ -55,6 +55,9 @@ class SESSIONS_EXPORT CommandStorageBackend
scoped_refptr<base::SequencedTaskRunner> owning_task_runner,
const base::FilePath& path);
+ // Returns true if the file at |path| was generated by this class.
+ static bool IsValidFile(const base::FilePath& path);
+
base::SequencedTaskRunner* owning_task_runner() {
return base::RefCountedDeleteOnSequence<
CommandStorageBackend>::owning_task_runner();
diff --git a/chromium/components/sessions/core/command_storage_backend_unittest.cc b/chromium/components/sessions/core/command_storage_backend_unittest.cc
index bafb0d5c666..6df2d8ff9ca 100644
--- a/chromium/components/sessions/core/command_storage_backend_unittest.cc
+++ b/chromium/components/sessions/core/command_storage_backend_unittest.cc
@@ -287,4 +287,20 @@ TEST_F(CommandStorageBackendTest, MaxSizeType) {
expected_size) == 0);
}
+TEST_F(CommandStorageBackendTest, IsValidFileWithInvalidFiles) {
+ base::WriteFile(path_, "z");
+ EXPECT_FALSE(CommandStorageBackend::IsValidFile(path_));
+
+ base::WriteFile(path_, "a longer string that does not match header");
+ EXPECT_FALSE(CommandStorageBackend::IsValidFile(path_));
+}
+
+TEST_F(CommandStorageBackendTest, IsValidFileWithValidFile) {
+ scoped_refptr<CommandStorageBackend> backend = CreateBackend();
+ backend->AppendCommands({}, true);
+ backend = nullptr;
+
+ EXPECT_TRUE(CommandStorageBackend::IsValidFile(path_));
+}
+
} // namespace sessions
diff --git a/chromium/components/sessions/core/session_service_commands.cc b/chromium/components/sessions/core/session_service_commands.cc
index 985868226e2..520f1e7bdf7 100644
--- a/chromium/components/sessions/core/session_service_commands.cc
+++ b/chromium/components/sessions/core/session_service_commands.cc
@@ -12,6 +12,7 @@
#include "base/containers/flat_set.h"
#include "base/guid.h"
+#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/pickle.h"
#include "base/token.h"
@@ -68,6 +69,7 @@ static const SessionCommand::id_type kCommandSetTabGroupMetadata = 26;
static const SessionCommand::id_type kCommandSetTabGroupMetadata2 = 27;
static const SessionCommand::id_type kCommandSetTabGuid = 28;
static const SessionCommand::id_type kCommandSetTabUserAgentOverride2 = 29;
+static const SessionCommand::id_type kCommandSetTabData = 30;
namespace {
@@ -807,6 +809,31 @@ bool CreateTabsAndWindows(
break;
}
+ case kCommandSetTabData: {
+ std::unique_ptr<base::Pickle> pickle(command->PayloadAsPickle());
+ base::PickleIterator it(*pickle);
+ SessionID::id_type tab_id = -1;
+ int size = 0;
+ if (!it.ReadInt(&tab_id) || !it.ReadInt(&size)) {
+ DVLOG(1) << "Failed reading command " << command->id();
+ return true;
+ }
+ std::map<std::string, std::string> data;
+ for (int i = 0; i < size; i++) {
+ std::string key;
+ std::string value;
+ if (!it.ReadString(&key) || !it.ReadString(&value)) {
+ DVLOG(1) << "Failed reading command " << command->id();
+ return true;
+ }
+ data.insert({key, value});
+ }
+
+ GetTab(SessionID::FromSerializedValue(tab_id), tabs)->data =
+ std::move(data);
+ break;
+ }
+
default:
DVLOG(1) << "Failed reading an unknown command " << command->id();
return true;
@@ -1022,6 +1049,19 @@ std::unique_ptr<SessionCommand> CreateSetTabGuidCommand(
return std::make_unique<SessionCommand>(kCommandSetTabGuid, pickle);
}
+std::unique_ptr<SessionCommand> CreateSetTabDataCommand(
+ const SessionID& tab_id,
+ const std::map<std::string, std::string>& data) {
+ base::Pickle pickle;
+ pickle.WriteInt(tab_id.id());
+ pickle.WriteInt(data.size());
+ for (const auto& kv : data) {
+ pickle.WriteString(kv.first);
+ pickle.WriteString(kv.second);
+ }
+ return std::make_unique<SessionCommand>(kCommandSetTabData, pickle);
+}
+
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 192e93d5205..ec982596282 100644
--- a/chromium/components/sessions/core/session_service_commands.h
+++ b/chromium/components/sessions/core/session_service_commands.h
@@ -93,6 +93,10 @@ SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateSetTabGuidCommand(
const SessionID& tab_id,
const std::string& guid);
+SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateSetTabDataCommand(
+ const SessionID& tab_id,
+ const std::map<std::string, 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 cb0ab534365..081fccf8bf9 100644
--- a/chromium/components/sessions/core/session_types.h
+++ b/chromium/components/sessions/core/session_types.h
@@ -101,6 +101,9 @@ struct SESSIONS_EXPORT SessionTab {
// guid associated with the tab, may be empty.
std::string guid;
+ // Data associated with the tab by the embedder.
+ std::map<std::string, std::string> data;
+
private:
DISALLOW_COPY_AND_ASSIGN(SessionTab);
};