Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: ui/base/clipboard/clipboard_android.cc

Issue 12041078: Clear the clipboard closing Incognito window (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed includes + style changes Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 22 matching lines...) Expand all
33 namespace { 33 namespace {
34 // Various formats we support. 34 // Various formats we support.
35 const char kPlainTextFormat[] = "text"; 35 const char kPlainTextFormat[] = "text";
36 const char kHTMLFormat[] = "html"; 36 const char kHTMLFormat[] = "html";
37 const char kRTFFormat[] = "rtf"; 37 const char kRTFFormat[] = "rtf";
38 const char kBitmapFormat[] = "bitmap"; 38 const char kBitmapFormat[] = "bitmap";
39 const char kWebKitSmartPasteFormat[] = "webkit_smart"; 39 const char kWebKitSmartPasteFormat[] = "webkit_smart";
40 const char kBookmarkFormat[] = "bookmark"; 40 const char kBookmarkFormat[] = "bookmark";
41 const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data"; 41 const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data";
42 const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data"; 42 const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data";
43 const char kSourceTagFormat[] = "source_tag";
43 44
44 class ClipboardMap { 45 class ClipboardMap {
45 public: 46 public:
46 ClipboardMap(); 47 ClipboardMap();
47 std::string Get(const std::string& format); 48 std::string Get(const std::string& format);
48 bool HasFormat(const std::string& format); 49 bool HasFormat(const std::string& format);
49 void Set(const std::string& format, const std::string& data); 50 void Set(const std::string& format, const std::string& data);
50 void Clear(); 51 void Clear();
51 52
52 private: 53 private:
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 return data_ == other.data_; 192 return data_ == other.data_;
192 } 193 }
193 194
194 Clipboard::Clipboard() { 195 Clipboard::Clipboard() {
195 } 196 }
196 197
197 Clipboard::~Clipboard() { 198 Clipboard::~Clipboard() {
198 } 199 }
199 200
200 // Main entry point used to write several values in the clipboard. 201 // Main entry point used to write several values in the clipboard.
201 void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) { 202 void Clipboard::WriteObjectsImpl(Buffer buffer,
203 const ObjectMap& objects,
204 SourceTag tag) {
202 DCHECK_EQ(buffer, BUFFER_STANDARD); 205 DCHECK_EQ(buffer, BUFFER_STANDARD);
203 g_map.Get().Clear(); 206 g_map.Get().Clear();
204 for (ObjectMap::const_iterator iter = objects.begin(); 207 for (ObjectMap::const_iterator iter = objects.begin();
205 iter != objects.end(); ++iter) { 208 iter != objects.end(); ++iter) {
206 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); 209 DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
207 } 210 }
211 WriteSourceTag(tag);
208 } 212 }
209 213
210 uint64 Clipboard::GetSequenceNumber(Clipboard::Buffer /* buffer */) { 214 uint64 Clipboard::GetSequenceNumber(Clipboard::Buffer /* buffer */) {
211 // TODO: implement this. For now this interface will advertise 215 // TODO: implement this. For now this interface will advertise
212 // that the clipboard never changes. That's fine as long as we 216 // that the clipboard never changes. That's fine as long as we
213 // don't rely on this signal. 217 // don't rely on this signal.
214 return 0; 218 return 0;
215 } 219 }
216 220
217 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, 221 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 307
304 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 308 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
305 NOTIMPLEMENTED(); 309 NOTIMPLEMENTED();
306 } 310 }
307 311
308 void Clipboard::ReadData(const Clipboard::FormatType& format, 312 void Clipboard::ReadData(const Clipboard::FormatType& format,
309 std::string* result) const { 313 std::string* result) const {
310 *result = g_map.Get().Get(format.data()); 314 *result = g_map.Get().Get(format.data());
311 } 315 }
312 316
317 Clipboard::SourceTag Clipboard::ReadSourceTag() const {
318 std::string result;
319 ReadData(GetSourceTagFormatType(), &result);
320 return Binary2SourceTag(result);
321 }
322
313 // static 323 // static
314 Clipboard::FormatType Clipboard::GetFormatType( 324 Clipboard::FormatType Clipboard::GetFormatType(
315 const std::string& format_string) { 325 const std::string& format_string) {
316 return FormatType::Deserialize(format_string); 326 return FormatType::Deserialize(format_string);
317 } 327 }
318 328
319 // static 329 // static
320 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { 330 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() {
321 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat)); 331 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPlainTextFormat));
322 return type; 332 return type;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); 367 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData));
358 return type; 368 return type;
359 } 369 }
360 370
361 // static 371 // static
362 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { 372 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() {
363 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); 373 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData));
364 return type; 374 return type;
365 } 375 }
366 376
377 // static
378 const Clipboard::FormatType& Clipboard::GetSourceTagFormatType() {
379 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kSourceTagFormat));
380 return type;
381 }
382
367 void Clipboard::WriteText(const char* text_data, size_t text_len) { 383 void Clipboard::WriteText(const char* text_data, size_t text_len) {
368 g_map.Get().Set(kPlainTextFormat, std::string(text_data, text_len)); 384 g_map.Get().Set(kPlainTextFormat, std::string(text_data, text_len));
369 } 385 }
370 386
371 void Clipboard::WriteHTML(const char* markup_data, 387 void Clipboard::WriteHTML(const char* markup_data,
372 size_t markup_len, 388 size_t markup_len,
373 const char* url_data, 389 const char* url_data,
374 size_t url_len) { 390 size_t url_len) {
375 g_map.Get().Set(kHTMLFormat, std::string(markup_data, markup_len)); 391 g_map.Get().Set(kHTMLFormat, std::string(markup_data, markup_len));
376 } 392 }
(...skipping 26 matching lines...) Expand all
403 std::string packed(size_data, sizeof(gfx::Size)); 419 std::string packed(size_data, sizeof(gfx::Size));
404 packed += std::string(pixel_data, bm_size); 420 packed += std::string(pixel_data, bm_size);
405 g_map.Get().Set(kBitmapFormat, packed); 421 g_map.Get().Set(kBitmapFormat, packed);
406 } 422 }
407 423
408 void Clipboard::WriteData(const Clipboard::FormatType& format, 424 void Clipboard::WriteData(const Clipboard::FormatType& format,
409 const char* data_data, size_t data_len) { 425 const char* data_data, size_t data_len) {
410 g_map.Get().Set(format.data(), std::string(data_data, data_len)); 426 g_map.Get().Set(format.data(), std::string(data_data, data_len));
411 } 427 }
412 428
429 void Clipboard::WriteSourceTag(SourceTag tag) {
430 if (tag != SourceTag()) {
431 ObjectMapParam binary = SourceTag2Binary(tag);
432 WriteData(GetSourceTagFormatType(), &binary[0], binary.size());
433 }
434 }
435
413 } // namespace ui 436 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698