blob: 49548625ed4a8d03b23cb546ab2b6d36d1b2390c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h"
#include <algorithm>
#include <string>
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_flash_clipboard.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebClipboard.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
#include "webkit/plugins/ppapi/var.h"
namespace webkit {
namespace ppapi {
namespace {
const size_t kMaxClipboardWriteSize = 1000000;
WebKit::WebClipboard::Buffer ConvertClipboardType(
PP_Flash_Clipboard_Type type) {
switch (type) {
case PP_FLASH_CLIPBOARD_TYPE_STANDARD:
return WebKit::WebClipboard::BufferStandard;
case PP_FLASH_CLIPBOARD_TYPE_SELECTION:
return WebKit::WebClipboard::BufferSelection;
case PP_FLASH_CLIPBOARD_TYPE_DRAG:
return WebKit::WebClipboard::BufferDrag;
default:
NOTREACHED();
return WebKit::WebClipboard::BufferStandard;
}
}
WebKit::WebClipboard::Format ConvertClipboardFormat(
PP_Flash_Clipboard_Format format) {
switch (format) {
case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT:
return WebKit::WebClipboard::FormatPlainText;
case PP_FLASH_CLIPBOARD_FORMAT_HTML:
return WebKit::WebClipboard::FormatHTML;
case PP_FLASH_CLIPBOARD_FORMAT_INVALID:
default:
NOTREACHED();
return WebKit::WebClipboard::FormatPlainText; // Gotta return something.
}
}
PP_Bool IsFormatAvailable(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) {
// If you don't give us an instance, we don't give you anything.
PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return PP_FALSE;
WebKit::WebClipboard* web_clipboard = WebKit::webKitClient()->clipboard();
if (!web_clipboard) {
NOTREACHED();
return PP_FALSE;
}
return BoolToPPBool(
web_clipboard->isFormatAvailable(ConvertClipboardFormat(format),
ConvertClipboardType(clipboard_type)));
}
PP_Var ReadPlainText(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type) {
PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return PP_MakeNull();
WebKit::WebClipboard* web_clipboard = WebKit::webKitClient()->clipboard();
if (!web_clipboard) {
NOTREACHED();
return PP_MakeNull();
}
WebKit::WebCString s =
web_clipboard->readPlainText(ConvertClipboardType(clipboard_type)).utf8();
return StringVar::StringToPPVar(instance->module(), s);
}
int32_t WritePlainText(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type,
PP_Var text) {
scoped_refptr<StringVar> text_string(StringVar::FromPPVar(text));
if (!text_string)
return PP_ERROR_BADARGUMENT;
if (text_string->value().length() > kMaxClipboardWriteSize)
return PP_ERROR_NOSPACE;
if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) {
NOTIMPLEMENTED();
return PP_ERROR_FAILED;
}
WebKit::WebClipboard* web_clipboard = WebKit::webKitClient()->clipboard();
if (!web_clipboard) {
NOTREACHED();
return PP_ERROR_FAILED;
}
web_clipboard->writePlainText(
WebKit::WebCString(text_string->value()).utf16());
return PP_OK;
}
const PPB_Flash_Clipboard ppb_flash_clipboard = {
&IsFormatAvailable,
&ReadPlainText,
&WritePlainText,
};
} // namespace
// static
const PPB_Flash_Clipboard*
PPB_Flash_Clipboard_Impl::GetInterface() {
return &ppb_flash_clipboard;
}
} // namespace ppapi
} // namespace webkit
|