OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/plugins/ppapi/var.h" | 5 #include "webkit/plugins/ppapi/var.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "base/string_number_conversions.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "ppapi/c/dev/ppb_var_deprecated.h" | 13 #include "ppapi/c/dev/ppb_var_deprecated.h" |
13 #include "ppapi/c/ppb_var.h" | 14 #include "ppapi/c/ppb_var.h" |
14 #include "ppapi/c/pp_var.h" | 15 #include "ppapi/c/pp_var.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
16 #include "webkit/plugins/ppapi/common.h" | 17 #include "webkit/plugins/ppapi/common.h" |
17 #include "webkit/plugins/ppapi/plugin_module.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
18 #include "webkit/plugins/ppapi/plugin_object.h" | 19 #include "webkit/plugins/ppapi/plugin_object.h" |
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
20 #include "webkit/plugins/ppapi/resource_tracker.h" | 21 #include "webkit/plugins/ppapi/resource_tracker.h" |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 int32_t int_value = 0; | 718 int32_t int_value = 0; |
718 bool is_string = false; | 719 bool is_string = false; |
719 WebBindings::extractIdentifierData(id, string_value, int_value, is_string); | 720 WebBindings::extractIdentifierData(id, string_value, int_value, is_string); |
720 if (is_string) | 721 if (is_string) |
721 return StringVar::StringToPPVar(module, string_value); | 722 return StringVar::StringToPPVar(module, string_value); |
722 | 723 |
723 return PP_MakeInt32(int_value); | 724 return PP_MakeInt32(int_value); |
724 } | 725 } |
725 | 726 |
726 // static | 727 // static |
| 728 std::string Var::PPVarToLogString(PP_Var var) { |
| 729 switch (var.type) { |
| 730 case PP_VARTYPE_UNDEFINED: |
| 731 return "[Undefined]"; |
| 732 case PP_VARTYPE_NULL: |
| 733 return "[Null]"; |
| 734 case PP_VARTYPE_BOOL: |
| 735 return var.value.as_bool ? "[True]" : "[False]"; |
| 736 case PP_VARTYPE_INT32: |
| 737 return base::IntToString(var.value.as_int); |
| 738 case PP_VARTYPE_DOUBLE: |
| 739 return base::DoubleToString(var.value.as_double); |
| 740 case PP_VARTYPE_STRING: { |
| 741 scoped_refptr<StringVar> string(StringVar::FromPPVar(var)); |
| 742 if (!string) |
| 743 return "[Invalid string]"; |
| 744 |
| 745 // Since this is for logging, escape NULLs. |
| 746 std::string result = string->value(); |
| 747 std::string null; |
| 748 null.push_back(0); |
| 749 ReplaceSubstringsAfterOffset(&result, 0, null, "\\0"); |
| 750 return result; |
| 751 } |
| 752 case PP_VARTYPE_OBJECT: |
| 753 return "[Object]"; |
| 754 default: |
| 755 return "[Invalid var]"; |
| 756 } |
| 757 } |
| 758 |
| 759 // static |
727 void Var::PluginAddRefPPVar(PP_Var var) { | 760 void Var::PluginAddRefPPVar(PP_Var var) { |
728 if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) { | 761 if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) { |
729 if (!ResourceTracker::Get()->AddRefVar(static_cast<int32>(var.value.as_id))) | 762 if (!ResourceTracker::Get()->AddRefVar(static_cast<int32>(var.value.as_id))) |
730 DLOG(WARNING) << "AddRefVar()ing a nonexistent string/object var."; | 763 DLOG(WARNING) << "AddRefVar()ing a nonexistent string/object var."; |
731 } | 764 } |
732 } | 765 } |
733 | 766 |
734 // static | 767 // static |
735 void Var::PluginReleasePPVar(PP_Var var) { | 768 void Var::PluginReleasePPVar(PP_Var var) { |
736 if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) { | 769 if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 } | 938 } |
906 | 939 |
907 // static | 940 // static |
908 void TryCatch::Catch(void* self, const char* message) { | 941 void TryCatch::Catch(void* self, const char* message) { |
909 static_cast<TryCatch*>(self)->SetException(message); | 942 static_cast<TryCatch*>(self)->SetException(message); |
910 } | 943 } |
911 | 944 |
912 } // namespace ppapi | 945 } // namespace ppapi |
913 } // namespace webkit | 946 } // namespace webkit |
914 | 947 |
OLD | NEW |