Workaround for xkbcommon dead keys.
[chromium-blink-merge.git] / components / bookmarks / browser / bookmark_node_data_views.cc
blob888ffccbb8a1d898142f654eefa8f98e39cc319b
1 // Copyright 2014 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 "components/bookmarks/browser/bookmark_node_data.h"
7 #include "base/logging.h"
8 #include "base/pickle.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/base/clipboard/clipboard.h"
12 namespace bookmarks {
14 namespace {
16 const char kJavaScriptScheme[] = "javascript";
18 } // namespace
20 // static
21 const ui::OSExchangeData::CustomFormat&
22 BookmarkNodeData::GetBookmarkCustomFormat() {
23 CR_DEFINE_STATIC_LOCAL(
24 ui::OSExchangeData::CustomFormat,
25 format,
26 (ui::Clipboard::GetFormatType(BookmarkNodeData::kClipboardFormatString)));
28 return format;
31 void BookmarkNodeData::Write(const base::FilePath& profile_path,
32 ui::OSExchangeData* data) const {
33 DCHECK(data);
35 // If there is only one element and it is a URL, write the URL to the
36 // clipboard.
37 if (elements.size() == 1 && elements[0].is_url) {
38 if (elements[0].url.SchemeIs(kJavaScriptScheme)) {
39 data->SetString(base::UTF8ToUTF16(elements[0].url.spec()));
40 } else {
41 data->SetURL(elements[0].url, elements[0].title);
45 Pickle data_pickle;
46 WriteToPickle(profile_path, &data_pickle);
48 data->SetPickledData(GetBookmarkCustomFormat(), data_pickle);
51 bool BookmarkNodeData::Read(const ui::OSExchangeData& data) {
52 elements.clear();
54 profile_path_.clear();
56 if (data.HasCustomFormat(GetBookmarkCustomFormat())) {
57 Pickle drag_data_pickle;
58 if (data.GetPickledData(GetBookmarkCustomFormat(), &drag_data_pickle)) {
59 if (!ReadFromPickle(&drag_data_pickle))
60 return false;
62 } else {
63 // See if there is a URL on the clipboard.
64 Element element;
65 GURL url;
66 base::string16 title;
67 if (data.GetURLAndTitle(
68 ui::OSExchangeData::CONVERT_FILENAMES, &url, &title))
69 ReadFromTuple(url, title);
72 return is_valid();
75 } // namespace bookmarks