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

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"
10 #include "ppapi/cpp/module_impl.h" 12 #include "ppapi/cpp/module_impl.h"
11 #include "ppapi/cpp/var.h" 13 #include "ppapi/cpp/var.h"
12 14
13 namespace pp { 15 namespace pp {
14 16
15 namespace { 17 namespace {
16 18
17 template <> const char* interface_name<PPB_Flash_Clipboard>() { 19 template <> const char* interface_name<PPB_Flash_Clipboard>() {
18 return PPB_FLASH_CLIPBOARD_INTERFACE; 20 return PPB_FLASH_CLIPBOARD_INTERFACE;
19 } 21 }
20 22
23 template <> const char* interface_name<PPB_Flash_Clipboard_3_0>() {
24 return PPB_FLASH_CLIPBOARD_INTERFACE_3_0;
25 }
26
21 } // namespace 27 } // namespace
22 28
23 namespace flash { 29 namespace flash {
24 30
25 // static 31 // static
26 bool Clipboard::IsAvailable() { 32 bool Clipboard::IsAvailable() {
27 return has_interface<PPB_Flash_Clipboard>(); 33 return has_interface<PPB_Flash_Clipboard>() ||
34 has_interface<PPB_Flash_Clipboard_3_0>();
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(
44 PP_Flash_Clipboard_Type clipboard_type, 51 Instance* instance,
dmichael (off chromium) 2012/02/23 18:13:25 brettw's been working on a change to replace Insta
raymes 2012/02/24 07:28:28 Ok On 2012/02/23 18:13:25, dmichael wrote:
45 std::string* text_out) { 52 PP_Flash_Clipboard_Type clipboard_type,
53 PP_Flash_Clipboard_Format clipboard_format,
54 PP_Var* out) {
46 bool rv = false; 55 bool rv = false;
47 if (has_interface<PPB_Flash_Clipboard>()) { 56 if (has_interface<PPB_Flash_Clipboard>()) {
48 Var v(Var::PassRef(), 57 *out = get_interface<PPB_Flash_Clipboard>()->ReadData(
49 get_interface<PPB_Flash_Clipboard>()->ReadPlainText( 58 instance->pp_instance(),
50 instance->pp_instance(), 59 clipboard_type,
51 clipboard_type)); 60 clipboard_format);
52 if (v.is_string()) { 61 rv = true;
53 rv = true; 62 } else if (has_interface<PPB_Flash_Clipboard_3_0>() &&
54 *text_out = v.AsString(); 63 clipboard_format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) {
55 } 64 *out = get_interface<PPB_Flash_Clipboard_3_0>()->ReadPlainText(
65 instance->pp_instance(),
66 clipboard_type);
dmichael (off chromium) 2012/02/23 18:13:25 Do you really need backwards compatibility here? T
raymes 2012/02/24 07:28:28 Spoke to vtl and he says that the backward compat
dmichael (off chromium) 2012/02/24 19:35:44 Okay, vtl understands what you need for Flash more
raymes 2012/02/24 21:38:17 According to vtl, both are needed. On 2012/02/24 1
67 rv = true;
56 } 68 }
57 return rv; 69 return rv;
58 } 70 }
59 71
60 // static 72 // static
61 bool Clipboard::WritePlainText(Instance* instance, 73 bool Clipboard::WriteData(
62 PP_Flash_Clipboard_Type clipboard_type, 74 Instance* instance,
63 const std::string& text) { 75 PP_Flash_Clipboard_Type clipboard_type,
76 const std::vector<PP_Flash_Clipboard_Data_Item>& data_items) {
64 bool rv = false; 77 bool rv = false;
78
65 if (has_interface<PPB_Flash_Clipboard>()) { 79 if (has_interface<PPB_Flash_Clipboard>()) {
66 rv = (get_interface<PPB_Flash_Clipboard>()->WritePlainText( 80 new PP_Flash_Clipboard_Data_Item[data_items.size()];
dmichael (off chromium) 2012/02/23 18:13:25 What is this line doing? Looks like a blatant leak
raymes 2012/02/24 07:28:28 =( undeleted line from an older patchset. Good cat
67 instance->pp_instance(), 81 rv = (get_interface<PPB_Flash_Clipboard>()->WriteData(
68 clipboard_type, 82 instance->pp_instance(),
69 Var(text).pp_var()) == PP_OK); 83 clipboard_type,
84 data_items.size(),
85 &data_items[0]) == PP_OK);
dmichael (off chromium) 2012/02/23 18:13:25 probably best to return early if data_items.empty(
raymes 2012/02/24 07:28:28 Done.
86 } else if (has_interface<PPB_Flash_Clipboard_3_0>()) {
87 // Take the last plaintext item and write it according to the API.
dmichael (off chromium) 2012/02/23 18:13:25 I think this backwards-compat part should probably
raymes 2012/02/24 07:28:28 The backward compat code is apparently necessary.
dmichael (off chromium) 2012/02/24 19:35:44 It might be that I don't understand how the clipbo
raymes 2012/02/24 21:38:17 Ah I see what you're saying. The thing is that eac
dmichael (off chromium) 2012/02/24 21:49:36 That makes sense, thanks for explaining. I think a
88 for (std::vector<PP_Flash_Clipboard_Data_Item>::const_reverse_iterator
89 i = data_items.rbegin(); i != data_items.rend(); ++i) {
90 if (i->format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) {
91 rv = (get_interface<PPB_Flash_Clipboard_3_0>()->WritePlainText(
92 instance->pp_instance(),
93 clipboard_type,
94 i->data) == PP_OK);
95 break;
96 }
97 }
70 } 98 }
99
71 return rv; 100 return rv;
72 } 101 }
73 102
74 } // namespace flash 103 } // namespace flash
75 } // namespace pp 104 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698