From a79442f3fa4962d579be42132f27d97885042de6 Mon Sep 17 00:00:00 2001 From: jianglinyang Date: Sun, 5 Nov 2023 13:25:07 +0000 Subject: [PATCH] =?UTF-8?q?Revert=20"=20AR000IHFC5=20JsBridge=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=9B=B4=E5=A4=9A=E6=A0=BC=E5=BC=8F=EF=BC=9AArray,Map?= =?UTF-8?q?,Object"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 116736bd547a0b9b02b127286083b114b73d4873. --- ohos_nweb/include/nweb.h | 6 +- .../include/nweb_javascript_result_callback.h | 36 +- ohos_nweb/include/nweb_value.h | 375 ++---------------- ohos_nweb/src/cef_delegate/nweb_delegate.cc | 37 +- ohos_nweb/src/cef_delegate/nweb_delegate.h | 8 +- .../src/cef_delegate/nweb_handler_delegate.cc | 246 +++--------- .../src/cef_delegate/nweb_handler_delegate.h | 25 +- ohos_nweb/src/nweb_delegate_interface.h | 3 +- ohos_nweb/src/nweb_impl.cc | 8 +- ohos_nweb/src/nweb_impl.h | 6 +- 10 files changed, 124 insertions(+), 626 deletions(-) diff --git a/ohos_nweb/include/nweb.h b/ohos_nweb/include/nweb.h index f46ea0e1aa..1dec8c978e 100644 --- a/ohos_nweb/include/nweb.h +++ b/ohos_nweb/include/nweb.h @@ -410,12 +410,10 @@ class OHOS_NWEB_EXPORT NWeb : public std::enable_shared_from_this { * * @param object_name String: objector name * @param method_list vector: vector list ,method list - * @param object_id int32_t: object id */ virtual void RegisterArkJSfunction( - const std::string& object_name, - const std::vector& method_list, - const int32_t object_id) = 0; + const std::string& object_name, + const std::vector& method_list) = 0; /** * UnregisterArkJSfunction diff --git a/ohos_nweb/include/nweb_javascript_result_callback.h b/ohos_nweb/include/nweb_javascript_result_callback.h index 00cc3a491b..96ec05f2b1 100644 --- a/ohos_nweb/include/nweb_javascript_result_callback.h +++ b/ohos_nweb/include/nweb_javascript_result_callback.h @@ -29,39 +29,9 @@ namespace OHOS::NWeb { virtual ~NWebJavaScriptResultCallBack() = default; virtual std::shared_ptr GetJavaScriptResult( - std::vector> args, - const std::string& method, - const std::string& object_name, - int32_t routing_id, - int32_t object_id) = 0; - - /* GetJavaScriptObjectMethods - * - * @param object_id: means the JavaScript object id - * @param object_id: means the method name - */ - virtual bool HasJavaScriptObjectMethods( - int32_t object_id, - const std::string& method_name) = 0; - - /* GetJavaScriptObjectMethods - * - * @param object_id: means the JavaScript object id - */ - virtual std::shared_ptr GetJavaScriptObjectMethods( - int32_t object_id) = 0; - - /* RemoveJavaScriptObjectHolder - * - * @param holder: means the JavaScript object is holded by - * it(routing_id) - * @param object_id: means the JavaScript object id - */ - virtual void RemoveJavaScriptObjectHolder(int32_t holder, - int32_t object_id) = 0; - - // Remove Transient JavaScript Object - virtual void RemoveTransientJavaScriptObject() = 0; + std::vector> args, + const std::string &method, + const std::string &object_name) = 0; }; } #endif \ No newline at end of file diff --git a/ohos_nweb/include/nweb_value.h b/ohos_nweb/include/nweb_value.h index ec4f9e1bee..9852198dd2 100644 --- a/ohos_nweb/include/nweb_value.h +++ b/ohos_nweb/include/nweb_value.h @@ -17,366 +17,69 @@ #define NWEB_VALUE_H_ #include -#include -#include #include -#include -#include #include "nweb_export.h" namespace OHOS::NWeb { -union data_union { - int n; - double f; - bool b; - data_union() {} - data_union(int value) : n(value) {} - data_union(double value) : f(value) {} - data_union(bool value) : b(value) {} -}; + union data_union { + int n; + double f; + bool b; + }; class OHOS_NWEB_EXPORT NWebValue { public: - enum class Type : unsigned char { - NONE = 0, - BOOLEAN, - INTEGER, - DOUBLE, - STRING, - BINARY, - DICTIONARY, - LIST, - ERROR, - STRINGARRAY, - BOOLEANARRAY, - DOUBLEARRAY, - INT64ARRAY - }; - - NWebValue() {} - explicit NWebValue(Type type) : type_(type) {} - explicit NWebValue(const int& value) : type_(Type::INTEGER), data_(value) {} - explicit NWebValue(const double& value) : type_(Type::DOUBLE), data_(value) {} - explicit NWebValue(const bool& value) : type_(Type::BOOLEAN), data_(value) {} - explicit NWebValue(const std::string& value) - : type_(Type::STRING), str_(value) {} - NWebValue(const char* data, size_t len) - : type_(Type::BINARY), str_(data, len) {} - explicit NWebValue(const std::vector& value) - : type_(Type::LIST), list_value_(value.begin(), value.end()) {} - explicit NWebValue(const std::map& value) - : type_(Type::DICTIONARY), dictionary_value_(value) {} - - explicit NWebValue(const NWebValue& value) : type_(value.type_) { - switch (type_) { - case Type::NONE: - break; - case Type::BOOLEAN: - data_.b = value.data_.b; - break; - case Type::INTEGER: - data_.n = value.data_.n; - break; - case Type::DOUBLE: - data_.f = value.data_.f; - break; - case Type::STRING: - str_ = value.str_; - break; - case Type::BINARY: - str_ = value.str_; - break; - case Type::LIST: - list_value_ = value.list_value_; - break; - case Type::DICTIONARY: - dictionary_value_ = value.dictionary_value_; - break; - default: - break; - } - } - - NWebValue(std::vector&& value) : type_(Type::LIST) { - std::swap(list_value_, value); - } - NWebValue(std::map&& value) - : type_(Type::DICTIONARY) { - std::swap(dictionary_value_, value); - } - NWebValue(NWebValue&& value) { *this = std::move(value); } - - ~NWebValue() = default; - - NWebValue& operator=(const NWebValue& value) { - SetType(value.type_); - switch (type_) { - case Type::NONE: - break; - case Type::BOOLEAN: - data_.b = value.data_.b; - break; - case Type::INTEGER: - data_.n = value.data_.n; - break; - case Type::DOUBLE: - data_.f = value.data_.f; - break; - case Type::STRING: - str_ = value.str_; - break; - case Type::BINARY: - str_ = value.str_; - break; - case Type::LIST: - list_value_ = value.list_value_; - break; - case Type::DICTIONARY: - dictionary_value_ = value.dictionary_value_; - break; - default: - std::cout << "error: Invalid type" << std::endl; - break; - } - return *this; - } - - NWebValue& operator=(NWebValue&& value) { - std::swap(type_, value.type_); - switch (type_) { - case Type::NONE: - break; - case Type::BOOLEAN: - std::swap(data_.b, value.data_.b); - break; - case Type::INTEGER: - std::swap(data_.n, value.data_.n); - break; - case Type::DOUBLE: - std::swap(data_.f, value.data_.f); - break; - case Type::STRING: - std::swap(str_, value.str_); - break; - case Type::BINARY: - std::swap(str_, value.str_); - break; - case Type::LIST: - std::swap(list_value_, value.list_value_); - break; - case Type::DICTIONARY: - std::swap(dictionary_value_, value.dictionary_value_); - break; - default: - std::cout << "error: Invalid type" << std::endl; - break; - } - return *this; - } - - bool operator==(NWebValue& oVal) { - if (type_ != oVal.type_) - return false; - switch (type_) { - case Type::NONE: - return false; - case Type::BOOLEAN: - return data_.b == oVal.data_.b; - case Type::INTEGER: - return data_.n == oVal.data_.n; - case Type::DOUBLE: - return data_.f == oVal.data_.f; - case Type::STRING: - return str_ == oVal.str_; - case Type::LIST: - if ((*this).list_value_.size() != oVal.list_value_.size()) - return false; - for (size_t i = 0; i < list_value_.size(); ++i) { - NWebValue& lVal = oVal.list_value_[i]; - NWebValue& rVal = (*this).list_value_[i]; - if (!(lVal == rVal)) { - return false; - } - } - return true; - case Type::DICTIONARY: - if ((*this).dictionary_value_.size() != oVal.dictionary_value_.size()) - return false; - for (auto item : dictionary_value_) { - NWebValue& lVal = oVal.dictionary_value_[item.first]; - NWebValue& rVal = (*this).dictionary_value_[item.first]; - if (!(lVal == rVal)) { - return false; - } - } - return true; - case Type::BINARY: - return str_ == oVal.str_; - default: - std::cout << "error: Invalid type" << std::endl; - return false; - } - return false; - } - - bool IsNone() { return GetType() == Type::NONE; } - - bool IsBoolean() { return GetType() == Type::BOOLEAN; } - - bool IsString() { return GetType() == Type::STRING; } - - bool IsDouble() { return GetType() == Type::DOUBLE; } - - bool IsINTEGER() { return GetType() == Type::INTEGER; } - - bool IsList() { return GetType() == Type::LIST; } - - bool IsDictionary() { return GetType() == Type::DICTIONARY; } - - bool IsBinary() { return GetType() == Type::BINARY; } - - bool GetBoolean() { - validateType(Type::BOOLEAN); - return data_.b; - } - - void SetBoolean(bool b) { - validateType(Type::BOOLEAN); - data_.b = b; - } - - void SetString(std::string str) { - validateType(Type::STRING); - str_ = str; - } - - std::string GetString() { - validateType(Type::STRING); - return str_; - } - - void SetDouble(double dou) { - validateType(Type::DOUBLE); - data_.f = dou; - } - - double GetDouble() { - validateType(Type::DOUBLE); - return data_.f; - } - - void SetInt(int num) { - validateType(Type::INTEGER); - data_.n = num; - } - - int GetInt() { - validateType(Type::INTEGER); - return data_.n; - } - - size_t GetListValueSize() { - validateType(Type::LIST); - return list_value_.size(); - } - - std::vector GetListValue() { - validateType(Type::LIST); - return list_value_; - } - - NWebValue& GetListValue(unsigned int index) { - validateType(Type::LIST); - if (index >= list_value_.size()) { - std::cout << "error: index larger than size()" << std::endl; - } - return list_value_[index]; - } - - void AddListValue(const NWebValue& value) { - validateType(Type::LIST); - SetType(Type::LIST); - list_value_.push_back(value); - } - - void deleteListValue() { - validateType(Type::LIST); - SetType(Type::LIST); - list_value_.pop_back(); - } + enum class Type : unsigned char { + NONE = 0, + BOOLEAN, + INTEGER, + DOUBLE, + STRING, + BINARY, + DICTIONARY, + LIST, + ERROR, + STRINGARRAY, + BOOLEANARRAY, + DOUBLEARRAY, + INT64ARRAY + }; - size_t GetDictionaryValueSize() { - validateType(Type::DICTIONARY); - return dictionary_value_.size(); - } + explicit NWebValue(Type type) : type_(type) {} - std::vector GetDictionaryValueKeys() { - validateType(Type::DICTIONARY); - std::vector ret; - for (auto& item : dictionary_value_) { - ret.push_back(item.first); - } - return ret; - } + ~NWebValue() = default; - bool HasDictionaryValueKey(std::string& key) { - validateType(Type::DICTIONARY); - return dictionary_value_.count(key) == 1; - } + bool GetBoolean() { return data_.b; } - std::map GetDictionaryValue() { - validateType(Type::DICTIONARY); - return dictionary_value_; - } + void SetBoolean(bool b) { data_.b = b; } - NWebValue& GetDictionaryValue(std::string& key) { - validateType(Type::DICTIONARY); - return dictionary_value_[key]; - } + void SetString(std::string str) { str_ = str; } - void AddDictionaryValue(std::string key, NWebValue& value) { - validateType(Type::DICTIONARY); - dictionary_value_[key] = value; - } + std::string GetString() { return str_; } - void DeleteDictionaryValue(std::string& key) { - validateType(Type::DICTIONARY); - dictionary_value_.erase(key); - } + void SetDouble(double dou) { data_.f = dou; } - size_t GetBinaryValueSize() { - validateType(Type::BINARY); - return str_.size(); - } + double GetDouble() { return data_.f; } - const char* GetBinaryValue() { - validateType(Type::BINARY); - return (const char*)str_.c_str(); - } + void SetInt(int num) { data_.n = num; } - void SetJsonString(std::string json_string) { str_json_ = json_string; } + int GetInt() { return data_.n; } - std::string GetJsonString() { return str_json_; } + void SetJsonString(std::string json_string) { str_json_ = json_string; } - Type GetType() { return type_; } + std::string GetJsonString() { return str_json_; } - void SetType(Type type) { type_ = type; } + Type GetType() { return type_; } - void validateType(Type type) const { - if (type_ != Type::NONE && type_ != type) { - std::cout << "error: Invalid type" << std::endl; - } - } + void SetType(Type type) { type_ = type; } - int error_ = 0; + int error_ = 0; private: - Type type_ = Type::NONE; - data_union data_; - std::string str_; - std::string str_json_; - std::map dictionary_value_; - std::vector list_value_; + Type type_ = Type::NONE; + data_union data_; + std::string str_; + std::string str_json_; }; } diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index 1d669fbe72..69d3a82da2 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.cc @@ -1047,7 +1047,7 @@ void NWebDelegate::InitializeCef(std::string url, handler_delegate_ = NWebHandlerDelegate::Create( preference_delegate_, render_handler_, event_handler_, find_delegate_, is_enhance_surface, window); - is_popup_ready_ = true; + is_ready_ = true; return; } handler_delegate_ = NWebHandlerDelegate::Create( @@ -1369,7 +1369,7 @@ const CefRefPtr NWebDelegate::GetBrowser() const { } bool NWebDelegate::IsReady() { - return is_popup_ready_ || GetBrowser() != nullptr; + return is_ready_ || GetBrowser() != nullptr; } void NWebDelegate::RequestVisitedHistory() { @@ -1398,32 +1398,13 @@ int NWebDelegate::ContentHeight() { void NWebDelegate::RegisterArkJSfunction( const std::string& object_name, - const std::vector& method_list, - const int32_t object_id) const { - LOG(INFO) << "RegisterArkJSfunction name : " << object_name.c_str(); + const std::vector& method_list) const { + LOG(DEBUG) << "RegisterArkJSfunction name : " << object_name.c_str(); std::vector method_vector; for (std::string method : method_list) { method_vector.push_back(method); } - - if (is_popup_ready_) { - if (handler_delegate_) { - LOG(INFO) << "NWebDelegate::RegisterArkJSfunction popup case, the " - "object_name is " - << object_name.c_str(); - handler_delegate_->SavaArkJSFunctionForPopup(object_name, method_list, - object_id); - } - return; - } else if (!GetBrowser()) { - LOG(ERROR) << "NWebDelegate::RegisterArkJSfunction fail due to " - "GetBrowser() return null, the object_name is " - << object_name.c_str(); - return; - } else { - GetBrowser()->GetHost()->RegisterArkJSfunction(object_name, method_vector, - object_id); - } + GetBrowser()->GetHost()->RegisterArkJSfunction(object_name, method_vector); } void NWebDelegate::UnregisterArkJSfunction( @@ -1434,14 +1415,6 @@ void NWebDelegate::UnregisterArkJSfunction( for (std::string method : method_list) { method_vector.push_back(method); } - - if (!GetBrowser()) { - LOG(ERROR) << "NWebDelegate::UnregisterArkJSfunction fail due to " - "GetBrowser() return null, the object_name is " - << object_name.c_str(); - return; - } - GetBrowser()->GetHost()->UnregisterArkJSfunction(object_name, method_vector); } diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.h b/ohos_nweb/src/cef_delegate/nweb_delegate.h index 3ed1eace47..7c96b23dbd 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.h @@ -144,9 +144,9 @@ class NWebDelegate : public NWebDelegateInterface, public virtual CefRefCount { const std::string& mimeType, const std::string& encoding) override; int ContentHeight() override; - void RegisterArkJSfunction(const std::string& object_name, - const std::vector& method_list, - const int32_t object_id) const override; + void RegisterArkJSfunction( + const std::string& object_name, + const std::vector& method_list) const override; void UnregisterArkJSfunction( const std::string& object_name, @@ -284,7 +284,7 @@ class NWebDelegate : public NWebDelegateInterface, public virtual CefRefCount { uint32_t nweb_id_; #endif bool is_enhance_surface_ = false; - bool is_popup_ready_ = false; + bool is_ready_ = false; bool is_onPause_ = false; static std::set focus_nweb_id_; }; diff --git a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc index 85aed558a0..f9e0a1505d 100644 --- a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc @@ -508,20 +508,6 @@ void NWebHandlerDelegate::OnAfterCreated(CefRefPtr browser) { main_browser_->GetHost()->SetBackgroundColor(preference_delegate_->GetBackgroundColor()); } main_browser_->GetHost()->SetNativeWindow(window_); - - // window new case, register ark js functions - ObjectMethodMap::iterator it; - for (it = javascript_method_map_.begin(); - it != javascript_method_map_.end(); ++it) { - std::vector method_vector; - for (std::string method : it->second.second) { - method_vector.push_back(method); - } - if(main_browser_ && main_browser_->GetHost()) { - main_browser_->GetHost()->RegisterArkJSfunction( - it->second.first, method_vector, it->first); - } - } } return; } @@ -601,25 +587,6 @@ void NWebHandlerDelegate::NotifyPopupWindowResult(bool result) { popupWindowCallback_ = nullptr; } -void NWebHandlerDelegate::SavaArkJSFunctionForPopup( - const std::string& object_name, - const std::vector& method_list, - const int32_t object_id) { - if (method_list.empty()) { - LOG(INFO) << "NWebHandlerDelegate::SavaArkJSFunctionForPopup method_list " - "is empty"; - return; - } - MethodPair object_pair; - std::unordered_set method_set; - for (std::string method : method_list) { - method_set.emplace(method); - } - object_pair.first = object_name; - object_pair.second = method_set; - javascript_method_map_[object_id] = object_pair; -} - bool NWebHandlerDelegate::OnPreBeforePopup(CefRefPtr browser, CefRefPtr frame, const CefString& target_url, @@ -2016,53 +1983,33 @@ const std::vector NWebHandlerDelegate::GetVisitedHistory() { return std::vector(); } -std::shared_ptr AddNWebValueCef(CefRefPtr argument) { - if (!argument) { - LOG(INFO) << "AddNWebValueCef: argument is null"; - return std::make_shared(); - } - - switch (argument->GetType()) { - case CefValueType::VTYPE_INT: - return std::make_shared(argument->GetInt()); - case CefValueType::VTYPE_DOUBLE: - return std::make_shared(argument->GetDouble()); - case CefValueType::VTYPE_BOOL: - return std::make_shared(argument->GetBool()); - case CefValueType::VTYPE_STRING: - return std::make_shared(argument->GetString().ToString()); - case CefValueType::VTYPE_LIST: { - size_t length = argument->GetList()->GetSize(); - std::vector vec; - for (size_t i = 0; i < length; ++i) { - vec.push_back(*AddNWebValueCef(argument->GetList()->GetValue(i))); - } - return std::make_shared(vec); - } - case CefValueType::VTYPE_DICTIONARY: { - std::map map; - auto dict = argument->GetDictionary(); - CefDictionaryValue::KeyList keys; - dict->GetKeys(keys); - for (auto& key : keys) { - auto val = dict->GetValue(key); - map[key.ToString()] = *AddNWebValueCef(val); - } - return std::make_shared(map); - } - case CefValueType::VTYPE_BINARY: { - auto size = argument->GetBinary()->GetSize(); - auto buff = std::make_unique(size); - argument->GetBinary()->GetData(buff.get(), size, 0); - return std::make_shared(buff.get(), size); +void AddNWebValueCef(std::vector>& vector, + NWebValue::Type type, + CefRefPtr argument) { + std::shared_ptr value = std::make_shared(type); + switch (type) { + case NWebValue::Type::INTEGER: + value->SetInt(argument->GetInt()); + vector.push_back(value); + break; + case NWebValue::Type::DOUBLE: { + value->SetDouble(argument->GetDouble()); + vector.push_back(value); + break; } - case CefValueType::VTYPE_INVALID: - return std::make_shared(); + case NWebValue::Type::BOOLEAN: + value->SetBoolean(argument->GetBool()); + vector.push_back(value); + break; + case NWebValue::Type::STRING: + value->SetString(argument->GetString().ToString()); + vector.push_back(value); + break; default: LOG(INFO) << "AddNWebValueCef: not support value"; + vector.push_back(value); break; } - return std::make_shared(); } std::vector> ParseCefValueTONWebValue( @@ -2071,7 +2018,28 @@ std::vector> ParseCefValueTONWebValue( std::vector> value_vector; for (int i = 0; i < size; i++) { CefRefPtr argument = args->GetValue(i); - value_vector.push_back(AddNWebValueCef(argument)); + switch (argument->GetType()) { + case CefValueType::VTYPE_INT: + AddNWebValueCef(value_vector, NWebValue::Type::INTEGER, argument); + break; + case CefValueType::VTYPE_DOUBLE: { + AddNWebValueCef(value_vector, NWebValue::Type::DOUBLE, argument); + break; + } + case CefValueType::VTYPE_BOOL: + AddNWebValueCef(value_vector, NWebValue::Type::BOOLEAN, argument); + break; + case CefValueType::VTYPE_STRING: + AddNWebValueCef(value_vector, NWebValue::Type::STRING, argument); + break; + case CefValueType::VTYPE_INVALID: + AddNWebValueCef(value_vector, NWebValue::Type::NONE, argument); + break; + default: + LOG(INFO) << "ParseCefValueTONWebValue: not support value"; + AddNWebValueCef(value_vector, NWebValue::Type::NONE, argument); + break; + } } return value_vector; } @@ -2100,78 +2068,37 @@ CefValueType TranslateCefType(NWebValue::Type type) { } } -CefRefPtr ParseNWebValueToValueHelper( - std::shared_ptr value) { - if (!value) { - LOG(ERROR) << "ParseNWebValueToValueHelper: value is null"; - return CefValue::Create(); - } - CefRefPtr cefValue = CefValue::Create(); +CefRefPtr ParseNWebValueToValue(std::shared_ptr value, + CefRefPtr result) { NWebValue::Type type = value->GetType(); switch (type) { case NWebValue::Type::INTEGER: - cefValue->SetInt(value->GetInt()); - return cefValue; + result->SetInt(0, value->GetInt()); + break; case NWebValue::Type::DOUBLE: { - cefValue->SetDouble(value->GetDouble()); - return cefValue; + result->SetDouble(0, value->GetDouble()); + break; } case NWebValue::Type::BOOLEAN: - cefValue->SetBool(value->GetBoolean()); - return cefValue; + result->SetBool(0, value->GetBoolean()); + break; case NWebValue::Type::STRING: - cefValue->SetString(value->GetString()); - return cefValue; - case NWebValue::Type::LIST: { - size_t length = value->GetListValueSize(); - auto cefList = CefListValue::Create(); - for (size_t i = 0; i < length; i++) { - auto nPtr = std::make_shared(value->GetListValue(i)); - auto cefVal = ParseNWebValueToValueHelper(nPtr); - cefList->SetValue(i, cefVal); - } - cefValue->SetList(cefList); - return cefValue; - } - case NWebValue::Type::DICTIONARY: { - auto dict = value->GetDictionaryValue(); - auto cefDict = CefDictionaryValue::Create(); - for (auto& item : dict) { - auto nPtr = std::make_shared(item.second); - auto cefVal = ParseNWebValueToValueHelper(nPtr); - cefDict->SetValue(CefString(item.first), cefVal.get()); - } - cefValue->SetDictionary(cefDict); - return cefValue; - } - case NWebValue::Type::BINARY: { - auto size = value->GetBinaryValueSize(); - auto buff = value->GetBinaryValue(); - auto cefDict = CefBinaryValue::Create(buff, size); - cefValue->SetBinary(cefDict); - return cefValue; - } + result->SetString(0, value->GetString()); + break; case NWebValue::Type::NONE: break; default: - LOG(ERROR) << "ParseNWebValueToValueHelper: not support value type"; + LOG(INFO) << "ParseNWebValueToValue: not support value type"; break; } - return cefValue; -} - -CefRefPtr ParseNWebValueToValue(std::shared_ptr value, - CefRefPtr result) { - result->SetValue(0, ParseNWebValueToValueHelper(value)); return result; } -int NWebHandlerDelegate::NotifyJavaScriptResult(CefRefPtr args, - const CefString& method, - const CefString& object_name, - CefRefPtr result, - int32_t routing_id, - int32_t object_id) { +int NWebHandlerDelegate::NotifyJavaScriptResult( + CefRefPtr args, + const CefString& method, + const CefString& object_name, + CefRefPtr result) { if (args.get() == nullptr || result.get() == nullptr) { return 0; } @@ -2182,8 +2109,8 @@ int NWebHandlerDelegate::NotifyJavaScriptResult(CefRefPtr args, } std::shared_ptr ark_result = - nweb_javascript_callback_->GetJavaScriptResult( - value_vector, method, object_name, routing_id, object_id); + nweb_javascript_callback_->GetJavaScriptResult(value_vector, method, + object_name); if (!ark_result) { return 1; @@ -2192,55 +2119,6 @@ int NWebHandlerDelegate::NotifyJavaScriptResult(CefRefPtr args, return ark_result->error_; } -bool NWebHandlerDelegate::HasJavaScriptObjectMethods( - int32_t object_id, - const CefString& method_name) { - if (!nweb_javascript_callback_) { - LOG(ERROR) << "NWebHandlerDelegate::GetJavaScriptObjectMethods " - "nweb_javascript_callback_ is null"; - return false; - } - return nweb_javascript_callback_->HasJavaScriptObjectMethods(object_id, - method_name); -} - -void NWebHandlerDelegate::GetJavaScriptObjectMethods( - int32_t object_id, - CefRefPtr returned_method_names) { - if (!nweb_javascript_callback_) { - LOG(ERROR) << "NWebHandlerDelegate::GetJavaScriptObjectMethods " - "nweb_javascript_callback_ is null"; - return; - } - std::shared_ptr ark_result = - nweb_javascript_callback_->GetJavaScriptObjectMethods(object_id); - if (!ark_result) { - LOG(ERROR) << "NWebHandlerDelegate::GetJavaScriptObjectMethods " - "result is null"; - return; - } - returned_method_names = ParseNWebValueToValueHelper(ark_result); -} - -void NWebHandlerDelegate::RemoveJavaScriptObjectHolder(int32_t holder, - int32_t object_id) { - if (!nweb_javascript_callback_) { - LOG(ERROR) << "NWebHandlerDelegate::RemoveJavaScriptObjectHolder " - "nweb_javascript_callback_ is null"; - return; - } - nweb_javascript_callback_->RemoveJavaScriptObjectHolder(holder, object_id); -} - -void NWebHandlerDelegate::RemoveTransientJavaScriptObject() { - if (!nweb_javascript_callback_) { - LOG(ERROR) << "NWebHandlerDelegate::RemoveTransientJavaScriptObject " - "nweb_javascript_callback_ is null"; - return; - } - nweb_javascript_callback_->RemoveTransientJavaScriptObject(); -} - #if defined(REPORT_SYS_EVENT) void NWebHandlerDelegate::SetNWebId(uint32_t nwebId) { nweb_id_ = nwebId; diff --git a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h index aa7c69229f..0a8f49abb7 100644 --- a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include "capi/nweb_app_client_extension_callback.h" #include "nweb_download_callback.h" #include "nweb_javascript_result_callback.h" @@ -128,17 +128,7 @@ class NWebHandlerDelegate : public CefClient, int NotifyJavaScriptResult(CefRefPtr args, const CefString& method, const CefString& object_name, - CefRefPtr result, - int32_t routing_id, - int32_t object_id) override; - bool HasJavaScriptObjectMethods(int32_t object_id, - const CefString& method_name) override; - void GetJavaScriptObjectMethods( - int32_t object_id, - CefRefPtr returned_method_names) override; - void RemoveJavaScriptObjectHolder(int32_t holder, int32_t object_id) override; - void RemoveTransientJavaScriptObject() override; - + CefRefPtr result) override; CefRefPtr GetFormHandler() override; // #if defined(OHOS_NWEB_EX) void ShowPasswordDialog(bool is_update, const CefString& url) override; @@ -502,12 +492,6 @@ class NWebHandlerDelegate : public CefClient, void SetContinueNeedFocus(bool continueNeedFocus); void NotifyPopupWindowResult(bool result); - - // save ark js function for window.open - void SavaArkJSFunctionForPopup(const std::string& object_name, - const std::vector& method_list, - const int32_t object_id); - private: void CopyImageToClipboard(CefRefPtr image); // List of existing browser windows. Only accessed on the CEF UI thread. @@ -567,11 +551,6 @@ class NWebHandlerDelegate : public CefClient, float scale_ = 100.0; bool focusState_ = false; bool continueNeedFocus_ = false; - - // js property name and object id - using MethodPair = std::pair>; - using ObjectMethodMap = std::map; - ObjectMethodMap javascript_method_map_; }; } // namespace OHOS::NWeb diff --git a/ohos_nweb/src/nweb_delegate_interface.h b/ohos_nweb/src/nweb_delegate_interface.h index 2aebc7026e..5da4bfc134 100644 --- a/ohos_nweb/src/nweb_delegate_interface.h +++ b/ohos_nweb/src/nweb_delegate_interface.h @@ -163,8 +163,7 @@ class NWebDelegateInterface virtual int ContentHeight() = 0; virtual void RegisterArkJSfunction( const std::string& object_name, - const std::vector& method_list, - const int32_t object_id) const = 0; + const std::vector& method_list) const = 0; virtual void UnregisterArkJSfunction( const std::string& object_name, const std::vector& method_list) const = 0; diff --git a/ohos_nweb/src/nweb_impl.cc b/ohos_nweb/src/nweb_impl.cc index f89027684b..2f05660138 100644 --- a/ohos_nweb/src/nweb_impl.cc +++ b/ohos_nweb/src/nweb_impl.cc @@ -865,14 +865,11 @@ int NWebImpl::LoadWithData(const std::string& data, void NWebImpl::RegisterArkJSfunction( const std::string& object_name, - const std::vector& method_list, - const int32_t object_id) { + const std::vector& method_list) { if (nweb_delegate_ == nullptr) { - WVLOG_E("fail to register ark js function"); return; } - return nweb_delegate_->RegisterArkJSfunction(object_name, method_list, - object_id); + return nweb_delegate_->RegisterArkJSfunction(object_name, method_list); } void NWebImpl::UnregisterArkJSfunction( @@ -1405,6 +1402,7 @@ extern "C" OHOS_NWEB_EXPORT void CreateNWeb(const NWebCreateInfo& create_info, create_info.init_args.is_enhance_surface); nweb = std::make_shared(nweb_id); if (nweb == nullptr) { + WVLOG_E("fail to create nweb instance"); return; } diff --git a/ohos_nweb/src/nweb_impl.h b/ohos_nweb/src/nweb_impl.h index 679e8316c0..96ac4c94f2 100644 --- a/ohos_nweb/src/nweb_impl.h +++ b/ohos_nweb/src/nweb_impl.h @@ -116,9 +116,9 @@ class NWebImpl : public NWeb { int LoadWithData(const std::string& data, const std::string& mimeType, const std::string& encoding) override; - void RegisterArkJSfunction(const std::string& object_name, - const std::vector& method_list, - const int32_t object_id) override; + void RegisterArkJSfunction( + const std::string& object_name, + const std::vector& method_list) override; void UnregisterArkJSfunction( const std::string& object_name, const std::vector& method_list) override; -- Gitee