27#if SO3_WEB_NAVIGATOR_BUILD == 1
28#include "include/cef_app.h"
29#include "include/cef_cookie.h"
30#include "include/cef_task.h"
34 namespace EmbeddedWebNavigator
37 WebNavigatorManager* WebNavigatorManager::thisInstance = 0;
39 WebNavigatorManager::WebNavigatorManager(
const ScolWindowHandle& scolMainWindow, std::string cacheDirectory) : scolMainWindowHandle(scolMainWindow)
42 assert(!WebNavigatorManager::thisInstance);
43 WebNavigatorManager::thisInstance =
this;
46 sCachePath = cacheDirectory;
47 std::replace(sCachePath.begin(), sCachePath.end(),
'/',
'\\');
50 synchroEventSetCookie = CreateEvent(NULL, TRUE, FALSE, NULL);
51 synchroEventDeleteCookie = CreateEvent(NULL, TRUE, FALSE, NULL);
54 bContextInitialized =
false;
57 WebNavigatorManager::WebNavigatorManager() : scolMainWindowHandle(0)
65 CloseHandle(synchroEventSetCookie);
66 synchroEventSetCookie = 0;
67 CloseHandle(synchroEventDeleteCookie);
68 synchroEventDeleteCookie = 0;
72 WebNavigatorList::iterator iWebNavigator = webNavigatorListCopy.begin();
73 if (iWebNavigator != webNavigatorListCopy.end())
80 assert(WebNavigatorManager::thisInstance);
81 WebNavigatorManager::thisInstance = 0;
86 bContextInitialized =
true;
89 void WebNavigatorManager::init()
92 CefEnableHighDPISupport();
96 CefString(&settings.cache_path).FromString(sCachePath);
97 CefString(&settings.log_file).FromString(sCachePath +
"\\libcef.log");
100 std::string strexePath;
101 GetModuleFileName(NULL, exePath, 512);
102 strexePath = exePath;
103 strexePath = strexePath.substr(0, strexePath.find_last_of(
'\\'));
105 CefString(&settings.resources_dir_path).FromString(strexePath +
"\\plugins\\cefres");
106 CefString(&settings.locales_dir_path).FromString(strexePath +
"\\plugins\\cefres\\locales");
109 CefString(&settings.locale).FromASCII(
"en-US");
113 settings.log_severity = LOGSEVERITY_ERROR;
117 settings.multi_threaded_message_loop =
true;
118 settings.windowless_rendering_enabled =
true;
119 settings.ignore_certificate_errors =
true;
120 settings.no_sandbox =
true;
124 CefInitialize(args, settings,
this, NULL);
130 assert(WebNavigatorManager::thisInstance);
131 return *WebNavigatorManager::thisInstance;
136 return WebNavigatorManager::thisInstance;
141 bool cefkill = (WebNavigatorManager::thisInstance && WebNavigatorManager::thisInstance->IsInitialized()) ?
true :
false;
142 SAFE_DELETE(WebNavigatorManager::thisInstance);
158 while (!bContextInitialized)
159 std::this_thread::sleep_for(std::chrono::milliseconds(1));
162 WebNavigator* newWebNavigator =
new WebNavigator(nextUniqueId, scolMainWindowHandle, parentWindowHandle, xPosition, yPosition, width, height, url);
165 webNavigatorList.insert(WebNavigatorList::value_type(nextUniqueId, newWebNavigator));
167 return newWebNavigator;
175 while (!bContextInitialized)
176 std::this_thread::sleep_for(std::chrono::milliseconds(1));
179 WebNavigator* newWebNavigator =
new WebNavigator(nextUniqueId, scolMainWindowHandle, parentWindowHandle, width, height, url, transparency);
182 webNavigatorList.insert(WebNavigatorList::value_type(nextUniqueId, newWebNavigator));
184 return newWebNavigator;
195 WebNavigatorList::iterator iWebNavigatorSearched = webNavigatorList.find(webNavigator->
GetUniqueId());
196 if (iWebNavigatorSearched != webNavigatorList.end())
199 WebNavigator* webNavigator = iWebNavigatorSearched->second;
200 webNavigatorList.erase(iWebNavigatorSearched);
203 delete(webNavigator);
210 WebNavigatorList::iterator iSearchedNavigator = webNavigatorList.find(uniqueId);
211 if (iSearchedNavigator != webNavigatorList.end())
212 return iSearchedNavigator->second;
217 bool WebNavigatorManager::SetCookie(
const std::string& url,
const std::string& name,
const std::string& value,
const std::string& domain,
const std::string& path,
const bool& secure,
const bool& httponly)
219 bool success =
false;
221 CefString(&newCookie.name).FromString(name);
222 CefString(&newCookie.value).FromString(value);
223 CefString(&newCookie.domain).FromString(domain);
224 CefString(&newCookie.path).FromString(path);
225 newCookie.secure = secure;
226 newCookie.httponly = httponly;
229 ResetEvent(synchroEventSetCookie);
231 WaitForSingleObject(synchroEventSetCookie, WEB_NAVIGATOR_SYNCHRO_DEFAULT_WAITING_TIME);
237 bool success =
false;
238 ResetEvent(synchroEventDeleteCookie);
240 WaitForSingleObject(synchroEventDeleteCookie, WEB_NAVIGATOR_SYNCHRO_DEFAULT_WAITING_TIME);
246 if (bInitialized && bContextInitialized)
256 if (targetWebNavigator != 0)
264 if (targetWebNavigator != 0)
272 if (targetWebNavigator != 0)
282 if (targetWebNavigator != 0)
292 if (targetWebNavigator != 0)
302 if (targetWebNavigator != 0)
312 if (targetWebNavigator != 0)
322 if (targetWebNavigator != 0)
332 if (targetWebNavigator != 0)
342 if (targetWebNavigator != 0)
345 targetWebNavigator->
GetListener()->
OnBeforePopup(targetWebNavigator, popupX, popupY, popupWidth, popupHeight, popupUrl);
352 if (targetWebNavigator != 0)
362 if (targetWebNavigator != 0)
372 if (targetWebNavigator != 0)
382 if (targetWebNavigator != 0)
385 targetWebNavigator->
GetListener()->
OnLoadError(targetWebNavigator, frameName, errorCode, failedUrl, errorText);
392 if (targetWebNavigator != 0)
395 targetWebNavigator->
GetListener()->
OnFindResult(targetWebNavigator, identifier, count, selectionRect, activeMatchOrdinal, finalUpdate);
unsigned long GetUniqueId()
WebNavigatorListener * GetListener()
virtual void OnLoadEnd(WebNavigator *sourceWebNavigator, const std::string &frameName, int httpStatusCode)
virtual void OnConsoleMessage(WebNavigator *sourceWebNavigator, const std::string &message, const std::string &source, int line)
virtual void RunModal(WebNavigator *sourceWebNavigator)
virtual void OnExternalCall(WebNavigator *sourceWebNavigator, const SScriptFunction &functionCalled)
virtual void OnLoadError(WebNavigator *sourceWebNavigator, const std::string &frameName, int errorCode, const std::string &failedUrl, std::string &errorText)
virtual void OnAddressChange(WebNavigator *sourceWebNavigator, const std::string &frameName, const std::string &url)
virtual void OnCursorChange(WebNavigator *sourceWebNavigator, HCURSOR newCursor)
virtual void OnExternalCallStr(WebNavigator *sourceWebNavigator, const SScriptFunction &functionCalled)
virtual void OnLoadStart(WebNavigator *sourceWebNavigator, const std::string &frameName)
virtual void OnStatusMessage(WebNavigator *sourceWebNavigator, const std::string &value)
virtual void OnTooltip(WebNavigator *sourceWebNavigator, std::string &text)
virtual void OnBeforePopup(WebNavigator *sourceWebNavigator, int popupX, int popupY, int popupWidth, int popupHeight, std::string popupUrl)
virtual void OnTitleChange(WebNavigator *sourceWebNavigator, const std::string &title)
virtual void OnNavStateChange(WebNavigator *sourceWebNavigator, bool canGoBack, bool canGoForward)
virtual void OnFindResult(WebNavigator *sourceWebNavigator, int identifier, int count, const CefRect &selectionRect, int activeMatchOrdinal, bool finalUpdate)
boost::asio::io_service mainThreadWebMessageQueue
void InvokeStatusMessage(unsigned long uniqueId, const std::string &value)
bool DeleteCookies(const std::string &url, const std::string &cookie_name)
void InvokeRunModal(unsigned long uniqueId)
static WebNavigatorManager * GetSingletonPtr()
void InvokeTooltip(unsigned long uniqueId, std::string &text)
static void DestroyManager()
std::map< unsigned long, WebNavigator * > WebNavigatorList
void InvokeNavStateChange(unsigned long uniqueId, bool canGoBack, bool canGoForward)
void InvokeConsoleMessage(unsigned long uniqueId, const std::string &message, const std::string &source, int line)
void InvokeExternalCall(unsigned long uniqueId, SScriptFunction functionCalled)
void InvokeLoadEnd(unsigned long uniqueId, const std::string &frameName, int httpStatusCode)
void InvokeLoadError(unsigned long uniqueId, const std::string &frameName, int errorCode, const std::string &failedUrl, std::string &errorText)
virtual void OnContextInitialized() OVERRIDE
static WebNavigatorManager & GetSingleton()
void DestroyNavigator(WebNavigator *webNavigator)
WebNavigator * CreateNavigator(const ScolWindowHandle &parentWindowHandle, int xPosition, int yPosition, int width, int height, std::string url)
void InvokeCursorChange(unsigned long uniqueId, HCURSOR newCursor)
void InvokeExternalCallStr(unsigned long uniqueId, SScriptFunction functionCalled)
void InvokeTitleChange(unsigned long uniqueId, const std::string &title)
WebNavigator * GetNavigator(unsigned long uniqueId)
void InvokeFindResult(unsigned long uniqueId, int identifier, int count, const CefRect &selectionRect, int activeMatchOrdinal, bool finalUpdate)
void InvokeLoadStart(unsigned long uniqueId, const std::string &frameName)
bool SetCookie(const std::string &url, const std::string &name, const std::string &value, const std::string &domain, const std::string &path, const bool &secure, const bool &httponly)
void InvokeBeforePopup(unsigned long uniqueId, int popupX, int popupY, int popupWidth, int popupHeight, std::string popupUrl)
std::shared_mutex webMessageQueueCriticalSection
void InvokeAddressChange(unsigned long uniqueId, const std::string &frameName, const std::string &url)
static void DeleteCookies(std::string url, std::string cookie_name, bool *result, HANDLE synchro)
static void SetCookie(std::string url, CefCookie cookie, bool *result, HANDLE synchro)