*\r
* The file contains the definition of _WebManager class.\r
*/\r
+#include <pthread.h>\r
#include <net_connection.h>\r
#include <FBaseSysLog.h>\r
#include <FUiControl.h>\r
namespace Tizen { namespace Web { namespace Controls\r
{\r
\r
+\r
+_WebManager* _WebManager::__pInstance = null;\r
+\r
+\r
_WebManager::_WebManager(void)\r
: __pWebList(null)\r
, __pCallbackList(null)\r
free(__pProxy);\r
}\r
\r
-_WebManager*\r
-_WebManager::GetInstance(void)\r
+\r
+void\r
+_WebManager::InitWebManager(void)\r
{\r
result r = E_SUCCESS;\r
- static _WebManager* pWebMgr = null;\r
\r
- if (pWebMgr == null)\r
- {\r
- pWebMgr = new (std::nothrow) _WebManager();\r
- SysTryReturn(NID_WEB_CTRL, pWebMgr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _WebManager allocation failed.");\r
+ std::unique_ptr<_WebManager> pInstance(new (std::nothrow) _WebManager());\r
+ SysTryReturnVoidResult(NID_WEB_CTRL, pInstance.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));\r
\r
- r = pWebMgr->Construct();\r
- SysTryCatch(NID_WEB_CTRL, !IsFailed(r), , r, "[%s] _WebManager construction failed.", GetErrorMessage(r));\r
- }\r
+ r = pInstance->Construct();\r
+ SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));\r
\r
- return pWebMgr;\r
+ __pInstance = pInstance.release();\r
+ std::atexit(DestroyWebManager);\r
+}\r
\r
-CATCH:\r
- delete pWebMgr;\r
- pWebMgr = null;\r
\r
- return null;\r
+void\r
+_WebManager::DestroyWebManager(void)\r
+{\r
+ delete __pInstance;\r
+ __pInstance = null;\r
}\r
\r
+\r
+_WebManager*\r
+_WebManager::GetInstance(void)\r
+{\r
+ static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;\r
+ if (__pInstance== null)\r
+ {\r
+ ClearLastResult();\r
+ pthread_once(&onceBlock, InitWebManager);\r
+ result r = GetLastResult();\r
+ if (IsFailed(r))\r
+ {\r
+ onceBlock = PTHREAD_ONCE_INIT;\r
+ }\r
+ }\r
+\r
+ return __pInstance;\r
+}\r
+\r
+\r
result\r
_WebManager::Construct(void)\r
{\r
result r = E_SUCCESS;\r
\r
- int ret = -1;\r
- connection_h handle = null;\r
- char* pProxy = null;\r
-\r
std::unique_ptr<ArrayListT< int> > pWebList(new (std::nothrow) ArrayListT< int >());\r
SysTryReturnResult(NID_WEB_CTRL, pWebList.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");\r
r = pWebList->Construct();\r
SysTryReturnResult(NID_WEB_CTRL, pCallbackList.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");\r
r = pCallbackList->Construct();\r
SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));\r
+\r
+ r = InitializeProxyAddress();\r
+ SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r)); \r
+ __pWebList = std::move(pWebList);\r
+ __pCallbackList = std::move(pCallbackList);\r
+\r
+ return E_SUCCESS;\r
+}\r
+\r
+\r
+result\r
+_WebManager::InitializeProxyAddress(void)\r
+{\r
+ int ret = -1;\r
+ connection_h handle = null;\r
+ char* pProxy = null;\r
+\r
ret = connection_create(&handle);
SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to create connection.");
\r
connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
ret = connection_get_proxy(handle, family, &pProxy);
- SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to get proxy address.");
-
+ SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to get proxy address.");\r
+\r
ret = connection_destroy(handle);
SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to destroy connection.");\r
\r
- __pWebList = std::move(pWebList);\r
- __pCallbackList = std::move(pCallbackList);\r
__pProxy = pProxy;\r
\r
return E_SUCCESS;\r
}\r
\r
+\r
result\r
_WebManager::AddWeb(int webAdress)\r
{\r
_Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));\r
\r
r = pWebCore->GetEflWebkit()->SetProxyAddress(__pProxy);\r
-\r
SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));\r
\r
r = __pWebList->Add(webAdress);\r
return E_SUCCESS;\r
}\r
\r
+\r
result\r
_WebManager::RemoveWeb(int webAdress)\r
{\r
r = __pWebList->Remove(webAdress);\r
SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));\r
\r
- r = __pCallbackList->Remove(webAdress);\r
- SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));\r
+ __pCallbackList->Remove(webAdress);\r
\r
return E_SUCCESS;\r
}\r
\r
+\r
bool\r
_WebManager::IsValidWeb(int webAdress) const\r
{\r
return E_SUCCESS;\r
}\r
\r
+\r
result\r
_WebManager::RemoveCallback(int callerAdress, int callbackAdress)\r
{\r
return E_SUCCESS;\r
}\r
\r
+\r
bool\r
_WebManager::IsValidCallback(int callerAdress, int callbackAdress) const\r
{\r
return ret;\r
}\r
\r
+\r
void\r
_WebManager::SetActiveWeb(Tizen::Web::Controls::_WebImpl* pWebAddress)\r
{\r
}\r
}\r
\r
+\r
void\r
_WebManager::RemoveActiveWeb(Tizen::Web::Controls::_WebImpl* pWebAddress)\r
{\r
}\r
}\r
\r
+\r
void\r
_WebManager::SetActivePopup(Tizen::Web::Controls::_WebPopup* pPopupAddress)\r
{\r
__pActivePopup = pPopupAddress;\r
}\r
\r
+\r
void\r
_WebManager::RemoveActivePopup(Tizen::Web::Controls::_WebPopup* pPopupAddress)\r
{\r
}\r
}\r
\r
+\r
} } }\r