| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/bookmarks/bookmark_node_data.h" | 5 #include "chrome/browser/bookmarks/bookmark_node_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/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
| 11 #include "ui/base/clipboard/clipboard.h" | 11 #include "ui/base/clipboard/clipboard.h" |
| 12 | 12 |
| 13 // static | |
| 14 const ui::OSExchangeData::CustomFormat& | |
| 15 BookmarkNodeData::GetBookmarkCustomFormat() { | |
| 16 CR_DEFINE_STATIC_LOCAL( | |
| 17 ui::OSExchangeData::CustomFormat, | |
| 18 format, | |
| 19 (ui::Clipboard::GetFormatType(BookmarkNodeData::kClipboardFormatString))); | |
| 20 | |
| 21 return format; | |
| 22 } | |
| 23 | |
| 24 void BookmarkNodeData::Write(Profile* profile, ui::OSExchangeData* data) const { | 13 void BookmarkNodeData::Write(Profile* profile, ui::OSExchangeData* data) const { |
| 25 DCHECK(data); | 14 DCHECK(data); |
| 26 | 15 |
| 27 // If there is only one element and it is a URL, write the URL to the | 16 // If there is only one element and it is a URL, write the URL to the |
| 28 // clipboard. | 17 // clipboard. |
| 29 if (elements.size() == 1 && elements[0].is_url) { | 18 if (elements.size() == 1 && elements[0].is_url) { |
| 30 if (elements[0].url.SchemeIs(content::kJavaScriptScheme)) { | 19 if (elements[0].url.SchemeIs(content::kJavaScriptScheme)) { |
| 31 data->SetString(base::UTF8ToUTF16(elements[0].url.spec())); | 20 data->SetString(base::UTF8ToUTF16(elements[0].url.spec())); |
| 32 } else { | 21 } else { |
| 33 data->SetURL(elements[0].url, elements[0].title); | 22 data->SetURL(elements[0].url, elements[0].title); |
| 34 } | 23 } |
| 35 } | 24 } |
| 36 | 25 |
| 37 Pickle data_pickle; | 26 Pickle data_pickle; |
| 38 WriteToPickle(profile, &data_pickle); | 27 WriteToPickle(profile, &data_pickle); |
| 39 | 28 |
| 40 data->SetPickledData(GetBookmarkCustomFormat(), data_pickle); | 29 data->SetPickledData(GetFormatType(), data_pickle); |
| 41 } | 30 } |
| 42 | 31 |
| 43 bool BookmarkNodeData::Read(const ui::OSExchangeData& data) { | 32 bool BookmarkNodeData::Read(const ui::OSExchangeData& data) { |
| 44 elements.clear(); | 33 elements.clear(); |
| 45 | 34 |
| 46 profile_path_.clear(); | 35 profile_path_.clear(); |
| 47 | 36 |
| 48 if (data.HasCustomFormat(GetBookmarkCustomFormat())) { | 37 if (data.HasCustomFormat(GetFormatType())) { |
| 49 Pickle drag_data_pickle; | 38 Pickle drag_data_pickle; |
| 50 if (data.GetPickledData(GetBookmarkCustomFormat(), &drag_data_pickle)) { | 39 if (data.GetPickledData(GetFormatType(), &drag_data_pickle)) { |
| 51 if (!ReadFromPickle(&drag_data_pickle)) | 40 if (!ReadFromPickle(&drag_data_pickle)) |
| 52 return false; | 41 return false; |
| 53 } | 42 } |
| 54 } else { | 43 } else { |
| 55 // See if there is a URL on the clipboard. | 44 // See if there is a URL on the clipboard. |
| 56 Element element; | 45 Element element; |
| 57 GURL url; | 46 GURL url; |
| 58 base::string16 title; | 47 base::string16 title; |
| 59 if (data.GetURLAndTitle( | 48 if (data.GetURLAndTitle( |
| 60 ui::OSExchangeData::CONVERT_FILENAMES, &url, &title)) | 49 ui::OSExchangeData::CONVERT_FILENAMES, &url, &title)) |
| 61 ReadFromTuple(url, title); | 50 ReadFromTuple(url, title); |
| 62 } | 51 } |
| 63 | 52 |
| 64 return is_valid(); | 53 return is_valid(); |
| 65 } | 54 } |
| OLD | NEW |