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

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

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