| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 ptrs.insert(iter->second.first); | 76 ptrs.insert(iter->second.first); |
| 77 } | 77 } |
| 78 | 78 |
| 79 for (std::set<char*>::iterator iter = ptrs.begin(); | 79 for (std::set<char*>::iterator iter = ptrs.begin(); |
| 80 iter != ptrs.end(); ++iter) | 80 iter != ptrs.end(); ++iter) |
| 81 delete[] *iter; | 81 delete[] *iter; |
| 82 | 82 |
| 83 delete map; | 83 delete map; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Frees the pointers in the given map and clears the map. | |
| 87 // Does not double-free any pointers. | |
| 88 void FreeTargetMap(Clipboard::TargetMap map) { | |
| 89 std::set<char*> ptrs; | |
| 90 | |
| 91 for (Clipboard::TargetMap::iterator iter = map.begin(); | |
| 92 iter != map.end(); ++iter) | |
| 93 ptrs.insert(iter->second.first); | |
| 94 | |
| 95 for (std::set<char*>::iterator iter = ptrs.begin(); | |
| 96 iter != ptrs.end(); ++iter) | |
| 97 delete[] *iter; | |
| 98 | |
| 99 map.clear(); | |
| 100 } | |
| 101 | |
| 102 // Called on GdkPixbuf destruction; see WriteBitmap(). | 86 // Called on GdkPixbuf destruction; see WriteBitmap(). |
| 103 void GdkPixbufFree(guchar* pixels, gpointer data) { | 87 void GdkPixbufFree(guchar* pixels, gpointer data) { |
| 104 free(pixels); | 88 free(pixels); |
| 105 } | 89 } |
| 106 | 90 |
| 107 } // namespace | 91 } // namespace |
| 108 | 92 |
| 109 Clipboard::Clipboard() { | 93 Clipboard::Clipboard() { |
| 110 clipboard_ = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | 94 clipboard_ = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); |
| 111 } | 95 } |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 322 |
| 339 if (iter != clipboard_data_->end()) { | 323 if (iter != clipboard_data_->end()) { |
| 340 if (strcmp(kMimeBmp, key) == 0) | 324 if (strcmp(kMimeBmp, key) == 0) |
| 341 g_object_unref(reinterpret_cast<GdkPixbuf*>(iter->second.first)); | 325 g_object_unref(reinterpret_cast<GdkPixbuf*>(iter->second.first)); |
| 342 else | 326 else |
| 343 delete[] iter->second.first; | 327 delete[] iter->second.first; |
| 344 } | 328 } |
| 345 | 329 |
| 346 (*clipboard_data_)[key] = std::make_pair(data, data_len); | 330 (*clipboard_data_)[key] = std::make_pair(data, data_len); |
| 347 } | 331 } |
| OLD | NEW |