This source file includes following definitions.
- GetBookmarkCustomFormat
- Write
- Read
#include "chrome/browser/bookmarks/bookmark_node_data.h"
#include "base/logging.h"
#include "base/pickle.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/common/url_constants.h"
#include "ui/base/clipboard/clipboard.h"
const ui::OSExchangeData::CustomFormat&
BookmarkNodeData::GetBookmarkCustomFormat() {
CR_DEFINE_STATIC_LOCAL(
ui::OSExchangeData::CustomFormat,
format,
(ui::Clipboard::GetFormatType(BookmarkNodeData::kClipboardFormatString)));
return format;
}
void BookmarkNodeData::Write(Profile* profile, ui::OSExchangeData* data) const {
DCHECK(data);
if (elements.size() == 1 && elements[0].is_url) {
if (elements[0].url.SchemeIs(content::kJavaScriptScheme)) {
data->SetString(base::UTF8ToUTF16(elements[0].url.spec()));
} else {
data->SetURL(elements[0].url, elements[0].title);
}
}
Pickle data_pickle;
WriteToPickle(profile, &data_pickle);
data->SetPickledData(GetBookmarkCustomFormat(), data_pickle);
}
bool BookmarkNodeData::Read(const ui::OSExchangeData& data) {
elements.clear();
profile_path_.clear();
if (data.HasCustomFormat(GetBookmarkCustomFormat())) {
Pickle drag_data_pickle;
if (data.GetPickledData(GetBookmarkCustomFormat(), &drag_data_pickle)) {
if (!ReadFromPickle(&drag_data_pickle))
return false;
}
} else {
Element element;
GURL url;
base::string16 title;
if (data.GetURLAndTitle(
ui::OSExchangeData::CONVERT_FILENAMES, &url, &title))
ReadFromTuple(url, title);
}
return is_valid();
}