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

Unified Diff: ppapi/cpp/var.cc

Issue 8826011: Remove PP_Module from parameters for PPB_Var.VarFromUtf8. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indentation. Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/cpp/var.h ('k') | ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_font_rpc_server.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/cpp/var.cc
diff --git a/ppapi/cpp/var.cc b/ppapi/cpp/var.cc
index d8128ed2d5f4c0f46b335d582f003e7bfb0926b2..ab98e91899da081dcf37358450779cb52336eab2 100644
--- a/ppapi/cpp/var.cc
+++ b/ppapi/cpp/var.cc
@@ -28,6 +28,9 @@ namespace {
template <> const char* interface_name<PPB_Var>() {
return PPB_VAR_INTERFACE;
}
+template <> const char* interface_name<PPB_Var_1_0>() {
+ return PPB_VAR_INTERFACE_1_0;
+}
// Technically you can call AddRef and Release on any Var, but it may involve
// cross-process calls depending on the plugin. This is an optimization so we
@@ -36,6 +39,21 @@ inline bool NeedsRefcounting(const PP_Var& var) {
return var.type > PP_VARTYPE_DOUBLE;
}
+// This helper function detects whether PPB_Var version 1.1 is available. If so,
+// it uses it to create a PP_Var for the given string. Otherwise it falls back
+// to PPB_Var version 1.0.
+PP_Var VarFromUtf8Helper(const char* utf8_str, uint32_t len) {
+ if (has_interface<PPB_Var>()) {
+ return get_interface<PPB_Var>()->VarFromUtf8(utf8_str, len);
+ } else if (has_interface<PPB_Var_1_0>()) {
+ return get_interface<PPB_Var_1_0>()->VarFromUtf8(Module::Get()->pp_module(),
+ utf8_str,
+ len);
+ } else {
+ return PP_MakeNull();
+ }
+}
+
} // namespace
Var::Var() {
@@ -72,27 +90,14 @@ Var::Var(double d) {
}
Var::Var(const char* utf8_str) {
- if (has_interface<PPB_Var>()) {
- uint32_t len = utf8_str ? static_cast<uint32_t>(strlen(utf8_str)) : 0;
- var_ = get_interface<PPB_Var>()->VarFromUtf8(Module::Get()->pp_module(),
- utf8_str, len);
- } else {
- var_.type = PP_VARTYPE_NULL;
- var_.padding = 0;
- }
+ uint32_t len = utf8_str ? static_cast<uint32_t>(strlen(utf8_str)) : 0;
+ var_ = VarFromUtf8Helper(utf8_str, len);
needs_release_ = (var_.type == PP_VARTYPE_STRING);
}
Var::Var(const std::string& utf8_str) {
- if (has_interface<PPB_Var>()) {
- var_ = get_interface<PPB_Var>()->VarFromUtf8(
- Module::Get()->pp_module(),
- utf8_str.c_str(),
- static_cast<uint32_t>(utf8_str.size()));
- } else {
- var_.type = PP_VARTYPE_NULL;
- var_.padding = 0;
- }
+ var_ = VarFromUtf8Helper(utf8_str.c_str(),
+ static_cast<uint32_t>(utf8_str.size()));
needs_release_ = (var_.type == PP_VARTYPE_STRING);
}
« no previous file with comments | « ppapi/cpp/var.h ('k') | ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_font_rpc_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698