OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 5 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 if (nodes.empty()) | 109 if (nodes.empty()) |
110 return false; | 110 return false; |
111 | 111 |
112 for (size_t i = 0; i < nodes.size(); ++i) | 112 for (size_t i = 0; i < nodes.size(); ++i) |
113 elements.push_back(Element(nodes[i])); | 113 elements.push_back(Element(nodes[i])); |
114 | 114 |
115 return true; | 115 return true; |
116 } | 116 } |
117 | 117 |
118 bool BookmarkNodeData::ReadFromTuple(const GURL& url, const string16& title) { | 118 bool BookmarkNodeData::ReadFromTuple(const GURL& url, const base::string16& titl
e) { |
119 Clear(); | 119 Clear(); |
120 | 120 |
121 if (!url.is_valid()) | 121 if (!url.is_valid()) |
122 return false; | 122 return false; |
123 | 123 |
124 Element element; | 124 Element element; |
125 element.title = title; | 125 element.title = title; |
126 element.url = url; | 126 element.url = url; |
127 element.is_url = true; | 127 element.is_url = true; |
128 | 128 |
129 elements.push_back(element); | 129 elements.push_back(element); |
130 | 130 |
131 return true; | 131 return true; |
132 } | 132 } |
133 | 133 |
134 #if !defined(OS_MACOSX) | 134 #if !defined(OS_MACOSX) |
135 void BookmarkNodeData::WriteToClipboard(ui::ClipboardType type) { | 135 void BookmarkNodeData::WriteToClipboard(ui::ClipboardType type) { |
136 DCHECK_EQ(type, ui::CLIPBOARD_TYPE_COPY_PASTE); | 136 DCHECK_EQ(type, ui::CLIPBOARD_TYPE_COPY_PASTE); |
137 ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(), | 137 ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(), |
138 ui::CLIPBOARD_TYPE_COPY_PASTE); | 138 ui::CLIPBOARD_TYPE_COPY_PASTE); |
139 | 139 |
140 // If there is only one element and it is a URL, write the URL to the | 140 // If there is only one element and it is a URL, write the URL to the |
141 // clipboard. | 141 // clipboard. |
142 if (elements.size() == 1 && elements[0].is_url) { | 142 if (elements.size() == 1 && elements[0].is_url) { |
143 const string16& title = elements[0].title; | 143 const base::string16& title = elements[0].title; |
144 const std::string url = elements[0].url.spec(); | 144 const std::string url = elements[0].url.spec(); |
145 | 145 |
146 scw.WriteBookmark(title, url); | 146 scw.WriteBookmark(title, url); |
147 | 147 |
148 // Don't call scw.WriteHyperlink() here, since some rich text editors will | 148 // Don't call scw.WriteHyperlink() here, since some rich text editors will |
149 // change fonts when such data is pasted in; besides, most such editors | 149 // change fonts when such data is pasted in; besides, most such editors |
150 // auto-linkify at some point anyway. | 150 // auto-linkify at some point anyway. |
151 | 151 |
152 // Also write the URL to the clipboard as text so that it can be pasted | 152 // Also write the URL to the clipboard as text so that it can be pasted |
153 // into text fields. We use WriteText instead of WriteURL because we don't | 153 // into text fields. We use WriteText instead of WriteURL because we don't |
(...skipping 15 matching lines...) Expand all Loading... |
169 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); | 169 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
170 clipboard->ReadData(ui::Clipboard::GetFormatType(kClipboardFormatString), | 170 clipboard->ReadData(ui::Clipboard::GetFormatType(kClipboardFormatString), |
171 &data); | 171 &data); |
172 | 172 |
173 if (!data.empty()) { | 173 if (!data.empty()) { |
174 Pickle pickle(data.data(), data.size()); | 174 Pickle pickle(data.data(), data.size()); |
175 if (ReadFromPickle(&pickle)) | 175 if (ReadFromPickle(&pickle)) |
176 return true; | 176 return true; |
177 } | 177 } |
178 | 178 |
179 string16 title; | 179 base::string16 title; |
180 std::string url; | 180 std::string url; |
181 clipboard->ReadBookmark(&title, &url); | 181 clipboard->ReadBookmark(&title, &url); |
182 if (!url.empty()) { | 182 if (!url.empty()) { |
183 Element element; | 183 Element element; |
184 element.is_url = true; | 184 element.is_url = true; |
185 element.url = GURL(url); | 185 element.url = GURL(url); |
186 element.title = title; | 186 element.title = title; |
187 | 187 |
188 elements.clear(); | 188 elements.clear(); |
189 elements.push_back(element); | 189 elements.push_back(element); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 DCHECK(profile_path_.empty()); | 254 DCHECK(profile_path_.empty()); |
255 | 255 |
256 if (profile) | 256 if (profile) |
257 profile_path_ = profile->GetPath(); | 257 profile_path_ = profile->GetPath(); |
258 } | 258 } |
259 | 259 |
260 bool BookmarkNodeData::IsFromProfile(Profile* profile) const { | 260 bool BookmarkNodeData::IsFromProfile(Profile* profile) const { |
261 // An empty path means the data is not associated with any profile. | 261 // An empty path means the data is not associated with any profile. |
262 return !profile_path_.empty() && profile_path_ == profile->GetPath(); | 262 return !profile_path_.empty() && profile_path_ == profile->GetPath(); |
263 } | 263 } |
OLD | NEW |