diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 23:52:24 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 23:52:24 +0000 |
commit | 26d2f47eba267fc034ae77d0ca1fefdc7cb86135 (patch) | |
tree | b74e28bcd8f16e914b88935bf4ca710bddc64586 | |
parent | 08173b245a9fbe6381a805cc5987d434a641d96e (diff) | |
download | chromium_src-26d2f47eba267fc034ae77d0ca1fefdc7cb86135.zip chromium_src-26d2f47eba267fc034ae77d0ca1fefdc7cb86135.tar.gz chromium_src-26d2f47eba267fc034ae77d0ca1fefdc7cb86135.tar.bz2 |
Don't allow dragging browser actions between regular and incognito windows.
This fixes a crash.
Also small fix to Pickle::ReadBytes to fix up the iterator if it is NULL.
BUG=39340
Review URL: http://codereview.chromium.org/1542007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43147 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/pickle.cc | 2 | ||||
-rw-r--r-- | base/pickle_unittest.cc | 14 | ||||
-rw-r--r-- | chrome/browser/views/extensions/browser_action_drag_data.cc | 25 | ||||
-rw-r--r-- | chrome/browser/views/extensions/browser_action_drag_data.h | 5 | ||||
-rw-r--r-- | chrome/browser/views/extensions/browser_action_drag_data_unittest.cc | 3 | ||||
-rw-r--r-- | ipc/ipc_fuzzing_tests.cc | 2 |
6 files changed, 33 insertions, 18 deletions
diff --git a/base/pickle.cc b/base/pickle.cc index 4fa206e..06a3be1 100644 --- a/base/pickle.cc +++ b/base/pickle.cc @@ -250,6 +250,8 @@ bool Pickle::ReadBytes(void** iter, const char** data, int length) const { DCHECK(iter); DCHECK(data); *data = 0; + if (!*iter) + *iter = const_cast<char*>(payload()); if (!IteratorHasRoomFor(*iter, length)) return false; diff --git a/base/pickle_unittest.cc b/base/pickle_unittest.cc index 1a98cd2..aea3830 100644 --- a/base/pickle_unittest.cc +++ b/base/pickle_unittest.cc @@ -259,3 +259,17 @@ TEST(PickleTest, ZeroLength) { // We can't assert that outdata is NULL. } +// Check that ReadBytes works properly with an iterator initialized to NULL. +TEST(PickleTest, ReadBytes) { + Pickle pickle; + int data = 0x7abcd; + EXPECT_TRUE(pickle.WriteBytes(&data, sizeof(data))); + + void* iter = NULL; + const char* outdata_char; + EXPECT_TRUE(pickle.ReadBytes(&iter, &outdata_char, sizeof(data))); + + int outdata; + memcpy(&outdata, outdata_char, sizeof(outdata)); + EXPECT_EQ(data, outdata); +} diff --git a/chrome/browser/views/extensions/browser_action_drag_data.cc b/chrome/browser/views/extensions/browser_action_drag_data.cc index 103738f..2d772ea 100644 --- a/chrome/browser/views/extensions/browser_action_drag_data.cc +++ b/chrome/browser/views/extensions/browser_action_drag_data.cc @@ -14,19 +14,16 @@ const char* BrowserActionDragData::kClipboardFormatString = "chromium/x-browser-actions"; BrowserActionDragData::BrowserActionDragData() - : index_(-1) { + : profile_id_(0), index_(-1) { } BrowserActionDragData::BrowserActionDragData( const std::string& id, int index) - : id_(id), - index_(index) { + : profile_id_(0), id_(id), index_(index) { } bool BrowserActionDragData::IsFromProfile(Profile* profile) const { - // An empty path means the data is not associated with any profile. - return (!profile_path_.empty() && - profile_path_ == profile->GetPath().value()); + return (profile_id_ == profile->GetRuntimeId()); } #if defined(TOOLKIT_VIEWS) @@ -69,25 +66,25 @@ OSExchangeData::CustomFormat void BrowserActionDragData::WriteToPickle( Profile* profile, Pickle* pickle) const { - FilePath::WriteStringTypeToPickle(pickle, profile->GetPath().value()); + ProfileId profile_id = profile->GetRuntimeId(); + pickle->WriteBytes(&profile_id, sizeof(profile_id)); pickle->WriteString(id_); - pickle->WriteInt(index_); + pickle->WriteSize(index_); } bool BrowserActionDragData::ReadFromPickle(Pickle* pickle) { void* data_iterator = NULL; - if (!FilePath::ReadStringTypeFromPickle(pickle, &data_iterator, - &profile_path_)) { + + const char* tmp; + if (!pickle->ReadBytes(&data_iterator, &tmp, sizeof(profile_id_))) return false; - } + memcpy(&profile_id_, tmp, sizeof(profile_id_)); if (!pickle->ReadString(&data_iterator, &id_)) return false; - int index; - if (!pickle->ReadInt(&data_iterator, &index)) + if (!pickle->ReadSize(&data_iterator, &index_)) return false; - index_ = index; return true; } diff --git a/chrome/browser/views/extensions/browser_action_drag_data.h b/chrome/browser/views/extensions/browser_action_drag_data.h index 8d5d514b..583185b 100644 --- a/chrome/browser/views/extensions/browser_action_drag_data.h +++ b/chrome/browser/views/extensions/browser_action_drag_data.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "chrome/browser/profile.h" #if defined(TOOLKIT_VIEWS) #include "app/os_exchange_data.h" @@ -44,8 +45,8 @@ class BrowserActionDragData { void WriteToPickle(Profile* profile, Pickle* pickle) const; bool ReadFromPickle(Pickle* pickle); - // Path of the profile we originated from. - FilePath::StringType profile_path_; + // ID of the profile we originated from. + ProfileId profile_id_; // The id of the view being dragged. std::string id_; diff --git a/chrome/browser/views/extensions/browser_action_drag_data_unittest.cc b/chrome/browser/views/extensions/browser_action_drag_data_unittest.cc index 7f54b0c..da4eb2c 100644 --- a/chrome/browser/views/extensions/browser_action_drag_data_unittest.cc +++ b/chrome/browser/views/extensions/browser_action_drag_data_unittest.cc @@ -37,8 +37,9 @@ TEST_F(BrowserActionDragDataTest, BrowserActionDragDataFormat) { profile.SetID(L"id"); const std::string extension_id = "42"; + const ProfileId profile_id = profile.GetRuntimeId(); Pickle pickle; - pickle.WriteWString(profile.GetPath().ToWStringHack()); + pickle.WriteBytes(&profile_id, sizeof(profile_id)); pickle.WriteString(extension_id); pickle.WriteInt(42); diff --git a/ipc/ipc_fuzzing_tests.cc b/ipc/ipc_fuzzing_tests.cc index c79d05a..951ccbb 100644 --- a/ipc/ipc_fuzzing_tests.cc +++ b/ipc/ipc_fuzzing_tests.cc @@ -51,7 +51,7 @@ TEST(IPCMessageIntegrity, ReadBytesBadIterator) { void* iter = NULL; const char* data = NULL; - EXPECT_FALSE(m.ReadBytes(&iter, &data, sizeof(int))); + EXPECT_TRUE(m.ReadBytes(&iter, &data, sizeof(int))); } TEST(IPCMessageIntegrity, ReadVectorNegativeSize) { |