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

Side by Side Diff: ppapi/cpp/private/flash_clipboard.cc

Issue 9212066: Modified the flash cipboard interface to add html clipboard support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 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 "ppapi/cpp/private/flash_clipboard.h" 5 #include "ppapi/cpp/private/flash_clipboard.h"
6 6
7 #include <vector>
8
7 #include "ppapi/c/pp_bool.h" 9 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/instance.h" 11 #include "ppapi/cpp/instance.h"
12 #include "ppapi/cpp/logging.h"
10 #include "ppapi/cpp/module_impl.h" 13 #include "ppapi/cpp/module_impl.h"
11 #include "ppapi/cpp/var.h" 14 #include "ppapi/cpp/var.h"
12 15
13 namespace pp { 16 namespace pp {
14 17
15 namespace { 18 namespace {
16 19
17 template <> const char* interface_name<PPB_Flash_Clipboard>() { 20 template <> const char* interface_name<PPB_Flash_Clipboard>() {
18 return PPB_FLASH_CLIPBOARD_INTERFACE; 21 return PPB_FLASH_CLIPBOARD_INTERFACE;
19 } 22 }
20 23
24 template <> const char* interface_name<PPB_Flash_Clipboard_3_0>() {
25 return PPB_FLASH_CLIPBOARD_INTERFACE_3_0;
26 }
27
21 } // namespace 28 } // namespace
22 29
23 namespace flash { 30 namespace flash {
24 31
25 // static 32 // static
26 bool Clipboard::IsAvailable() { 33 bool Clipboard::IsAvailable() {
27 return has_interface<PPB_Flash_Clipboard>(); 34 return has_interface<PPB_Flash_Clipboard>();
28 } 35 }
29 36
30 // static 37 // static
31 bool Clipboard::IsFormatAvailable(Instance* instance, 38 bool Clipboard::IsFormatAvailable(Instance* instance,
32 PP_Flash_Clipboard_Type clipboard_type, 39 PP_Flash_Clipboard_Type clipboard_type,
33 PP_Flash_Clipboard_Format format) { 40 PP_Flash_Clipboard_Format format) {
34 bool rv = false; 41 bool rv = false;
35 if (has_interface<PPB_Flash_Clipboard>()) { 42 if (has_interface<PPB_Flash_Clipboard>()) {
36 rv = PP_ToBool(get_interface<PPB_Flash_Clipboard>()->IsFormatAvailable( 43 rv = PP_ToBool(get_interface<PPB_Flash_Clipboard>()->IsFormatAvailable(
37 instance->pp_instance(), clipboard_type, format)); 44 instance->pp_instance(), clipboard_type, format));
38 } 45 }
39 return rv; 46 return rv;
40 } 47 }
41 48
42 // static 49 // static
43 bool Clipboard::ReadPlainText(Instance* instance, 50 bool Clipboard::ReadData(Instance* instance,
viettrungluu 2012/02/08 22:25:01 nit: Move "Instance* instance," to the next line (
raymes 2012/02/09 00:20:27 Done.
44 PP_Flash_Clipboard_Type clipboard_type, 51 PP_Flash_Clipboard_Type clipboard_type,
45 std::string* text_out) { 52 PP_Flash_Clipboard_Format clipboard_format,
46 bool rv = false; 53 PP_Var* out) {
47 if (has_interface<PPB_Flash_Clipboard>()) { 54 if (has_interface<PPB_Flash_Clipboard>() ||
viettrungluu 2012/02/08 22:25:01 This function is just wrong. I'd prefer, in any c
raymes 2012/02/09 00:20:27 Umm yes...don't know what I was thinking when I ch
48 Var v(Var::PassRef(), 55 (has_interface<PPB_Flash_Clipboard_3_0>() &&
49 get_interface<PPB_Flash_Clipboard>()->ReadPlainText( 56 clipboard_format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT)) {
50 instance->pp_instance(), 57 bool rv = false;
51 clipboard_type)); 58 if (has_interface<PPB_Flash_Clipboard>()) {
52 if (v.is_string()) { 59 *out = get_interface<PPB_Flash_Clipboard>()->ReadData(
53 rv = true; 60 instance->pp_instance(),
54 *text_out = v.AsString(); 61 clipboard_type,
62 clipboard_format);
55 } 63 }
64 return rv;
56 } 65 }
57 return rv; 66 else {
67 return false;
68 }
58 } 69 }
59 70
60 // static 71 // static
61 bool Clipboard::WritePlainText(Instance* instance, 72 bool Clipboard::WriteData(Instance* instance,
62 PP_Flash_Clipboard_Type clipboard_type, 73 PP_Flash_Clipboard_Type clipboard_type,
63 const std::string& text) { 74 const std::vector<PP_Flash_Clipboard_Data_Item>& data_items) {
64 bool rv = false; 75 if (has_interface<PPB_Flash_Clipboard>() ||
viettrungluu 2012/02/08 22:25:01 Again, I'd prefer the above completed-separated wa
raymes 2012/02/09 00:20:27 Done.
65 if (has_interface<PPB_Flash_Clipboard>()) { 76 has_interface<PPB_Flash_Clipboard_3_0>()) {
66 rv = (get_interface<PPB_Flash_Clipboard>()->WritePlainText( 77 bool rv = false;
78 PP_Flash_Clipboard_Data_Item* data_items_array =
79 new PP_Flash_Clipboard_Data_Item[data_items.size()];
80
81 uint32_t data_items_array_size = 0;
82 for (std::vector<PP_Flash_Clipboard_Data_Item>::const_iterator
83 i = data_items.begin(); i != data_items.end(); ++i) {
84 if (has_interface<PPB_Flash_Clipboard_3_0>() &&
85 i->format != PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) {
86 continue;
87 }
88
89 data_items_array[data_items_array_size] = *i;
90 ++data_items_array_size;
91 }
92
93 rv = (get_interface<PPB_Flash_Clipboard>()->WriteData(
viettrungluu 2012/02/08 22:25:01 E.g., you'd need to use PPB_Flash_Clipboard_3_0 fo
raymes 2012/02/09 00:20:27 Done.
67 instance->pp_instance(), 94 instance->pp_instance(),
68 clipboard_type, 95 clipboard_type,
69 Var(text).pp_var()) == PP_OK); 96 data_items_array_size,
97 data_items_array) == PP_OK);
98 delete[] data_items_array;
99 return rv;
70 } 100 }
71 return rv; 101 else {
102 return false;
103 }
72 } 104 }
73 105
74 } // namespace flash 106 } // namespace flash
75 } // namespace pp 107 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698