| 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" |
| 11 #include "ui/base/clipboard/clipboard.h" | 11 #include "ui/base/clipboard/clipboard.h" |
| 12 | 12 |
| 13 namespace { | 13 const char* BrowserActionDragData::kClipboardFormatString = |
| 14 | 14 "chromium/x-browser-actions"; |
| 15 // The MIME type for the clipboard format for BrowserActionDragData. | |
| 16 const char kClipboardFormatString[] = "chromium/x-browser-actions"; | |
| 17 | |
| 18 } | |
| 19 | 15 |
| 20 BrowserActionDragData::BrowserActionDragData() | 16 BrowserActionDragData::BrowserActionDragData() |
| 21 : profile_(NULL), index_(static_cast<size_t>(-1)) { | 17 : profile_(NULL), index_(static_cast<size_t>(-1)) { |
| 22 } | 18 } |
| 23 | 19 |
| 24 BrowserActionDragData::BrowserActionDragData( | 20 BrowserActionDragData::BrowserActionDragData( |
| 25 const std::string& id, int index) | 21 const std::string& id, int index) |
| 26 : profile_(NULL), id_(id), index_(index) { | 22 : profile_(NULL), id_(id), index_(index) { |
| 27 } | 23 } |
| 28 | 24 |
| 29 bool BrowserActionDragData::GetDropFormats( | 25 bool BrowserActionDragData::IsFromProfile(Profile* profile) const { |
| 30 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) { | |
| 31 custom_formats->insert(GetBrowserActionCustomFormat()); | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 bool BrowserActionDragData::AreDropTypesRequired() { | |
| 36 return true; | |
| 37 } | |
| 38 | |
| 39 bool BrowserActionDragData::CanDrop(const ui::OSExchangeData& data, | |
| 40 const Profile* profile) { | |
| 41 BrowserActionDragData drop_data; | |
| 42 return drop_data.Read(data) && drop_data.IsFromProfile(profile); | |
| 43 } | |
| 44 | |
| 45 bool BrowserActionDragData::IsFromProfile(const Profile* profile) const { | |
| 46 return profile_ == profile; | 26 return profile_ == profile; |
| 47 } | 27 } |
| 48 | 28 |
| 49 #if defined(TOOLKIT_VIEWS) | 29 #if defined(TOOLKIT_VIEWS) |
| 50 void BrowserActionDragData::Write( | 30 void BrowserActionDragData::Write( |
| 51 Profile* profile, ui::OSExchangeData* data) const { | 31 Profile* profile, ui::OSExchangeData* data) const { |
| 52 DCHECK(data); | 32 DCHECK(data); |
| 53 Pickle data_pickle; | 33 Pickle data_pickle; |
| 54 WriteToPickle(profile, &data_pickle); | 34 WriteToPickle(profile, &data_pickle); |
| 55 data->SetPickledData(GetBrowserActionCustomFormat(), data_pickle); | 35 data->SetPickledData(GetBrowserActionCustomFormat(), data_pickle); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 if (!pickle->ReadString(&data_iterator, &id_)) | 79 if (!pickle->ReadString(&data_iterator, &id_)) |
| 100 return false; | 80 return false; |
| 101 | 81 |
| 102 uint64 index; | 82 uint64 index; |
| 103 if (!pickle->ReadUInt64(&data_iterator, &index)) | 83 if (!pickle->ReadUInt64(&data_iterator, &index)) |
| 104 return false; | 84 return false; |
| 105 index_ = static_cast<size_t>(index); | 85 index_ = static_cast<size_t>(index); |
| 106 | 86 |
| 107 return true; | 87 return true; |
| 108 } | 88 } |
| OLD | NEW |