diff --git a/ohos_nweb/include/nweb.h b/ohos_nweb/include/nweb.h index 1dec8c978e72ddebff590bae53b7bf25a5704c74..f661215e88e38303ae9b8cecf721d8e8d3f63f41 100644 --- a/ohos_nweb/include/nweb.h +++ b/ohos_nweb/include/nweb.h @@ -792,6 +792,17 @@ class OHOS_NWEB_EXPORT NWeb : public std::enable_shared_from_this { * Set the virtual keyboard to override the web status. */ virtual bool ShouldVirtualKeyboardOverlay() = 0; + + /** + * load the URL with postData using POST method. + * + * @param url String: the URL of the resource to load This value cannot be null. + * @param postData the data will be passed to "POST" request, + * whilch must be "application/x-www-form-urlencoded" encoded. + * + * @return title string for the current page. + */ + virtual int PostUrl(const std::string& url, std::vector& postData) = 0; }; } // namespace OHOS::NWeb diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_delegate.cc index 4cc7c77698ed3c3e01548d5761d947af4d9236c8..5d572f38cf5ebfb31b9f8d6cb3fdeffc04f5cc05 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.cc @@ -678,6 +678,25 @@ int NWebDelegate::Load(const std::string& url) { return NWEB_OK; } +int NWebDelegate::PostUrl(const std::string& url, std::vector& postData) { + GURL gurl = GURL(url); + if (gurl.is_empty() || !gurl.is_valid()) { + GURL gurlWithHttp = GURL("https://" + url); + if (!gurlWithHttp.is_valid()) { + return NWEB_INVALID_URL; + } + } + LOG(DEBUG) << "NWebDelegate::PostUrl url=" << url; + auto browser = GetBrowser(); + if (browser == nullptr) { + LOG(ERROR) << "NWebDelegate::PostUrl browser is nullptr"; + return NWEB_ERR; + } + browser->GetMainFrame()->PostURL(CefString(url), postData); + RequestVisitedHistory(); + return NWEB_OK; +} + bool NWebDelegate::IsNavigatebackwardAllowed() const { LOG(DEBUG) << "NWebDelegate::IsNavigatebackwardAllowed"; if (GetBrowser().get()) { diff --git a/ohos_nweb/src/cef_delegate/nweb_delegate.h b/ohos_nweb/src/cef_delegate/nweb_delegate.h index 7c96b23dbd0b1a38cd9237c791c777043f66362f..d4392e5b67354418f0d28c38f3042f6283112c67 100644 --- a/ohos_nweb/src/cef_delegate/nweb_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_delegate.h @@ -238,6 +238,7 @@ class NWebDelegate : public NWebDelegateInterface, public virtual CefRefCount { void SetToken(void* token) override; void SetVirtualPixelRatio(float ratio) override; void SetNestedScrollMode(const NestedScrollMode& nestedScrollMode) override; + int PostUrl(const std::string& url, std::vector& postData) override; public: int argc_; diff --git a/ohos_nweb/src/nweb_delegate_interface.h b/ohos_nweb/src/nweb_delegate_interface.h index 5da4bfc1340f452d87533d649dcae659b428f714..63a67460e5c35b42e912b75626c070bcbb7779e6 100644 --- a/ohos_nweb/src/nweb_delegate_interface.h +++ b/ohos_nweb/src/nweb_delegate_interface.h @@ -243,6 +243,7 @@ class NWebDelegateInterface virtual void SetNestedScrollMode(const NestedScrollMode& nestedScrollMode) = 0; virtual void SetVirtualKeyBoardArg(int32_t width, int32_t height, double keyboard) = 0; virtual bool ShouldVirtualKeyboardOverlay() = 0; + virtual int PostUrl(const std::string& url, std::vector& postData) = 0; }; } // namespace OHOS::NWeb diff --git a/ohos_nweb/src/nweb_impl.cc b/ohos_nweb/src/nweb_impl.cc index dc18ea2062d4fc2f90a597d4b68a188e9628c634..e14a89dc2d2a764da2c1f8f46b030505b4d13617 100644 --- a/ohos_nweb/src/nweb_impl.cc +++ b/ohos_nweb/src/nweb_impl.cc @@ -842,6 +842,14 @@ int NWebImpl::Load(std::string& url, return nweb_delegate_->Load(url, additionalHttpHeaders); } +int NWebImpl::PostUrl(const std::string& url, + std::vector& postData) { + if (nweb_delegate_ == nullptr) { + return NWEB_ERR; + } + return nweb_delegate_->PostUrl(url, postData); +} + int NWebImpl::LoadWithDataAndBaseUrl(const std::string& baseUrl, const std::string& data, const std::string& mimeType, diff --git a/ohos_nweb/src/nweb_impl.h b/ohos_nweb/src/nweb_impl.h index e541ccf48bb01d29e5c00557a49a467e7f87b6aa..c40dc44cac549bf664c55d4192bbbf328ee461f1 100644 --- a/ohos_nweb/src/nweb_impl.h +++ b/ohos_nweb/src/nweb_impl.h @@ -180,6 +180,7 @@ class NWebImpl : public NWeb { return nweb_delegate_ ? nweb_delegate_->GetCefClient() : nullptr; } void AddNWebToMap(uint32_t id, std::shared_ptr& nweb); + int PostUrl(const std::string& url, std::vector& postData) override; #if defined (OHOS_NWEB_EX) static const std::vector& GetCommandLineArgsForNWebEx();