| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/clipboard.h" | 5 #include "base/clipboard.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Take ownership of the GTK clipboard and inform it of the targets we support. | 114 // Take ownership of the GTK clipboard and inform it of the targets we support. |
| 115 void Clipboard::SetGtkClipboard() { | 115 void Clipboard::SetGtkClipboard() { |
| 116 scoped_array<GtkTargetEntry> targets( | 116 scoped_array<GtkTargetEntry> targets( |
| 117 new GtkTargetEntry[clipboard_data_->size()]); | 117 new GtkTargetEntry[clipboard_data_->size()]); |
| 118 | 118 |
| 119 int i = 0; | 119 int i = 0; |
| 120 for (Clipboard::TargetMap::iterator iter = clipboard_data_->begin(); | 120 for (Clipboard::TargetMap::iterator iter = clipboard_data_->begin(); |
| 121 iter != clipboard_data_->end(); ++iter, ++i) { | 121 iter != clipboard_data_->end(); ++iter, ++i) { |
| 122 targets[i].target = strndup(iter->first.data(), iter->first.size()); | 122 targets[i].target = static_cast<gchar*>(malloc(iter->first.size() + 1)); |
| 123 memcpy(targets[i].target, iter->first.data(), iter->first.size()); |
| 124 targets[i].target[iter->first.size()] = '\0'; |
| 125 |
| 123 targets[i].flags = 0; | 126 targets[i].flags = 0; |
| 124 targets[i].info = i; | 127 targets[i].info = i; |
| 125 } | 128 } |
| 126 | 129 |
| 127 gtk_clipboard_set_with_data(clipboard_, targets.get(), | 130 gtk_clipboard_set_with_data(clipboard_, targets.get(), |
| 128 clipboard_data_->size(), | 131 clipboard_data_->size(), |
| 129 GetData, ClearData, | 132 GetData, ClearData, |
| 130 clipboard_data_); | 133 clipboard_data_); |
| 131 | 134 |
| 132 for (size_t i = 0; i < clipboard_data_->size(); i++) | 135 for (size_t i = 0; i < clipboard_data_->size(); i++) |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 348 |
| 346 if (iter != clipboard_data_->end()) { | 349 if (iter != clipboard_data_->end()) { |
| 347 if (strcmp(kMimeBmp, key) == 0) | 350 if (strcmp(kMimeBmp, key) == 0) |
| 348 g_object_unref(reinterpret_cast<GdkPixbuf*>(iter->second.first)); | 351 g_object_unref(reinterpret_cast<GdkPixbuf*>(iter->second.first)); |
| 349 else | 352 else |
| 350 delete[] iter->second.first; | 353 delete[] iter->second.first; |
| 351 } | 354 } |
| 352 | 355 |
| 353 (*clipboard_data_)[key] = std::make_pair(data, data_len); | 356 (*clipboard_data_)[key] = std::make_pair(data, data_len); |
| 354 } | 357 } |
| OLD | NEW |