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

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

Issue 658963003: Change Clipboard to use virtual methods for testing purposes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 6 years, 2 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
« no previous file with comments | « ui/base/clipboard/clipboard_aurax11.h ('k') | ui/base/clipboard/clipboard_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_aurax11.h"
6 6
7 #include <X11/extensions/Xfixes.h> 7 #include <X11/extensions/Xfixes.h>
8 #include <X11/Xatom.h> 8 #include <X11/Xatom.h>
9 #include <list> 9 #include <list>
10 #include <set> 10 #include <set>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ref_counted_memory.h" 15 #include "base/memory/ref_counted_memory.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 bool Clipboard::FormatType::operator<(const FormatType& other) const { 216 bool Clipboard::FormatType::operator<(const FormatType& other) const {
217 return data_ < other.data_; 217 return data_ < other.data_;
218 } 218 }
219 219
220 bool Clipboard::FormatType::Equals(const FormatType& other) const { 220 bool Clipboard::FormatType::Equals(const FormatType& other) const {
221 return data_ == other.data_; 221 return data_ == other.data_;
222 } 222 }
223 223
224 /////////////////////////////////////////////////////////////////////////////// 224 ///////////////////////////////////////////////////////////////////////////////
225 // Clipboard::AuraX11Details 225 // ClipboardAuraX11::AuraX11Details
226 226
227 // Private implementation of our X11 integration. Keeps X11 headers out of the 227 // Private implementation of our X11 integration. Keeps X11 headers out of the
228 // majority of chrome, which break badly. 228 // majority of chrome, which break badly.
229 class Clipboard::AuraX11Details : public PlatformEventDispatcher { 229 class ClipboardAuraX11::AuraX11Details : public PlatformEventDispatcher {
230 public: 230 public:
231 AuraX11Details(); 231 AuraX11Details();
232 virtual ~AuraX11Details(); 232 virtual ~AuraX11Details();
233 233
234 X11AtomCache* atom_cache() { return &atom_cache_; } 234 X11AtomCache* atom_cache() { return &atom_cache_; }
235 235
236 // Returns the X11 type that we pass to various XSelection functions for the 236 // Returns the X11 type that we pass to various XSelection functions for the
237 // given type. 237 // given type.
238 ::Atom LookupSelectionForClipboardType(ClipboardType type) const; 238 ::Atom LookupSelectionForClipboardType(ClipboardType type) const;
239 239
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // Temporary target map that we write to during DispatchObects. 308 // Temporary target map that we write to during DispatchObects.
309 SelectionFormatMap clipboard_data_; 309 SelectionFormatMap clipboard_data_;
310 310
311 // Objects which offer selection data to other windows. 311 // Objects which offer selection data to other windows.
312 SelectionOwner clipboard_owner_; 312 SelectionOwner clipboard_owner_;
313 SelectionOwner primary_owner_; 313 SelectionOwner primary_owner_;
314 314
315 DISALLOW_COPY_AND_ASSIGN(AuraX11Details); 315 DISALLOW_COPY_AND_ASSIGN(AuraX11Details);
316 }; 316 };
317 317
318 Clipboard::AuraX11Details::AuraX11Details() 318 ClipboardAuraX11::AuraX11Details::AuraX11Details()
319 : x_display_(gfx::GetXDisplay()), 319 : x_display_(gfx::GetXDisplay()),
320 x_root_window_(DefaultRootWindow(x_display_)), 320 x_root_window_(DefaultRootWindow(x_display_)),
321 x_window_(XCreateWindow( 321 x_window_(XCreateWindow(x_display_,
322 x_display_, x_root_window_, 322 x_root_window_,
323 -100, -100, 10, 10, // x, y, width, height 323 -100,
324 0, // border width 324 -100,
325 CopyFromParent, // depth 325 10,
326 InputOnly, 326 10, // x, y, width, height
327 CopyFromParent, // visual 327 0, // border width
328 0, 328 CopyFromParent, // depth
329 NULL)), 329 InputOnly,
330 CopyFromParent, // visual
331 0,
332 NULL)),
330 atom_cache_(x_display_, kAtomsToCache), 333 atom_cache_(x_display_, kAtomsToCache),
331 selection_requestor_(x_display_, x_window_, this), 334 selection_requestor_(x_display_, x_window_, this),
332 clipboard_owner_(x_display_, x_window_, atom_cache_.GetAtom(kClipboard)), 335 clipboard_owner_(x_display_, x_window_, atom_cache_.GetAtom(kClipboard)),
333 primary_owner_(x_display_, x_window_, XA_PRIMARY) { 336 primary_owner_(x_display_, x_window_, XA_PRIMARY) {
334 // We don't know all possible MIME types at compile time. 337 // We don't know all possible MIME types at compile time.
335 atom_cache_.allow_uncached_atoms(); 338 atom_cache_.allow_uncached_atoms();
336 339
337 XStoreName(x_display_, x_window_, "Chromium clipboard"); 340 XStoreName(x_display_, x_window_, "Chromium clipboard");
338 XSelectInput(x_display_, x_window_, PropertyChangeMask); 341 XSelectInput(x_display_, x_window_, PropertyChangeMask);
339 342
340 if (PlatformEventSource::GetInstance()) 343 if (PlatformEventSource::GetInstance())
341 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); 344 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
342 } 345 }
343 346
344 Clipboard::AuraX11Details::~AuraX11Details() { 347 ClipboardAuraX11::AuraX11Details::~AuraX11Details() {
345 if (PlatformEventSource::GetInstance()) 348 if (PlatformEventSource::GetInstance())
346 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); 349 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
347 350
348 XDestroyWindow(x_display_, x_window_); 351 XDestroyWindow(x_display_, x_window_);
349 } 352 }
350 353
351 ::Atom Clipboard::AuraX11Details::LookupSelectionForClipboardType( 354 ::Atom ClipboardAuraX11::AuraX11Details::LookupSelectionForClipboardType(
352 ClipboardType type) const { 355 ClipboardType type) const {
353 if (type == CLIPBOARD_TYPE_COPY_PASTE) 356 if (type == CLIPBOARD_TYPE_COPY_PASTE)
354 return GetCopyPasteSelection(); 357 return GetCopyPasteSelection();
355 358
356 return XA_PRIMARY; 359 return XA_PRIMARY;
357 } 360 }
358 361
359 ::Atom Clipboard::AuraX11Details::GetCopyPasteSelection() const { 362 ::Atom ClipboardAuraX11::AuraX11Details::GetCopyPasteSelection() const {
360 return atom_cache_.GetAtom(kClipboard); 363 return atom_cache_.GetAtom(kClipboard);
361 } 364 }
362 365
363 const SelectionFormatMap& Clipboard::AuraX11Details::LookupStorageForAtom( 366 const SelectionFormatMap&
364 ::Atom atom) { 367 ClipboardAuraX11::AuraX11Details::LookupStorageForAtom(::Atom atom) {
365 if (atom == XA_PRIMARY) 368 if (atom == XA_PRIMARY)
366 return primary_owner_.selection_format_map(); 369 return primary_owner_.selection_format_map();
367 370
368 DCHECK_EQ(GetCopyPasteSelection(), atom); 371 DCHECK_EQ(GetCopyPasteSelection(), atom);
369 return clipboard_owner_.selection_format_map(); 372 return clipboard_owner_.selection_format_map();
370 } 373 }
371 374
372 void Clipboard::AuraX11Details::CreateNewClipboardData() { 375 void ClipboardAuraX11::AuraX11Details::CreateNewClipboardData() {
373 clipboard_data_ = SelectionFormatMap(); 376 clipboard_data_ = SelectionFormatMap();
374 } 377 }
375 378
376 void Clipboard::AuraX11Details::InsertMapping( 379 void ClipboardAuraX11::AuraX11Details::InsertMapping(
377 const std::string& key, 380 const std::string& key,
378 const scoped_refptr<base::RefCountedMemory>& memory) { 381 const scoped_refptr<base::RefCountedMemory>& memory) {
379 ::Atom atom_key = atom_cache_.GetAtom(key.c_str()); 382 ::Atom atom_key = atom_cache_.GetAtom(key.c_str());
380 clipboard_data_.Insert(atom_key, memory); 383 clipboard_data_.Insert(atom_key, memory);
381 } 384 }
382 385
383 void Clipboard::AuraX11Details::TakeOwnershipOfSelection(ClipboardType type) { 386 void ClipboardAuraX11::AuraX11Details::TakeOwnershipOfSelection(
387 ClipboardType type) {
384 if (type == CLIPBOARD_TYPE_COPY_PASTE) 388 if (type == CLIPBOARD_TYPE_COPY_PASTE)
385 return clipboard_owner_.TakeOwnershipOfSelection(clipboard_data_); 389 return clipboard_owner_.TakeOwnershipOfSelection(clipboard_data_);
386 else 390 else
387 return primary_owner_.TakeOwnershipOfSelection(clipboard_data_); 391 return primary_owner_.TakeOwnershipOfSelection(clipboard_data_);
388 } 392 }
389 393
390 SelectionData Clipboard::AuraX11Details::RequestAndWaitForTypes( 394 SelectionData ClipboardAuraX11::AuraX11Details::RequestAndWaitForTypes(
391 ClipboardType type, 395 ClipboardType type,
392 const std::vector< ::Atom>& types) { 396 const std::vector<::Atom>& types) {
393 ::Atom selection_name = LookupSelectionForClipboardType(type); 397 ::Atom selection_name = LookupSelectionForClipboardType(type);
394 if (XGetSelectionOwner(x_display_, selection_name) == x_window_) { 398 if (XGetSelectionOwner(x_display_, selection_name) == x_window_) {
395 // We can local fastpath instead of playing the nested message loop game 399 // We can local fastpath instead of playing the nested message loop game
396 // with the X server. 400 // with the X server.
397 const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name); 401 const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name);
398 402
399 for (std::vector< ::Atom>::const_iterator it = types.begin(); 403 for (std::vector< ::Atom>::const_iterator it = types.begin();
400 it != types.end(); ++it) { 404 it != types.end(); ++it) {
401 SelectionFormatMap::const_iterator format_map_it = format_map.find(*it); 405 SelectionFormatMap::const_iterator format_map_it = format_map.find(*it);
402 if (format_map_it != format_map.end()) 406 if (format_map_it != format_map.end())
403 return SelectionData(format_map_it->first, format_map_it->second); 407 return SelectionData(format_map_it->first, format_map_it->second);
404 } 408 }
405 } else { 409 } else {
406 TargetList targets = WaitAndGetTargetsList(type); 410 TargetList targets = WaitAndGetTargetsList(type);
407 411
408 ::Atom selection_name = LookupSelectionForClipboardType(type); 412 ::Atom selection_name = LookupSelectionForClipboardType(type);
409 std::vector< ::Atom> intersection; 413 std::vector< ::Atom> intersection;
410 ui::GetAtomIntersection(types, targets.target_list(), &intersection); 414 ui::GetAtomIntersection(types, targets.target_list(), &intersection);
411 return selection_requestor_.RequestAndWaitForTypes(selection_name, 415 return selection_requestor_.RequestAndWaitForTypes(selection_name,
412 intersection); 416 intersection);
413 } 417 }
414 418
415 return SelectionData(); 419 return SelectionData();
416 } 420 }
417 421
418 TargetList Clipboard::AuraX11Details::WaitAndGetTargetsList( 422 TargetList ClipboardAuraX11::AuraX11Details::WaitAndGetTargetsList(
419 ClipboardType type) { 423 ClipboardType type) {
420 ::Atom selection_name = LookupSelectionForClipboardType(type); 424 ::Atom selection_name = LookupSelectionForClipboardType(type);
421 std::vector< ::Atom> out; 425 std::vector< ::Atom> out;
422 if (XGetSelectionOwner(x_display_, selection_name) == x_window_) { 426 if (XGetSelectionOwner(x_display_, selection_name) == x_window_) {
423 // We can local fastpath and return the list of local targets. 427 // We can local fastpath and return the list of local targets.
424 const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name); 428 const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name);
425 429
426 for (SelectionFormatMap::const_iterator it = format_map.begin(); 430 for (SelectionFormatMap::const_iterator it = format_map.begin();
427 it != format_map.end(); ++it) { 431 it != format_map.end(); ++it) {
428 out.push_back(it->first); 432 out.push_back(it->first);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 type == *it) { 468 type == *it) {
465 out.push_back(*it); 469 out.push_back(*it);
466 } 470 }
467 } 471 }
468 } 472 }
469 } 473 }
470 474
471 return TargetList(out, &atom_cache_); 475 return TargetList(out, &atom_cache_);
472 } 476 }
473 477
474 std::vector< ::Atom> Clipboard::AuraX11Details::GetTextAtoms() const { 478 std::vector<::Atom> ClipboardAuraX11::AuraX11Details::GetTextAtoms() const {
475 return GetTextAtomsFrom(&atom_cache_); 479 return GetTextAtomsFrom(&atom_cache_);
476 } 480 }
477 481
478 std::vector< ::Atom> Clipboard::AuraX11Details::GetAtomsForFormat( 482 std::vector<::Atom> ClipboardAuraX11::AuraX11Details::GetAtomsForFormat(
479 const Clipboard::FormatType& format) { 483 const Clipboard::FormatType& format) {
480 std::vector< ::Atom> atoms; 484 std::vector< ::Atom> atoms;
481 atoms.push_back(atom_cache_.GetAtom(format.ToString().c_str())); 485 atoms.push_back(atom_cache_.GetAtom(format.ToString().c_str()));
482 return atoms; 486 return atoms;
483 } 487 }
484 488
485 void Clipboard::AuraX11Details::Clear(ClipboardType type) { 489 void ClipboardAuraX11::AuraX11Details::Clear(ClipboardType type) {
486 if (type == CLIPBOARD_TYPE_COPY_PASTE) 490 if (type == CLIPBOARD_TYPE_COPY_PASTE)
487 clipboard_owner_.ClearSelectionOwner(); 491 clipboard_owner_.ClearSelectionOwner();
488 else 492 else
489 primary_owner_.ClearSelectionOwner(); 493 primary_owner_.ClearSelectionOwner();
490 } 494 }
491 495
492 void Clipboard::AuraX11Details::StoreCopyPasteDataAndWait() { 496 void ClipboardAuraX11::AuraX11Details::StoreCopyPasteDataAndWait() {
493 ::Atom selection = GetCopyPasteSelection(); 497 ::Atom selection = GetCopyPasteSelection();
494 if (XGetSelectionOwner(x_display_, selection) != x_window_) 498 if (XGetSelectionOwner(x_display_, selection) != x_window_)
495 return; 499 return;
496 500
497 ::Atom clipboard_manager_atom = atom_cache_.GetAtom(kClipboardManager); 501 ::Atom clipboard_manager_atom = atom_cache_.GetAtom(kClipboardManager);
498 if (XGetSelectionOwner(x_display_, clipboard_manager_atom) == None) 502 if (XGetSelectionOwner(x_display_, clipboard_manager_atom) == None)
499 return; 503 return;
500 504
501 const SelectionFormatMap& format_map = LookupStorageForAtom(selection); 505 const SelectionFormatMap& format_map = LookupStorageForAtom(selection);
502 if (format_map.size() == 0) 506 if (format_map.size() == 0)
503 return; 507 return;
504 std::vector<Atom> targets = format_map.GetTypes(); 508 std::vector<Atom> targets = format_map.GetTypes();
505 509
506 base::TimeTicks start = base::TimeTicks::Now(); 510 base::TimeTicks start = base::TimeTicks::Now();
507 selection_requestor_.PerformBlockingConvertSelectionWithParameter( 511 selection_requestor_.PerformBlockingConvertSelectionWithParameter(
508 atom_cache_.GetAtom(kClipboardManager), 512 atom_cache_.GetAtom(kClipboardManager),
509 atom_cache_.GetAtom(kSaveTargets), 513 atom_cache_.GetAtom(kSaveTargets),
510 targets); 514 targets);
511 UMA_HISTOGRAM_TIMES("Clipboard.X11StoreCopyPasteDuration", 515 UMA_HISTOGRAM_TIMES("Clipboard.X11StoreCopyPasteDuration",
512 base::TimeTicks::Now() - start); 516 base::TimeTicks::Now() - start);
513 } 517 }
514 518
515 bool Clipboard::AuraX11Details::CanDispatchEvent(const PlatformEvent& event) { 519 bool ClipboardAuraX11::AuraX11Details::CanDispatchEvent(
520 const PlatformEvent& event) {
516 if (event->xany.window == x_window_) 521 if (event->xany.window == x_window_)
517 return true; 522 return true;
518 523
519 if (event->type == PropertyNotify) { 524 if (event->type == PropertyNotify) {
520 return primary_owner_.CanDispatchPropertyEvent(*event) || 525 return primary_owner_.CanDispatchPropertyEvent(*event) ||
521 clipboard_owner_.CanDispatchPropertyEvent(*event) || 526 clipboard_owner_.CanDispatchPropertyEvent(*event) ||
522 selection_requestor_.CanDispatchPropertyEvent(*event); 527 selection_requestor_.CanDispatchPropertyEvent(*event);
523 } 528 }
524 return false; 529 return false;
525 } 530 }
526 531
527 uint32_t Clipboard::AuraX11Details::DispatchEvent(const PlatformEvent& xev) { 532 uint32_t ClipboardAuraX11::AuraX11Details::DispatchEvent(
533 const PlatformEvent& xev) {
528 switch (xev->type) { 534 switch (xev->type) {
529 case SelectionRequest: { 535 case SelectionRequest: {
530 if (xev->xselectionrequest.selection == XA_PRIMARY) { 536 if (xev->xselectionrequest.selection == XA_PRIMARY) {
531 primary_owner_.OnSelectionRequest(*xev); 537 primary_owner_.OnSelectionRequest(*xev);
532 } else { 538 } else {
533 // We should not get requests for the CLIPBOARD_MANAGER selection 539 // We should not get requests for the CLIPBOARD_MANAGER selection
534 // because we never take ownership of it. 540 // because we never take ownership of it.
535 DCHECK_EQ(GetCopyPasteSelection(), xev->xselectionrequest.selection); 541 DCHECK_EQ(GetCopyPasteSelection(), xev->xselectionrequest.selection);
536 clipboard_owner_.OnSelectionRequest(*xev); 542 clipboard_owner_.OnSelectionRequest(*xev);
537 } 543 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 return type; 645 return type;
640 } 646 }
641 647
642 // static 648 // static
643 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { 649 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() {
644 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); 650 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData));
645 return type; 651 return type;
646 } 652 }
647 653
648 /////////////////////////////////////////////////////////////////////////////// 654 ///////////////////////////////////////////////////////////////////////////////
649 // Clipboard 655 // Clipboard factory method.
656 Clipboard* Clipboard::Create() {
657 return new ClipboardAuraX11;
658 }
650 659
651 Clipboard::Clipboard() 660 ///////////////////////////////////////////////////////////////////////////////
652 : aurax11_details_(new AuraX11Details) { 661 // ClipboardAuraX11
662
663 ClipboardAuraX11::ClipboardAuraX11() : aurax11_details_(new AuraX11Details) {
653 DCHECK(CalledOnValidThread()); 664 DCHECK(CalledOnValidThread());
654 } 665 }
655 666
656 Clipboard::~Clipboard() { 667 ClipboardAuraX11::~ClipboardAuraX11() {
657 DCHECK(CalledOnValidThread()); 668 DCHECK(CalledOnValidThread());
658 669
659 aurax11_details_->StoreCopyPasteDataAndWait(); 670 aurax11_details_->StoreCopyPasteDataAndWait();
660 } 671 }
661 672
662 uint64 Clipboard::GetSequenceNumber(ClipboardType type) { 673 uint64 ClipboardAuraX11::GetSequenceNumber(ClipboardType type) {
663 DCHECK(CalledOnValidThread()); 674 DCHECK(CalledOnValidThread());
664 if (type == CLIPBOARD_TYPE_COPY_PASTE) 675 if (type == CLIPBOARD_TYPE_COPY_PASTE)
665 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number(); 676 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number();
666 else 677 else
667 return SelectionChangeObserver::GetInstance()->primary_sequence_number(); 678 return SelectionChangeObserver::GetInstance()->primary_sequence_number();
668 } 679 }
669 680
670 bool Clipboard::IsFormatAvailable(const FormatType& format, 681 bool ClipboardAuraX11::IsFormatAvailable(const FormatType& format,
671 ClipboardType type) const { 682 ClipboardType type) const {
672 DCHECK(CalledOnValidThread()); 683 DCHECK(CalledOnValidThread());
673 DCHECK(IsSupportedClipboardType(type)); 684 DCHECK(IsSupportedClipboardType(type));
674 685
675 TargetList target_list = aurax11_details_->WaitAndGetTargetsList(type); 686 TargetList target_list = aurax11_details_->WaitAndGetTargetsList(type);
676 if (format.Equals(GetPlainTextFormatType()) || 687 if (format.Equals(GetPlainTextFormatType()) ||
677 format.Equals(GetUrlFormatType())) { 688 format.Equals(GetUrlFormatType())) {
678 return target_list.ContainsText(); 689 return target_list.ContainsText();
679 } 690 }
680 return target_list.ContainsFormat(format); 691 return target_list.ContainsFormat(format);
681 } 692 }
682 693
683 void Clipboard::Clear(ClipboardType type) { 694 void ClipboardAuraX11::Clear(ClipboardType type) {
684 DCHECK(CalledOnValidThread()); 695 DCHECK(CalledOnValidThread());
685 DCHECK(IsSupportedClipboardType(type)); 696 DCHECK(IsSupportedClipboardType(type));
686 aurax11_details_->Clear(type); 697 aurax11_details_->Clear(type);
687 } 698 }
688 699
689 void Clipboard::ReadAvailableTypes(ClipboardType type, 700 void ClipboardAuraX11::ReadAvailableTypes(ClipboardType type,
690 std::vector<base::string16>* types, 701 std::vector<base::string16>* types,
691 bool* contains_filenames) const { 702 bool* contains_filenames) const {
692 DCHECK(CalledOnValidThread()); 703 DCHECK(CalledOnValidThread());
693 if (!types || !contains_filenames) { 704 if (!types || !contains_filenames) {
694 NOTREACHED(); 705 NOTREACHED();
695 return; 706 return;
696 } 707 }
697 708
698 TargetList target_list = aurax11_details_->WaitAndGetTargetsList(type); 709 TargetList target_list = aurax11_details_->WaitAndGetTargetsList(type);
699 710
700 types->clear(); 711 types->clear();
701 712
702 if (target_list.ContainsText()) 713 if (target_list.ContainsText())
703 types->push_back(base::UTF8ToUTF16(kMimeTypeText)); 714 types->push_back(base::UTF8ToUTF16(kMimeTypeText));
704 if (target_list.ContainsFormat(GetHtmlFormatType())) 715 if (target_list.ContainsFormat(GetHtmlFormatType()))
705 types->push_back(base::UTF8ToUTF16(kMimeTypeHTML)); 716 types->push_back(base::UTF8ToUTF16(kMimeTypeHTML));
706 if (target_list.ContainsFormat(GetRtfFormatType())) 717 if (target_list.ContainsFormat(GetRtfFormatType()))
707 types->push_back(base::UTF8ToUTF16(kMimeTypeRTF)); 718 types->push_back(base::UTF8ToUTF16(kMimeTypeRTF));
708 if (target_list.ContainsFormat(GetBitmapFormatType())) 719 if (target_list.ContainsFormat(GetBitmapFormatType()))
709 types->push_back(base::UTF8ToUTF16(kMimeTypePNG)); 720 types->push_back(base::UTF8ToUTF16(kMimeTypePNG));
710 *contains_filenames = false; 721 *contains_filenames = false;
711 722
712 SelectionData data(aurax11_details_->RequestAndWaitForTypes( 723 SelectionData data(aurax11_details_->RequestAndWaitForTypes(
713 type, aurax11_details_->GetAtomsForFormat(GetWebCustomDataFormatType()))); 724 type, aurax11_details_->GetAtomsForFormat(GetWebCustomDataFormatType())));
714 if (data.IsValid()) 725 if (data.IsValid())
715 ReadCustomDataTypes(data.GetData(), data.GetSize(), types); 726 ReadCustomDataTypes(data.GetData(), data.GetSize(), types);
716 } 727 }
717 728
718 void Clipboard::ReadText(ClipboardType type, base::string16* result) const { 729 void ClipboardAuraX11::ReadText(ClipboardType type,
730 base::string16* result) const {
719 DCHECK(CalledOnValidThread()); 731 DCHECK(CalledOnValidThread());
720 732
721 SelectionData data(aurax11_details_->RequestAndWaitForTypes( 733 SelectionData data(aurax11_details_->RequestAndWaitForTypes(
722 type, aurax11_details_->GetTextAtoms())); 734 type, aurax11_details_->GetTextAtoms()));
723 if (data.IsValid()) { 735 if (data.IsValid()) {
724 std::string text = data.GetText(); 736 std::string text = data.GetText();
725 *result = base::UTF8ToUTF16(text); 737 *result = base::UTF8ToUTF16(text);
726 } 738 }
727 } 739 }
728 740
729 void Clipboard::ReadAsciiText(ClipboardType type, std::string* result) const { 741 void ClipboardAuraX11::ReadAsciiText(ClipboardType type,
742 std::string* result) const {
730 DCHECK(CalledOnValidThread()); 743 DCHECK(CalledOnValidThread());
731 744
732 SelectionData data(aurax11_details_->RequestAndWaitForTypes( 745 SelectionData data(aurax11_details_->RequestAndWaitForTypes(
733 type, aurax11_details_->GetTextAtoms())); 746 type, aurax11_details_->GetTextAtoms()));
734 if (data.IsValid()) 747 if (data.IsValid())
735 result->assign(data.GetText()); 748 result->assign(data.GetText());
736 } 749 }
737 750
738 // TODO(estade): handle different charsets. 751 // TODO(estade): handle different charsets.
739 // TODO(port): set *src_url. 752 // TODO(port): set *src_url.
740 void Clipboard::ReadHTML(ClipboardType type, 753 void ClipboardAuraX11::ReadHTML(ClipboardType type,
741 base::string16* markup, 754 base::string16* markup,
742 std::string* src_url, 755 std::string* src_url,
743 uint32* fragment_start, 756 uint32* fragment_start,
744 uint32* fragment_end) const { 757 uint32* fragment_end) const {
745 DCHECK(CalledOnValidThread()); 758 DCHECK(CalledOnValidThread());
746 markup->clear(); 759 markup->clear();
747 if (src_url) 760 if (src_url)
748 src_url->clear(); 761 src_url->clear();
749 *fragment_start = 0; 762 *fragment_start = 0;
750 *fragment_end = 0; 763 *fragment_end = 0;
751 764
752 SelectionData data(aurax11_details_->RequestAndWaitForTypes( 765 SelectionData data(aurax11_details_->RequestAndWaitForTypes(
753 type, aurax11_details_->GetAtomsForFormat(GetHtmlFormatType()))); 766 type, aurax11_details_->GetAtomsForFormat(GetHtmlFormatType())));
754 if (data.IsValid()) { 767 if (data.IsValid()) {
755 *markup = data.GetHtml(); 768 *markup = data.GetHtml();
756 769
757 *fragment_start = 0; 770 *fragment_start = 0;
758 DCHECK(markup->length() <= kuint32max); 771 DCHECK(markup->length() <= kuint32max);
759 *fragment_end = static_cast<uint32>(markup->length()); 772 *fragment_end = static_cast<uint32>(markup->length());
760 } 773 }
761 } 774 }
762 775
763 void Clipboard::ReadRTF(ClipboardType type, std::string* result) const { 776 void ClipboardAuraX11::ReadRTF(ClipboardType type, std::string* result) const {
764 DCHECK(CalledOnValidThread()); 777 DCHECK(CalledOnValidThread());
765 778
766 SelectionData data(aurax11_details_->RequestAndWaitForTypes( 779 SelectionData data(aurax11_details_->RequestAndWaitForTypes(
767 type, aurax11_details_->GetAtomsForFormat(GetRtfFormatType()))); 780 type, aurax11_details_->GetAtomsForFormat(GetRtfFormatType())));
768 if (data.IsValid()) 781 if (data.IsValid())
769 data.AssignTo(result); 782 data.AssignTo(result);
770 } 783 }
771 784
772 SkBitmap Clipboard::ReadImage(ClipboardType type) const { 785 SkBitmap ClipboardAuraX11::ReadImage(ClipboardType type) const {
773 DCHECK(CalledOnValidThread()); 786 DCHECK(CalledOnValidThread());
774 787
775 SelectionData data(aurax11_details_->RequestAndWaitForTypes( 788 SelectionData data(aurax11_details_->RequestAndWaitForTypes(
776 type, aurax11_details_->GetAtomsForFormat(GetBitmapFormatType()))); 789 type, aurax11_details_->GetAtomsForFormat(GetBitmapFormatType())));
777 if (data.IsValid()) { 790 if (data.IsValid()) {
778 SkBitmap bitmap; 791 SkBitmap bitmap;
779 if (gfx::PNGCodec::Decode(data.GetData(), data.GetSize(), &bitmap)) 792 if (gfx::PNGCodec::Decode(data.GetData(), data.GetSize(), &bitmap))
780 return SkBitmap(bitmap); 793 return SkBitmap(bitmap);
781 } 794 }
782 795
783 return SkBitmap(); 796 return SkBitmap();
784 } 797 }
785 798
786 void Clipboard::ReadCustomData(ClipboardType clipboard_type, 799 void ClipboardAuraX11::ReadCustomData(ClipboardType clipboard_type,
787 const base::string16& type, 800 const base::string16& type,
788 base::string16* result) const { 801 base::string16* result) const {
789 DCHECK(CalledOnValidThread()); 802 DCHECK(CalledOnValidThread());
790 803
791 SelectionData data(aurax11_details_->RequestAndWaitForTypes( 804 SelectionData data(aurax11_details_->RequestAndWaitForTypes(
792 clipboard_type, 805 clipboard_type,
793 aurax11_details_->GetAtomsForFormat(GetWebCustomDataFormatType()))); 806 aurax11_details_->GetAtomsForFormat(GetWebCustomDataFormatType())));
794 if (data.IsValid()) 807 if (data.IsValid())
795 ReadCustomDataForType(data.GetData(), data.GetSize(), type, result); 808 ReadCustomDataForType(data.GetData(), data.GetSize(), type, result);
796 } 809 }
797 810
798 void Clipboard::ReadBookmark(base::string16* title, std::string* url) const { 811 void ClipboardAuraX11::ReadBookmark(base::string16* title,
812 std::string* url) const {
799 DCHECK(CalledOnValidThread()); 813 DCHECK(CalledOnValidThread());
800 // TODO(erg): This was left NOTIMPLEMENTED() in the gtk port too. 814 // TODO(erg): This was left NOTIMPLEMENTED() in the gtk port too.
801 NOTIMPLEMENTED(); 815 NOTIMPLEMENTED();
802 } 816 }
803 817
804 void Clipboard::ReadData(const FormatType& format, std::string* result) const { 818 void ClipboardAuraX11::ReadData(const FormatType& format,
819 std::string* result) const {
805 DCHECK(CalledOnValidThread()); 820 DCHECK(CalledOnValidThread());
806 821
807 SelectionData data(aurax11_details_->RequestAndWaitForTypes( 822 SelectionData data(aurax11_details_->RequestAndWaitForTypes(
808 CLIPBOARD_TYPE_COPY_PASTE, aurax11_details_->GetAtomsForFormat(format))); 823 CLIPBOARD_TYPE_COPY_PASTE, aurax11_details_->GetAtomsForFormat(format)));
809 if (data.IsValid()) 824 if (data.IsValid())
810 data.AssignTo(result); 825 data.AssignTo(result);
811 } 826 }
812 827
813 void Clipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { 828 void ClipboardAuraX11::WriteObjects(ClipboardType type,
829 const ObjectMap& objects) {
814 DCHECK(CalledOnValidThread()); 830 DCHECK(CalledOnValidThread());
815 DCHECK(IsSupportedClipboardType(type)); 831 DCHECK(IsSupportedClipboardType(type));
816 832
817 aurax11_details_->CreateNewClipboardData(); 833 aurax11_details_->CreateNewClipboardData();
818 for (ObjectMap::const_iterator iter = objects.begin(); 834 for (ObjectMap::const_iterator iter = objects.begin(); iter != objects.end();
819 iter != objects.end(); ++iter) { 835 ++iter) {
820 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); 836 DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
821 } 837 }
822 aurax11_details_->TakeOwnershipOfSelection(type); 838 aurax11_details_->TakeOwnershipOfSelection(type);
823 839
824 if (type == CLIPBOARD_TYPE_COPY_PASTE) { 840 if (type == CLIPBOARD_TYPE_COPY_PASTE) {
825 ObjectMap::const_iterator text_iter = objects.find(CBF_TEXT); 841 ObjectMap::const_iterator text_iter = objects.find(CBF_TEXT);
826 if (text_iter != objects.end()) { 842 if (text_iter != objects.end()) {
827 aurax11_details_->CreateNewClipboardData(); 843 aurax11_details_->CreateNewClipboardData();
828 const ObjectMapParams& params_vector = text_iter->second; 844 const ObjectMapParams& params_vector = text_iter->second;
829 if (params_vector.size()) { 845 if (params_vector.size()) {
830 const ObjectMapParam& char_vector = params_vector[0]; 846 const ObjectMapParam& char_vector = params_vector[0];
831 if (char_vector.size()) 847 if (char_vector.size())
832 WriteText(&char_vector.front(), char_vector.size()); 848 WriteText(&char_vector.front(), char_vector.size());
833 } 849 }
834 aurax11_details_->TakeOwnershipOfSelection(CLIPBOARD_TYPE_SELECTION); 850 aurax11_details_->TakeOwnershipOfSelection(CLIPBOARD_TYPE_SELECTION);
835 } 851 }
836 } 852 }
837 } 853 }
838 854
839 void Clipboard::WriteText(const char* text_data, size_t text_len) { 855 void ClipboardAuraX11::WriteText(const char* text_data, size_t text_len) {
840 std::string str(text_data, text_len); 856 std::string str(text_data, text_len);
841 scoped_refptr<base::RefCountedMemory> mem( 857 scoped_refptr<base::RefCountedMemory> mem(
842 base::RefCountedString::TakeString(&str)); 858 base::RefCountedString::TakeString(&str));
843 859
844 aurax11_details_->InsertMapping(kMimeTypeText, mem); 860 aurax11_details_->InsertMapping(kMimeTypeText, mem);
845 aurax11_details_->InsertMapping(kText, mem); 861 aurax11_details_->InsertMapping(kText, mem);
846 aurax11_details_->InsertMapping(kString, mem); 862 aurax11_details_->InsertMapping(kString, mem);
847 aurax11_details_->InsertMapping(kUtf8String, mem); 863 aurax11_details_->InsertMapping(kUtf8String, mem);
848 } 864 }
849 865
850 void Clipboard::WriteHTML(const char* markup_data, 866 void ClipboardAuraX11::WriteHTML(const char* markup_data,
851 size_t markup_len, 867 size_t markup_len,
852 const char* url_data, 868 const char* url_data,
853 size_t url_len) { 869 size_t url_len) {
854 // TODO(estade): We need to expand relative links with |url_data|. 870 // TODO(estade): We need to expand relative links with |url_data|.
855 static const char* html_prefix = "<meta http-equiv=\"content-type\" " 871 static const char* html_prefix = "<meta http-equiv=\"content-type\" "
856 "content=\"text/html; charset=utf-8\">"; 872 "content=\"text/html; charset=utf-8\">";
857 std::string data = html_prefix; 873 std::string data = html_prefix;
858 data += std::string(markup_data, markup_len); 874 data += std::string(markup_data, markup_len);
859 // Some programs expect NULL-terminated data. See http://crbug.com/42624 875 // Some programs expect NULL-terminated data. See http://crbug.com/42624
860 data += '\0'; 876 data += '\0';
861 877
862 scoped_refptr<base::RefCountedMemory> mem( 878 scoped_refptr<base::RefCountedMemory> mem(
863 base::RefCountedString::TakeString(&data)); 879 base::RefCountedString::TakeString(&data));
864 aurax11_details_->InsertMapping(kMimeTypeHTML, mem); 880 aurax11_details_->InsertMapping(kMimeTypeHTML, mem);
865 } 881 }
866 882
867 void Clipboard::WriteRTF(const char* rtf_data, size_t data_len) { 883 void ClipboardAuraX11::WriteRTF(const char* rtf_data, size_t data_len) {
868 WriteData(GetRtfFormatType(), rtf_data, data_len); 884 WriteData(GetRtfFormatType(), rtf_data, data_len);
869 } 885 }
870 886
871 void Clipboard::WriteBookmark(const char* title_data, 887 void ClipboardAuraX11::WriteBookmark(const char* title_data,
872 size_t title_len, 888 size_t title_len,
873 const char* url_data, 889 const char* url_data,
874 size_t url_len) { 890 size_t url_len) {
875 // Write as a mozilla url (UTF16: URL, newline, title). 891 // Write as a mozilla url (UTF16: URL, newline, title).
876 base::string16 url = base::UTF8ToUTF16(std::string(url_data, url_len) + "\n"); 892 base::string16 url = base::UTF8ToUTF16(std::string(url_data, url_len) + "\n");
877 base::string16 title = base::UTF8ToUTF16(std::string(title_data, title_len)); 893 base::string16 title = base::UTF8ToUTF16(std::string(title_data, title_len));
878 894
879 std::vector<unsigned char> data; 895 std::vector<unsigned char> data;
880 ui::AddString16ToVector(url, &data); 896 ui::AddString16ToVector(url, &data);
881 ui::AddString16ToVector(title, &data); 897 ui::AddString16ToVector(title, &data);
882 scoped_refptr<base::RefCountedMemory> mem( 898 scoped_refptr<base::RefCountedMemory> mem(
883 base::RefCountedBytes::TakeVector(&data)); 899 base::RefCountedBytes::TakeVector(&data));
884 900
885 aurax11_details_->InsertMapping(kMimeTypeMozillaURL, mem); 901 aurax11_details_->InsertMapping(kMimeTypeMozillaURL, mem);
886 } 902 }
887 903
888 // Write an extra flavor that signifies WebKit was the last to modify the 904 // Write an extra flavor that signifies WebKit was the last to modify the
889 // pasteboard. This flavor has no data. 905 // pasteboard. This flavor has no data.
890 void Clipboard::WriteWebSmartPaste() { 906 void ClipboardAuraX11::WriteWebSmartPaste() {
891 std::string empty; 907 std::string empty;
892 aurax11_details_->InsertMapping( 908 aurax11_details_->InsertMapping(
893 kMimeTypeWebkitSmartPaste, 909 kMimeTypeWebkitSmartPaste,
894 scoped_refptr<base::RefCountedMemory>( 910 scoped_refptr<base::RefCountedMemory>(
895 base::RefCountedString::TakeString(&empty))); 911 base::RefCountedString::TakeString(&empty)));
896 } 912 }
897 913
898 void Clipboard::WriteBitmap(const SkBitmap& bitmap) { 914 void ClipboardAuraX11::WriteBitmap(const SkBitmap& bitmap) {
899 // Encode the bitmap as a PNG for transport. 915 // Encode the bitmap as a PNG for transport.
900 std::vector<unsigned char> output; 916 std::vector<unsigned char> output;
901 if (gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, false, &output)) { 917 if (gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, false, &output)) {
902 aurax11_details_->InsertMapping(kMimeTypePNG, 918 aurax11_details_->InsertMapping(kMimeTypePNG,
903 base::RefCountedBytes::TakeVector( 919 base::RefCountedBytes::TakeVector(
904 &output)); 920 &output));
905 } 921 }
906 } 922 }
907 923
908 void Clipboard::WriteData(const FormatType& format, 924 void ClipboardAuraX11::WriteData(const FormatType& format,
909 const char* data_data, 925 const char* data_data,
910 size_t data_len) { 926 size_t data_len) {
911 // We assume that certain mapping types are only written by trusted code. 927 // We assume that certain mapping types are only written by trusted code.
912 // Therefore we must upkeep their integrity. 928 // Therefore we must upkeep their integrity.
913 if (format.Equals(GetBitmapFormatType())) 929 if (format.Equals(GetBitmapFormatType()))
914 return; 930 return;
915 931
916 std::vector<unsigned char> bytes(data_data, data_data + data_len); 932 std::vector<unsigned char> bytes(data_data, data_data + data_len);
917 scoped_refptr<base::RefCountedMemory> mem( 933 scoped_refptr<base::RefCountedMemory> mem(
918 base::RefCountedBytes::TakeVector(&bytes)); 934 base::RefCountedBytes::TakeVector(&bytes));
919 aurax11_details_->InsertMapping(format.ToString(), mem); 935 aurax11_details_->InsertMapping(format.ToString(), mem);
920 } 936 }
921 937
922 } // namespace ui 938 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_aurax11.h ('k') | ui/base/clipboard/clipboard_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698