From 16d64b71d57b2a2083e7b1c6f32014dd82a515eb Mon Sep 17 00:00:00 2001 From: Jusonex Date: Wed, 9 Sep 2015 13:31:37 +0200 Subject: [PATCH] CEF cleanups --- MTA10/core/CWebView.cpp | 57 ++++--------------- MTA10/core/CWebView.h | 9 +-- MTA10/mods/shared_logic/CClientWebBrowser.cpp | 13 ++--- MTA10/mods/shared_logic/CClientWebBrowser.h | 5 +- .../lua/CLuaFunctionDefs.Browser.cpp | 11 +--- MTA10/sdk/core/CWebViewInterface.h | 5 +- 6 files changed, 22 insertions(+), 78 deletions(-) diff --git a/MTA10/core/CWebView.cpp b/MTA10/core/CWebView.cpp index d47cba7e47..a6d62fe126 100644 --- a/MTA10/core/CWebView.cpp +++ b/MTA10/core/CWebView.cpp @@ -140,20 +140,17 @@ bool CWebView::IsLoading () return m_pWebView->IsLoading (); } -void CWebView::GetURL ( SString& outURL ) +SString CWebView::GetURL () { if ( !m_pWebView ) - return; + return ""; - if ( !m_bIsLocal ) - outURL = static_cast < SString > ( m_pWebView->GetMainFrame ()->GetURL () ); - else - outURL = m_strTempURL; + return UTF16ToMbUTF8 ( m_pWebView->GetMainFrame ()->GetURL () ); } -void CWebView::GetTitle ( SString& outTitle ) +const SString& CWebView::GetTitle () { - outTitle = m_CurrentTitle; + return m_CurrentTitle; } void CWebView::SetRenderingPaused ( bool bPaused ) @@ -535,9 +532,7 @@ void CWebView::OnCursorChange ( CefRefPtr browser, CefCursorHandle c //////////////////////////////////////////////////////////////////// void CWebView::OnLoadStart ( CefRefPtr browser, CefRefPtr frame ) { - SString strURL; - ConvertURL ( frame->GetURL (), strURL ); - + SString strURL = UTF16ToMbUTF8 ( frame->GetURL () ); if ( strURL == "blank" ) return; @@ -559,8 +554,7 @@ void CWebView::OnLoadEnd ( CefRefPtr browser, CefRefPtr fr if ( frame->IsMain () ) { - SString strURL; - ConvertURL ( frame->GetURL (), strURL ); + SString strURL = UTF16ToMbUTF8 ( frame->GetURL () ); // Queue event to run on the main thread auto func = std::bind ( &CWebBrowserEventsInterface::Events_OnDocumentReady, m_pEventsInterface, strURL ); @@ -576,8 +570,7 @@ void CWebView::OnLoadEnd ( CefRefPtr browser, CefRefPtr fr //////////////////////////////////////////////////////////////////// void CWebView::OnLoadError ( CefRefPtr browser, CefRefPtr frame, CefLoadHandler::ErrorCode errorCode, const CefString& errorText, const CefString& failedURL ) { - SString strURL; - ConvertURL ( failedURL, strURL ); + SString strURL = UTF16ToMbUTF8 ( frame->GetURL () ); // Queue event to run on the main thread auto func = std::bind ( &CWebBrowserEventsInterface::Events_OnLoadingFailed, m_pEventsInterface, strURL, errorCode, SString ( errorText ) ); @@ -734,9 +727,8 @@ bool CWebView::OnBeforePopup ( CefRefPtr browser, CefRefPtrGetURL (), strOpenerURL ); + SString strTagetURL = UTF16ToMbUTF8 ( target_url ); + SString strOpenerURL = UTF16ToMbUTF8 ( frame->GetURL () ); // Queue event to run on the main thread auto func = std::bind ( &CWebBrowserEventsInterface::Events_OnPopup, m_pEventsInterface, strTagetURL, strOpenerURL ); @@ -836,32 +828,3 @@ bool CWebView::OnConsoleMessage ( CefRefPtr browser, const CefString return true; } - - -void CWebView::ConvertURL ( const CefString& url, SString& convertedURL ) -{ - CefURLParts urlParts; - if ( !CefParseURL ( url, urlParts ) ) - { - convertedURL = ""; - return; - } - WString scheme = urlParts.scheme.str; - - if ( scheme == L"http" || scheme == L"https" ) - { - convertedURL = UTF16ToMbUTF8 ( urlParts.spec.str ); - } - else - { - // Get the file name (charsequence after last /) - WString tempStr = urlParts.path.str; - size_t pos = tempStr.find_last_of ( L"/" ); - - if ( pos != std::wstring::npos && pos < tempStr.size () ) - convertedURL = UTF16ToMbUTF8 ( tempStr.SubStr ( pos + 1 ) ); - else - convertedURL = ""; - } -} - diff --git a/MTA10/core/CWebView.h b/MTA10/core/CWebView.h index 73377338f1..c11b83bab6 100644 --- a/MTA10/core/CWebView.h +++ b/MTA10/core/CWebView.h @@ -45,8 +45,8 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH // Exported methods bool LoadURL ( const SString& strURL, bool bFilterEnabled = true, const SString& strPostData = SString(), bool bURLEncoded = true, bool bIgnoreCache = false ); bool IsLoading (); - void GetURL ( SString& outURL ); - void GetTitle ( SString& outTitle ); + SString GetURL (); + const SString& GetTitle (); void SetRenderingPaused ( bool bPaused ); void Focus ( bool state = true ); IDirect3DTexture9* GetTexture () { return static_cast(m_pWebBrowserRenderItem->m_pD3DTexture); } @@ -67,7 +67,6 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH void InjectKeyboardEvent ( const CefKeyEvent& keyEvent ); bool IsLocal () { return m_bIsLocal; }; - void SetTempURL ( const SString& strTempURL ) { m_strTempURL = strTempURL; }; inline float GetAudioVolume () { return m_fVolume; }; bool SetAudioVolume ( float fVolume ); @@ -121,9 +120,6 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH virtual void OnTitleChange ( CefRefPtr browser, const CefString& title ) override; virtual bool OnTooltip ( CefRefPtr browser, CefString& text ) override; virtual bool OnConsoleMessage ( CefRefPtr browser, const CefString& message, const CefString& source, int line ) override; - -protected: - void ConvertURL ( const CefString& url, SString& convertedURL ); private: CefRefPtr m_pWebView; @@ -132,7 +128,6 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH bool m_bBeingDestroyed; bool m_bIsLocal; bool m_bIsTransparent; - SString m_strTempURL; POINT m_vecMousePosition; SString m_CurrentTitle; float m_fVolume; diff --git a/MTA10/mods/shared_logic/CClientWebBrowser.cpp b/MTA10/mods/shared_logic/CClientWebBrowser.cpp index bddb1bb66b..45967d3d89 100644 --- a/MTA10/mods/shared_logic/CClientWebBrowser.cpp +++ b/MTA10/mods/shared_logic/CClientWebBrowser.cpp @@ -56,14 +56,14 @@ bool CClientWebBrowser::LoadURL ( const SString& strURL, bool bFilterEnabled, co return m_pWebView->LoadURL ( strURL, bFilterEnabled, strPostData, bURLEncoded, bIgnoreCache ); } -void CClientWebBrowser::GetTitle ( SString& outPageTitle ) +const SString& CClientWebBrowser::GetTitle () { - m_pWebView->GetTitle ( outPageTitle ); + return m_pWebView->GetTitle (); } -void CClientWebBrowser::GetURL ( SString& outURL ) +SString CClientWebBrowser::GetURL () { - m_pWebView->GetURL ( outURL ); + return m_pWebView->GetURL (); } void CClientWebBrowser::SetRenderingPaused ( bool bPaused ) @@ -121,11 +121,6 @@ bool CClientWebBrowser::IsLocal () return m_pWebView->IsLocal (); } -void CClientWebBrowser::SetTempURL ( const SString& strTempURL ) -{ - m_pWebView->SetTempURL ( strTempURL ); -} - float CClientWebBrowser::GetAudioVolume () { return m_pWebView->GetAudioVolume (); diff --git a/MTA10/mods/shared_logic/CClientWebBrowser.h b/MTA10/mods/shared_logic/CClientWebBrowser.h index a3cec2f134..dbde0fae77 100644 --- a/MTA10/mods/shared_logic/CClientWebBrowser.h +++ b/MTA10/mods/shared_logic/CClientWebBrowser.h @@ -29,8 +29,8 @@ class CClientWebBrowser : public CClientTexture, public CWebBrowserEventsInterfa bool IsLoading (); bool LoadURL ( const SString& strURL, bool bFilterEnabled = true, const SString& strPostData = SString(), bool bURLEncoded = true, bool bIgnoreCache = false ); - void GetTitle ( SString& outPageTitle ); - void GetURL ( SString& outURL ); + const SString& GetTitle (); + SString GetURL (); void SetRenderingPaused ( bool bPaused ); void Focus (); @@ -45,7 +45,6 @@ class CClientWebBrowser : public CClientTexture, public CWebBrowserEventsInterfa void InjectMouseWheel ( int iScrollVert, int iScrollHorz ); bool IsLocal (); - void SetTempURL ( const SString& strTempURL ); inline CResource* GetResource () { return m_pResource; } inline void SetResource ( CResource* pResource ) { m_pResource = pResource; } diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp index 9a2685686b..7882ff4dad 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp @@ -149,7 +149,6 @@ int CLuaFunctionDefs::LoadBrowserURL ( lua_State* luaVM ) // Output deprecated warning, TODO: Remove this at a later point m_pScriptDebugging->LogWarning ( luaVM, "This URL scheme is deprecated and may not work in future versions. Please consider using http://mta/* instead. See https://wiki.mtasa.com/wiki/LoadBrowserURL for details" ); - pWebBrowser->SetTempURL ( strURL ); lua_pushboolean ( luaVM, pWebBrowser->LoadURL ( "mtalocal://" + strURL, false, strPostData, bURLEncoded, bIgnoreCache ) ); return 1; } @@ -281,10 +280,7 @@ int CLuaFunctionDefs::GetBrowserTitle ( lua_State* luaVM ) if ( !argStream.HasErrors () ) { - SString strPageTitle; - pWebBrowser->GetTitle ( strPageTitle ); - - lua_pushstring ( luaVM, strPageTitle ); + lua_pushstring ( luaVM, pWebBrowser->GetTitle () ); return 1; } else @@ -304,10 +300,7 @@ int CLuaFunctionDefs::GetBrowserURL ( lua_State* luaVM ) if ( !argStream.HasErrors () ) { - SString strURL; - pWebBrowser->GetURL ( strURL ); - - lua_pushstring ( luaVM, strURL ); + lua_pushstring ( luaVM, pWebBrowser->GetURL () ); return 1; } else diff --git a/MTA10/sdk/core/CWebViewInterface.h b/MTA10/sdk/core/CWebViewInterface.h index cc334da1c2..66dec2e354 100644 --- a/MTA10/sdk/core/CWebViewInterface.h +++ b/MTA10/sdk/core/CWebViewInterface.h @@ -24,8 +24,8 @@ class CWebViewInterface virtual bool IsLoading () = 0; virtual void SetBeingDestroyed ( bool state ) = 0; - virtual void GetURL ( SString& outURL ) = 0; - virtual void GetTitle ( SString& outTitle ) = 0; + virtual SString GetURL () = 0; + virtual const SString& GetTitle () = 0; virtual void SetRenderingPaused ( bool bPaused ) = 0; virtual void Focus ( bool state = true ) = 0; virtual IDirect3DTexture9* GetTexture () = 0; @@ -43,7 +43,6 @@ class CWebViewInterface virtual void InjectMouseWheel ( int iScrollVert, int iScrollHorz ) = 0; virtual bool IsLocal () = 0; - virtual void SetTempURL ( const SString& strTempURL ) = 0; virtual float GetAudioVolume () = 0; virtual bool SetAudioVolume ( float fVolume ) = 0;