OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 5 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 | 44 |
45 bool BrowserActionDragData::IsFromProfile(const Profile* profile) const { | 45 bool BrowserActionDragData::IsFromProfile(const Profile* profile) const { |
46 return profile_ == profile; | 46 return profile_ == profile; |
47 } | 47 } |
48 | 48 |
49 #if defined(TOOLKIT_VIEWS) | 49 #if defined(TOOLKIT_VIEWS) |
50 void BrowserActionDragData::Write( | 50 void BrowserActionDragData::Write( |
51 Profile* profile, ui::OSExchangeData* data) const { | 51 Profile* profile, ui::OSExchangeData* data) const { |
52 DCHECK(data); | 52 DCHECK(data); |
53 Pickle data_pickle; | 53 base::Pickle data_pickle; |
54 WriteToPickle(profile, &data_pickle); | 54 WriteToPickle(profile, &data_pickle); |
55 data->SetPickledData(GetBrowserActionCustomFormat(), data_pickle); | 55 data->SetPickledData(GetBrowserActionCustomFormat(), data_pickle); |
56 } | 56 } |
57 | 57 |
58 bool BrowserActionDragData::Read(const ui::OSExchangeData& data) { | 58 bool BrowserActionDragData::Read(const ui::OSExchangeData& data) { |
59 if (!data.HasCustomFormat(GetBrowserActionCustomFormat())) | 59 if (!data.HasCustomFormat(GetBrowserActionCustomFormat())) |
60 return false; | 60 return false; |
61 | 61 |
62 Pickle drag_data_pickle; | 62 base::Pickle drag_data_pickle; |
63 if (!data.GetPickledData(GetBrowserActionCustomFormat(), &drag_data_pickle)) | 63 if (!data.GetPickledData(GetBrowserActionCustomFormat(), &drag_data_pickle)) |
64 return false; | 64 return false; |
65 | 65 |
66 if (!ReadFromPickle(&drag_data_pickle)) | 66 if (!ReadFromPickle(&drag_data_pickle)) |
67 return false; | 67 return false; |
68 | 68 |
69 return true; | 69 return true; |
70 } | 70 } |
71 | 71 |
72 // static | 72 // static |
73 const ui::OSExchangeData::CustomFormat& | 73 const ui::OSExchangeData::CustomFormat& |
74 BrowserActionDragData::GetBrowserActionCustomFormat() { | 74 BrowserActionDragData::GetBrowserActionCustomFormat() { |
75 CR_DEFINE_STATIC_LOCAL( | 75 CR_DEFINE_STATIC_LOCAL( |
76 ui::OSExchangeData::CustomFormat, | 76 ui::OSExchangeData::CustomFormat, |
77 format, | 77 format, |
78 (ui::Clipboard::GetFormatType(kClipboardFormatString))); | 78 (ui::Clipboard::GetFormatType(kClipboardFormatString))); |
79 | 79 |
80 return format; | 80 return format; |
81 } | 81 } |
82 #endif | 82 #endif |
83 | 83 |
84 void BrowserActionDragData::WriteToPickle( | 84 void BrowserActionDragData::WriteToPickle(Profile* profile, |
85 Profile* profile, base::Pickle* pickle) const { | 85 base::Pickle* pickle) const { |
86 pickle->WriteBytes(&profile, sizeof(profile)); | 86 pickle->WriteBytes(&profile, sizeof(profile)); |
87 pickle->WriteString(id_); | 87 pickle->WriteString(id_); |
88 pickle->WriteUInt64(index_); | 88 pickle->WriteUInt64(index_); |
89 } | 89 } |
90 | 90 |
91 bool BrowserActionDragData::ReadFromPickle(Pickle* pickle) { | 91 bool BrowserActionDragData::ReadFromPickle(base::Pickle* pickle) { |
92 PickleIterator data_iterator(*pickle); | 92 base::PickleIterator data_iterator(*pickle); |
93 | 93 |
94 const char* tmp; | 94 const char* tmp; |
95 if (!data_iterator.ReadBytes(&tmp, sizeof(profile_))) | 95 if (!data_iterator.ReadBytes(&tmp, sizeof(profile_))) |
96 return false; | 96 return false; |
97 memcpy(&profile_, tmp, sizeof(profile_)); | 97 memcpy(&profile_, tmp, sizeof(profile_)); |
98 | 98 |
99 if (!data_iterator.ReadString(&id_)) | 99 if (!data_iterator.ReadString(&id_)) |
100 return false; | 100 return false; |
101 | 101 |
102 uint64 index; | 102 uint64 index; |
103 if (!data_iterator.ReadUInt64(&index)) | 103 if (!data_iterator.ReadUInt64(&index)) |
104 return false; | 104 return false; |
105 index_ = static_cast<size_t>(index); | 105 index_ = static_cast<size_t>(index); |
106 | 106 |
107 return true; | 107 return true; |
108 } | 108 } |
OLD | NEW |