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

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 "ppapi/c/pp_bool.h" 7 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/instance.h" 9 #include "ppapi/cpp/instance.h"
10 #include "ppapi/cpp/logging.h"
10 #include "ppapi/cpp/module_impl.h" 11 #include "ppapi/cpp/module_impl.h"
11 #include "ppapi/cpp/var.h" 12 #include "ppapi/cpp/var.h"
12 13
13 namespace pp { 14 namespace pp {
14 15
15 namespace { 16 namespace {
16 17
17 template <> const char* interface_name<PPB_Flash_Clipboard>() { 18 template <> const char* interface_name<PPB_Flash_Clipboard>() {
18 return PPB_FLASH_CLIPBOARD_INTERFACE; 19 return PPB_FLASH_CLIPBOARD_INTERFACE;
viettrungluu 2012/02/06 21:29:29 For ease of updating Flapper (in conjunction with
raymes 2012/02/07 00:02:25 Done.
19 } 20 }
20 21
21 } // namespace 22 } // namespace
22 23
23 namespace flash { 24 namespace flash {
24 25
26 void ClipboardData::SetPlainText(const std::string& text) {
27 SetTextVar(text, PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT);
28 }
29
30 void ClipboardData::SetHTML(const std::string& html) {
31 SetTextVar(html, PP_FLASH_CLIPBOARD_FORMAT_HTML);
32 }
33
34 void ClipboardData::SetTextVar(const std::string& text,
35 PP_Flash_Clipboard_Format format) {
36 uint32_t index = GetFormatIndex(format);
37 data_items_[index].format = format;
38 data_items_[index].data = Var(text).pp_var();
39 }
40
41 uint32_t ClipboardData::GetFormatIndex(PP_Flash_Clipboard_Format format) {
42 for (uint32_t i = 0; i < data_item_count_; ++i) {
43 if (data_items_[i].format == format) {
44 return i;
45 }
46 }
47 uint32_t index = data_item_count_;
48 ++data_item_count_;
49 PP_DCHECK(index <= ClipboardData::kMaxFormats);
50 return index;
51 }
52
53 void ClipboardData::Clear() {
54 data_item_count_ = 0;
55 }
56
57 PP_Flash_Clipboard_Data_Item const*
58 ClipboardData::GetDataItems(uint32_t* data_item_count_out) const {
59 *data_item_count_out = data_item_count_;
60 return data_items_;
61 }
62
25 // static 63 // static
26 bool Clipboard::IsAvailable() { 64 bool Clipboard::IsAvailable() {
27 return has_interface<PPB_Flash_Clipboard>(); 65 return has_interface<PPB_Flash_Clipboard>();
28 } 66 }
29 67
30 // static 68 // static
31 bool Clipboard::IsFormatAvailable(Instance* instance, 69 bool Clipboard::IsFormatAvailable(Instance* instance,
32 PP_Flash_Clipboard_Type clipboard_type, 70 PP_Flash_Clipboard_Type clipboard_type,
33 PP_Flash_Clipboard_Format format) { 71 PP_Flash_Clipboard_Format format) {
34 bool rv = false; 72 bool rv = false;
35 if (has_interface<PPB_Flash_Clipboard>()) { 73 if (has_interface<PPB_Flash_Clipboard>()) {
36 rv = PP_ToBool(get_interface<PPB_Flash_Clipboard>()->IsFormatAvailable( 74 rv = PP_ToBool(get_interface<PPB_Flash_Clipboard>()->IsFormatAvailable(
37 instance->pp_instance(), clipboard_type, format)); 75 instance->pp_instance(), clipboard_type, format));
38 } 76 }
39 return rv; 77 return rv;
40 } 78 }
41 79
42 // static 80 // static
43 bool Clipboard::ReadPlainText(Instance* instance, 81 bool Clipboard::ReadTextVar(Instance* instance,
44 PP_Flash_Clipboard_Type clipboard_type, 82 PP_Flash_Clipboard_Type clipboard_type,
45 std::string* text_out) { 83 PP_Flash_Clipboard_Format clipboard_format,
84 std::string* text_out) {
46 bool rv = false; 85 bool rv = false;
47 if (has_interface<PPB_Flash_Clipboard>()) { 86 if (has_interface<PPB_Flash_Clipboard>()) {
48 Var v(Var::PassRef(), 87 Var v(Var::PassRef(),
49 get_interface<PPB_Flash_Clipboard>()->ReadPlainText( 88 get_interface<PPB_Flash_Clipboard>()->ReadData(
50 instance->pp_instance(), 89 instance->pp_instance(),
51 clipboard_type)); 90 clipboard_type,
91 clipboard_format));
52 if (v.is_string()) { 92 if (v.is_string()) {
53 rv = true; 93 rv = true;
54 *text_out = v.AsString(); 94 *text_out = v.AsString();
55 } 95 }
56 } 96 }
57 return rv; 97 return rv;
58 } 98 }
59 99
60 // static 100 // static
61 bool Clipboard::WritePlainText(Instance* instance, 101 bool Clipboard::ReadPlainText(Instance* instance,
62 PP_Flash_Clipboard_Type clipboard_type, 102 PP_Flash_Clipboard_Type clipboard_type,
63 const std::string& text) { 103 std::string* text_out) {
104 return ReadTextVar(instance,
105 clipboard_type,
106 PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT,
107 text_out);
108 }
109
110 // static
111 bool Clipboard::ReadHTML(Instance* instance,
112 PP_Flash_Clipboard_Type clipboard_type,
113 std::string* html_out) {
114 return ReadTextVar(instance,
115 clipboard_type,
116 PP_FLASH_CLIPBOARD_FORMAT_HTML,
117 html_out);
118 }
119
120 // static
121 bool Clipboard::WriteData(Instance* instance,
122 PP_Flash_Clipboard_Type clipboard_type,
123 const ClipboardData& data) {
64 bool rv = false; 124 bool rv = false;
125 uint32_t data_item_count;
126 PP_Flash_Clipboard_Data_Item const* data_items =
127 data.GetDataItems(&data_item_count);
65 if (has_interface<PPB_Flash_Clipboard>()) { 128 if (has_interface<PPB_Flash_Clipboard>()) {
66 rv = (get_interface<PPB_Flash_Clipboard>()->WritePlainText( 129 rv = (get_interface<PPB_Flash_Clipboard>()->WriteData(
67 instance->pp_instance(), 130 instance->pp_instance(),
68 clipboard_type, 131 clipboard_type,
69 Var(text).pp_var()) == PP_OK); 132 data_item_count,
133 data_items) == PP_OK);
70 } 134 }
71 return rv; 135 return rv;
72 } 136 }
73 137
74 } // namespace flash 138 } // namespace flash
75 } // namespace pp 139 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698