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

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

Issue 10787039: PPAPI Flash: Remove support for PPB_Flash 12.0-12.2 and PPB_Flash_Clipboard 3.0 from C++ wrappers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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
« no previous file with comments | « ppapi/cpp/private/flash.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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> 7 #include <vector>
8 8
9 #include "ppapi/c/pp_bool.h" 9 #include "ppapi/c/pp_bool.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/cpp/instance_handle.h" 11 #include "ppapi/cpp/instance_handle.h"
12 #include "ppapi/cpp/module_impl.h" 12 #include "ppapi/cpp/module_impl.h"
13 #include "ppapi/cpp/var.h" 13 #include "ppapi/cpp/var.h"
14 14
15 namespace pp { 15 namespace pp {
16 16
17 namespace { 17 namespace {
18 18
19 template <> const char* interface_name<PPB_Flash_Clipboard>() { 19 template <> const char* interface_name<PPB_Flash_Clipboard_4_0>() {
20 return PPB_FLASH_CLIPBOARD_INTERFACE; 20 return PPB_FLASH_CLIPBOARD_INTERFACE_4_0;
21 }
22
23 template <> const char* interface_name<PPB_Flash_Clipboard_3_0>() {
24 return PPB_FLASH_CLIPBOARD_INTERFACE_3_0;
25 } 21 }
26 22
27 } // namespace 23 } // namespace
28 24
29 namespace flash { 25 namespace flash {
30 26
31 // static 27 // static
32 bool Clipboard::IsAvailable() { 28 bool Clipboard::IsAvailable() {
33 return has_interface<PPB_Flash_Clipboard>() || 29 return has_interface<PPB_Flash_Clipboard_4_0>();
34 has_interface<PPB_Flash_Clipboard_3_0>();
35 } 30 }
36 31
37 // static 32 // static
38 bool Clipboard::IsFormatAvailable(const InstanceHandle& instance, 33 bool Clipboard::IsFormatAvailable(const InstanceHandle& instance,
39 PP_Flash_Clipboard_Type clipboard_type, 34 PP_Flash_Clipboard_Type clipboard_type,
40 PP_Flash_Clipboard_Format format) { 35 PP_Flash_Clipboard_Format format) {
41 bool rv = false; 36 bool rv = false;
42 if (has_interface<PPB_Flash_Clipboard>()) { 37 if (has_interface<PPB_Flash_Clipboard_4_0>()) {
43 rv = PP_ToBool(get_interface<PPB_Flash_Clipboard>()->IsFormatAvailable( 38 rv = PP_ToBool(get_interface<PPB_Flash_Clipboard_4_0>()->IsFormatAvailable(
44 instance.pp_instance(), clipboard_type, format)); 39 instance.pp_instance(), clipboard_type, format));
45 } 40 }
46 return rv; 41 return rv;
47 } 42 }
48 43
49 // static 44 // static
50 bool Clipboard::ReadData( 45 bool Clipboard::ReadData(
51 const InstanceHandle& instance, 46 const InstanceHandle& instance,
52 PP_Flash_Clipboard_Type clipboard_type, 47 PP_Flash_Clipboard_Type clipboard_type,
53 PP_Flash_Clipboard_Format clipboard_format, 48 PP_Flash_Clipboard_Format clipboard_format,
54 Var* out) { 49 Var* out) {
55 bool rv = false; 50 bool rv = false;
56 if (has_interface<PPB_Flash_Clipboard>()) { 51 if (has_interface<PPB_Flash_Clipboard_4_0>()) {
57 PP_Var result = get_interface<PPB_Flash_Clipboard>()->ReadData( 52 PP_Var result = get_interface<PPB_Flash_Clipboard_4_0>()->ReadData(
58 instance.pp_instance(), 53 instance.pp_instance(),
59 clipboard_type, 54 clipboard_type,
60 clipboard_format); 55 clipboard_format);
61 *out = Var(PASS_REF, result); 56 *out = Var(PASS_REF, result);
62 rv = true; 57 rv = true;
63 } else if (has_interface<PPB_Flash_Clipboard_3_0>() &&
64 clipboard_format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) {
65 PP_Var result = get_interface<PPB_Flash_Clipboard_3_0>()->ReadPlainText(
66 instance.pp_instance(),
67 clipboard_type);
68 *out = Var(PASS_REF, result);
69 rv = true;
70 } 58 }
71 return rv; 59 return rv;
72 } 60 }
73 61
74 // static 62 // static
75 bool Clipboard::WriteData( 63 bool Clipboard::WriteData(
76 const InstanceHandle& instance, 64 const InstanceHandle& instance,
77 PP_Flash_Clipboard_Type clipboard_type, 65 PP_Flash_Clipboard_Type clipboard_type,
78 const std::vector<PP_Flash_Clipboard_Format>& formats, 66 const std::vector<PP_Flash_Clipboard_Format>& formats,
79 const std::vector<Var>& data_items) { 67 const std::vector<Var>& data_items) {
80 if (formats.size() != data_items.size()) 68 if (formats.size() != data_items.size())
81 return false; 69 return false;
82 70
83 bool rv = false; 71 bool rv = false;
84 if (has_interface<PPB_Flash_Clipboard>()) { 72 if (has_interface<PPB_Flash_Clipboard_4_0>()) {
85 // Convert vector of pp::Var into a vector of PP_Var. 73 // Convert vector of pp::Var into a vector of PP_Var.
86 std::vector<PP_Var> data_items_vector; 74 std::vector<PP_Var> data_items_vector;
87 for (uint32_t i = 0; i < data_items.size(); ++i) 75 for (uint32_t i = 0; i < data_items.size(); ++i)
88 data_items_vector.push_back(data_items[i].pp_var()); 76 data_items_vector.push_back(data_items[i].pp_var());
89 77
90 // Ensure that we don't dereference the memory in empty vectors. We still 78 // Ensure that we don't dereference the memory in empty vectors. We still
91 // want to call WriteData because it has the effect of clearing the 79 // want to call WriteData because it has the effect of clearing the
92 // clipboard. 80 // clipboard.
93 const PP_Flash_Clipboard_Format* formats_ptr(NULL); 81 const PP_Flash_Clipboard_Format* formats_ptr(NULL);
94 const PP_Var* data_items_ptr(NULL); 82 const PP_Var* data_items_ptr(NULL);
95 if (data_items.size() > 0) { 83 if (data_items.size() > 0) {
96 formats_ptr = &formats[0]; 84 formats_ptr = &formats[0];
97 data_items_ptr = &data_items_vector[0]; 85 data_items_ptr = &data_items_vector[0];
98 } 86 }
99 87
100 rv = (get_interface<PPB_Flash_Clipboard>()->WriteData( 88 rv = (get_interface<PPB_Flash_Clipboard_4_0>()->WriteData(
101 instance.pp_instance(), 89 instance.pp_instance(),
102 clipboard_type, 90 clipboard_type,
103 data_items.size(), 91 data_items.size(),
104 formats_ptr, 92 formats_ptr,
105 data_items_ptr) == PP_OK); 93 data_items_ptr) == PP_OK);
106 } else if (has_interface<PPB_Flash_Clipboard_3_0>()) {
107 // The API specifies that only the last item of each format needs to be
108 // written. Since we are only writing plain text items for the 3_0
109 // interface, we just need to write the last one in the array.
110 for (int32_t i = formats.size() - 1; i >= 0; --i) {
111 if (formats[i] == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) {
112 rv = (get_interface<PPB_Flash_Clipboard_3_0>()->WritePlainText(
113 instance.pp_instance(),
114 clipboard_type,
115 data_items[i].pp_var()) == PP_OK);
116 break;
117 }
118 }
119 } 94 }
120 95
121 return rv; 96 return rv;
122 } 97 }
123 98
124 } // namespace flash 99 } // namespace flash
125 } // namespace pp 100 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/private/flash.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698