Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / bookmarks / bookmark_node_data_views.cc
blob87b8cb4936fd8ab19a707ce1cdfd1cae6615dc4f
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"
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)));
21 return format;
24 void BookmarkNodeData::Write(Profile* profile, ui::OSExchangeData* data) const {
25 DCHECK(data);
27 // If there is only one element and it is a URL, write the URL to the
28 // clipboard.
29 if (elements.size() == 1 && elements[0].is_url) {
30 if (elements[0].url.SchemeIs(content::kJavaScriptScheme)) {
31 data->SetString(base::UTF8ToUTF16(elements[0].url.spec()));
32 } else {
33 data->SetURL(elements[0].url, elements[0].title);
37 Pickle data_pickle;
38 WriteToPickle(profile, &data_pickle);
40 data->SetPickledData(GetBookmarkCustomFormat(), data_pickle);
43 bool BookmarkNodeData::Read(const ui::OSExchangeData& data) {
44 elements.clear();
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))
52 return false;
54 } else {
55 // See if there is a URL on the clipboard.
56 Element element;
57 GURL url;
58 base::string16 title;
59 if (data.GetURLAndTitle(
60 ui::OSExchangeData::CONVERT_FILENAMES, &url, &title))
61 ReadFromTuple(url, title);
64 return is_valid();