diff --git a/include/cef.h b/include/cef.h index 4049a74b..97e69679 100644 --- a/include/cef.h +++ b/include/cef.h @@ -2663,8 +2663,8 @@ public: /// // Returns true if the object has a value with the specified identifier. /// - /*--cef(capi_name=has_value_byindex)--*/ - virtual bool HasValue(size_t index) =0; + /*--cef(capi_name=has_value_byindex,index_param=index)--*/ + virtual bool HasValue(int index) =0; /// // Delete the value with the specified identifier. @@ -2674,8 +2674,8 @@ public: /// // Delete the value with the specified identifier. /// - /*--cef(capi_name=delete_value_byindex)--*/ - virtual bool DeleteValue(size_t index) =0; + /*--cef(capi_name=delete_value_byindex,index_param=index)--*/ + virtual bool DeleteValue(int index) =0; /// // Returns the value with the specified identifier. @@ -2685,8 +2685,8 @@ public: /// // Returns the value with the specified identifier. /// - /*--cef(capi_name=get_value_byindex)--*/ - virtual CefRefPtr GetValue(size_t index) =0; + /*--cef(capi_name=get_value_byindex,index_param=index)--*/ + virtual CefRefPtr GetValue(int index) =0; /// // Associate a value with the specified identifier. @@ -2697,8 +2697,8 @@ public: /// // Associate a value with the specified identifier. /// - /*--cef(capi_name=set_value_byindex)--*/ - virtual bool SetValue(size_t index, CefRefPtr value) =0; + /*--cef(capi_name=set_value_byindex,index_param=index)--*/ + virtual bool SetValue(int index, CefRefPtr value) =0; /// // Register an identifier whose access will be forwarded to the CefV8Accessor @@ -3137,8 +3137,8 @@ public: /// // Returns the value of the attribute at the specified 0-based index. /// - /*--cef(capi_name=get_attribute_byindex)--*/ - virtual CefString GetAttribute(size_t index) =0; + /*--cef(capi_name=get_attribute_byindex,index_param=index)--*/ + virtual CefString GetAttribute(int index) =0; /// // Returns the value of the attribute with the specified qualified name. @@ -3182,8 +3182,8 @@ public: // Moves the cursor to the attribute at the specified 0-based index. Returns // true if the cursor position was set successfully. /// - /*--cef(capi_name=move_to_attribute_byindex)--*/ - virtual bool MoveToAttribute(size_t index) =0; + /*--cef(capi_name=move_to_attribute_byindex,index_param=index)--*/ + virtual bool MoveToAttribute(int index) =0; /// // Moves the cursor to the attribute with the specified qualified name. diff --git a/include/cef_capi.h b/include/cef_capi.h index cca6673b..e0c47306 100644 --- a/include/cef_capi.h +++ b/include/cef_capi.h @@ -2375,8 +2375,7 @@ typedef struct _cef_v8value_t /// // Returns true (1) if the object has a value with the specified identifier. /// - int (CEF_CALLBACK *has_value_byindex)(struct _cef_v8value_t* self, - size_t index); + int (CEF_CALLBACK *has_value_byindex)(struct _cef_v8value_t* self, int index); /// // Delete the value with the specified identifier. @@ -2388,7 +2387,7 @@ typedef struct _cef_v8value_t // Delete the value with the specified identifier. /// int (CEF_CALLBACK *delete_value_byindex)(struct _cef_v8value_t* self, - size_t index); + int index); /// // Returns the value with the specified identifier. @@ -2400,7 +2399,7 @@ typedef struct _cef_v8value_t // Returns the value with the specified identifier. /// struct _cef_v8value_t* (CEF_CALLBACK *get_value_byindex)( - struct _cef_v8value_t* self, size_t index); + struct _cef_v8value_t* self, int index); /// // Associate a value with the specified identifier. @@ -2412,8 +2411,8 @@ typedef struct _cef_v8value_t /// // Associate a value with the specified identifier. /// - int (CEF_CALLBACK *set_value_byindex)(struct _cef_v8value_t* self, - size_t index, struct _cef_v8value_t* value); + int (CEF_CALLBACK *set_value_byindex)(struct _cef_v8value_t* self, int index, + struct _cef_v8value_t* value); /// // Register an identifier whose access will be forwarded to the @@ -2917,7 +2916,7 @@ typedef struct _cef_xml_reader_t /// // The resulting string must be freed by calling cef_string_userfree_free(). cef_string_userfree_t (CEF_CALLBACK *get_attribute_byindex)( - struct _cef_xml_reader_t* self, size_t index); + struct _cef_xml_reader_t* self, int index); /// // Returns the value of the attribute with the specified qualified name. @@ -2965,7 +2964,7 @@ typedef struct _cef_xml_reader_t // true (1) if the cursor position was set successfully. /// int (CEF_CALLBACK *move_to_attribute_byindex)(struct _cef_xml_reader_t* self, - size_t index); + int index); /// // Moves the cursor to the attribute with the specified qualified name. diff --git a/libcef/v8_impl.cc b/libcef/v8_impl.cc index 10bfebcb..6d97094d 100644 --- a/libcef/v8_impl.cc +++ b/libcef/v8_impl.cc @@ -851,13 +851,17 @@ bool CefV8ValueImpl::HasValue(const CefString& key) return obj->Has(GetV8String(key)); } -bool CefV8ValueImpl::HasValue(size_t index) +bool CefV8ValueImpl::HasValue(int index) { CEF_REQUIRE_UI_THREAD(false); if(!GetHandle()->IsObject()) { NOTREACHED() << "V8 value is not an object"; return false; } + if (index < 0) { + NOTREACHED() << "invalid input parameter"; + return false; + } v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); @@ -882,13 +886,17 @@ bool CefV8ValueImpl::DeleteValue(const CefString& key) return obj->Delete(GetV8String(key)); } -bool CefV8ValueImpl::DeleteValue(size_t index) +bool CefV8ValueImpl::DeleteValue(int index) { CEF_REQUIRE_UI_THREAD(false); if(!GetHandle()->IsObject()) { NOTREACHED() << "V8 value is not an object"; return false; } + if (index < 0) { + NOTREACHED() << "invalid input parameter"; + return false; + } v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); @@ -913,13 +921,17 @@ CefRefPtr CefV8ValueImpl::GetValue(const CefString& key) return new CefV8ValueImpl(obj->Get(GetV8String(key))); } -CefRefPtr CefV8ValueImpl::GetValue(size_t index) +CefRefPtr CefV8ValueImpl::GetValue(int index) { CEF_REQUIRE_UI_THREAD(NULL); if(!GetHandle()->IsObject()) { NOTREACHED() << "V8 value is not an object"; return NULL; } + if (index < 0) { + NOTREACHED() << "invalid input parameter"; + return false; + } v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); @@ -948,7 +960,7 @@ bool CefV8ValueImpl::SetValue(const CefString& key, } } -bool CefV8ValueImpl::SetValue(size_t index, CefRefPtr value) +bool CefV8ValueImpl::SetValue(int index, CefRefPtr value) { CEF_REQUIRE_UI_THREAD(false); @@ -956,6 +968,10 @@ bool CefV8ValueImpl::SetValue(size_t index, CefRefPtr value) NOTREACHED() << "V8 value is not an object"; return false; } + if (index < 0) { + NOTREACHED() << "invalid input parameter"; + return false; + } CefV8ValueImpl *impl = static_cast(value.get()); if(impl) { diff --git a/libcef/v8_impl.h b/libcef/v8_impl.h index 2d56f2b6..4eec2275 100644 --- a/libcef/v8_impl.h +++ b/libcef/v8_impl.h @@ -127,14 +127,14 @@ public: virtual CefTime GetDateValue() OVERRIDE; virtual CefString GetStringValue() OVERRIDE; virtual bool HasValue(const CefString& key) OVERRIDE; - virtual bool HasValue(size_t index) OVERRIDE; + virtual bool HasValue(int index) OVERRIDE; virtual bool DeleteValue(const CefString& key) OVERRIDE; - virtual bool DeleteValue(size_t index) OVERRIDE; + virtual bool DeleteValue(int index) OVERRIDE; virtual CefRefPtr GetValue(const CefString& key) OVERRIDE; - virtual CefRefPtr GetValue(size_t index) OVERRIDE; + virtual CefRefPtr GetValue(int index) OVERRIDE; virtual bool SetValue(const CefString& key, CefRefPtr value, PropertyAttribute attribute) OVERRIDE; - virtual bool SetValue(size_t index, CefRefPtr value) OVERRIDE; + virtual bool SetValue(int index, CefRefPtr value) OVERRIDE; virtual bool SetValue(const CefString& key, AccessControl settings, PropertyAttribute attribute) OVERRIDE; virtual bool GetKeys(std::vector& keys) OVERRIDE; diff --git a/libcef/xml_reader_impl.cc b/libcef/xml_reader_impl.cc index 2921e581..0215b58d 100644 --- a/libcef/xml_reader_impl.cc +++ b/libcef/xml_reader_impl.cc @@ -355,7 +355,7 @@ size_t CefXmlReaderImpl::GetAttributeCount() return xmlTextReaderAttributeCount(reader_); } -CefString CefXmlReaderImpl::GetAttribute(size_t index) +CefString CefXmlReaderImpl::GetAttribute(int index) { if (!VerifyContext()) return CefString(); @@ -409,7 +409,7 @@ int CefXmlReaderImpl::GetLineNumber() return xmlTextReaderGetParserLineNumber(reader_); } -bool CefXmlReaderImpl::MoveToAttribute(size_t index) +bool CefXmlReaderImpl::MoveToAttribute(int index) { if (!VerifyContext()) return false; diff --git a/libcef/xml_reader_impl.h b/libcef/xml_reader_impl.h index 9d8ceb46..1de73375 100644 --- a/libcef/xml_reader_impl.h +++ b/libcef/xml_reader_impl.h @@ -38,14 +38,14 @@ public: virtual CefString GetValue() OVERRIDE; virtual bool HasAttributes() OVERRIDE; virtual size_t GetAttributeCount() OVERRIDE; - virtual CefString GetAttribute(size_t index) OVERRIDE; + virtual CefString GetAttribute(int index) OVERRIDE; virtual CefString GetAttribute(const CefString& qualifiedName) OVERRIDE; virtual CefString GetAttribute(const CefString& localName, const CefString& namespaceURI) OVERRIDE; virtual CefString GetInnerXml() OVERRIDE; virtual CefString GetOuterXml() OVERRIDE; virtual int GetLineNumber() OVERRIDE; - virtual bool MoveToAttribute(size_t index) OVERRIDE; + virtual bool MoveToAttribute(int index) OVERRIDE; virtual bool MoveToAttribute(const CefString& qualifiedName) OVERRIDE; virtual bool MoveToAttribute(const CefString& localName, const CefString& namespaceURI) OVERRIDE; diff --git a/libcef_dll/cpptoc/v8value_cpptoc.cc b/libcef_dll/cpptoc/v8value_cpptoc.cc index 25513f51..057ca58e 100644 --- a/libcef_dll/cpptoc/v8value_cpptoc.cc +++ b/libcef_dll/cpptoc/v8value_cpptoc.cc @@ -477,13 +477,17 @@ int CEF_CALLBACK v8value_has_value_bykey(struct _cef_v8value_t* self, int CEF_CALLBACK v8value_has_value_byindex(struct _cef_v8value_t* self, - size_t index) + int index) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); if (!self) return 0; + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return 0; // Execute bool _retval = CefV8ValueCppToC::Get(self)->HasValue( @@ -517,13 +521,17 @@ int CEF_CALLBACK v8value_delete_value_bykey(struct _cef_v8value_t* self, int CEF_CALLBACK v8value_delete_value_byindex(struct _cef_v8value_t* self, - size_t index) + int index) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); if (!self) return 0; + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return 0; // Execute bool _retval = CefV8ValueCppToC::Get(self)->DeleteValue( @@ -557,13 +565,17 @@ struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_bykey( struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_byindex( - struct _cef_v8value_t* self, size_t index) + struct _cef_v8value_t* self, int index) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); if (!self) return NULL; + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return NULL; // Execute CefRefPtr _retval = CefV8ValueCppToC::Get(self)->GetValue( @@ -604,13 +616,17 @@ int CEF_CALLBACK v8value_set_value_bykey(struct _cef_v8value_t* self, int CEF_CALLBACK v8value_set_value_byindex(struct _cef_v8value_t* self, - size_t index, struct _cef_v8value_t* value) + int index, struct _cef_v8value_t* value) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); if (!self) return 0; + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return 0; // Verify param: value; type: refptr_same DCHECK(value); if (!value) diff --git a/libcef_dll/cpptoc/xml_reader_cpptoc.cc b/libcef_dll/cpptoc/xml_reader_cpptoc.cc index 14aee2ee..e79344d3 100644 --- a/libcef_dll/cpptoc/xml_reader_cpptoc.cc +++ b/libcef_dll/cpptoc/xml_reader_cpptoc.cc @@ -327,13 +327,17 @@ size_t CEF_CALLBACK xml_reader_get_attribute_count( cef_string_userfree_t CEF_CALLBACK xml_reader_get_attribute_byindex( - struct _cef_xml_reader_t* self, size_t index) + struct _cef_xml_reader_t* self, int index) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); if (!self) return NULL; + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return NULL; // Execute CefString _retval = CefXmlReaderCppToC::Get(self)->GetAttribute( @@ -445,13 +449,17 @@ int CEF_CALLBACK xml_reader_get_line_number(struct _cef_xml_reader_t* self) int CEF_CALLBACK xml_reader_move_to_attribute_byindex( - struct _cef_xml_reader_t* self, size_t index) + struct _cef_xml_reader_t* self, int index) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); if (!self) return 0; + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return 0; // Execute bool _retval = CefXmlReaderCppToC::Get(self)->MoveToAttribute( diff --git a/libcef_dll/ctocpp/v8value_ctocpp.cc b/libcef_dll/ctocpp/v8value_ctocpp.cc index adf9739d..78adb9d9 100644 --- a/libcef_dll/ctocpp/v8value_ctocpp.cc +++ b/libcef_dll/ctocpp/v8value_ctocpp.cc @@ -452,13 +452,18 @@ bool CefV8ValueCToCpp::HasValue(const CefString& key) } -bool CefV8ValueCToCpp::HasValue(size_t index) +bool CefV8ValueCToCpp::HasValue(int index) { if (CEF_MEMBER_MISSING(struct_, has_value_byindex)) return false; // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return false; + // Execute int _retval = struct_->has_value_byindex(struct_, index); @@ -489,13 +494,18 @@ bool CefV8ValueCToCpp::DeleteValue(const CefString& key) } -bool CefV8ValueCToCpp::DeleteValue(size_t index) +bool CefV8ValueCToCpp::DeleteValue(int index) { if (CEF_MEMBER_MISSING(struct_, delete_value_byindex)) return false; // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return false; + // Execute int _retval = struct_->delete_value_byindex(struct_, index); @@ -526,13 +536,18 @@ CefRefPtr CefV8ValueCToCpp::GetValue(const CefString& key) } -CefRefPtr CefV8ValueCToCpp::GetValue(size_t index) +CefRefPtr CefV8ValueCToCpp::GetValue(int index) { if (CEF_MEMBER_MISSING(struct_, get_value_byindex)) return NULL; // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return NULL; + // Execute cef_v8value_t* _retval = struct_->get_value_byindex(struct_, index); @@ -570,13 +585,17 @@ bool CefV8ValueCToCpp::SetValue(const CefString& key, } -bool CefV8ValueCToCpp::SetValue(size_t index, CefRefPtr value) +bool CefV8ValueCToCpp::SetValue(int index, CefRefPtr value) { if (CEF_MEMBER_MISSING(struct_, set_value_byindex)) return false; // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return false; // Verify param: value; type: refptr_same DCHECK(value.get()); if (!value.get()) diff --git a/libcef_dll/ctocpp/v8value_ctocpp.h b/libcef_dll/ctocpp/v8value_ctocpp.h index d570075e..c824d03d 100644 --- a/libcef_dll/ctocpp/v8value_ctocpp.h +++ b/libcef_dll/ctocpp/v8value_ctocpp.h @@ -49,14 +49,14 @@ public: virtual CefTime GetDateValue() OVERRIDE; virtual CefString GetStringValue() OVERRIDE; virtual bool HasValue(const CefString& key) OVERRIDE; - virtual bool HasValue(size_t index) OVERRIDE; + virtual bool HasValue(int index) OVERRIDE; virtual bool DeleteValue(const CefString& key) OVERRIDE; - virtual bool DeleteValue(size_t index) OVERRIDE; + virtual bool DeleteValue(int index) OVERRIDE; virtual CefRefPtr GetValue(const CefString& key) OVERRIDE; - virtual CefRefPtr GetValue(size_t index) OVERRIDE; + virtual CefRefPtr GetValue(int index) OVERRIDE; virtual bool SetValue(const CefString& key, CefRefPtr value, PropertyAttribute attribute) OVERRIDE; - virtual bool SetValue(size_t index, CefRefPtr value) OVERRIDE; + virtual bool SetValue(int index, CefRefPtr value) OVERRIDE; virtual bool SetValue(const CefString& key, AccessControl settings, PropertyAttribute attribute) OVERRIDE; virtual bool GetKeys(std::vector& keys) OVERRIDE; diff --git a/libcef_dll/ctocpp/xml_reader_ctocpp.cc b/libcef_dll/ctocpp/xml_reader_ctocpp.cc index 75899225..23f7351b 100644 --- a/libcef_dll/ctocpp/xml_reader_ctocpp.cc +++ b/libcef_dll/ctocpp/xml_reader_ctocpp.cc @@ -315,13 +315,18 @@ size_t CefXmlReaderCToCpp::GetAttributeCount() } -CefString CefXmlReaderCToCpp::GetAttribute(size_t index) +CefString CefXmlReaderCToCpp::GetAttribute(int index) { if (CEF_MEMBER_MISSING(struct_, get_attribute_byindex)) return CefString(); // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return CefString(); + // Execute cef_string_userfree_t _retval = struct_->get_attribute_byindex(struct_, index); @@ -434,13 +439,18 @@ int CefXmlReaderCToCpp::GetLineNumber() } -bool CefXmlReaderCToCpp::MoveToAttribute(size_t index) +bool CefXmlReaderCToCpp::MoveToAttribute(int index) { if (CEF_MEMBER_MISSING(struct_, move_to_attribute_byindex)) return false; // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + // Verify param: index; type: simple_byval + DCHECK(index >= 0); + if (index < 0) + return false; + // Execute int _retval = struct_->move_to_attribute_byindex(struct_, index); diff --git a/libcef_dll/ctocpp/xml_reader_ctocpp.h b/libcef_dll/ctocpp/xml_reader_ctocpp.h index acf8745f..27bbdc70 100644 --- a/libcef_dll/ctocpp/xml_reader_ctocpp.h +++ b/libcef_dll/ctocpp/xml_reader_ctocpp.h @@ -49,14 +49,14 @@ public: virtual CefString GetValue() OVERRIDE; virtual bool HasAttributes() OVERRIDE; virtual size_t GetAttributeCount() OVERRIDE; - virtual CefString GetAttribute(size_t index) OVERRIDE; + virtual CefString GetAttribute(int index) OVERRIDE; virtual CefString GetAttribute(const CefString& qualifiedName) OVERRIDE; virtual CefString GetAttribute(const CefString& localName, const CefString& namespaceURI) OVERRIDE; virtual CefString GetInnerXml() OVERRIDE; virtual CefString GetOuterXml() OVERRIDE; virtual int GetLineNumber() OVERRIDE; - virtual bool MoveToAttribute(size_t index) OVERRIDE; + virtual bool MoveToAttribute(int index) OVERRIDE; virtual bool MoveToAttribute(const CefString& qualifiedName) OVERRIDE; virtual bool MoveToAttribute(const CefString& localName, const CefString& namespaceURI) OVERRIDE; diff --git a/tools/make_cpptoc_impl.py b/tools/make_cpptoc_impl.py index e3d366d7..e1c8293c 100644 --- a/tools/make_cpptoc_impl.py +++ b/tools/make_cpptoc_impl.py @@ -114,6 +114,14 @@ def make_cpptoc_function_impl_new(name, func, defined_names): '\n if ('+arg_name+'Count > 0 && !'+arg_name+')'\ '\n return'+retval_default+';' + # check index params + index_params = arg.parent.get_attrib_list('index_param') + if not index_params is None and arg_name in index_params: + result += comment+\ + '\n DCHECK('+arg_name+' >= 0);'\ + '\n if ('+arg_name+' < 0)'\ + '\n return'+retval_default+';' + if len(optional) > 0: result += '\n // Unverified params: '+string.join(optional,', ') diff --git a/tools/make_ctocpp_impl.py b/tools/make_ctocpp_impl.py index a74cb56e..dd8a7496 100644 --- a/tools/make_ctocpp_impl.py +++ b/tools/make_ctocpp_impl.py @@ -118,7 +118,15 @@ def make_ctocpp_function_impl_new(clsname, name, func): result += comment+\ '\n DCHECK(!'+arg_name+'.empty());'\ '\n if ('+arg_name+'.empty())'\ - '\n return'+retval_default+';' + '\n return'+retval_default+';' + + # check index params + index_params = arg.parent.get_attrib_list('index_param') + if not index_params is None and arg_name in index_params: + result += comment+\ + '\n DCHECK('+arg_name+' >= 0);'\ + '\n if ('+arg_name+' < 0)'\ + '\n return'+retval_default+';' if len(optional) > 0: result += '\n // Unverified params: '+string.join(optional,', ') diff --git a/tools/translator.README.txt b/tools/translator.README.txt index b4f0fe16..1c5b8645 100644 --- a/tools/translator.README.txt +++ b/tools/translator.README.txt @@ -79,6 +79,8 @@ Supported method/function attributes: resulting C API function. optional_param=[param] (Optional) Parameter name that will be optional instead of required. + index_param=[param] (Optional) Parameter name representing an index + value that will be verified as >= 0. default_retval=[string] (Required for enumeration types, Optional for other types) Specify the default return value. count_func=[param:func] (Required for non-const non-string std::vector