| OLD | NEW |
| 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 Loading... |
| 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(); | |
| 100 return PP_FALSE; | 104 return PP_FALSE; |
| 101 } | 105 } |
| 102 | 106 |
| 103 PP_Var PPB_Flash_Clipboard_Impl::ReadData( | 107 PP_Var PPB_Flash_Clipboard_Impl::ReadData( |
| 104 PP_Instance instance, | 108 PP_Instance instance, |
| 105 PP_Flash_Clipboard_Type clipboard_type, | 109 PP_Flash_Clipboard_Type clipboard_type, |
| 106 PP_Flash_Clipboard_Format format) { | 110 PP_Flash_Clipboard_Format format) { |
| 107 if (!Init()) | 111 if (!Init()) |
| 108 return PP_MakeUndefined(); | 112 return PP_MakeUndefined(); |
| 109 | 113 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 GURL gurl; | 147 GURL gurl; |
| 144 uint32 fragment_start; | 148 uint32 fragment_start; |
| 145 uint32 fragment_end; | 149 uint32 fragment_end; |
| 146 client_->ReadHTML(buffer_type, | 150 client_->ReadHTML(buffer_type, |
| 147 &html_stdstr, | 151 &html_stdstr, |
| 148 &gurl, | 152 &gurl, |
| 149 &fragment_start, | 153 &fragment_start, |
| 150 &fragment_end); | 154 &fragment_end); |
| 151 return StringVar::StringToPPVar(UTF16ToUTF8(html_stdstr)); | 155 return StringVar::StringToPPVar(UTF16ToUTF8(html_stdstr)); |
| 152 } | 156 } |
| 157 case PP_FLASH_CLIPBOARD_FORMAT_RTF: { |
| 158 std::string result; |
| 159 client_->ReadRTF(buffer_type, &result); |
| 160 return ::ppapi::PpapiGlobals::Get()->GetVarTracker()-> |
| 161 MakeArrayBufferPPVar(result.size(), result.data()); |
| 162 } |
| 153 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: | 163 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: |
| 154 break; | 164 break; |
| 155 } | 165 } |
| 156 | 166 |
| 157 NOTREACHED(); | |
| 158 return PP_MakeUndefined(); | 167 return PP_MakeUndefined(); |
| 159 } | 168 } |
| 160 | 169 |
| 161 int32_t PPB_Flash_Clipboard_Impl::WriteDataItem( | 170 int32_t PPB_Flash_Clipboard_Impl::WriteDataItem( |
| 162 const PP_Flash_Clipboard_Format format, | 171 const PP_Flash_Clipboard_Format format, |
| 163 const PP_Var& data, | 172 const PP_Var& data, |
| 164 ScopedClipboardWriterGlue* scw) { | 173 ScopedClipboardWriterGlue* scw) { |
| 165 switch (format) { | 174 switch (format) { |
| 166 case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { | 175 case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { |
| 167 StringVar* text_string = StringVar::FromPPVar(data); | 176 StringVar* text_string = StringVar::FromPPVar(data); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 178 StringVar* text_string = StringVar::FromPPVar(data); | 187 StringVar* text_string = StringVar::FromPPVar(data); |
| 179 if (!text_string) | 188 if (!text_string) |
| 180 return PP_ERROR_BADARGUMENT; | 189 return PP_ERROR_BADARGUMENT; |
| 181 | 190 |
| 182 if (text_string->value().length() > kMaxClipboardWriteSize) | 191 if (text_string->value().length() > kMaxClipboardWriteSize) |
| 183 return PP_ERROR_NOSPACE; | 192 return PP_ERROR_NOSPACE; |
| 184 | 193 |
| 185 scw->WriteHTML(UTF8ToUTF16(text_string->value()), ""); | 194 scw->WriteHTML(UTF8ToUTF16(text_string->value()), ""); |
| 186 return PP_OK; | 195 return PP_OK; |
| 187 } | 196 } |
| 197 case PP_FLASH_CLIPBOARD_FORMAT_RTF: { |
| 198 ::ppapi::ArrayBufferVar* rtf_data = |
| 199 ::ppapi::ArrayBufferVar::FromPPVar(data); |
| 200 if (!rtf_data) |
| 201 return PP_ERROR_BADARGUMENT; |
| 202 |
| 203 if (rtf_data->ByteLength() > kMaxClipboardWriteSize) |
| 204 return PP_ERROR_NOSPACE; |
| 205 |
| 206 scw->WriteRTF(std::string(static_cast<char*>(rtf_data->Map()), |
| 207 rtf_data->ByteLength())); |
| 208 return PP_OK; |
| 209 } |
| 188 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: | 210 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: |
| 189 break; | 211 break; |
| 190 } | 212 } |
| 191 | 213 |
| 192 NOTREACHED(); | |
| 193 return PP_ERROR_BADARGUMENT; | 214 return PP_ERROR_BADARGUMENT; |
| 194 } | 215 } |
| 195 | 216 |
| 196 int32_t PPB_Flash_Clipboard_Impl::WriteData( | 217 int32_t PPB_Flash_Clipboard_Impl::WriteData( |
| 197 PP_Instance instance, | 218 PP_Instance instance, |
| 198 PP_Flash_Clipboard_Type clipboard_type, | 219 PP_Flash_Clipboard_Type clipboard_type, |
| 199 uint32_t data_item_count, | 220 uint32_t data_item_count, |
| 200 const PP_Flash_Clipboard_Format formats[], | 221 const PP_Flash_Clipboard_Format formats[], |
| 201 const PP_Var data_items[]) { | 222 const PP_Var data_items[]) { |
| 202 if (!Init()) | 223 if (!Init()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 219 scw.Reset(); | 240 scw.Reset(); |
| 220 return res; | 241 return res; |
| 221 } | 242 } |
| 222 } | 243 } |
| 223 | 244 |
| 224 return PP_OK; | 245 return PP_OK; |
| 225 } | 246 } |
| 226 | 247 |
| 227 } // namespace ppapi | 248 } // namespace ppapi |
| 228 } // namespace webkit | 249 } // namespace webkit |
| OLD | NEW |