2 // Open Service Platform
\r
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
\r
5 // Licensed under the Apache License, Version 2.0 (the License);
\r
6 // you may not use this file except in compliance with the License.
\r
7 // You may obtain a copy of the License at
\r
9 // http://www.apache.org/licenses/LICENSE-2.0
\r
11 // Unless required by applicable law or agreed to in writing, software
\r
12 // distributed under the License is distributed on an "AS IS" BASIS,
\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 // See the License for the specific language governing permissions and
\r
15 // limitations under the License.
\r
19 * @file FWebCtrl_WebManager.cpp
\r
20 * @brief The file contains the definition of _WebManager class.
\r
22 * The file contains the definition of _WebManager class.
\r
24 #include <pthread.h>
\r
25 #include <net_connection.h>
\r
26 #include <FBaseSysLog.h>
\r
27 #include <FUiControl.h>
\r
28 #include <FUiCtrl_FormImpl.h>
\r
29 #include "FWebCtrl_EflWebkit.h"
\r
30 #include "FWebCtrl_Web.h"
\r
31 #include "FWebCtrl_WebImpl.h"
\r
32 #include "FWebCtrl_WebManager.h"
\r
33 #include "FWebCtrl_WebPopup.h"
\r
35 using namespace Tizen::Base;
\r
36 using namespace Tizen::Base::Collection;
\r
37 using namespace Tizen::Ui;
\r
38 using namespace Tizen::Ui::Controls;
\r
40 namespace Tizen { namespace Web { namespace Controls
\r
44 _WebManager* _WebManager::__pInstance = null;
\r
47 _WebManager::_WebManager(void)
\r
49 , __pCallbackList(null)
\r
50 , __pActiveWeb(null)
\r
51 , __pActivePopup(null)
\r
56 _WebManager::~_WebManager(void)
\r
63 _WebManager::InitWebManager(void)
\r
65 result r = E_SUCCESS;
\r
67 std::unique_ptr<_WebManager> pInstance(new (std::nothrow) _WebManager());
\r
68 SysTryReturnVoidResult(NID_WEB_CTRL, pInstance.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
\r
70 r = pInstance->Construct();
\r
71 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
\r
73 __pInstance = pInstance.release();
\r
74 std::atexit(DestroyWebManager);
\r
79 _WebManager::DestroyWebManager(void)
\r
87 _WebManager::GetInstance(void)
\r
89 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
\r
90 if (__pInstance== null)
\r
93 pthread_once(&onceBlock, InitWebManager);
\r
94 result r = GetLastResult();
\r
97 onceBlock = PTHREAD_ONCE_INIT;
\r
101 return __pInstance;
\r
106 _WebManager::Construct(void)
\r
108 result r = E_SUCCESS;
\r
110 std::unique_ptr<ArrayListT< int> > pWebList(new (std::nothrow) ArrayListT< int >());
\r
111 SysTryReturnResult(NID_WEB_CTRL, pWebList.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
\r
112 r = pWebList->Construct();
\r
113 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
115 std::unique_ptr<MultiHashMapT< int, int > > pCallbackList(new (std::nothrow) MultiHashMapT< int, int >());
\r
116 SysTryReturnResult(NID_WEB_CTRL, pCallbackList.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
\r
117 r = pCallbackList->Construct();
\r
118 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
120 r = InitializeProxyAddress();
\r
121 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
123 __pWebList = std::move(pWebList);
\r
124 __pCallbackList = std::move(pCallbackList);
\r
131 _WebManager::InitializeProxyAddress(void)
\r
134 connection_h handle = null;
\r
135 char* pProxy = null;
\r
137 ret = connection_create(&handle);
138 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to create connection.");
140 connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
142 ret = connection_get_proxy(handle, family, &pProxy);
143 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to get proxy address.");
\r
145 ret = connection_destroy(handle);
146 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to destroy connection.");
\r
155 _WebManager::AddWeb(int webAdress)
\r
157 result r = E_SUCCESS;
\r
159 _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(webAdress);
\r
161 _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
\r
163 r = pWebCore->GetEflWebkit()->SetProxyAddress(__pProxy);
\r
164 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
166 r = __pWebList->Add(webAdress);
\r
167 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
174 _WebManager::RemoveWeb(int webAdress)
\r
176 result r = E_SUCCESS;
\r
178 r = __pWebList->Remove(webAdress);
\r
179 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
181 __pCallbackList->Remove(webAdress);
\r
188 _WebManager::IsValidWeb(int webAdress) const
\r
190 return __pWebList->Contains(webAdress);
\r
195 _WebManager::AddCallback(int callerAdress, int callbackAdress)
\r
197 result r = E_SUCCESS;
\r
199 r = __pCallbackList->Add(callerAdress, callbackAdress);
\r
200 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
207 _WebManager::RemoveCallback(int callerAdress, int callbackAdress)
\r
209 result r = E_SUCCESS;
\r
211 r = __pCallbackList->Remove(callerAdress, callbackAdress);
\r
212 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
219 _WebManager::IsValidCallback(int callerAdress, int callbackAdress) const
\r
223 result r = __pCallbackList->Contains(callerAdress, callbackAdress, ret);
\r
224 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
\r
231 _WebManager::SetActiveWeb(Tizen::Web::Controls::_WebImpl* pWebAddress)
\r
233 if (__pActiveWeb == null)
\r
235 __pActiveWeb = pWebAddress;
\r
239 if (__pActiveWeb->IsVisible() == true)
\r
243 __pActiveWeb = pWebAddress;
\r
246 if (__pActivePopup != null)
\r
248 __pActivePopup->SetShowState(false);
\r
250 _FormImpl* pFormImpl = __pActiveWeb->GetParentFormImpl(__pActiveWeb);
\r
252 if (pFormImpl != null)
\r
254 __pActivePopup->SetOwner(&pFormImpl->GetPublic());
\r
258 __pActivePopup->SetOwner(&__pActiveWeb->GetPublic());
\r
261 __pActivePopup->SetShowState(true);
\r
262 __pActivePopup->Show();
\r
268 _WebManager::RemoveActiveWeb(Tizen::Web::Controls::_WebImpl* pWebAddress)
\r
270 if (__pActiveWeb == pWebAddress)
\r
272 __pActiveWeb = null;
\r
278 _WebManager::SetActivePopup(Tizen::Web::Controls::_WebPopup* pPopupAddress)
\r
280 __pActivePopup = pPopupAddress;
\r
285 _WebManager::RemoveActivePopup(Tizen::Web::Controls::_WebPopup* pPopupAddress)
\r
287 if (__pActivePopup == pPopupAddress)
\r
289 __pActivePopup = null;
\r