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

Side by Side Diff: webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc

Issue 6611034: Pepper/Flapper: Add very basic clipboard support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minus string.h Created 9 years, 9 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 | « webkit/plugins/ppapi/ppb_flash_clipboard_impl.h ('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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h"
6
7 #include <algorithm>
8 #include <string>
9
10 #include "base/logging.h"
11 #include "base/ref_counted.h"
12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/c/private/ppb_flash_clipboard.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebClipboard.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
20 #include "webkit/plugins/ppapi/resource_tracker.h"
21 #include "webkit/plugins/ppapi/var.h"
22
23 namespace webkit {
24 namespace ppapi {
25
26 namespace {
27
28 const size_t kMaxClipboardWriteSize = 1000000;
29
30 WebKit::WebClipboard::Buffer ConvertClipboardType(
31 PP_Flash_Clipboard_Type type) {
32 switch (type) {
33 case PP_FLASH_CLIPBOARD_TYPE_STANDARD:
34 return WebKit::WebClipboard::BufferStandard;
35 case PP_FLASH_CLIPBOARD_TYPE_SELECTION:
36 return WebKit::WebClipboard::BufferSelection;
37 case PP_FLASH_CLIPBOARD_TYPE_DRAG:
38 return WebKit::WebClipboard::BufferDrag;
39 default:
40 NOTREACHED();
41 return WebKit::WebClipboard::BufferStandard;
42 }
43 }
44
45 PP_Var ReadPlainText(PP_Instance instance_id,
46 PP_Flash_Clipboard_Type clipboard_type) {
47 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
48 if (!instance)
49 return PP_MakeNull();
50
51 WebKit::WebClipboard* web_clipboard = WebKit::webKitClient()->clipboard();
52 if (!web_clipboard) {
53 NOTREACHED();
54 return PP_MakeNull();
55 }
56
57 WebKit::WebCString s =
58 web_clipboard->readPlainText(ConvertClipboardType(clipboard_type)).utf8();
59 return StringVar::StringToPPVar(instance->module(), s);
60 }
61
62 int32_t WritePlainText(PP_Instance instance_id,
63 PP_Flash_Clipboard_Type clipboard_type,
64 PP_Var text) {
65 scoped_refptr<StringVar> text_string(StringVar::FromPPVar(text));
66 if (!text_string)
67 return PP_ERROR_BADARGUMENT;
68
69 if (text_string->value().length() > kMaxClipboardWriteSize)
70 return PP_ERROR_NOSPACE;
71
72 if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) {
73 NOTIMPLEMENTED();
74 return PP_ERROR_FAILED;
75 }
76
77 WebKit::WebClipboard* web_clipboard = WebKit::webKitClient()->clipboard();
78 if (!web_clipboard) {
79 NOTREACHED();
80 return PP_ERROR_FAILED;
81 }
82
83 web_clipboard->writePlainText(
84 WebKit::WebCString(text_string->value()).utf16());
85 return PP_OK;
86 }
87
88 const PPB_Flash_Clipboard ppb_flash_clipboard = {
89 &ReadPlainText,
90 &WritePlainText,
91 };
92
93 } // namespace
94
95 // static
96 const PPB_Flash_Clipboard*
97 PPB_Flash_Clipboard_Impl::GetInterface() {
98 return &ppb_flash_clipboard;
99 }
100
101 } // namespace ppapi
102 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_flash_clipboard_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698