| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "ChromiumBridge.h" | 6 #include "ChromiumBridge.h" |
| 7 | 7 |
| 8 #include "BitmapImage.h" | 8 #include "BitmapImage.h" |
| 9 #include "ClipboardUtilitiesChromium.h" | |
| 10 #include "Cursor.h" | 9 #include "Cursor.h" |
| 11 #include "Frame.h" | 10 #include "Frame.h" |
| 12 #include "FrameView.h" | 11 #include "FrameView.h" |
| 13 #include "HostWindow.h" | 12 #include "HostWindow.h" |
| 14 #include "KURL.h" | 13 #include "KURL.h" |
| 15 #include "NativeImageSkia.h" | 14 #include "NativeImageSkia.h" |
| 16 #include "Page.h" | 15 #include "Page.h" |
| 17 #include "PasteboardPrivate.h" | 16 #include "PasteboardPrivate.h" |
| 18 #include "PlatformContextSkia.h" | 17 #include "PlatformContextSkia.h" |
| 19 #include "PlatformString.h" | 18 #include "PlatformString.h" |
| 20 #include "PlatformWidget.h" | 19 #include "PlatformWidget.h" |
| 21 #include "PluginData.h" | 20 #include "PluginData.h" |
| 22 #include "PluginInfoStore.h" | 21 #include "PluginInfoStore.h" |
| 23 #include "ScrollbarTheme.h" | 22 #include "ScrollbarTheme.h" |
| 24 #include "ScrollView.h" | 23 #include "ScrollView.h" |
| 25 #include "SystemTime.h" | 24 #include "SystemTime.h" |
| 26 #include "Widget.h" | 25 #include "Widget.h" |
| 27 #include <wtf/CurrentTime.h> | 26 #include <wtf/CurrentTime.h> |
| 28 | 27 |
| 29 #undef LOG | 28 #undef LOG |
| 30 #include "base/clipboard.h" | |
| 31 #include "base/file_util.h" | 29 #include "base/file_util.h" |
| 32 #include "base/message_loop.h" | 30 #include "base/message_loop.h" |
| 33 #include "base/stats_counters.h" | 31 #include "base/stats_counters.h" |
| 34 #include "base/string_util.h" | 32 #include "base/string_util.h" |
| 35 #include "base/time.h" | 33 #include "base/time.h" |
| 36 #include "base/trace_event.h" | 34 #include "base/trace_event.h" |
| 37 #include "build/build_config.h" | 35 #include "build/build_config.h" |
| 38 #include "googleurl/src/url_util.h" | 36 #include "googleurl/src/url_util.h" |
| 39 #include "net/base/mime_util.h" | 37 #include "net/base/mime_util.h" |
| 40 #include "skia/ext/skia_utils_win.h" | 38 #include "skia/ext/skia_utils_win.h" |
| 41 #if USE(V8) | 39 #if USE(V8) |
| 42 #include <v8.h> | 40 #include <v8.h> |
| 43 #endif | 41 #endif |
| 44 #include "grit/webkit_resources.h" | 42 #include "grit/webkit_resources.h" |
| 45 #include "webkit/glue/chrome_client_impl.h" | 43 #include "webkit/glue/chrome_client_impl.h" |
| 46 #include "webkit/glue/glue_util.h" | 44 #include "webkit/glue/glue_util.h" |
| 47 #include "webkit/glue/plugins/plugin_instance.h" | 45 #include "webkit/glue/plugins/plugin_instance.h" |
| 48 #include "webkit/glue/scoped_clipboard_writer_glue.h" | |
| 49 #include "webkit/glue/webcursor.h" | 46 #include "webkit/glue/webcursor.h" |
| 50 #include "webkit/glue/webkit_glue.h" | 47 #include "webkit/glue/webkit_glue.h" |
| 51 #include "webkit/glue/webplugin_impl.h" | 48 #include "webkit/glue/webplugin_impl.h" |
| 52 | 49 |
| 53 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 54 #include <windows.h> | 51 #include <windows.h> |
| 55 #include <vssym32.h> | 52 #include <vssym32.h> |
| 56 | 53 |
| 57 #include "base/gfx/native_theme.h" | 54 #include "base/gfx/native_theme.h" |
| 58 #endif | 55 #endif |
| (...skipping 27 matching lines...) Expand all Loading... |
| 86 return NULL; | 83 return NULL; |
| 87 } | 84 } |
| 88 | 85 |
| 89 WebCore::Page* page = view->frame() ? view->frame()->page() : NULL; | 86 WebCore::Page* page = view->frame() ? view->frame()->page() : NULL; |
| 90 if (!page) | 87 if (!page) |
| 91 return NULL; | 88 return NULL; |
| 92 | 89 |
| 93 return static_cast<ChromeClientImpl*>(page->chrome()->client()); | 90 return static_cast<ChromeClientImpl*>(page->chrome()->client()); |
| 94 } | 91 } |
| 95 | 92 |
| 96 std::wstring UrlToImageMarkup(const WebCore::KURL& url, | |
| 97 const WebCore::String& alt_str) { | |
| 98 std::wstring markup(L"<img src=\""); | |
| 99 markup.append(webkit_glue::StringToStdWString(url.string())); | |
| 100 markup.append(L"\""); | |
| 101 if (!alt_str.isEmpty()) { | |
| 102 markup.append(L" alt=\""); | |
| 103 std::wstring alt_stdstr = webkit_glue::StringToStdWString(alt_str); | |
| 104 ReplaceSubstringsAfterOffset(&alt_stdstr, 0, L"\"", L"""); | |
| 105 markup.append(alt_stdstr); | |
| 106 markup.append(L"\""); | |
| 107 } | |
| 108 markup.append(L"/>"); | |
| 109 return markup; | |
| 110 } | |
| 111 | |
| 112 } // namespace | 93 } // namespace |
| 113 | 94 |
| 114 namespace WebCore { | 95 namespace WebCore { |
| 115 | 96 |
| 116 bool ChromiumBridge::clipboardIsFormatAvailable( | |
| 117 PasteboardPrivate::ClipboardFormat format) { | |
| 118 switch (format) { | |
| 119 case PasteboardPrivate::HTMLFormat: | |
| 120 return webkit_glue::ClipboardIsFormatAvailable( | |
| 121 ::Clipboard::GetHtmlFormatType()); | |
| 122 | |
| 123 case PasteboardPrivate::WebSmartPasteFormat: | |
| 124 return webkit_glue::ClipboardIsFormatAvailable( | |
| 125 ::Clipboard::GetWebKitSmartPasteFormatType()); | |
| 126 | |
| 127 case PasteboardPrivate::BookmarkFormat: | |
| 128 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 129 return webkit_glue::ClipboardIsFormatAvailable( | |
| 130 ::Clipboard::GetUrlWFormatType()); | |
| 131 #endif | |
| 132 | |
| 133 default: | |
| 134 NOTREACHED(); | |
| 135 return false; | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 String ChromiumBridge::clipboardReadPlainText() { | |
| 140 if (webkit_glue::ClipboardIsFormatAvailable( | |
| 141 ::Clipboard::GetPlainTextWFormatType())) { | |
| 142 std::wstring text; | |
| 143 webkit_glue::ClipboardReadText(&text); | |
| 144 if (!text.empty()) | |
| 145 return webkit_glue::StdWStringToString(text); | |
| 146 } | |
| 147 | |
| 148 if (webkit_glue::ClipboardIsFormatAvailable( | |
| 149 ::Clipboard::GetPlainTextFormatType())) { | |
| 150 std::string text; | |
| 151 webkit_glue::ClipboardReadAsciiText(&text); | |
| 152 if (!text.empty()) | |
| 153 return webkit_glue::StdStringToString(text); | |
| 154 } | |
| 155 | |
| 156 return String(); | |
| 157 } | |
| 158 | |
| 159 void ChromiumBridge::clipboardReadHTML(String* html, KURL* url) { | |
| 160 std::wstring html_stdstr; | |
| 161 GURL gurl; | |
| 162 webkit_glue::ClipboardReadHTML(&html_stdstr, &gurl); | |
| 163 *html = webkit_glue::StdWStringToString(html_stdstr); | |
| 164 *url = webkit_glue::GURLToKURL(gurl); | |
| 165 } | |
| 166 | |
| 167 void ChromiumBridge::clipboardWriteSelection(const String& html, | |
| 168 const KURL& url, | |
| 169 const String& plain_text, | |
| 170 bool can_smart_copy_or_delete) { | |
| 171 ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); | |
| 172 scw.WriteHTML(webkit_glue::StringToStdWString(html), | |
| 173 #if USE(GOOGLEURL) | |
| 174 webkit_glue::CStringToStdString(url.utf8String())); | |
| 175 #else | |
| 176 webkit_glue::StringToStdString(url.string())); | |
| 177 #endif | |
| 178 scw.WriteText(webkit_glue::StringToStdWString(plain_text)); | |
| 179 | |
| 180 if (can_smart_copy_or_delete) | |
| 181 scw.WriteWebSmartPaste(); | |
| 182 } | |
| 183 | |
| 184 void ChromiumBridge::clipboardWriteURL(const KURL& url, const String& title) { | |
| 185 ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); | |
| 186 | |
| 187 GURL gurl = webkit_glue::KURLToGURL(url); | |
| 188 scw.WriteBookmark(webkit_glue::StringToStdWString(title), gurl.spec()); | |
| 189 | |
| 190 std::wstring link(webkit_glue::StringToStdWString(urlToMarkup(url, title))); | |
| 191 scw.WriteHTML(link, ""); | |
| 192 | |
| 193 scw.WriteText(ASCIIToWide(gurl.spec())); | |
| 194 } | |
| 195 | |
| 196 void ChromiumBridge::clipboardWriteImage(const NativeImageSkia* bitmap, | |
| 197 const KURL& url, const String& title) { | |
| 198 ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); | |
| 199 | |
| 200 #if defined(OS_WIN) | |
| 201 if (bitmap) | |
| 202 scw.WriteBitmap(*bitmap); | |
| 203 #endif | |
| 204 if (!url.isEmpty()) { | |
| 205 GURL gurl = webkit_glue::KURLToGURL(url); | |
| 206 scw.WriteBookmark(webkit_glue::StringToStdWString(title), gurl.spec()); | |
| 207 scw.WriteHTML(UrlToImageMarkup(url, title), ""); | |
| 208 scw.WriteText(ASCIIToWide(gurl.spec())); | |
| 209 } | |
| 210 } | |
| 211 | |
| 212 // Cookies -------------------------------------------------------------------- | 97 // Cookies -------------------------------------------------------------------- |
| 213 | 98 |
| 214 void ChromiumBridge::setCookies( | 99 void ChromiumBridge::setCookies( |
| 215 const KURL& url, const KURL& policy_url, const String& cookie) { | 100 const KURL& url, const KURL& policy_url, const String& cookie) { |
| 216 webkit_glue::SetCookie( | 101 webkit_glue::SetCookie( |
| 217 webkit_glue::KURLToGURL(url), | 102 webkit_glue::KURLToGURL(url), |
| 218 webkit_glue::KURLToGURL(policy_url), | 103 webkit_glue::KURLToGURL(policy_url), |
| 219 webkit_glue::StringToStdString(cookie)); | 104 webkit_glue::StringToStdString(cookie)); |
| 220 } | 105 } |
| 221 | 106 |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 chrome_client->SetCursor(WebCursor(cursor.impl())); | 586 chrome_client->SetCursor(WebCursor(cursor.impl())); |
| 702 } | 587 } |
| 703 | 588 |
| 704 void ChromiumBridge::widgetSetFocus(Widget* widget) { | 589 void ChromiumBridge::widgetSetFocus(Widget* widget) { |
| 705 ChromeClientImpl* chrome_client = ToChromeClient(widget); | 590 ChromeClientImpl* chrome_client = ToChromeClient(widget); |
| 706 if (chrome_client) | 591 if (chrome_client) |
| 707 chrome_client->focus(); | 592 chrome_client->focus(); |
| 708 } | 593 } |
| 709 | 594 |
| 710 } // namespace WebCore | 595 } // namespace WebCore |
| OLD | NEW |