OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/glue/webclipboard_impl.h" | 5 #include "webkit/glue/webclipboard_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 markup.append("\""); | 53 markup.append("\""); |
54 if (!title.isEmpty()) { | 54 if (!title.isEmpty()) { |
55 markup.append(" alt=\""); | 55 markup.append(" alt=\""); |
56 markup.append(net::EscapeForHTML(UTF16ToUTF8(title))); | 56 markup.append(net::EscapeForHTML(UTF16ToUTF8(title))); |
57 markup.append("\""); | 57 markup.append("\""); |
58 } | 58 } |
59 markup.append("/>"); | 59 markup.append("/>"); |
60 return markup; | 60 return markup; |
61 } | 61 } |
62 | 62 |
| 63 WebClipboardImpl::WebClipboardImpl(ClipboardClient* client) |
| 64 : client_(client) { |
| 65 } |
| 66 |
63 WebClipboardImpl::~WebClipboardImpl() { | 67 WebClipboardImpl::~WebClipboardImpl() { |
64 } | 68 } |
65 | 69 |
66 uint64 WebClipboardImpl::getSequenceNumber() { | 70 uint64 WebClipboardImpl::getSequenceNumber() { |
67 return sequenceNumber(BufferStandard); | 71 return sequenceNumber(BufferStandard); |
68 } | 72 } |
69 | 73 |
70 uint64 WebClipboardImpl::sequenceNumber(Buffer buffer) { | 74 uint64 WebClipboardImpl::sequenceNumber(Buffer buffer) { |
71 ui::Clipboard::Buffer buffer_type; | 75 ui::Clipboard::Buffer buffer_type; |
72 if (!ConvertBufferType(buffer, &buffer_type)) | 76 if (!ConvertBufferType(buffer, &buffer_type)) |
73 return 0; | 77 return 0; |
74 | 78 |
75 return ClipboardGetSequenceNumber(buffer_type); | 79 return client_->GetSequenceNumber(buffer_type); |
76 } | 80 } |
77 | 81 |
78 bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { | 82 bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { |
79 ui::Clipboard::FormatType format_type; | 83 ui::Clipboard::FormatType format_type; |
80 ui::Clipboard::Buffer buffer_type; | 84 ui::Clipboard::Buffer buffer_type; |
81 | 85 |
82 if (!ConvertBufferType(buffer, &buffer_type)) | 86 if (!ConvertBufferType(buffer, &buffer_type)) |
83 return false; | 87 return false; |
84 | 88 |
85 switch (format) { | 89 switch (format) { |
86 case FormatPlainText: | 90 case FormatPlainText: |
87 return ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), | 91 return client_->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), |
88 buffer_type) || | 92 buffer_type) || |
89 ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), | 93 client_->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), |
90 buffer_type); | 94 buffer_type); |
91 case FormatHTML: | 95 case FormatHTML: |
92 format_type = ui::Clipboard::GetHtmlFormatType(); | 96 format_type = ui::Clipboard::GetHtmlFormatType(); |
93 break; | 97 break; |
94 case FormatSmartPaste: | 98 case FormatSmartPaste: |
95 format_type = ui::Clipboard::GetWebKitSmartPasteFormatType(); | 99 format_type = ui::Clipboard::GetWebKitSmartPasteFormatType(); |
96 break; | 100 break; |
97 case FormatBookmark: | 101 case FormatBookmark: |
98 #if defined(OS_WIN) || defined(OS_MACOSX) | 102 #if defined(OS_WIN) || defined(OS_MACOSX) |
99 format_type = ui::Clipboard::GetUrlWFormatType(); | 103 format_type = ui::Clipboard::GetUrlWFormatType(); |
100 break; | 104 break; |
101 #endif | 105 #endif |
102 default: | 106 default: |
103 NOTREACHED(); | 107 NOTREACHED(); |
104 return false; | 108 return false; |
105 } | 109 } |
106 | 110 |
107 return ClipboardIsFormatAvailable(format_type, buffer_type); | 111 return client_->IsFormatAvailable(format_type, buffer_type); |
108 } | 112 } |
109 | 113 |
110 WebVector<WebString> WebClipboardImpl::readAvailableTypes( | 114 WebVector<WebString> WebClipboardImpl::readAvailableTypes( |
111 Buffer buffer, bool* contains_filenames) { | 115 Buffer buffer, bool* contains_filenames) { |
112 ui::Clipboard::Buffer buffer_type; | 116 ui::Clipboard::Buffer buffer_type; |
113 std::vector<string16> types; | 117 std::vector<string16> types; |
114 if (ConvertBufferType(buffer, &buffer_type)) { | 118 if (ConvertBufferType(buffer, &buffer_type)) { |
115 ClipboardReadAvailableTypes(buffer_type, &types, contains_filenames); | 119 client_->ReadAvailableTypes(buffer_type, &types, contains_filenames); |
116 } | 120 } |
117 return types; | 121 return types; |
118 } | 122 } |
119 | 123 |
120 WebString WebClipboardImpl::readPlainText(Buffer buffer) { | 124 WebString WebClipboardImpl::readPlainText(Buffer buffer) { |
121 ui::Clipboard::Buffer buffer_type; | 125 ui::Clipboard::Buffer buffer_type; |
122 if (!ConvertBufferType(buffer, &buffer_type)) | 126 if (!ConvertBufferType(buffer, &buffer_type)) |
123 return WebString(); | 127 return WebString(); |
124 | 128 |
125 if (ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), | 129 if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), |
126 buffer_type)) { | 130 buffer_type)) { |
127 string16 text; | 131 string16 text; |
128 ClipboardReadText(buffer_type, &text); | 132 client_->ReadText(buffer_type, &text); |
129 if (!text.empty()) | 133 if (!text.empty()) |
130 return text; | 134 return text; |
131 } | 135 } |
132 | 136 |
133 if (ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), | 137 if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), |
134 buffer_type)) { | 138 buffer_type)) { |
135 std::string text; | 139 std::string text; |
136 ClipboardReadAsciiText(buffer_type, &text); | 140 client_->ReadAsciiText(buffer_type, &text); |
137 if (!text.empty()) | 141 if (!text.empty()) |
138 return ASCIIToUTF16(text); | 142 return ASCIIToUTF16(text); |
139 } | 143 } |
140 | 144 |
141 return WebString(); | 145 return WebString(); |
142 } | 146 } |
143 | 147 |
144 WebString WebClipboardImpl::readHTML(Buffer buffer, WebURL* source_url, | 148 WebString WebClipboardImpl::readHTML(Buffer buffer, WebURL* source_url, |
145 unsigned* fragment_start, | 149 unsigned* fragment_start, |
146 unsigned* fragment_end) { | 150 unsigned* fragment_end) { |
147 ui::Clipboard::Buffer buffer_type; | 151 ui::Clipboard::Buffer buffer_type; |
148 if (!ConvertBufferType(buffer, &buffer_type)) | 152 if (!ConvertBufferType(buffer, &buffer_type)) |
149 return WebString(); | 153 return WebString(); |
150 | 154 |
151 string16 html_stdstr; | 155 string16 html_stdstr; |
152 GURL gurl; | 156 GURL gurl; |
153 ClipboardReadHTML(buffer_type, &html_stdstr, &gurl, | 157 client_->ReadHTML(buffer_type, &html_stdstr, &gurl, |
154 static_cast<uint32*>(fragment_start), | 158 static_cast<uint32*>(fragment_start), |
155 static_cast<uint32*>(fragment_end)); | 159 static_cast<uint32*>(fragment_end)); |
156 *source_url = gurl; | 160 *source_url = gurl; |
157 return html_stdstr; | 161 return html_stdstr; |
158 } | 162 } |
159 | 163 |
160 WebData WebClipboardImpl::readImage(Buffer buffer) { | 164 WebData WebClipboardImpl::readImage(Buffer buffer) { |
161 ui::Clipboard::Buffer buffer_type; | 165 ui::Clipboard::Buffer buffer_type; |
162 if (!ConvertBufferType(buffer, &buffer_type)) | 166 if (!ConvertBufferType(buffer, &buffer_type)) |
163 return WebData(); | 167 return WebData(); |
164 | 168 |
165 std::string png_data; | 169 std::string png_data; |
166 ClipboardReadImage(buffer_type, &png_data); | 170 client_->ReadImage(buffer_type, &png_data); |
167 return WebData(png_data); | 171 return WebData(png_data); |
168 } | 172 } |
169 | 173 |
170 void WebClipboardImpl::writeHTML( | 174 void WebClipboardImpl::writeHTML( |
171 const WebString& html_text, const WebURL& source_url, | 175 const WebString& html_text, const WebURL& source_url, |
172 const WebString& plain_text, bool write_smart_paste) { | 176 const WebString& plain_text, bool write_smart_paste) { |
173 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); | 177 ScopedClipboardWriterGlue scw(client_); |
174 scw.WriteHTML(html_text, source_url.spec()); | 178 scw.WriteHTML(html_text, source_url.spec()); |
175 scw.WriteText(plain_text); | 179 scw.WriteText(plain_text); |
176 | 180 |
177 if (write_smart_paste) | 181 if (write_smart_paste) |
178 scw.WriteWebSmartPaste(); | 182 scw.WriteWebSmartPaste(); |
179 } | 183 } |
180 | 184 |
181 void WebClipboardImpl::writePlainText(const WebString& plain_text) { | 185 void WebClipboardImpl::writePlainText(const WebString& plain_text) { |
182 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); | 186 ScopedClipboardWriterGlue scw(client_); |
183 scw.WriteText(plain_text); | 187 scw.WriteText(plain_text); |
184 } | 188 } |
185 | 189 |
186 void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { | 190 void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { |
187 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); | 191 ScopedClipboardWriterGlue scw(client_); |
188 | 192 |
189 scw.WriteBookmark(title, url.spec()); | 193 scw.WriteBookmark(title, url.spec()); |
190 scw.WriteHTML(UTF8ToUTF16(URLToMarkup(url, title)), ""); | 194 scw.WriteHTML(UTF8ToUTF16(URLToMarkup(url, title)), ""); |
191 scw.WriteText(UTF8ToUTF16(std::string(url.spec()))); | 195 scw.WriteText(UTF8ToUTF16(std::string(url.spec()))); |
192 } | 196 } |
193 | 197 |
194 void WebClipboardImpl::writeImage( | 198 void WebClipboardImpl::writeImage( |
195 const WebImage& image, const WebURL& url, const WebString& title) { | 199 const WebImage& image, const WebURL& url, const WebString& title) { |
196 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); | 200 ScopedClipboardWriterGlue scw(client_); |
197 | 201 |
198 if (!image.isNull()) { | 202 if (!image.isNull()) { |
199 #if WEBKIT_USING_SKIA | 203 #if WEBKIT_USING_SKIA |
200 const SkBitmap& bitmap = image.getSkBitmap(); | 204 const SkBitmap& bitmap = image.getSkBitmap(); |
201 #elif WEBKIT_USING_CG | 205 #elif WEBKIT_USING_CG |
202 const SkBitmap& bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef()); | 206 const SkBitmap& bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef()); |
203 #endif | 207 #endif |
204 SkAutoLockPixels locked(bitmap); | 208 SkAutoLockPixels locked(bitmap); |
205 scw.WriteBitmapFromPixels(bitmap.getPixels(), image.size()); | 209 scw.WriteBitmapFromPixels(bitmap.getPixels(), image.size()); |
206 } | 210 } |
(...skipping 25 matching lines...) Expand all Loading... |
232 break; | 236 break; |
233 #endif | 237 #endif |
234 default: | 238 default: |
235 NOTREACHED(); | 239 NOTREACHED(); |
236 return false; | 240 return false; |
237 } | 241 } |
238 return true; | 242 return true; |
239 } | 243 } |
240 | 244 |
241 } // namespace webkit_glue | 245 } // namespace webkit_glue |
OLD | NEW |