| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 | 11 |
| 12 const char* BrowserActionDragData::kClipboardFormatString = | 12 const char* BrowserActionDragData::kClipboardFormatString = |
| 13 "chromium/x-browser-actions"; | 13 "chromium/x-browser-actions"; |
| 14 | 14 |
| 15 BrowserActionDragData::BrowserActionDragData() | 15 BrowserActionDragData::BrowserActionDragData() |
| 16 : profile_id_(0), index_(-1) { | 16 : profile_id_(0), index_(-1) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 BrowserActionDragData::BrowserActionDragData( | 19 BrowserActionDragData::BrowserActionDragData( |
| 20 const std::string& id, int index) | 20 const std::string& id, int index) |
| 21 : profile_id_(0), id_(id), index_(index) { | 21 : profile_id_(0), id_(id), index_(index) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool BrowserActionDragData::IsFromProfile(Profile* profile) const { | 24 bool BrowserActionDragData::IsFromProfile(Profile* profile) const { |
| 25 return (profile_id_ == profile->GetRuntimeId()); | 25 return (profile_id_ == profile->GetRuntimeId()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 #if defined(TOOLKIT_VIEWS) | 28 #if defined(TOOLKIT_VIEWS) |
| 29 void BrowserActionDragData::Write( | 29 void BrowserActionDragData::Write( |
| 30 Profile* profile, OSExchangeData* data) const { | 30 Profile* profile, ui::OSExchangeData* data) const { |
| 31 DCHECK(data); | 31 DCHECK(data); |
| 32 Pickle data_pickle; | 32 Pickle data_pickle; |
| 33 WriteToPickle(profile, &data_pickle); | 33 WriteToPickle(profile, &data_pickle); |
| 34 data->SetPickledData(GetBrowserActionCustomFormat(), data_pickle); | 34 data->SetPickledData(GetBrowserActionCustomFormat(), data_pickle); |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool BrowserActionDragData::Read(const OSExchangeData& data) { | 37 bool BrowserActionDragData::Read(const ui::OSExchangeData& data) { |
| 38 if (!data.HasCustomFormat(GetBrowserActionCustomFormat())) | 38 if (!data.HasCustomFormat(GetBrowserActionCustomFormat())) |
| 39 return false; | 39 return false; |
| 40 | 40 |
| 41 Pickle drag_data_pickle; | 41 Pickle drag_data_pickle; |
| 42 if (!data.GetPickledData(GetBrowserActionCustomFormat(), &drag_data_pickle)) | 42 if (!data.GetPickledData(GetBrowserActionCustomFormat(), &drag_data_pickle)) |
| 43 return false; | 43 return false; |
| 44 | 44 |
| 45 if (!ReadFromPickle(&drag_data_pickle)) | 45 if (!ReadFromPickle(&drag_data_pickle)) |
| 46 return false; | 46 return false; |
| 47 | 47 |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // static | 51 // static |
| 52 OSExchangeData::CustomFormat | 52 ui::OSExchangeData::CustomFormat |
| 53 BrowserActionDragData::GetBrowserActionCustomFormat() { | 53 BrowserActionDragData::GetBrowserActionCustomFormat() { |
| 54 static OSExchangeData::CustomFormat format; | 54 static ui::OSExchangeData::CustomFormat format; |
| 55 static bool format_valid = false; | 55 static bool format_valid = false; |
| 56 | 56 |
| 57 if (!format_valid) { | 57 if (!format_valid) { |
| 58 format_valid = true; | 58 format_valid = true; |
| 59 format = OSExchangeData::RegisterCustomFormat( | 59 format = ui::OSExchangeData::RegisterCustomFormat( |
| 60 BrowserActionDragData::kClipboardFormatString); | 60 BrowserActionDragData::kClipboardFormatString); |
| 61 } | 61 } |
| 62 return format; | 62 return format; |
| 63 } | 63 } |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 void BrowserActionDragData::WriteToPickle( | 66 void BrowserActionDragData::WriteToPickle( |
| 67 Profile* profile, Pickle* pickle) const { | 67 Profile* profile, Pickle* pickle) const { |
| 68 ProfileId profile_id = profile->GetRuntimeId(); | 68 ProfileId profile_id = profile->GetRuntimeId(); |
| 69 pickle->WriteBytes(&profile_id, sizeof(profile_id)); | 69 pickle->WriteBytes(&profile_id, sizeof(profile_id)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 80 memcpy(&profile_id_, tmp, sizeof(profile_id_)); | 80 memcpy(&profile_id_, tmp, sizeof(profile_id_)); |
| 81 | 81 |
| 82 if (!pickle->ReadString(&data_iterator, &id_)) | 82 if (!pickle->ReadString(&data_iterator, &id_)) |
| 83 return false; | 83 return false; |
| 84 | 84 |
| 85 if (!pickle->ReadSize(&data_iterator, &index_)) | 85 if (!pickle->ReadSize(&data_iterator, &index_)) |
| 86 return false; | 86 return false; |
| 87 | 87 |
| 88 return true; | 88 return true; |
| 89 } | 89 } |
| OLD | NEW |