summaryrefslogtreecommitdiffstats
path: root/chrome/browser/bookmarks/bookmark_drag_data.cc
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-09 23:08:13 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-09 23:08:13 +0000
commit68de8b76186059157dc916c499923d46bedb56b1 (patch)
tree870704b95740f2cafc144ced59b6bbf3c77c39d1 /chrome/browser/bookmarks/bookmark_drag_data.cc
parentd9b168764a9e7ad7dcd2561791041f660a54cdde (diff)
downloadchromium_src-68de8b76186059157dc916c499923d46bedb56b1.zip
chromium_src-68de8b76186059157dc916c499923d46bedb56b1.tar.gz
chromium_src-68de8b76186059157dc916c499923d46bedb56b1.tar.bz2
Moves bookmark related classes into bookmarks directory. There are no
code changes here (other than converting to COPY_AND_BLAH_BLAH and updating include guards). BUG=none TEST=none Review URL: http://codereview.chromium.org/1868 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1944 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks/bookmark_drag_data.cc')
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data.cc118
1 files changed, 118 insertions, 0 deletions
diff --git a/chrome/browser/bookmarks/bookmark_drag_data.cc b/chrome/browser/bookmarks/bookmark_drag_data.cc
new file mode 100644
index 0000000..61c9ccc
--- /dev/null
+++ b/chrome/browser/bookmarks/bookmark_drag_data.cc
@@ -0,0 +1,118 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/bookmarks/bookmark_drag_data.h"
+
+#include "base/pickle.h"
+#include "chrome/browser/bookmarks/bookmark_bar_model.h"
+#include "chrome/common/os_exchange_data.h"
+
+static CLIPFORMAT clipboard_format = 0;
+
+static void RegisterFormat() {
+ if (clipboard_format == 0) {
+ clipboard_format = RegisterClipboardFormat(L"chrome/x-bookmark-entry");
+ DCHECK(clipboard_format);
+ }
+}
+
+BookmarkDragData::BookmarkDragData() : is_url(false), is_valid(false) {
+}
+
+BookmarkDragData::BookmarkDragData(BookmarkBarNode* node)
+ : is_url(node->GetType() == history::StarredEntry::URL),
+ url(node->GetURL()),
+ title(node->GetTitle()),
+ is_valid(true),
+ id_(node->id()) {
+ if (!is_url)
+ AddChildren(node);
+}
+
+void BookmarkDragData::Write(OSExchangeData* data) const {
+ RegisterFormat();
+
+ DCHECK(data);
+
+ if (is_url) {
+ data->SetURL(url, title);
+ }
+ Pickle data_pickle;
+ WriteToPickle(&data_pickle);
+ data->SetPickledData(clipboard_format, data_pickle);
+}
+
+bool BookmarkDragData::Read(const OSExchangeData& data) {
+ RegisterFormat();
+
+ is_valid = data.GetURLAndTitle(&url, &title) && url.is_valid();
+ is_url = is_valid;
+ profile_id.clear();
+
+ if (data.HasFormat(clipboard_format)) {
+ Pickle drag_data_pickle;
+ if (data.GetPickledData(clipboard_format, &drag_data_pickle)) {
+ void* data_iterator = NULL;
+ if (ReadFromPickle(&drag_data_pickle, &data_iterator)) {
+ is_valid = true;
+ }
+ }
+ }
+ return is_valid;
+}
+
+BookmarkBarNode* BookmarkDragData::GetNode(BookmarkBarModel* model) const {
+ DCHECK(!is_url && id_ && is_valid);
+ return model->GetNodeByID(id_);
+}
+
+void BookmarkDragData::WriteToPickle(Pickle* pickle) const {
+ pickle->WriteBool(is_url);
+ pickle->WriteWString(profile_id);
+ pickle->WriteString(url.spec());
+ pickle->WriteWString(title);
+ if (!is_url) {
+ pickle->WriteInt(id_);
+ pickle->WriteInt(static_cast<int>(children.size()));
+ for (std::vector<BookmarkDragData>::const_iterator i = children.begin();
+ i != children.end(); ++i) {
+ i->WriteToPickle(pickle);
+ }
+ }
+}
+
+bool BookmarkDragData::ReadFromPickle(Pickle* pickle, void** iterator) {
+ std::string url_spec;
+ is_valid = false;
+ if (!pickle->ReadBool(iterator, &is_url) ||
+ !pickle->ReadWString(iterator, &profile_id) ||
+ !pickle->ReadString(iterator, &url_spec) ||
+ !pickle->ReadWString(iterator, &title)) {
+ return false;
+ }
+ url = GURL(url_spec);
+ if (!is_url) {
+ id_ = 0;
+ children.clear();
+ if (!pickle->ReadInt(iterator, &id_))
+ return false;
+ int children_count;
+ if (!pickle->ReadInt(iterator, &children_count))
+ return false;
+ children.resize(children_count);
+ for (std::vector<BookmarkDragData>::iterator i = children.begin();
+ i != children.end(); ++i) {
+ if (!i->ReadFromPickle(pickle, iterator))
+ return false;
+ }
+ }
+ is_valid = true;
+ return true;
+}
+
+void BookmarkDragData::AddChildren(BookmarkBarNode* node) {
+ for (int i = 0, max = node->GetChildCount(); i < max; ++i)
+ children.push_back(BookmarkDragData(node->GetChild(i)));
+}
+