summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 22:01:15 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 22:01:15 +0000
commitc033cbe94c504d2346c5e99c1ac12fda41f3f46a (patch)
tree85e1dae7db66e8cf0cc56edb64d15d4a59a70010 /base
parent75d52ac5b9e0c0531b17095a5750918c281a7f0d (diff)
downloadchromium_src-c033cbe94c504d2346c5e99c1ac12fda41f3f46a.zip
chromium_src-c033cbe94c504d2346c5e99c1ac12fda41f3f46a.tar.gz
chromium_src-c033cbe94c504d2346c5e99c1ac12fda41f3f46a.tar.bz2
This changes the base clipboard class, as accomplishing paste requires that Clipboard::FormatType be IPC-able. The lowest-common denominator of unsigned int, NSString*, and GdkAtom is string, so string it is. (Linux changes by estade.)
Review URL: http://codereview.chromium.org/41012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11383 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/clipboard.h24
-rw-r--r--base/clipboard_linux.cc27
-rw-r--r--base/clipboard_mac.mm38
-rw-r--r--base/clipboard_win.cc46
4 files changed, 75 insertions, 60 deletions
diff --git a/base/clipboard.h b/base/clipboard.h
index 5abf4774..546c498 100644
--- a/base/clipboard.h
+++ b/base/clipboard.h
@@ -14,24 +14,12 @@
#include "base/string16.h"
#include "base/gfx/size.h"
-#if defined(OS_MACOSX)
-#if defined(__OBJC__)
-@class NSString;
-#else
-class NSString;
-#endif
-#endif
-
class Clipboard {
public:
-#if defined(OS_WIN)
- typedef unsigned int FormatType;
-#elif defined(OS_MACOSX)
- typedef NSString *FormatType;
-#elif defined(OS_LINUX)
- typedef struct _GdkAtom* FormatType;
+ typedef std::string FormatType;
+#if defined(OS_LINUX)
typedef struct _GtkClipboard GtkClipboard;
- typedef std::map<std::string, std::pair<char*, size_t> > TargetMap;
+ typedef std::map<FormatType, std::pair<char*, size_t> > TargetMap;
#endif
// ObjectType designates the type of data to be stored in the clipboard. This
@@ -95,7 +83,7 @@ class Clipboard {
void WriteObjects(const ObjectMap& objects, base::ProcessHandle process);
// Tests whether the clipboard contains a certain format
- bool IsFormatAvailable(FormatType format) const;
+ bool IsFormatAvailable(const FormatType& format) const;
// Reads UNICODE text from the clipboard, if available.
void ReadText(string16* result) const;
@@ -173,14 +161,14 @@ class Clipboard {
const gfx::Size& size);
// Safely write to system clipboard. Free |handle| on failure.
- void WriteToClipboard(FormatType format, HANDLE handle);
+ void WriteToClipboard(unsigned int format, HANDLE handle);
static void ParseBookmarkClipboardFormat(const string16& bookmark,
string16* title,
std::string* url);
// Free a handle depending on its type (as intuited from format)
- static void FreeData(FormatType format, HANDLE data);
+ static void FreeData(unsigned int format, HANDLE data);
// Return the window that should be the clipboard owner, creating it
// if neccessary. Marked const for lazily initialization by const methods.
diff --git a/base/clipboard_linux.cc b/base/clipboard_linux.cc
index 17ecf6c..0f4bd36 100644
--- a/base/clipboard_linux.cc
+++ b/base/clipboard_linux.cc
@@ -17,6 +17,17 @@ static const char* kMimeHtml = "text/html";
static const char* kMimeText = "text/plain";
static const char* kMimeWebkitSmartPaste = "chrome-internal/webkit-paste";
+std::string GdkAtomToString(const GdkAtom& atom) {
+ gchar* name = gdk_atom_name(atom);
+ std::string rv(name);
+ g_free(name);
+ return rv;
+}
+
+GdkAtom StringToGdkAtom(const std::string& str) {
+ return gdk_atom_intern(str.c_str(), false);
+}
+
// GtkClipboardGetFunc callback.
// GTK will call this when an application wants data we copied to the clipboard.
void GetData(GtkClipboard* clipboard,
@@ -27,7 +38,7 @@ void GetData(GtkClipboard* clipboard,
reinterpret_cast<Clipboard::TargetMap*>(user_data);
Clipboard::TargetMap::iterator iter =
- data_map->find(std::string(gdk_atom_name(selection_data->target)));
+ data_map->find(GdkAtomToString(selection_data->target));
if (iter == data_map->end())
return;
@@ -174,7 +185,7 @@ void Clipboard::WriteFiles(const char* file_data, size_t file_len) {
// to use gtk_clipboard_wait_is_target_available. Also, catch requests
// for plain text and change them to gtk_clipboard_wait_is_text_available
// (which checks for several standard text targets).
-bool Clipboard::IsFormatAvailable(Clipboard::FormatType format) const {
+bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const {
bool retval = false;
GdkAtom* targets = NULL;
GtkSelectionData* data =
@@ -187,8 +198,10 @@ bool Clipboard::IsFormatAvailable(Clipboard::FormatType format) const {
int num = 0;
gtk_selection_data_get_targets(data, &targets, &num);
+ GdkAtom format_atom = StringToGdkAtom(format);
+
for (int i = 0; i < num; i++) {
- if (targets[i] == format) {
+ if (targets[i] == format_atom) {
retval = true;
break;
}
@@ -232,7 +245,7 @@ void Clipboard::ReadHTML(string16* markup, std::string* src_url) const {
markup->clear();
GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard_,
- GetHtmlFormatType());
+ StringToGdkAtom(GetHtmlFormatType()));
if (!data)
return;
@@ -245,7 +258,7 @@ void Clipboard::ReadHTML(string16* markup, std::string* src_url) const {
// static
Clipboard::FormatType Clipboard::GetPlainTextFormatType() {
- return GDK_TARGET_STRING;
+ return GdkAtomToString(GDK_TARGET_STRING);
}
// static
@@ -255,12 +268,12 @@ Clipboard::FormatType Clipboard::GetPlainTextWFormatType() {
// static
Clipboard::FormatType Clipboard::GetHtmlFormatType() {
- return gdk_atom_intern(kMimeHtml, false);
+ return std::string(kMimeHtml);
}
// static
Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
- return gdk_atom_intern(kMimeWebkitSmartPaste, false);
+ return std::string(kMimeWebkitSmartPaste);
}
// Insert the key/value pair in the clipboard_data structure. If
diff --git a/base/clipboard_mac.mm b/base/clipboard_mac.mm
index f2b6294..8363ffb 100644
--- a/base/clipboard_mac.mm
+++ b/base/clipboard_mac.mm
@@ -129,15 +129,18 @@ void Clipboard::WriteFiles(const char* file_data, size_t file_len) {
// pasteboard. This flavor has no data.
void Clipboard::WriteWebSmartPaste() {
NSPasteboard* pb = GetPasteboard();
- [pb addTypes:[NSArray arrayWithObject:GetWebKitSmartPasteFormatType()] owner:nil];
- [pb setData:nil forType:GetWebKitSmartPasteFormatType()];
+ NSString* format = base::SysUTF8ToNSString(GetWebKitSmartPasteFormatType());
+ [pb addTypes:[NSArray arrayWithObject:format] owner:nil];
+ [pb setData:nil forType:format];
}
-bool Clipboard::IsFormatAvailable(NSString* format) const {
+bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const {
+ NSString* format_ns = base::SysUTF8ToNSString(format);
+
NSPasteboard* pb = GetPasteboard();
NSArray* types = [pb types];
- return [types containsObject:format];
+ return [types containsObject:format_ns];
}
void Clipboard::ReadText(string16* result) const {
@@ -230,40 +233,51 @@ void Clipboard::ReadFiles(std::vector<FilePath>* files) const {
// static
Clipboard::FormatType Clipboard::GetUrlFormatType() {
- return NSURLPboardType;
+ static const std::string type = base::SysNSStringToUTF8(NSURLPboardType);
+ return type;
}
// static
Clipboard::FormatType Clipboard::GetUrlWFormatType() {
- return NSURLPboardType;
+ static const std::string type = base::SysNSStringToUTF8(NSURLPboardType);
+ return type;
}
// static
Clipboard::FormatType Clipboard::GetPlainTextFormatType() {
- return NSStringPboardType;
+ static const std::string type = base::SysNSStringToUTF8(NSStringPboardType);
+ return type;
}
// static
Clipboard::FormatType Clipboard::GetPlainTextWFormatType() {
- return NSStringPboardType;
+ static const std::string type = base::SysNSStringToUTF8(NSStringPboardType);
+ return type;
}
// static
Clipboard::FormatType Clipboard::GetFilenameFormatType() {
- return NSFilenamesPboardType;
+ static const std::string type =
+ base::SysNSStringToUTF8(NSFilenamesPboardType);
+ return type;
}
// static
Clipboard::FormatType Clipboard::GetFilenameWFormatType() {
- return NSFilenamesPboardType;
+ static const std::string type =
+ base::SysNSStringToUTF8(NSFilenamesPboardType);
+ return type;
}
// static
Clipboard::FormatType Clipboard::GetHtmlFormatType() {
- return NSHTMLPboardType;
+ static const std::string type = base::SysNSStringToUTF8(NSHTMLPboardType);
+ return type;
}
// static
Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
- return kWebSmartPastePboardType;
+ static const std::string type =
+ base::SysNSStringToUTF8(kWebSmartPastePboardType);
+ return type;
}
diff --git a/base/clipboard_win.cc b/base/clipboard_win.cc
index b765f5f..5ce479f 100644
--- a/base/clipboard_win.cc
+++ b/base/clipboard_win.cc
@@ -190,7 +190,7 @@ void Clipboard::WriteHTML(const char* markup_data,
std::string html_fragment = ClipboardUtil::HtmlToCFHtml(markup, url);
HGLOBAL glob = CreateGlobalData(html_fragment);
- WriteToClipboard(GetHtmlFormatType(), glob);
+ WriteToClipboard(StringToInt(GetHtmlFormatType()), glob);
}
void Clipboard::WriteBookmark(const char* title_data,
@@ -204,7 +204,7 @@ void Clipboard::WriteBookmark(const char* title_data,
string16 wide_bookmark = UTF8ToWide(bookmark);
HGLOBAL glob = CreateGlobalData(wide_bookmark);
- WriteToClipboard(GetUrlWFormatType(), glob);
+ WriteToClipboard(StringToInt(GetUrlWFormatType()), glob);
}
void Clipboard::WriteHyperlink(const char* title_data,
@@ -230,7 +230,7 @@ void Clipboard::WriteHyperlink(const char* title_data,
void Clipboard::WriteWebSmartPaste() {
DCHECK(clipboard_owner_);
- ::SetClipboardData(GetWebKitSmartPasteFormatType(), NULL);
+ ::SetClipboardData(StringToInt(GetWebKitSmartPasteFormatType()), NULL);
}
void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) {
@@ -371,7 +371,7 @@ void Clipboard::WriteFiles(const char* file_data, size_t file_len) {
WriteToClipboard(CF_HDROP, hdata);
}
-void Clipboard::WriteToClipboard(FormatType format, HANDLE handle) {
+void Clipboard::WriteToClipboard(unsigned int format, HANDLE handle) {
DCHECK(clipboard_owner_);
if (handle && !::SetClipboardData(format, handle)) {
DCHECK(ERROR_CLIPBOARD_NOT_OPEN != GetLastError());
@@ -379,8 +379,8 @@ void Clipboard::WriteToClipboard(FormatType format, HANDLE handle) {
}
}
-bool Clipboard::IsFormatAvailable(unsigned int format) const {
- return ::IsClipboardFormatAvailable(format) != FALSE;
+bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const {
+ return ::IsClipboardFormatAvailable(StringToInt(format)) != FALSE;
}
void Clipboard::ReadText(string16* result) const {
@@ -437,7 +437,7 @@ void Clipboard::ReadHTML(string16* markup, std::string* src_url) const {
if (!clipboard.Acquire(GetClipboardWindow()))
return;
- HANDLE data = ::GetClipboardData(GetHtmlFormatType());
+ HANDLE data = ::GetClipboardData(StringToInt(GetHtmlFormatType()));
if (!data)
return;
@@ -461,7 +461,7 @@ void Clipboard::ReadBookmark(string16* title, std::string* url) const {
if (!clipboard.Acquire(GetClipboardWindow()))
return;
- HANDLE data = ::GetClipboardData(GetUrlWFormatType());
+ HANDLE data = ::GetClipboardData(StringToInt(GetUrlWFormatType()));
if (!data)
return;
@@ -536,69 +536,69 @@ void Clipboard::ParseBookmarkClipboardFormat(const string16& bookmark,
// static
Clipboard::FormatType Clipboard::GetUrlFormatType() {
- return ClipboardUtil::GetUrlFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetUrlFormat()->cfFormat);
}
// static
Clipboard::FormatType Clipboard::GetUrlWFormatType() {
- return ClipboardUtil::GetUrlWFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetUrlWFormat()->cfFormat);
}
// static
Clipboard::FormatType Clipboard::GetMozUrlFormatType() {
- return ClipboardUtil::GetMozUrlFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetMozUrlFormat()->cfFormat);
}
// static
Clipboard::FormatType Clipboard::GetPlainTextFormatType() {
- return ClipboardUtil::GetPlainTextFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetPlainTextFormat()->cfFormat);
}
// static
Clipboard::FormatType Clipboard::GetPlainTextWFormatType() {
- return ClipboardUtil::GetPlainTextWFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetPlainTextWFormat()->cfFormat);
}
// static
Clipboard::FormatType Clipboard::GetFilenameFormatType() {
- return ClipboardUtil::GetFilenameFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetFilenameFormat()->cfFormat);
}
// static
Clipboard::FormatType Clipboard::GetFilenameWFormatType() {
- return ClipboardUtil::GetFilenameWFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetFilenameWFormat()->cfFormat);
}
// MS HTML Format
// static
Clipboard::FormatType Clipboard::GetHtmlFormatType() {
- return ClipboardUtil::GetHtmlFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetHtmlFormat()->cfFormat);
}
// static
Clipboard::FormatType Clipboard::GetBitmapFormatType() {
- return CF_BITMAP;
+ return IntToString(CF_BITMAP);
}
// Firefox text/html
// static
Clipboard::FormatType Clipboard::GetTextHtmlFormatType() {
- return ClipboardUtil::GetTextHtmlFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetTextHtmlFormat()->cfFormat);
}
// static
Clipboard::FormatType Clipboard::GetCFHDropFormatType() {
- return ClipboardUtil::GetCFHDropFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetCFHDropFormat()->cfFormat);
}
// static
Clipboard::FormatType Clipboard::GetFileDescriptorFormatType() {
- return ClipboardUtil::GetFileDescriptorFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetFileDescriptorFormat()->cfFormat);
}
// static
Clipboard::FormatType Clipboard::GetFileContentFormatZeroType() {
- return ClipboardUtil::GetFileContentFormatZero()->cfFormat;
+ return IntToString(ClipboardUtil::GetFileContentFormatZero()->cfFormat);
}
// static
@@ -627,11 +627,11 @@ void Clipboard::DuplicateRemoteHandles(base::ProcessHandle process,
// static
Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
- return ClipboardUtil::GetWebKitSmartPasteFormat()->cfFormat;
+ return IntToString(ClipboardUtil::GetWebKitSmartPasteFormat()->cfFormat);
}
// static
-void Clipboard::FreeData(FormatType format, HANDLE data) {
+void Clipboard::FreeData(unsigned int format, HANDLE data) {
if (format == CF_BITMAP)
::DeleteObject(static_cast<HBITMAP>(data));
else