summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc2
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc9
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h2
-rw-r--r--chrome/common/render_messages_internal.h2
-rw-r--r--chrome/common/temp_scaffolding_stubs.cc7
-rw-r--r--chrome/renderer/renderer_glue.cc12
-rw-r--r--chrome/views/text_field.cc2
-rw-r--r--webkit/glue/simple_clipboard_impl.cc2
-rw-r--r--webkit/glue/webkit_glue.h2
13 files changed, 84 insertions, 91 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
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index 6df7ff4..a25845d 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -2017,7 +2017,7 @@ void AutocompleteEditViewWin::TextChanged() {
std::wstring AutocompleteEditViewWin::GetClipboardText() const {
// Try text format.
ClipboardService* clipboard = g_browser_process->clipboard_service();
- if (clipboard->IsFormatAvailable(CF_UNICODETEXT)) {
+ if (clipboard->IsFormatAvailable(Clipboard::GetPlainTextWFormatType())) {
std::wstring text;
clipboard->ReadText(&text);
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 4fce635..8492cc6 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -540,15 +540,10 @@ void ResourceMessageFilter::OnClipboardWriteObjects(
new WriteClipboardTask(long_living_objects));
}
-void ResourceMessageFilter::OnClipboardIsFormatAvailable(unsigned int format,
- bool* result) {
-#if defined(OS_WIN)
+void ResourceMessageFilter::OnClipboardIsFormatAvailable(
+ Clipboard::FormatType format, bool* result) {
DCHECK(result);
*result = GetClipboardService()->IsFormatAvailable(format);
-#else
- NOTIMPLEMENTED(); // TODO(port) this function should take a
- // Clipboard::FormatType instead of an int.
-#endif
}
void ResourceMessageFilter::OnClipboardReadText(string16* result) {
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index 823685a..55ce1be 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -155,7 +155,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
void OnReceiveContextMenuMsg(const IPC::Message& msg);
// Clipboard messages
void OnClipboardWriteObjects(const Clipboard::ObjectMap& objects);
- void OnClipboardIsFormatAvailable(unsigned int format, bool* result);
+ void OnClipboardIsFormatAvailable(Clipboard::FormatType format, bool* result);
void OnClipboardReadText(string16* result);
void OnClipboardReadAsciiText(std::string* result);
void OnClipboardReadHTML(string16* markup, GURL* src_url);
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 80b78e1..bdbabaa 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -842,7 +842,7 @@ IPC_BEGIN_MESSAGES(ViewHost)
IPC_SYNC_MESSAGE_CONTROL1_0(ViewHostMsg_ClipboardWriteObjectsSync,
Clipboard::ObjectMap /* objects */)
IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_ClipboardIsFormatAvailable,
- int /* format */,
+ std::string /* format */,
bool /* result */)
IPC_SYNC_MESSAGE_CONTROL0_1(ViewHostMsg_ClipboardReadText,
string16 /* result */)
diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc
index 5d1e633..5d7f5c3 100644
--- a/chrome/common/temp_scaffolding_stubs.cc
+++ b/chrome/common/temp_scaffolding_stubs.cc
@@ -325,13 +325,6 @@ bool IsDefaultPluginEnabled() {
return false;
}
-#if defined(OS_MACOSX)
-bool ClipboardIsFormatAvailable(Clipboard::FormatType format) {
- NOTIMPLEMENTED();
- return false;
-}
-#endif
-
} // webkit_glue
#ifndef CHROME_DEBUGGER_DISABLED
diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc
index 22b2775..6cace23 100644
--- a/chrome/renderer/renderer_glue.cc
+++ b/chrome/renderer/renderer_glue.cc
@@ -189,17 +189,7 @@ Clipboard* ClipboardGetClipboard(){
return NULL;
}
-#if defined(OS_LINUX)
-// TODO(port): This should replace the method below (the unsigned int is a
-// windows type). We may need to convert the type of format so it can be sent
-// over IPC.
-bool ClipboardIsFormatAvailable(Clipboard::FormatType format) {
- NOTIMPLEMENTED();
- return false;
-}
-#endif
-
-bool ClipboardIsFormatAvailable(unsigned int format) {
+bool ClipboardIsFormatAvailable(const Clipboard::FormatType& format) {
bool result;
RenderThread::current()->Send(
new ViewHostMsg_ClipboardIsFormatAvailable(format, &result));
diff --git a/chrome/views/text_field.cc b/chrome/views/text_field.cc
index d0ec3da..10a154c 100644
--- a/chrome/views/text_field.cc
+++ b/chrome/views/text_field.cc
@@ -761,7 +761,7 @@ void TextField::Edit::OnPaste() {
ClipboardService* clipboard = g_browser_process->clipboard_service();
- if (!clipboard->IsFormatAvailable(CF_UNICODETEXT))
+ if (!clipboard->IsFormatAvailable(Clipboard::GetPlainTextWFormatType()))
return;
std::wstring clipboard_str;
diff --git a/webkit/glue/simple_clipboard_impl.cc b/webkit/glue/simple_clipboard_impl.cc
index 1674f4f..264dfa5 100644
--- a/webkit/glue/simple_clipboard_impl.cc
+++ b/webkit/glue/simple_clipboard_impl.cc
@@ -34,7 +34,7 @@ Clipboard* ClipboardGetClipboard() {
return clipboard.Pointer();
}
-bool ClipboardIsFormatAvailable(Clipboard::FormatType format) {
+bool ClipboardIsFormatAvailable(const Clipboard::FormatType& format) {
return ClipboardGetClipboard()->IsFormatAvailable(format);
}
diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h
index 7b79ff9..6db5680 100644
--- a/webkit/glue/webkit_glue.h
+++ b/webkit/glue/webkit_glue.h
@@ -152,7 +152,7 @@ HCURSOR LoadCursor(int cursor_id);
Clipboard* ClipboardGetClipboard();
// Tests whether the clipboard contains a certain format
-bool ClipboardIsFormatAvailable(Clipboard::FormatType format);
+bool ClipboardIsFormatAvailable(const Clipboard::FormatType& format);
// Reads UNICODE text from the clipboard, if available.
void ClipboardReadText(string16* result);