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
3 // found in the LICENSE file.
5 #include "chrome/browser/bookmarks/bookmark_node_data.h"
7 #include "base/logging.h"
8 #include "base/pickle.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "content/public/common/url_constants.h"
11 #include "ui/base/clipboard/clipboard.h"
14 const ui::OSExchangeData::CustomFormat&
15 BookmarkNodeData::GetBookmarkCustomFormat() {
16 CR_DEFINE_STATIC_LOCAL(
17 ui::OSExchangeData::CustomFormat,
19 (ui::Clipboard::GetFormatType(BookmarkNodeData::kClipboardFormatString)));
24 void BookmarkNodeData::Write(Profile* profile, ui::OSExchangeData* data) const {
27 // If there is only one element and it is a URL, write the URL to the
29 if (elements.size() == 1 && elements[0].is_url) {
30 if (elements[0].url.SchemeIs(content::kJavaScriptScheme)) {
31 data->SetString(UTF8ToUTF16(elements[0].url.spec()));
33 data->SetURL(elements[0].url, elements[0].title);
38 WriteToPickle(profile, &data_pickle);
40 data->SetPickledData(GetBookmarkCustomFormat(), data_pickle);
43 bool BookmarkNodeData::Read(const ui::OSExchangeData& data) {
46 profile_path_.clear();
48 if (data.HasCustomFormat(GetBookmarkCustomFormat())) {
49 Pickle drag_data_pickle;
50 if (data.GetPickledData(GetBookmarkCustomFormat(), &drag_data_pickle)) {
51 if (!ReadFromPickle(&drag_data_pickle))
55 // See if there is a URL on the clipboard.
59 if (data.GetURLAndTitle(&url, &title))
60 ReadFromTuple(url, title);