summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 15:55:55 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 15:55:55 +0000
commit83c0f7cc5aa3bba61e0b5cdc88635825fdef24c9 (patch)
treea3bbffb480685ad7e2247edb7612d929601807bf
parent9454fca36c2e74354b252f9122248c65520d4e47 (diff)
downloadchromium_src-83c0f7cc5aa3bba61e0b5cdc88635825fdef24c9.zip
chromium_src-83c0f7cc5aa3bba61e0b5cdc88635825fdef24c9.tar.gz
chromium_src-83c0f7cc5aa3bba61e0b5cdc88635825fdef24c9.tar.bz2
Merge 82291 - Add an initial crypto interface to fill a given buffer with random data. Thishas the same implementation as the WebKit one on ChromeOS.TEST=noneBUG=noneReview URL: http://codereview.chromium.org/6880053
TBR=brettw@chromium.org BUG=80168 Review URL: http://codereview.chromium.org/6894024 git-svn-id: svn://svn.chromium.org/chrome/branches/742/src@82654 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ppapi/c/dev/ppb_crypto_dev.h21
-rw-r--r--ppapi/ppapi_shared_proxy.gypi4
-rw-r--r--ppapi/proxy/dispatcher.cc3
-rw-r--r--ppapi/proxy/interface_id.h1
-rw-r--r--ppapi/proxy/ppb_crypto_proxy.cc54
-rw-r--r--ppapi/proxy/ppb_crypto_proxy.h33
-rw-r--r--ppapi/shared_impl/crypto_impl.cc25
-rw-r--r--ppapi/shared_impl/crypto_impl.h22
-rw-r--r--ppapi/tests/all_c_includes.h1
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc4
-rw-r--r--webkit/plugins/ppapi/ppb_crypto_impl.cc28
-rw-r--r--webkit/plugins/ppapi/ppb_crypto_impl.h21
13 files changed, 219 insertions, 0 deletions
diff --git a/ppapi/c/dev/ppb_crypto_dev.h b/ppapi/c/dev/ppb_crypto_dev.h
new file mode 100644
index 0000000..266a782
--- /dev/null
+++ b/ppapi/c/dev/ppb_crypto_dev.h
@@ -0,0 +1,21 @@
+/* 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.
+ */
+#ifndef PPAPI_C_DEV_PPB_CRYPTO_DEV_H_
+#define PPAPI_C_DEV_PPB_CRYPTO_DEV_H_
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_stdint.h"
+
+#define PPB_CRYPTO_DEV_INTERFACE "PPB_Crypto(Dev);0.1"
+
+struct PPB_Crypto_Dev {
+ /**
+ * Fills the given buffer with random bytes. This is potentially slow so only
+ * request the amount of data you need.
+ */
+ void (*GetRandomBytes)(char* buffer, uint32_t num_bytes);
+};
+
+#endif
diff --git a/ppapi/ppapi_shared_proxy.gypi b/ppapi/ppapi_shared_proxy.gypi
index c6b88f8..341e1f3 100644
--- a/ppapi/ppapi_shared_proxy.gypi
+++ b/ppapi/ppapi_shared_proxy.gypi
@@ -22,6 +22,8 @@
'shared_impl/audio_impl.h',
'shared_impl/char_set_impl.cc',
'shared_impl/char_set_impl.h',
+ 'shared_impl/crypto_impl.cc',
+ 'shared_impl/crypto_impl.h',
'shared_impl/image_data_impl.cc',
'shared_impl/image_data_impl.h',
'shared_impl/url_util_impl.cc',
@@ -97,6 +99,8 @@
'proxy/ppb_context_3d_proxy.h',
'proxy/ppb_core_proxy.cc',
'proxy/ppb_core_proxy.h',
+ 'proxy/ppb_crypto_proxy.cc',
+ 'proxy/ppb_crypto_proxy.h',
'proxy/ppb_cursor_control_proxy.cc',
'proxy/ppb_cursor_control_proxy.h',
'proxy/ppb_file_chooser_proxy.cc',
diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc
index 2964835..f5d5668 100644
--- a/ppapi/proxy/dispatcher.cc
+++ b/ppapi/proxy/dispatcher.cc
@@ -14,6 +14,7 @@
#include "ppapi/c/dev/ppb_buffer_dev.h"
#include "ppapi/c/dev/ppb_char_set_dev.h"
#include "ppapi/c/dev/ppb_context_3d_dev.h"
+#include "ppapi/c/dev/ppb_crypto_dev.h"
#include "ppapi/c/dev/ppb_cursor_control_dev.h"
#include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h"
#include "ppapi/c/dev/ppb_font_dev.h"
@@ -50,6 +51,7 @@
#include "ppapi/proxy/ppb_console_proxy.h"
#include "ppapi/proxy/ppb_context_3d_proxy.h"
#include "ppapi/proxy/ppb_core_proxy.h"
+#include "ppapi/proxy/ppb_crypto_proxy.h"
#include "ppapi/proxy/ppb_cursor_control_proxy.h"
#include "ppapi/proxy/ppb_file_chooser_proxy.h"
#include "ppapi/proxy/ppb_file_ref_proxy.h"
@@ -113,6 +115,7 @@ InterfaceList::InterfaceList() {
AddPPB(PPB_Console_Proxy::GetInfo());
AddPPB(PPB_Context3D_Proxy::GetInfo());
AddPPB(PPB_Core_Proxy::GetInfo());
+ AddPPB(PPB_Crypto_Proxy::GetInfo());
AddPPB(PPB_CursorControl_Proxy::GetInfo());
AddPPB(PPB_FileChooser_Proxy::GetInfo());
AddPPB(PPB_FileRef_Proxy::GetInfo());
diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h
index 10ef8c4..c7346b5 100644
--- a/ppapi/proxy/interface_id.h
+++ b/ppapi/proxy/interface_id.h
@@ -21,6 +21,7 @@ enum InterfaceID {
INTERFACE_ID_PPB_CONSOLE,
INTERFACE_ID_PPB_CONTEXT_3D,
INTERFACE_ID_PPB_CORE,
+ INTERFACE_ID_PPB_CRYPTO,
INTERFACE_ID_PPB_CURSORCONTROL,
INTERFACE_ID_PPB_FILE_CHOOSER,
INTERFACE_ID_PPB_FILE_REF,
diff --git a/ppapi/proxy/ppb_crypto_proxy.cc b/ppapi/proxy/ppb_crypto_proxy.cc
new file mode 100644
index 0000000..207b400
--- /dev/null
+++ b/ppapi/proxy/ppb_crypto_proxy.cc
@@ -0,0 +1,54 @@
+// 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 "ppapi/proxy/ppb_crypto_proxy.h"
+
+#include "ppapi/c/dev/ppb_crypto_dev.h"
+#include "ppapi/proxy/interface_id.h"
+#include "ppapi/shared_impl/crypto_impl.h"
+
+namespace pp {
+namespace proxy {
+
+namespace {
+
+const PPB_Crypto_Dev crypto_interface = {
+ &pp::shared_impl::CryptoImpl::GetRandomBytes
+};
+
+InterfaceProxy* CreateCryptoProxy(Dispatcher* dispatcher,
+ const void* target_interface) {
+ return new PPB_Crypto_Proxy(dispatcher, target_interface);
+}
+
+} // namespace
+
+PPB_Crypto_Proxy::PPB_Crypto_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+ NOTREACHED(); // See comment in the header file.
+}
+
+PPB_Crypto_Proxy::~PPB_Crypto_Proxy() {
+}
+
+// static
+const InterfaceProxy::Info* PPB_Crypto_Proxy::GetInfo() {
+ static const Info info = {
+ &crypto_interface,
+ PPB_CRYPTO_DEV_INTERFACE,
+ INTERFACE_ID_PPB_CRYPTO,
+ false,
+ &CreateCryptoProxy,
+ };
+ return &info;
+}
+
+bool PPB_Crypto_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ NOTREACHED();
+ return false;
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppb_crypto_proxy.h b/ppapi/proxy/ppb_crypto_proxy.h
new file mode 100644
index 0000000..e801892
--- /dev/null
+++ b/ppapi/proxy/ppb_crypto_proxy.h
@@ -0,0 +1,33 @@
+// 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.
+
+#ifndef PPAPI_PROXY_PPB_CRYPTO_PROXY_H_
+#define PPAPI_PROXY_PPB_CRYPTO_PROXY_H_
+
+#include "ppapi/proxy/interface_proxy.h"
+
+namespace pp {
+namespace proxy {
+
+class PPB_Crypto_Proxy : public InterfaceProxy {
+ public:
+ // This class should not normally be instantiated since there's only one
+ // function that's implemented entirely within the plugin. However, we need
+ // to support this so the machinery for automatically handling interfaces
+ // works. As a result, this constructor will assert if it's actually used.
+ PPB_Crypto_Proxy(Dispatcher* dispatcher, const void* target_interface);
+ virtual ~PPB_Crypto_Proxy();
+
+ static const Info* GetInfo();
+
+ private:
+ virtual bool OnMessageReceived(const IPC::Message& msg);
+
+ DISALLOW_COPY_AND_ASSIGN(PPB_Crypto_Proxy);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PROXY_PPB_CRYPTO_PROXY_H_
diff --git a/ppapi/shared_impl/crypto_impl.cc b/ppapi/shared_impl/crypto_impl.cc
new file mode 100644
index 0000000..6295bb2
--- /dev/null
+++ b/ppapi/shared_impl/crypto_impl.cc
@@ -0,0 +1,25 @@
+// 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 "ppapi/shared_impl/crypto_impl.h"
+
+#include "base/rand_util.h"
+
+namespace pp {
+namespace shared_impl {
+
+// static
+void CryptoImpl::GetRandomBytes(char* buffer, uint32_t num_bytes) {
+ // Note: this is a copy of WebKitClientImpl::cryptographicallyRandomValues.
+ uint64 bytes = 0;
+ for (uint32_t i = 0; i < num_bytes; ++i) {
+ uint32_t offset = i % sizeof(bytes);
+ if (!offset)
+ bytes = base::RandUint64();
+ buffer[i] = reinterpret_cast<char*>(&bytes)[offset];
+ }
+}
+
+} // namespace shared_impl
+} // namespace pp
diff --git a/ppapi/shared_impl/crypto_impl.h b/ppapi/shared_impl/crypto_impl.h
new file mode 100644
index 0000000..c3b3cd4
--- /dev/null
+++ b/ppapi/shared_impl/crypto_impl.h
@@ -0,0 +1,22 @@
+// 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.
+
+#ifndef PPAPI_SHARED_IMPL_CRYPTO_IMPL_H_
+#define PPAPI_SHARED_IMPL_CRYPTO_IMPL_H_
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_stdint.h"
+
+namespace pp {
+namespace shared_impl {
+
+class CryptoImpl {
+ public:
+ static void GetRandomBytes(char* buffer, uint32_t num_bytes);
+};
+
+} // namespace shared_impl
+} // namespace pp
+
+#endif // PPAPI_SHARED_IMPL_CRYPTO_IMPL_H_
diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h
index ab68dd1..176af2a 100644
--- a/ppapi/tests/all_c_includes.h
+++ b/ppapi/tests/all_c_includes.h
@@ -18,6 +18,7 @@
#include "ppapi/c/dev/ppb_console_dev.h"
#include "ppapi/c/dev/ppb_context_3d_dev.h"
#include "ppapi/c/dev/ppb_context_3d_trusted_dev.h"
+#include "ppapi/c/dev/ppb_crypto_dev.h"
#include "ppapi/c/dev/ppb_cursor_control_dev.h"
#include "ppapi/c/dev/ppb_directory_reader_dev.h"
#include "ppapi/c/dev/ppb_file_chooser_dev.h"
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 16fe656..1b5be84 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -238,6 +238,8 @@
'../plugins/ppapi/ppb_console_impl.h',
'../plugins/ppapi/ppb_context_3d_impl.cc',
'../plugins/ppapi/ppb_context_3d_impl.h',
+ '../plugins/ppapi/ppb_crypto_impl.cc',
+ '../plugins/ppapi/ppb_crypto_impl.h',
'../plugins/ppapi/ppb_cursor_control_impl.cc',
'../plugins/ppapi/ppb_cursor_control_impl.h',
'../plugins/ppapi/ppb_directory_reader_impl.cc',
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index 7fc683e..a7a7dd2 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -17,6 +17,7 @@
#include "ppapi/c/dev/ppb_context_3d_dev.h"
#include "ppapi/c/dev/ppb_context_3d_trusted_dev.h"
#include "ppapi/c/dev/ppb_console_dev.h"
+#include "ppapi/c/dev/ppb_crypto_dev.h"
#include "ppapi/c/dev/ppb_cursor_control_dev.h"
#include "ppapi/c/dev/ppb_directory_reader_dev.h"
#include "ppapi/c/dev/ppb_file_io_dev.h"
@@ -70,6 +71,7 @@
#include "webkit/plugins/ppapi/ppb_buffer_impl.h"
#include "webkit/plugins/ppapi/ppb_char_set_impl.h"
#include "webkit/plugins/ppapi/ppb_console_impl.h"
+#include "webkit/plugins/ppapi/ppb_crypto_impl.h"
#include "webkit/plugins/ppapi/ppb_cursor_control_impl.h"
#include "webkit/plugins/ppapi/ppb_directory_reader_impl.h"
#include "webkit/plugins/ppapi/ppb_file_chooser_impl.h"
@@ -241,6 +243,8 @@ const void* GetInterface(const char* name) {
return PPB_Console_Impl::GetInterface();
if (strcmp(name, PPB_CORE_INTERFACE) == 0)
return &core_interface;
+ if (strcmp(name, PPB_CRYPTO_DEV_INTERFACE) == 0)
+ return PPB_Crypto_Impl::GetInterface();
if (strcmp(name, PPB_CURSOR_CONTROL_DEV_INTERFACE) == 0)
return GetCursorControlInterface();
if (strcmp(name, PPB_DIRECTORYREADER_DEV_INTERFACE) == 0)
diff --git a/webkit/plugins/ppapi/ppb_crypto_impl.cc b/webkit/plugins/ppapi/ppb_crypto_impl.cc
new file mode 100644
index 0000000..8f3a73b
--- /dev/null
+++ b/webkit/plugins/ppapi/ppb_crypto_impl.cc
@@ -0,0 +1,28 @@
+// 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_crypto_impl.h"
+
+#include "ppapi/c/dev/ppb_crypto_dev.h"
+#include "ppapi/shared_impl/crypto_impl.h"
+
+namespace webkit {
+namespace ppapi {
+
+namespace {
+
+const PPB_Crypto_Dev ppb_crypto = {
+ &pp::shared_impl::CryptoImpl::GetRandomBytes
+};
+
+} // namespace
+
+// static
+const PPB_Crypto_Dev* PPB_Crypto_Impl::GetInterface() {
+ return &ppb_crypto;
+}
+
+} // namespace ppapi
+} // namespace webkit
+
diff --git a/webkit/plugins/ppapi/ppb_crypto_impl.h b/webkit/plugins/ppapi/ppb_crypto_impl.h
new file mode 100644
index 0000000..3b3bb48
--- /dev/null
+++ b/webkit/plugins/ppapi/ppb_crypto_impl.h
@@ -0,0 +1,21 @@
+// 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.
+
+#ifndef WEBKIT_PLUGINS_PPAPI_PPB_CRYPTO_IMPL_H_
+#define WEBKIT_PLUGINS_PPAPI_PPB_CRYPTO_IMPL_H_
+
+struct PPB_Crypto_Dev;
+
+namespace webkit {
+namespace ppapi {
+
+class PPB_Crypto_Impl {
+ public:
+ static const PPB_Crypto_Dev* GetInterface();
+};
+
+} // namespace ppapi
+} // namespace webkit
+
+#endif // WEBKIT_PLUGINS_PPAPI_PPB_CRYPTO_IMPL_H_