Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Side by Side Diff: webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc

Issue 9921018: Added RTF support to pepper API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/plugins/ppapi/ppb_flash_clipboard_impl.h" 5 #include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "ppapi/c/pp_errors.h" 13 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/c/private/ppb_flash_clipboard.h" 14 #include "ppapi/c/private/ppb_flash_clipboard.h"
15 #include "ppapi/shared_impl/ppapi_globals.h"
15 #include "ppapi/shared_impl/var.h" 16 #include "ppapi/shared_impl/var.h"
17 #include "ppapi/shared_impl/var_tracker.h"
16 #include "webkit/glue/clipboard_client.h" 18 #include "webkit/glue/clipboard_client.h"
17 #include "webkit/glue/scoped_clipboard_writer_glue.h" 19 #include "webkit/glue/scoped_clipboard_writer_glue.h"
18 #include "webkit/plugins/ppapi/common.h" 20 #include "webkit/plugins/ppapi/common.h"
19 #include "webkit/plugins/ppapi/host_globals.h" 21 #include "webkit/plugins/ppapi/host_globals.h"
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
21 23
22 using ppapi::StringVar; 24 using ppapi::StringVar;
23 25
24 namespace webkit { 26 namespace webkit {
25 namespace ppapi { 27 namespace ppapi {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { 87 case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: {
86 bool plain = client_->IsFormatAvailable( 88 bool plain = client_->IsFormatAvailable(
87 ui::Clipboard::GetPlainTextFormatType(), buffer_type); 89 ui::Clipboard::GetPlainTextFormatType(), buffer_type);
88 bool plainw = client_->IsFormatAvailable( 90 bool plainw = client_->IsFormatAvailable(
89 ui::Clipboard::GetPlainTextWFormatType(), buffer_type); 91 ui::Clipboard::GetPlainTextWFormatType(), buffer_type);
90 return BoolToPPBool(plain || plainw); 92 return BoolToPPBool(plain || plainw);
91 } 93 }
92 case PP_FLASH_CLIPBOARD_FORMAT_HTML: 94 case PP_FLASH_CLIPBOARD_FORMAT_HTML:
93 return BoolToPPBool(client_->IsFormatAvailable( 95 return BoolToPPBool(client_->IsFormatAvailable(
94 ui::Clipboard::GetHtmlFormatType(), buffer_type)); 96 ui::Clipboard::GetHtmlFormatType(), buffer_type));
97 case PP_FLASH_CLIPBOARD_FORMAT_RTF:
98 return BoolToPPBool(client_->IsFormatAvailable(
99 ui::Clipboard::GetRtfFormatType(), buffer_type));
95 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: 100 case PP_FLASH_CLIPBOARD_FORMAT_INVALID:
96 break; 101 break;
97 } 102 }
98 103
99 NOTREACHED(); 104 NOTREACHED();
100 return PP_FALSE; 105 return PP_FALSE;
101 } 106 }
102 107
103 PP_Var PPB_Flash_Clipboard_Impl::ReadData( 108 PP_Var PPB_Flash_Clipboard_Impl::ReadData(
104 PP_Instance instance, 109 PP_Instance instance,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 GURL gurl; 148 GURL gurl;
144 uint32 fragment_start; 149 uint32 fragment_start;
145 uint32 fragment_end; 150 uint32 fragment_end;
146 client_->ReadHTML(buffer_type, 151 client_->ReadHTML(buffer_type,
147 &html_stdstr, 152 &html_stdstr,
148 &gurl, 153 &gurl,
149 &fragment_start, 154 &fragment_start,
150 &fragment_end); 155 &fragment_end);
151 return StringVar::StringToPPVar(UTF16ToUTF8(html_stdstr)); 156 return StringVar::StringToPPVar(UTF16ToUTF8(html_stdstr));
152 } 157 }
158 case PP_FLASH_CLIPBOARD_FORMAT_RTF: {
159 std::string result;
160 client_->ReadRTF(buffer_type, &result);
161 return ::ppapi::PpapiGlobals::Get()->GetVarTracker()->
162 MakeArrayBufferPPVar(result.size(), result.data());
163 }
153 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: 164 case PP_FLASH_CLIPBOARD_FORMAT_INVALID:
154 break; 165 break;
155 } 166 }
156 167
157 NOTREACHED(); 168 NOTREACHED();
158 return PP_MakeUndefined(); 169 return PP_MakeUndefined();
159 } 170 }
160 171
161 int32_t PPB_Flash_Clipboard_Impl::WriteDataItem( 172 int32_t PPB_Flash_Clipboard_Impl::WriteDataItem(
162 const PP_Flash_Clipboard_Format format, 173 const PP_Flash_Clipboard_Format format,
(...skipping 15 matching lines...) Expand all
178 StringVar* text_string = StringVar::FromPPVar(data); 189 StringVar* text_string = StringVar::FromPPVar(data);
179 if (!text_string) 190 if (!text_string)
180 return PP_ERROR_BADARGUMENT; 191 return PP_ERROR_BADARGUMENT;
181 192
182 if (text_string->value().length() > kMaxClipboardWriteSize) 193 if (text_string->value().length() > kMaxClipboardWriteSize)
183 return PP_ERROR_NOSPACE; 194 return PP_ERROR_NOSPACE;
184 195
185 scw->WriteHTML(UTF8ToUTF16(text_string->value()), ""); 196 scw->WriteHTML(UTF8ToUTF16(text_string->value()), "");
186 return PP_OK; 197 return PP_OK;
187 } 198 }
199 case PP_FLASH_CLIPBOARD_FORMAT_RTF: {
200 ::ppapi::ArrayBufferVar* rtf_data =
201 ::ppapi::ArrayBufferVar::FromPPVar(data);
202 if (!rtf_data)
203 return PP_ERROR_BADARGUMENT;
204
205 if (rtf_data->ByteLength() > kMaxClipboardWriteSize)
206 return PP_ERROR_NOSPACE;
207
208 scw->WriteRTF(std::string(static_cast<char*>(rtf_data->Map()),
209 rtf_data->ByteLength()));
210 return PP_OK;
211 }
188 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: 212 case PP_FLASH_CLIPBOARD_FORMAT_INVALID:
189 break; 213 break;
190 } 214 }
191 215
192 NOTREACHED(); 216 NOTREACHED();
193 return PP_ERROR_BADARGUMENT; 217 return PP_ERROR_BADARGUMENT;
194 } 218 }
195 219
196 int32_t PPB_Flash_Clipboard_Impl::WriteData( 220 int32_t PPB_Flash_Clipboard_Impl::WriteData(
197 PP_Instance instance, 221 PP_Instance instance,
(...skipping 21 matching lines...) Expand all
219 scw.Reset(); 243 scw.Reset();
220 return res; 244 return res;
221 } 245 }
222 } 246 }
223 247
224 return PP_OK; 248 return PP_OK;
225 } 249 }
226 250
227 } // namespace ppapi 251 } // namespace ppapi
228 } // namespace webkit 252 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698