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

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

Issue 9167002: Revert 116956 - GTK: Seal up GSEALs, focusing on GtkSelectionData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/tab_contents/web_drag_source_gtk.cc ('k') | ui/base/dragdrop/gtk_dnd_util.cc » ('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) 2011 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 <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <X11/extensions/Xfixes.h> 8 #include <X11/extensions/Xfixes.h>
9 #include <X11/Xatom.h> 9 #include <X11/Xatom.h>
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 // GtkClipboardGetFunc callback. 123 // GtkClipboardGetFunc callback.
124 // GTK will call this when an application wants data we copied to the clipboard. 124 // GTK will call this when an application wants data we copied to the clipboard.
125 void GetData(GtkClipboard* clipboard, 125 void GetData(GtkClipboard* clipboard,
126 GtkSelectionData* selection_data, 126 GtkSelectionData* selection_data,
127 guint info, 127 guint info,
128 gpointer user_data) { 128 gpointer user_data) {
129 Clipboard::TargetMap* data_map = 129 Clipboard::TargetMap* data_map =
130 reinterpret_cast<Clipboard::TargetMap*>(user_data); 130 reinterpret_cast<Clipboard::TargetMap*>(user_data);
131 131
132 std::string target_string = GdkAtomToString( 132 std::string target_string = GdkAtomToString(selection_data->target);
133 gtk_selection_data_get_target(selection_data));
134 Clipboard::TargetMap::iterator iter = data_map->find(target_string); 133 Clipboard::TargetMap::iterator iter = data_map->find(target_string);
135 134
136 if (iter == data_map->end()) 135 if (iter == data_map->end())
137 return; 136 return;
138 137
139 if (target_string == kMimeTypeBitmap) { 138 if (target_string == kMimeTypeBitmap) {
140 gtk_selection_data_set_pixbuf(selection_data, 139 gtk_selection_data_set_pixbuf(selection_data,
141 reinterpret_cast<GdkPixbuf*>(iter->second.first)); 140 reinterpret_cast<GdkPixbuf*>(iter->second.first));
142 } else { 141 } else {
143 gtk_selection_data_set(selection_data, 142 gtk_selection_data_set(selection_data, selection_data->target, 8,
144 gtk_selection_data_get_target(selection_data), 8,
145 reinterpret_cast<guchar*>(iter->second.first), 143 reinterpret_cast<guchar*>(iter->second.first),
146 iter->second.second); 144 iter->second.second);
147 } 145 }
148 } 146 }
149 147
150 // GtkClipboardClearFunc callback. 148 // GtkClipboardClearFunc callback.
151 // We are guaranteed this will be called exactly once for each call to 149 // We are guaranteed this will be called exactly once for each call to
152 // gtk_clipboard_set_with_data. 150 // gtk_clipboard_set_with_data.
153 void ClearData(GtkClipboard* clipboard, 151 void ClearData(GtkClipboard* clipboard,
154 gpointer user_data) { 152 gpointer user_data) {
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 *contains_filenames = false; 414 *contains_filenames = false;
417 415
418 GtkClipboard* clipboard = LookupBackingClipboard(buffer); 416 GtkClipboard* clipboard = LookupBackingClipboard(buffer);
419 if (!clipboard) 417 if (!clipboard)
420 return; 418 return;
421 419
422 GtkSelectionData* data = gtk_clipboard_wait_for_contents( 420 GtkSelectionData* data = gtk_clipboard_wait_for_contents(
423 clipboard, GetWebCustomDataFormatType().ToGdkAtom()); 421 clipboard, GetWebCustomDataFormatType().ToGdkAtom());
424 if (!data) 422 if (!data)
425 return; 423 return;
426 ReadCustomDataTypes(gtk_selection_data_get_data(data), 424 ReadCustomDataTypes(data->data, data->length, types);
427 gtk_selection_data_get_length(data),
428 types);
429 gtk_selection_data_free(data); 425 gtk_selection_data_free(data);
430 } 426 }
431 427
432 428
433 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { 429 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const {
434 GtkClipboard* clipboard = LookupBackingClipboard(buffer); 430 GtkClipboard* clipboard = LookupBackingClipboard(buffer);
435 if (clipboard == NULL) 431 if (clipboard == NULL)
436 return; 432 return;
437 433
438 result->clear(); 434 result->clear();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 if (clipboard == NULL) 477 if (clipboard == NULL)
482 return; 478 return;
483 GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, 479 GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard,
484 GetHtmlFormatType().ToGdkAtom()); 480 GetHtmlFormatType().ToGdkAtom());
485 481
486 if (!data) 482 if (!data)
487 return; 483 return;
488 484
489 // If the data starts with 0xFEFF, i.e., Byte Order Mark, assume it is 485 // If the data starts with 0xFEFF, i.e., Byte Order Mark, assume it is
490 // UTF-16, otherwise assume UTF-8. 486 // UTF-16, otherwise assume UTF-8.
491 gint data_length = gtk_selection_data_get_length(data); 487 if (data->length >= 2 &&
492 const guchar* raw_data = gtk_selection_data_get_data(data); 488 reinterpret_cast<uint16_t*>(data->data)[0] == 0xFEFF) {
493 489 markup->assign(reinterpret_cast<uint16_t*>(data->data) + 1,
494 if (data_length >= 2 && 490 (data->length / 2) - 1);
495 reinterpret_cast<const uint16_t*>(raw_data)[0] == 0xFEFF) {
496 markup->assign(reinterpret_cast<const uint16_t*>(raw_data) + 1,
497 (data_length / 2) - 1);
498 } else { 491 } else {
499 UTF8ToUTF16(reinterpret_cast<const char*>(raw_data), data_length, markup); 492 UTF8ToUTF16(reinterpret_cast<char*>(data->data), data->length, markup);
500 } 493 }
501 494
502 // If there is a terminating NULL, drop it. 495 // If there is a terminating NULL, drop it.
503 if (!markup->empty() && markup->at(markup->length() - 1) == '\0') 496 if (!markup->empty() && markup->at(markup->length() - 1) == '\0')
504 markup->resize(markup->length() - 1); 497 markup->resize(markup->length() - 1);
505 498
506 *fragment_start = 0; 499 *fragment_start = 0;
507 DCHECK(markup->length() <= kuint32max); 500 DCHECK(markup->length() <= kuint32max);
508 *fragment_end = static_cast<uint32>(markup->length()); 501 *fragment_end = static_cast<uint32>(markup->length());
509 502
(...skipping 22 matching lines...) Expand all
532 const string16& type, 525 const string16& type,
533 string16* result) const { 526 string16* result) const {
534 GtkClipboard* clipboard = LookupBackingClipboard(buffer); 527 GtkClipboard* clipboard = LookupBackingClipboard(buffer);
535 if (!clipboard) 528 if (!clipboard)
536 return; 529 return;
537 530
538 GtkSelectionData* data = gtk_clipboard_wait_for_contents( 531 GtkSelectionData* data = gtk_clipboard_wait_for_contents(
539 clipboard, GetWebCustomDataFormatType().ToGdkAtom()); 532 clipboard, GetWebCustomDataFormatType().ToGdkAtom());
540 if (!data) 533 if (!data)
541 return; 534 return;
542 ReadCustomDataForType(gtk_selection_data_get_data(data), 535 ReadCustomDataForType(data->data, data->length, type, result);
543 gtk_selection_data_get_length(data),
544 type, result);
545 gtk_selection_data_free(data); 536 gtk_selection_data_free(data);
546 } 537 }
547 538
548 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 539 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
549 // TODO(estade): implement this. 540 // TODO(estade): implement this.
550 NOTIMPLEMENTED(); 541 NOTIMPLEMENTED();
551 } 542 }
552 543
553 void Clipboard::ReadData(const FormatType& format, std::string* result) const { 544 void Clipboard::ReadData(const FormatType& format, std::string* result) const {
554 GtkSelectionData* data = 545 GtkSelectionData* data =
555 gtk_clipboard_wait_for_contents(clipboard_, format.ToGdkAtom()); 546 gtk_clipboard_wait_for_contents(clipboard_, format.ToGdkAtom());
556 if (!data) 547 if (!data)
557 return; 548 return;
558 result->assign(reinterpret_cast<const char*>( 549 result->assign(reinterpret_cast<char*>(data->data), data->length);
559 gtk_selection_data_get_data(data)),
560 gtk_selection_data_get_length(data));
561 gtk_selection_data_free(data); 550 gtk_selection_data_free(data);
562 } 551 }
563 552
564 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { 553 uint64 Clipboard::GetSequenceNumber(Buffer buffer) {
565 if (buffer == BUFFER_STANDARD) 554 if (buffer == BUFFER_STANDARD)
566 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number(); 555 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number();
567 else 556 else
568 return SelectionChangeObserver::GetInstance()->primary_sequence_number(); 557 return SelectionChangeObserver::GetInstance()->primary_sequence_number();
569 } 558 }
570 559
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 return clipboard_; 612 return clipboard_;
624 case BUFFER_SELECTION: 613 case BUFFER_SELECTION:
625 return primary_selection_; 614 return primary_selection_;
626 default: 615 default:
627 NOTREACHED(); 616 NOTREACHED();
628 return NULL; 617 return NULL;
629 } 618 }
630 } 619 }
631 620
632 } // namespace ui 621 } // namespace ui
OLDNEW
« no previous file with comments | « content/browser/tab_contents/web_drag_source_gtk.cc ('k') | ui/base/dragdrop/gtk_dnd_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698