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 "ui/base/clipboard/clipboard.h" | 5 #include "ui/base/clipboard/clipboard.h" |
6 | 6 |
7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 } | 172 } |
173 it = map_.find(kHTMLFormat); | 173 it = map_.find(kHTMLFormat); |
174 if (it != map_.end()) { | 174 if (it != map_.end()) { |
175 map_.erase(kHTMLFormat); | 175 map_.erase(kHTMLFormat); |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 } // namespace | 179 } // namespace |
180 | 180 |
| 181 // Clipboard::FormatType implementation. |
181 Clipboard::FormatType::FormatType() { | 182 Clipboard::FormatType::FormatType() { |
182 } | 183 } |
183 | 184 |
184 Clipboard::FormatType::FormatType(const std::string& native_format) | 185 Clipboard::FormatType::FormatType(const std::string& native_format) |
185 : data_(native_format) { | 186 : data_(native_format) { |
186 } | 187 } |
187 | 188 |
188 Clipboard::FormatType::~FormatType() { | 189 Clipboard::FormatType::~FormatType() { |
189 } | 190 } |
190 | 191 |
191 std::string Clipboard::FormatType::Serialize() const { | 192 std::string Clipboard::FormatType::Serialize() const { |
192 return data_; | 193 return data_; |
193 } | 194 } |
194 | 195 |
195 // static | 196 // static |
196 Clipboard::FormatType Clipboard::FormatType::Deserialize( | 197 Clipboard::FormatType Clipboard::FormatType::Deserialize( |
197 const std::string& serialization) { | 198 const std::string& serialization) { |
198 return FormatType(serialization); | 199 return FormatType(serialization); |
199 } | 200 } |
200 | 201 |
201 bool Clipboard::FormatType::Equals(const FormatType& other) const { | 202 bool Clipboard::FormatType::Equals(const FormatType& other) const { |
202 return data_ == other.data_; | 203 return data_ == other.data_; |
203 } | 204 } |
204 | 205 |
| 206 // Various predefined FormatTypes. |
| 207 // static |
| 208 Clipboard::FormatType Clipboard::GetFormatType( |
| 209 const std::string& format_string) { |
| 210 return FormatType::Deserialize(format_string); |
| 211 } |
| 212 |
| 213 // static |
| 214 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { |
| 215 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat)); |
| 216 return type; |
| 217 } |
| 218 |
| 219 // static |
| 220 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { |
| 221 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat)); |
| 222 return type; |
| 223 } |
| 224 |
| 225 // static |
| 226 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { |
| 227 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kWebKitSmartPasteFormat)); |
| 228 return type; |
| 229 } |
| 230 |
| 231 // static |
| 232 const Clipboard::FormatType& Clipboard::GetHtmlFormatType() { |
| 233 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kHTMLFormat)); |
| 234 return type; |
| 235 } |
| 236 |
| 237 // static |
| 238 const Clipboard::FormatType& Clipboard::GetRtfFormatType() { |
| 239 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kRTFFormat)); |
| 240 return type; |
| 241 } |
| 242 |
| 243 // static |
| 244 const Clipboard::FormatType& Clipboard::GetBitmapFormatType() { |
| 245 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kBitmapFormat)); |
| 246 return type; |
| 247 } |
| 248 |
| 249 // static |
| 250 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { |
| 251 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); |
| 252 return type; |
| 253 } |
| 254 |
| 255 // static |
| 256 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
| 257 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); |
| 258 return type; |
| 259 } |
| 260 |
| 261 // Clipboard implementation. |
205 Clipboard::Clipboard() { | 262 Clipboard::Clipboard() { |
206 DCHECK(CalledOnValidThread()); | 263 DCHECK(CalledOnValidThread()); |
207 } | 264 } |
208 | 265 |
209 Clipboard::~Clipboard() { | 266 Clipboard::~Clipboard() { |
210 DCHECK(CalledOnValidThread()); | 267 DCHECK(CalledOnValidThread()); |
211 } | 268 } |
212 | 269 |
213 // Main entry point used to write several values in the clipboard. | |
214 void Clipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { | |
215 DCHECK(CalledOnValidThread()); | |
216 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | |
217 g_map.Get().Clear(); | |
218 for (ObjectMap::const_iterator iter = objects.begin(); | |
219 iter != objects.end(); ++iter) { | |
220 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); | |
221 } | |
222 } | |
223 | |
224 uint64 Clipboard::GetSequenceNumber(ClipboardType /* type */) { | 270 uint64 Clipboard::GetSequenceNumber(ClipboardType /* type */) { |
225 DCHECK(CalledOnValidThread()); | 271 DCHECK(CalledOnValidThread()); |
226 // TODO: implement this. For now this interface will advertise | 272 // TODO: implement this. For now this interface will advertise |
227 // that the clipboard never changes. That's fine as long as we | 273 // that the clipboard never changes. That's fine as long as we |
228 // don't rely on this signal. | 274 // don't rely on this signal. |
229 return 0; | 275 return 0; |
230 } | 276 } |
231 | 277 |
232 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, | 278 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, |
233 ClipboardType type) const { | 279 ClipboardType type) const { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 DCHECK(CalledOnValidThread()); | 372 DCHECK(CalledOnValidThread()); |
327 NOTIMPLEMENTED(); | 373 NOTIMPLEMENTED(); |
328 } | 374 } |
329 | 375 |
330 void Clipboard::ReadData(const Clipboard::FormatType& format, | 376 void Clipboard::ReadData(const Clipboard::FormatType& format, |
331 std::string* result) const { | 377 std::string* result) const { |
332 DCHECK(CalledOnValidThread()); | 378 DCHECK(CalledOnValidThread()); |
333 *result = g_map.Get().Get(format.data()); | 379 *result = g_map.Get().Get(format.data()); |
334 } | 380 } |
335 | 381 |
336 // static | 382 // Main entry point used to write several values in the clipboard. |
337 Clipboard::FormatType Clipboard::GetFormatType( | 383 void Clipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { |
338 const std::string& format_string) { | 384 DCHECK(CalledOnValidThread()); |
339 return FormatType::Deserialize(format_string); | 385 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
340 } | 386 g_map.Get().Clear(); |
341 | 387 for (ObjectMap::const_iterator iter = objects.begin(); |
342 // static | 388 iter != objects.end(); ++iter) { |
343 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { | 389 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); |
344 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat)); | 390 } |
345 return type; | |
346 } | |
347 | |
348 // static | |
349 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { | |
350 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat)); | |
351 return type; | |
352 } | |
353 | |
354 // static | |
355 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { | |
356 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kWebKitSmartPasteFormat)); | |
357 return type; | |
358 } | |
359 | |
360 // static | |
361 const Clipboard::FormatType& Clipboard::GetHtmlFormatType() { | |
362 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kHTMLFormat)); | |
363 return type; | |
364 } | |
365 | |
366 // static | |
367 const Clipboard::FormatType& Clipboard::GetRtfFormatType() { | |
368 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kRTFFormat)); | |
369 return type; | |
370 } | |
371 | |
372 // static | |
373 const Clipboard::FormatType& Clipboard::GetBitmapFormatType() { | |
374 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kBitmapFormat)); | |
375 return type; | |
376 } | |
377 | |
378 // static | |
379 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { | |
380 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); | |
381 return type; | |
382 } | |
383 | |
384 // static | |
385 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | |
386 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); | |
387 return type; | |
388 } | 391 } |
389 | 392 |
390 void Clipboard::WriteText(const char* text_data, size_t text_len) { | 393 void Clipboard::WriteText(const char* text_data, size_t text_len) { |
391 g_map.Get().Set(kPlainTextFormat, std::string(text_data, text_len)); | 394 g_map.Get().Set(kPlainTextFormat, std::string(text_data, text_len)); |
392 } | 395 } |
393 | 396 |
394 void Clipboard::WriteHTML(const char* markup_data, | 397 void Clipboard::WriteHTML(const char* markup_data, |
395 size_t markup_len, | 398 size_t markup_len, |
396 const char* url_data, | 399 const char* url_data, |
397 size_t url_len) { | 400 size_t url_len) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 const char* data_data, size_t data_len) { | 436 const char* data_data, size_t data_len) { |
434 g_map.Get().Set(format.data(), std::string(data_data, data_len)); | 437 g_map.Get().Set(format.data(), std::string(data_data, data_len)); |
435 } | 438 } |
436 | 439 |
437 // See clipboard_android_initialization.h for more information. | 440 // See clipboard_android_initialization.h for more information. |
438 bool RegisterClipboardAndroid(JNIEnv* env) { | 441 bool RegisterClipboardAndroid(JNIEnv* env) { |
439 return RegisterNativesImpl(env); | 442 return RegisterNativesImpl(env); |
440 } | 443 } |
441 | 444 |
442 } // namespace ui | 445 } // namespace ui |
OLD | NEW |