Skip to content

Commit

Permalink
CEF cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jushar committed Sep 9, 2015
1 parent 85df037 commit 16d64b7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 78 deletions.
57 changes: 10 additions & 47 deletions MTA10/core/CWebView.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -535,9 +532,7 @@ void CWebView::OnCursorChange ( CefRefPtr<CefBrowser> browser, CefCursorHandle c
////////////////////////////////////////////////////////////////////
void CWebView::OnLoadStart ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame )
{
SString strURL;
ConvertURL ( frame->GetURL (), strURL );

SString strURL = UTF16ToMbUTF8 ( frame->GetURL () );
if ( strURL == "blank" )
return;

Expand All @@ -559,8 +554,7 @@ void CWebView::OnLoadEnd ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> 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 );
Expand All @@ -576,8 +570,7 @@ void CWebView::OnLoadEnd ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> fr
////////////////////////////////////////////////////////////////////
void CWebView::OnLoadError ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> 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 ) );
Expand Down Expand Up @@ -734,9 +727,8 @@ bool CWebView::OnBeforePopup ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame
// ATTENTION: This method is called on the IO thread

// Trigger the popup/new tab event
SString strTagetURL, strOpenerURL;
ConvertURL ( target_url, strTagetURL );
ConvertURL ( frame->GetURL (), 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 );
Expand Down Expand Up @@ -836,32 +828,3 @@ bool CWebView::OnConsoleMessage ( CefRefPtr<CefBrowser> 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 = "";
}
}

9 changes: 2 additions & 7 deletions MTA10/core/CWebView.h
Expand Up @@ -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<IDirect3DTexture9*>(m_pWebBrowserRenderItem->m_pD3DTexture); }
Expand All @@ -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 );
Expand Down Expand Up @@ -121,9 +120,6 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH
virtual void OnTitleChange ( CefRefPtr<CefBrowser> browser, const CefString& title ) override;
virtual bool OnTooltip ( CefRefPtr<CefBrowser> browser, CefString& text ) override;
virtual bool OnConsoleMessage ( CefRefPtr<CefBrowser> browser, const CefString& message, const CefString& source, int line ) override;

protected:
void ConvertURL ( const CefString& url, SString& convertedURL );

private:
CefRefPtr<CefBrowser> m_pWebView;
Expand All @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions MTA10/mods/shared_logic/CClientWebBrowser.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 ();
Expand Down
5 changes: 2 additions & 3 deletions MTA10/mods/shared_logic/CClientWebBrowser.h
Expand Up @@ -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 ();

Expand All @@ -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; }
Expand Down
11 changes: 2 additions & 9 deletions MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions MTA10/sdk/core/CWebViewInterface.h
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 16d64b7

Please sign in to comment.