Skip to content

Commit b7224fd

Browse files
committed
CEF cleanups
1 parent e75555b commit b7224fd

File tree

6 files changed

+22
-78
lines changed

6 files changed

+22
-78
lines changed

MTA10/core/CWebView.cpp

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,17 @@ bool CWebView::IsLoading ()
140140
return m_pWebView->IsLoading ();
141141
}
142142

143-
void CWebView::GetURL ( SString& outURL )
143+
SString CWebView::GetURL ()
144144
{
145145
if ( !m_pWebView )
146-
return;
146+
return "";
147147

148-
if ( !m_bIsLocal )
149-
outURL = static_cast < SString > ( m_pWebView->GetMainFrame ()->GetURL () );
150-
else
151-
outURL = m_strTempURL;
148+
return UTF16ToMbUTF8 ( m_pWebView->GetMainFrame ()->GetURL () );
152149
}
153150

154-
void CWebView::GetTitle ( SString& outTitle )
151+
const SString& CWebView::GetTitle ()
155152
{
156-
outTitle = m_CurrentTitle;
153+
return m_CurrentTitle;
157154
}
158155

159156
void CWebView::SetRenderingPaused ( bool bPaused )
@@ -535,9 +532,7 @@ void CWebView::OnCursorChange ( CefRefPtr<CefBrowser> browser, CefCursorHandle c
535532
////////////////////////////////////////////////////////////////////
536533
void CWebView::OnLoadStart ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame )
537534
{
538-
SString strURL;
539-
ConvertURL ( frame->GetURL (), strURL );
540-
535+
SString strURL = UTF16ToMbUTF8 ( frame->GetURL () );
541536
if ( strURL == "blank" )
542537
return;
543538

@@ -559,8 +554,7 @@ void CWebView::OnLoadEnd ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> fr
559554

560555
if ( frame->IsMain () )
561556
{
562-
SString strURL;
563-
ConvertURL ( frame->GetURL (), strURL );
557+
SString strURL = UTF16ToMbUTF8 ( frame->GetURL () );
564558

565559
// Queue event to run on the main thread
566560
auto func = std::bind ( &CWebBrowserEventsInterface::Events_OnDocumentReady, m_pEventsInterface, strURL );
@@ -576,8 +570,7 @@ void CWebView::OnLoadEnd ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> fr
576570
////////////////////////////////////////////////////////////////////
577571
void CWebView::OnLoadError ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefLoadHandler::ErrorCode errorCode, const CefString& errorText, const CefString& failedURL )
578572
{
579-
SString strURL;
580-
ConvertURL ( failedURL, strURL );
573+
SString strURL = UTF16ToMbUTF8 ( frame->GetURL () );
581574

582575
// Queue event to run on the main thread
583576
auto func = std::bind ( &CWebBrowserEventsInterface::Events_OnLoadingFailed, m_pEventsInterface, strURL, errorCode, SString ( errorText ) );
@@ -734,9 +727,8 @@ bool CWebView::OnBeforePopup ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame
734727
// ATTENTION: This method is called on the IO thread
735728

736729
// Trigger the popup/new tab event
737-
SString strTagetURL, strOpenerURL;
738-
ConvertURL ( target_url, strTagetURL );
739-
ConvertURL ( frame->GetURL (), strOpenerURL );
730+
SString strTagetURL = UTF16ToMbUTF8 ( target_url );
731+
SString strOpenerURL = UTF16ToMbUTF8 ( frame->GetURL () );
740732

741733
// Queue event to run on the main thread
742734
auto func = std::bind ( &CWebBrowserEventsInterface::Events_OnPopup, m_pEventsInterface, strTagetURL, strOpenerURL );
@@ -836,32 +828,3 @@ bool CWebView::OnConsoleMessage ( CefRefPtr<CefBrowser> browser, const CefString
836828

837829
return true;
838830
}
839-
840-
841-
void CWebView::ConvertURL ( const CefString& url, SString& convertedURL )
842-
{
843-
CefURLParts urlParts;
844-
if ( !CefParseURL ( url, urlParts ) )
845-
{
846-
convertedURL = "";
847-
return;
848-
}
849-
WString scheme = urlParts.scheme.str;
850-
851-
if ( scheme == L"http" || scheme == L"https" )
852-
{
853-
convertedURL = UTF16ToMbUTF8 ( urlParts.spec.str );
854-
}
855-
else
856-
{
857-
// Get the file name (charsequence after last /)
858-
WString tempStr = urlParts.path.str;
859-
size_t pos = tempStr.find_last_of ( L"/" );
860-
861-
if ( pos != std::wstring::npos && pos < tempStr.size () )
862-
convertedURL = UTF16ToMbUTF8 ( tempStr.SubStr ( pos + 1 ) );
863-
else
864-
convertedURL = "";
865-
}
866-
}
867-

MTA10/core/CWebView.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH
4545
// Exported methods
4646
bool LoadURL ( const SString& strURL, bool bFilterEnabled = true, const SString& strPostData = SString(), bool bURLEncoded = true, bool bIgnoreCache = false );
4747
bool IsLoading ();
48-
void GetURL ( SString& outURL );
49-
void GetTitle ( SString& outTitle );
48+
SString GetURL ();
49+
const SString& GetTitle ();
5050
void SetRenderingPaused ( bool bPaused );
5151
void Focus ( bool state = true );
5252
IDirect3DTexture9* GetTexture () { return static_cast<IDirect3DTexture9*>(m_pWebBrowserRenderItem->m_pD3DTexture); }
@@ -67,7 +67,6 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH
6767
void InjectKeyboardEvent ( const CefKeyEvent& keyEvent );
6868

6969
bool IsLocal () { return m_bIsLocal; };
70-
void SetTempURL ( const SString& strTempURL ) { m_strTempURL = strTempURL; };
7170

7271
inline float GetAudioVolume () { return m_fVolume; };
7372
bool SetAudioVolume ( float fVolume );
@@ -121,9 +120,6 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH
121120
virtual void OnTitleChange ( CefRefPtr<CefBrowser> browser, const CefString& title ) override;
122121
virtual bool OnTooltip ( CefRefPtr<CefBrowser> browser, CefString& text ) override;
123122
virtual bool OnConsoleMessage ( CefRefPtr<CefBrowser> browser, const CefString& message, const CefString& source, int line ) override;
124-
125-
protected:
126-
void ConvertURL ( const CefString& url, SString& convertedURL );
127123

128124
private:
129125
CefRefPtr<CefBrowser> m_pWebView;
@@ -132,7 +128,6 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH
132128
bool m_bBeingDestroyed;
133129
bool m_bIsLocal;
134130
bool m_bIsTransparent;
135-
SString m_strTempURL;
136131
POINT m_vecMousePosition;
137132
SString m_CurrentTitle;
138133
float m_fVolume;

MTA10/mods/shared_logic/CClientWebBrowser.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ bool CClientWebBrowser::LoadURL ( const SString& strURL, bool bFilterEnabled, co
5656
return m_pWebView->LoadURL ( strURL, bFilterEnabled, strPostData, bURLEncoded, bIgnoreCache );
5757
}
5858

59-
void CClientWebBrowser::GetTitle ( SString& outPageTitle )
59+
const SString& CClientWebBrowser::GetTitle ()
6060
{
61-
m_pWebView->GetTitle ( outPageTitle );
61+
return m_pWebView->GetTitle ();
6262
}
6363

64-
void CClientWebBrowser::GetURL ( SString& outURL )
64+
SString CClientWebBrowser::GetURL ()
6565
{
66-
m_pWebView->GetURL ( outURL );
66+
return m_pWebView->GetURL ();
6767
}
6868

6969
void CClientWebBrowser::SetRenderingPaused ( bool bPaused )
@@ -121,11 +121,6 @@ bool CClientWebBrowser::IsLocal ()
121121
return m_pWebView->IsLocal ();
122122
}
123123

124-
void CClientWebBrowser::SetTempURL ( const SString& strTempURL )
125-
{
126-
m_pWebView->SetTempURL ( strTempURL );
127-
}
128-
129124
float CClientWebBrowser::GetAudioVolume ()
130125
{
131126
return m_pWebView->GetAudioVolume ();

MTA10/mods/shared_logic/CClientWebBrowser.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class CClientWebBrowser : public CClientTexture, public CWebBrowserEventsInterfa
2929

3030
bool IsLoading ();
3131
bool LoadURL ( const SString& strURL, bool bFilterEnabled = true, const SString& strPostData = SString(), bool bURLEncoded = true, bool bIgnoreCache = false );
32-
void GetTitle ( SString& outPageTitle );
33-
void GetURL ( SString& outURL );
32+
const SString& GetTitle ();
33+
SString GetURL ();
3434
void SetRenderingPaused ( bool bPaused );
3535
void Focus ();
3636

@@ -45,7 +45,6 @@ class CClientWebBrowser : public CClientTexture, public CWebBrowserEventsInterfa
4545
void InjectMouseWheel ( int iScrollVert, int iScrollHorz );
4646

4747
bool IsLocal ();
48-
void SetTempURL ( const SString& strTempURL );
4948

5049
inline CResource* GetResource () { return m_pResource; }
5150
inline void SetResource ( CResource* pResource ) { m_pResource = pResource; }

MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ int CLuaFunctionDefs::LoadBrowserURL ( lua_State* luaVM )
149149
// Output deprecated warning, TODO: Remove this at a later point
150150
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" );
151151

152-
pWebBrowser->SetTempURL ( strURL );
153152
lua_pushboolean ( luaVM, pWebBrowser->LoadURL ( "mtalocal://" + strURL, false, strPostData, bURLEncoded, bIgnoreCache ) );
154153
return 1;
155154
}
@@ -281,10 +280,7 @@ int CLuaFunctionDefs::GetBrowserTitle ( lua_State* luaVM )
281280

282281
if ( !argStream.HasErrors () )
283282
{
284-
SString strPageTitle;
285-
pWebBrowser->GetTitle ( strPageTitle );
286-
287-
lua_pushstring ( luaVM, strPageTitle );
283+
lua_pushstring ( luaVM, pWebBrowser->GetTitle () );
288284
return 1;
289285
}
290286
else
@@ -304,10 +300,7 @@ int CLuaFunctionDefs::GetBrowserURL ( lua_State* luaVM )
304300

305301
if ( !argStream.HasErrors () )
306302
{
307-
SString strURL;
308-
pWebBrowser->GetURL ( strURL );
309-
310-
lua_pushstring ( luaVM, strURL );
303+
lua_pushstring ( luaVM, pWebBrowser->GetURL () );
311304
return 1;
312305
}
313306
else

MTA10/sdk/core/CWebViewInterface.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class CWebViewInterface
2424
virtual bool IsLoading () = 0;
2525
virtual void SetBeingDestroyed ( bool state ) = 0;
2626

27-
virtual void GetURL ( SString& outURL ) = 0;
28-
virtual void GetTitle ( SString& outTitle ) = 0;
27+
virtual SString GetURL () = 0;
28+
virtual const SString& GetTitle () = 0;
2929
virtual void SetRenderingPaused ( bool bPaused ) = 0;
3030
virtual void Focus ( bool state = true ) = 0;
3131
virtual IDirect3DTexture9* GetTexture () = 0;
@@ -43,7 +43,6 @@ class CWebViewInterface
4343
virtual void InjectMouseWheel ( int iScrollVert, int iScrollHorz ) = 0;
4444

4545
virtual bool IsLocal () = 0;
46-
virtual void SetTempURL ( const SString& strTempURL ) = 0;
4746

4847
virtual float GetAudioVolume () = 0;
4948
virtual bool SetAudioVolume ( float fVolume ) = 0;

0 commit comments

Comments
 (0)