From 0dcc6870aa1909155d1e3ab6fa7b1fd7cfce99d3 Mon Sep 17 00:00:00 2001 From: "huayong.xu" Date: Mon, 22 Feb 2021 19:54:23 +0800 Subject: [PATCH] Add APIs for console message & loading error in web engine. This patch is to add some APIs into web engine for console message and loading error. Change-Id: Ifc5647fc82322bad0c028e59b63b78096f09c2a0 --- .../adaptor-framework/web-engine-console-message.h | 82 ++++++++++++++ .../adaptor-framework/web-engine-load-error.h | 106 ++++++++++++++++++ .../adaptor-framework/web-engine-plugin.h | 120 ++++++++++++--------- dali/devel-api/adaptor-framework/web-engine.cpp | 9 +- dali/devel-api/adaptor-framework/web-engine.h | 7 ++ dali/devel-api/file.list | 2 + .../internal/web-engine/common/web-engine-impl.cpp | 7 ++ dali/internal/web-engine/common/web-engine-impl.h | 5 + 8 files changed, 284 insertions(+), 54 deletions(-) create mode 100755 dali/devel-api/adaptor-framework/web-engine-console-message.h create mode 100755 dali/devel-api/adaptor-framework/web-engine-load-error.h mode change 100644 => 100755 dali/internal/web-engine/common/web-engine-impl.h diff --git a/dali/devel-api/adaptor-framework/web-engine-console-message.h b/dali/devel-api/adaptor-framework/web-engine-console-message.h new file mode 100755 index 0000000..22e19fe --- /dev/null +++ b/dali/devel-api/adaptor-framework/web-engine-console-message.h @@ -0,0 +1,82 @@ +#ifndef DALI_WEB_ENGINE_CONSOLE_MESSAGE_H +#define DALI_WEB_ENGINE_CONSOLE_MESSAGE_H + +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +namespace Dali +{ +/** + * @brief A class WebEngineConsoleMessage for console message of web engine. + */ +class WebEngineConsoleMessage +{ +public: + /** + * @brief Enumeration that provides level of log severity. + */ + enum class SeverityLevel + { + EMPTY, + LOG, + WARNING, + ERROR, + DEBUG, + INFO, + }; + + /** + * @brief Constructor. + */ + WebEngineConsoleMessage() = default; + + /** + * @brief Destructor. + */ + virtual ~WebEngineConsoleMessage() = default; + + /** + * @brief Return the source of the console message. + * @return source of the console message if succeded or empty string if failed + */ + virtual std::string GetSource() const = 0; + + /** + * @brief Return line no of the console message. + * @return the line number of the message if succeded or 0 if failed + */ + virtual uint32_t GetLine() const = 0; + + /** + * @brief Return the log severity of the console message. + * @return SeverityLevel indicating the console message level + */ + virtual SeverityLevel GetSeverityLevel() const = 0; + + /** + * @brief Return the console message text. + * @return console message text if succeded or empty string if failed + */ + virtual std::string GetText() const = 0; +}; + +} // namespace Dali + +#endif // DALI_WEB_ENGINE_CONSOLE_MESSAGE_H diff --git a/dali/devel-api/adaptor-framework/web-engine-load-error.h b/dali/devel-api/adaptor-framework/web-engine-load-error.h new file mode 100755 index 0000000..f9d0854 --- /dev/null +++ b/dali/devel-api/adaptor-framework/web-engine-load-error.h @@ -0,0 +1,106 @@ +#ifndef DALI_WEB_ENGINE_LOAD_ERROR_H +#define DALI_WEB_ENGINE_LOAD_ERROR_H + +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +namespace Dali +{ +/** + * @brief A class WebEngineLoadError for loading error of web engine. + */ +class WebEngineLoadError +{ +public: + /** + * @brief Enumeration for indicating error code of page loading. + */ + enum class ErrorCode + { + UNKNOWN = 0, ///< Unknown. + CANCELED, ///< User canceled. + CANT_SUPPORT_MIMETYPE, ///< Can't show the page for this MIME type. + FAILED_FILE_IO, ///< File IO error. + CANT_CONNECT, ///< Cannot connect to the network. + CANT_LOOKUP_HOST, ///< Fail to look up host from the DNS. + FAILED_TLS_HANDSHAKE, ///< Fail to SSL/TLS handshake. + INVALID_CERTIFICATE, ///< Received certificate is invalid. + REQUEST_TIMEOUT, ///< Connection timeout. + TOO_MANY_REDIRECTS, ///< Too many redirects. + TOO_MANY_REQUESTS, ///< Too many requests during this load. + BAD_URL, ///< Malformed URL. + UNSUPPORTED_SCHEME, ///< Unsupported scheme. + AUTHENTICATION, ///< User authentication failed on the server. + INTERNAL_SERVER, ///< Web server has an internal server error. + OTHER, ///< other error. + }; + + /** + * @brief Enumeration that provides type of loading error. + */ + enum class ErrorType + { + NONE, + INTERNAL, + NETWORK, + POLICY, + PLUGIN, + DOWNLOAD, + PRINT, + }; + + /** + * @brief Constructor. + */ + WebEngineLoadError() = default; + + /** + * @brief Destructor. + */ + virtual ~WebEngineLoadError() = default; + + /** + * @brief Query failing URL for this error. + * @return URL that failed to load + */ + virtual std::string GetUrl() const = 0; + + /** + * @brief Query the error code. + * @return The error code + */ + virtual ErrorCode GetCode() const = 0; + + /** + * @brief Query description for this error. + * @return SeverityLevel indicating the console message level + */ + virtual std::string GetDescription() const = 0; + + /** + * @brief Query type for this error. + * @return the error type + */ + virtual ErrorType GetType() const = 0; +}; + +} // namespace Dali + +#endif // DALI_WEB_ENGINE_LOAD_ERROR_H diff --git a/dali/devel-api/adaptor-framework/web-engine-plugin.h b/dali/devel-api/adaptor-framework/web-engine-plugin.h index f71d023..3530b1b 100644 --- a/dali/devel-api/adaptor-framework/web-engine-plugin.h +++ b/dali/devel-api/adaptor-framework/web-engine-plugin.h @@ -32,10 +32,12 @@ class KeyEvent; class PixelData; class TouchEvent; class WebEngineBackForwardList; +class WebEngineConsoleMessage; class WebEngineContext; class WebEngineCookieManager; class WebEngineFormRepostDecision; class WebEngineRequestInterceptor; +class WebEngineLoadError; class WebEngineSettings; class HoverEvent; class WheelEvent; @@ -55,7 +57,7 @@ public: /** * @brief WebView signal type related with page loading error. */ - using WebEnginePageLoadErrorSignalType = Signal; + using WebEnginePageLoadErrorSignalType = Signal)>; // forward declaration. enum class ScrollEdge; @@ -94,6 +96,11 @@ public: using WebEngineRequestInterceptorSignalType = Signal)>; /** + * @brief WebView signal type related with console message will be logged. + */ + using WebEngineConsoleMessageSignalType = Signal)>; + + /** * @brief Alert callback when JavaScript alert is called with a message. * It returns true if a pop-up is created successfully, false otherwise. */ @@ -160,7 +167,7 @@ public: virtual ~WebEnginePlugin() = default; /** - * @brief Creates WebEngine instance. + * @brief Create WebEngine instance. * * @param [in] width The width of Web * @param [in] height The height of Web @@ -170,7 +177,7 @@ public: virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0; /** - * @brief Creates WebEngine instance. + * @brief Create WebEngine instance. * * @param [in] width The width of Web * @param [in] height The height of Web @@ -180,7 +187,7 @@ public: virtual void Create(int width, int height, int argc, char** argv) = 0; /** - * @brief Destroys WebEngine instance. + * @brief Destroy WebEngine instance. */ virtual void Destroy() = 0; @@ -205,28 +212,28 @@ public: virtual WebEngineBackForwardList& GetBackForwardList() const = 0; /** - * @brief Loads a web page based on a given URL. + * @brief Load a web page based on a given URL. * * @param [in] url The URL of the resource to load */ virtual void LoadUrl(const std::string& url) = 0; /** - * @brief Returns the title of the Web. + * @brief Return the title of the Web. * * @return The title of web page */ virtual std::string GetTitle() const = 0; /** - * @brief Returns the Favicon of the Web. + * @brief Return the Favicon of the Web. * * @return Favicon of Dali::PixelData& type */ virtual Dali::PixelData GetFavicon() const = 0; /** - * @brief Gets image to render. + * @brief Get image to render. */ virtual NativeImageInterfacePtr GetNativeImageSource() = 0; @@ -238,7 +245,7 @@ public: virtual const std::string& GetUrl() = 0; /** - * @brief Loads a given string as web contents. + * @brief Load a given string as web contents. * * @param [in] htmlString The string to use as the contents of the web page */ @@ -256,7 +263,7 @@ public: virtual bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) = 0; /** - * @brief Requests loading the given contents by MIME type into the view object + * @brief Request loading the given contents by MIME type into the view object * * @param[in] contents The content to load * @param[in] contentSize The size of contents (in bytes) @@ -269,27 +276,27 @@ public: virtual bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) = 0; /** - * @brief Reloads the Web. + * @brief Reload the Web. */ virtual void Reload() = 0; /** - * @brief Reloads the current page's document without cache + * @brief Reload the current page's document without cache */ virtual bool ReloadWithoutCache() = 0; /** - * @brief Stops loading web contents on the current page. + * @brief Stop loading web contents on the current page. */ virtual void StopLoading() = 0; /** - * @brief Suspends the operation associated with the view. + * @brief Suspend the operation associated with the view. */ virtual void Suspend() = 0; /** - * @brief Resumes the operation associated with the view object after calling Suspend(). + * @brief Resume the operation associated with the view object after calling Suspend(). */ virtual void Resume() = 0; @@ -339,7 +346,7 @@ public: virtual bool StopInspectorServer() = 0; /** - * @brief Scrolls web page of view by deltaX and deltaY. + * @brief Scroll web page of view by deltaX and deltaY. * * @param[in] deltaX horizontal offset to scroll * @param[in] deltaY vertical offset to scroll @@ -347,7 +354,7 @@ public: virtual void ScrollBy(int deltaX, int deltaY) = 0; /** - * @brief Scrolls edge of view by deltaX and deltaY. + * @brief Scroll edge of view by deltaX and deltaY. * * @param[in] deltaX horizontal offset to scroll * @param[in] deltaY vertical offset to scroll @@ -362,41 +369,41 @@ public: virtual void SetScrollPosition(int x, int y) = 0; /** - * @brief Gets the current scroll position of the given view. + * @brief Get the current scroll position of the given view. */ virtual Dali::Vector2 GetScrollPosition() const = 0; /** - * @brief Gets the possible scroll size of the given view. + * @brief Get the possible scroll size of the given view. */ virtual Dali::Vector2 GetScrollSize() const = 0; /** - * @brief Gets the last known content's size. + * @brief Get the last known content's size. */ virtual Dali::Vector2 GetContentSize() const = 0; /** - * @brief Returns whether forward is possible. + * @brief Return whether forward is possible. * * @return True if forward is possible, false otherwise */ virtual bool CanGoForward() = 0; /** - * @brief Goes to forward. + * @brief Go to forward. */ virtual void GoForward() = 0; /** - * @brief Returns whether backward is possible. + * @brief Return whether backward is possible. * * @return True if backward is possible, false otherwise */ virtual bool CanGoBack() = 0; /** - * @brief Goes to back. + * @brief Go to back. */ virtual void GoBack() = 0; @@ -453,12 +460,12 @@ public: virtual void JavaScriptPromptReply(const std::string& result) = 0; /** - * @brief Clears the history of Web. + * @brief Clear the history of Web. */ virtual void ClearHistory() = 0; /** - * @brief Clears all tiles resources of Web. + * @brief Clear all tiles resources of Web. */ virtual void ClearAllTilesResources() = 0; @@ -482,47 +489,47 @@ public: virtual void SetSize(int width, int height) = 0; /** - * @brief Sets background color of web page. + * @brief Set background color of web page. * * @param[in] color Background color */ virtual void SetDocumentBackgroundColor(Dali::Vector4 color) = 0; /** - * @brief Clears tiles when hidden. + * @brief Clear tiles when hidden. * * @param[in] cleared Whether tiles are cleared or not */ virtual void ClearTilesWhenHidden(bool cleared) = 0; /** - * @brief Sets multiplier of cover area of tile. + * @brief Set multiplier of cover area of tile. * * @param[in] multiplier The multiplier of cover area */ virtual void SetTileCoverAreaMultiplier(float multiplier) = 0; /** - * @brief Enables cursor by client. + * @brief Enable cursor by client. * * @param[in] enabled Whether cursor is enabled or not */ virtual void EnableCursorByClient(bool enabled) = 0; /** - * @brief Gets the selected text. + * @brief Get the selected text. * * @return the selected text */ virtual std::string GetSelectedText() const = 0; /** - * @brief Sends Touch Events. + * @brief Send Touch Events. */ virtual bool SendTouchEvent(const TouchEvent& touch) = 0; /** - * @brief Sends Key Events. + * @brief Send Key Events. */ virtual bool SendKeyEvent(const KeyEvent& event) = 0; @@ -539,50 +546,50 @@ public: virtual void EnableKeyEvents(bool enabled) = 0; /** - * @brief Sets focus. + * @brief Set focus. * @param[in] focused True if focus is gained, false lost. */ virtual void SetFocus(bool focused) = 0; /** - * @brief Sets zoom factor of the current page. + * @brief Set zoom factor of the current page. * @param[in] zoomFactor a new factor to be set. */ virtual void SetPageZoomFactor(float zoomFactor) = 0; /** - * @brief Queries the current zoom factor of the page。 + * @brief Query the current zoom factor of the page。 * @return The current page zoom factor. */ virtual float GetPageZoomFactor() const = 0; /** - * @brief Sets the current text zoom level。. + * @brief Set the current text zoom level。. * @param[in] zoomFactor a new factor to be set. */ virtual void SetTextZoomFactor(float zoomFactor) = 0; /** - * @brief Gets the current text zoom level. + * @brief Get the current text zoom level. * @return The current text zoom factor. */ virtual float GetTextZoomFactor() const = 0; /** - * @brief Gets the current load progress of the page. + * @brief Get the current load progress of the page. * @return The load progress of the page. */ virtual float GetLoadProgressPercentage() const = 0; /** - * @brief Scales the current page, centered at the given point. + * @brief Scale the current page, centered at the given point. * @param[in] scaleFactor a new factor to be scaled. * @param[in] point a center coordinate. */ virtual void SetScaleFactor(float scaleFactor, Dali::Vector2 point) = 0; /** - * @brief Gets the current scale factor of the page. + * @brief Get the current scale factor of the page. * @return The current scale factor. */ virtual float GetScaleFactor() const = 0; @@ -602,7 +609,7 @@ public: virtual bool SetVisibility(bool visible) = 0; /** - * @brief Searches and highlights the given string in the document. + * @brief Search and highlight the given string in the document. * @param[in] text The text to find * @param[in] options The options to find * @param[in] maxMatchCount The maximum match count to find @@ -649,7 +656,7 @@ public: virtual bool CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) = 0; /** - * @brief Sets callback which will be called upon geolocation permission request. + * @brief Set callback which will be called upon geolocation permission request. * * @param[in] callback The callback for requesting geolocation permission */ @@ -668,68 +675,68 @@ public: virtual void EnableVideoHole(bool enabled) = 0; /** - * @brief Sends Hover Events. + * @brief Send Hover Events. * @param[in] event The hover event would be sent. */ virtual bool SendHoverEvent(const HoverEvent& event) = 0; /** - * @brief Sends Wheel Events. + * @brief Send Wheel Events. * @param[in] event The wheel event would be sent. */ virtual bool SendWheelEvent(const WheelEvent& event) = 0; /** - * @brief Connects to this signal to be notified when page loading is started. + * @brief Connect to this signal to be notified when page loading is started. * * @return A signal object to connect with. */ virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0; /** - * @brief Connects to this signal to be notified when page loading is in progress. + * @brief Connect to this signal to be notified when page loading is in progress. * * @return A signal object to connect with. */ virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0; /** - * @brief Connects to this signal to be notified when page loading is finished. + * @brief Connect to this signal to be notified when page loading is finished. * * @return A signal object to connect with. */ virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0; /** - * @brief Connects to this signal to be notified when an error occurs in page loading. + * @brief Connect to this signal to be notified when an error occurs in page loading. * * @return A signal object to connect with. */ virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0; /** - * @brief Connects to this signal to be notified when scroll edge is reached. + * @brief Connect to this signal to be notified when scroll edge is reached. * * @return A signal object to connect with. */ virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0; /** - * @brief Connects to this signal to be notified when url is changed. + * @brief Connect to this signal to be notified when url is changed. * * @return A signal object to connect with. */ virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0; /** - * @brief Connects to this signal to be notified when form repost decision is requested. + * @brief Connect to this signal to be notified when form repost decision is requested. * * @return A signal object to connect with. */ virtual WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal() = 0; /** - * @brief Connects to this signal to be notified when frame is rendered. + * @brief Connect to this signal to be notified when frame is rendered. * * @return A signal object to connect with. */ @@ -741,6 +748,13 @@ public: * @return A signal object to connect with. */ virtual WebEngineRequestInterceptorSignalType& RequestInterceptorSignal() = 0; + + /** + * @brief Connect to this signal to be notified when console message will be logged. + * + * @return A signal object to connect with. + */ + virtual WebEngineConsoleMessageSignalType& ConsoleMessageSignal() = 0; }; // specialization has to be done in the same namespace diff --git a/dali/devel-api/adaptor-framework/web-engine.cpp b/dali/devel-api/adaptor-framework/web-engine.cpp index 65a93dc..d186a61 100755 --- a/dali/devel-api/adaptor-framework/web-engine.cpp +++ b/dali/devel-api/adaptor-framework/web-engine.cpp @@ -15,14 +15,16 @@ * */ -// CLASS HEADER +// CLASSHEADER #include // INTERNAL INCLUDES #include +#include #include #include #include +#include #include #include @@ -505,4 +507,9 @@ Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& WebEngine::Request return GetImplementation(*this).RequestInterceptorSignal(); } +Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& WebEngine::ConsoleMessageSignal() +{ + return GetImplementation(*this).ConsoleMessageSignal(); +} + } // namespace Dali diff --git a/dali/devel-api/adaptor-framework/web-engine.h b/dali/devel-api/adaptor-framework/web-engine.h index 1684f02..1c6e97a 100755 --- a/dali/devel-api/adaptor-framework/web-engine.h +++ b/dali/devel-api/adaptor-framework/web-engine.h @@ -671,6 +671,13 @@ public: */ Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal(); + /** + * @brief Connects to this signal to be notified when console message will be logged. + * + * @return A signal object to connect with. + */ + Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& ConsoleMessageSignal(); + private: // Not intended for application developers /** * @brief Internal constructor diff --git a/dali/devel-api/file.list b/dali/devel-api/file.list index a3064b4..b1aca21 100755 --- a/dali/devel-api/file.list +++ b/dali/devel-api/file.list @@ -91,9 +91,11 @@ SET( devel_api_adaptor_framework_header_files ${adaptor_devel_api_dir}/adaptor-framework/web-engine.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-back-forward-list-item.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-back-forward-list.h + ${adaptor_devel_api_dir}/adaptor-framework/web-engine-console-message.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-context.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-cookie-manager.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-form-repost-decision.h + ${adaptor_devel_api_dir}/adaptor-framework/web-engine-load-error.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-plugin.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-request-interceptor.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-settings.h diff --git a/dali/internal/web-engine/common/web-engine-impl.cpp b/dali/internal/web-engine/common/web-engine-impl.cpp index a8acdb1..bd2f0e2 100755 --- a/dali/internal/web-engine/common/web-engine-impl.cpp +++ b/dali/internal/web-engine/common/web-engine-impl.cpp @@ -27,9 +27,11 @@ // INTERNAL INCLUDES #include #include +#include #include #include #include +#include #include #include #include @@ -600,6 +602,11 @@ Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& WebEngine::Request return mPlugin->RequestInterceptorSignal(); } +Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& WebEngine::ConsoleMessageSignal() +{ + return mPlugin->ConsoleMessageSignal(); +} + } // namespace Adaptor } // namespace Internal } // namespace Dali diff --git a/dali/internal/web-engine/common/web-engine-impl.h b/dali/internal/web-engine/common/web-engine-impl.h old mode 100644 new mode 100755 index b9b37d3..bfac881 --- a/dali/internal/web-engine/common/web-engine-impl.h +++ b/dali/internal/web-engine/common/web-engine-impl.h @@ -489,6 +489,11 @@ public: */ Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal(); + /** + @copydoc Dali::WebEngine::ConsoleMessageSignal() + */ + Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& ConsoleMessageSignal(); + private: /** * @brief Constructor. -- 2.7.4