2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FWebCtrl_EflWebkit.cpp
20 * @brief The file contains the definition of _EflWebkit class.
22 * The file contains the definition of _EflWebkit class.
24 #include <unique_ptr.h>
26 #include <net_connection.h>
28 #include <FGrpPoint.h>
29 #include <FGrpRectangle.h>
30 #include <FIoDbEnumerator.h>
31 #include <FSysVibrator.h>
32 #include <FUiAnimVisualElement.h>
33 #include <FApp_AppInfo.h>
34 #include <FBaseSysLog.h>
35 #include <FBase_StringConverter.h>
36 #include <FGrp_CoordinateSystem.h>
37 #include <FIo_DirectoryImpl.h>
38 #include <FIo_DatabaseImpl.h>
39 #include <FIo_FileImpl.h>
40 #include <FSecCert_CertService.h>
41 #include <FSys_VibratorImpl.h>
42 #include <FUi_Control.h>
43 #include <FUi_Window.h>
44 #include "FUiAnim_EflNode.h"
45 #include "FUiAnim_VisualElementImpl.h"
46 #include "FUiAnim_VisualElementSurfaceImpl.h"
47 #include "FWebCtrl_EflWebkit.h"
48 #include "FWebCtrl_Utility.h"
49 #include "FWebCtrl_WebImpl.h"
52 using namespace Tizen::Base;
53 using namespace Tizen::Graphics;
54 using namespace Tizen::Io;
55 using namespace Tizen::Security::Cert;
56 using namespace Tizen::Ui;
57 using namespace Tizen::Ui::Animations;
60 namespace Tizen { namespace Web { namespace Controls
64 static const char PLUGIN_DIRECTORY_PATH[] = "/usr/lib/osp/browser-plugin/";
67 extern const wchar_t CUSTOM_DB_DIRECTORY_PATH[] = L"data/.webkit/customDatabase/";
68 extern const wchar_t USER_CONFIRM_DB_NAME[] = L"userConfirm.db";
69 extern const wchar_t GEOLOCATION_TABLE_NAME[] = L"geolocationPermission";
70 extern const wchar_t CUSTOM_PROTOCOL_TABLE_NAME[] = L"customProtocol";
71 extern const wchar_t CUSTOM_CONTENT_TABLE_NAME[] = L"customContent";
72 extern const wchar_t CERTIFICATE_TABLE_NAME[] = L"certificate";
75 static const int CUSTOM_DB_TABLE_COUNT= 4;
78 _EflWebkit::_EflWebkit(void)
80 , __pContainerVisualElement(null)
86 _EflWebkit::~_EflWebkit(void)
88 if (__pContainerVisualElement)
90 __pContainerVisualElement->SetSurface(null);
93 // evas_object_smart_member_del(__pWebFrame);
94 evas_object_del(__pWebFrame);
100 _EflWebkit::Construct(const Rectangle& rect, VisualElement& containerVisualElement, _Control* pControl)
102 result r = E_SUCCESS;
104 const _VisualElementImpl* pWebVisualElementImpl = _VisualElementImpl::GetInstance(containerVisualElement);
105 SysAssertf(pWebVisualElementImpl, "Failed to get VisualElement of Web control.");
107 _EflNode* pEflNode = dynamic_cast< _EflNode* >(pWebVisualElementImpl->GetNativeNode());
108 SysAssertf(pEflNode, "Failed to get native node.");
110 Evas* pEvas = pEflNode->GetEvas();
111 SysAssertf(pEvas, "Failed to get Evas.");
113 __pWebFrame = ewk_view_add(pEvas);
114 SysTryReturnResult(NID_WEB_CTRL, __pWebFrame, E_SYSTEM, "A system error has been occurred. Failed to create webkit instance.");
116 evas_object_pass_events_set(__pWebFrame, EINA_TRUE);
118 r = SetWebConfiguration();
119 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
121 _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetTransformer();
122 SysAssertf(pXformer, "Failed to get coordinate transformer.");
124 evas_object_resize(__pWebFrame, pXformer->TransformHorizontal(rect.width), pXformer->TransformVertical(rect.height));
125 evas_object_move(__pWebFrame, pXformer->TransformHorizontal(rect.x), pXformer->TransformVertical(rect.y));
128 pEflNode->AddNativeSmartObject(containerVisualElement, __pWebFrame);
130 __pContainerVisualElement = &containerVisualElement;
132 DisplayContext* pDisplayContext = pControl->GetRootWindow()->GetDisplayContext();
133 SysTryReturn(NID_WEB_CTRL, pDisplayContext, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
135 __pSurface = _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(*pDisplayContext, (Handle)__pWebFrame, Dimension(rect.width, rect.height));
136 SysTryReturn(NID_WEB_CTRL, __pSurface, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
138 containerVisualElement.SetSurface(__pSurface);
146 _EflWebkit::SetWebConfiguration(void) const
148 result r = E_SUCCESS;
150 Ewk_Context* pContext = ewk_view_context_get(__pWebFrame);
151 SysAssertf(pContext, "Failed to request.");
153 Ewk_Settings* pSettings = ewk_view_settings_get(__pWebFrame);
154 SysAssertf(pSettings, "Failed to get webkit instance.");
156 ewk_context_cache_model_set(pContext, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
158 ewk_settings_text_selection_enabled_set(pSettings, EINA_FALSE);
160 ewk_context_additional_plugin_path_set(pContext, PLUGIN_DIRECTORY_PATH);
162 String certPath(_CertService::GetCertificateCrtFilePath());
163 std::unique_ptr<char[]> pcertPath(_StringConverter::CopyToCharArrayN(certPath));
164 SysTryReturn(NID_WEB_CTRL, pcertPath.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
166 ewk_context_certificate_file_set(pContext, pcertPath.get());
168 r = CreateResourceDirectory();
169 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
171 r = InitializeCustomDb();
172 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
174 r = SetProxyAddress();
175 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
182 _EflWebkit::CreateResourceDirectory(void) const
184 String html5FeaturesPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH);
186 if (!_FileImpl::IsFileExist(html5FeaturesPath))
188 result r = E_SUCCESS;
190 r = _DirectoryImpl::Create(html5FeaturesPath, true);
191 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. create html5 features directory.");
199 _EflWebkit::InitializeCustomDb(void) const
201 result r = E_SUCCESS;
204 String path(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
205 String geolocationTable(GEOLOCATION_TABLE_NAME);
206 String protocolTable(CUSTOM_PROTOCOL_TABLE_NAME);
207 String contentTable(CUSTOM_CONTENT_TABLE_NAME);
208 String certificateTable(CERTIFICATE_TABLE_NAME);
210 r = db.Construct(path, "a+", null);
211 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
213 std::unique_ptr<DbEnumerator> pEnum(db.QueryN(L"Select count(name) from sqlite_master Where type='table' And name in ('" + geolocationTable + L"', '" + protocolTable + L"', '" + contentTable + L"', '" + certificateTable + L"')"));
218 r = pEnum->MoveNext();
219 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
221 r = pEnum->GetIntAt(0, count);
222 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
224 if (count == CUSTOM_DB_TABLE_COUNT)
231 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + geolocationTable + L"'"));
235 L"CREATE TABLE IF NOT EXISTS " + geolocationTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, origin TEXT, permission INTEGER)",
237 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
241 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + protocolTable + L"'"));
245 L"CREATE TABLE IF NOT EXISTS " + protocolTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, baseUrl TEXT, url TEXT, mime TEXT, allow INTEGER)",
247 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
251 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + contentTable + L"'"));
255 L"CREATE TABLE IF NOT EXISTS " + contentTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, baseUrl TEXT, url TEXT, mime TEXT, allow INTEGER)",
257 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
261 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + certificateTable + L"'"));
265 L"CREATE TABLE IF NOT EXISTS " + certificateTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, pem TEXT, allow INTEGER)",
267 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
275 _EflWebkit::SetProxyAddress(void) const
278 connection_h handle = null;
280 ret = connection_create(&handle);
281 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to create connection.");
284 connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
286 ret = connection_get_proxy(handle, family, &pProxy);
287 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to get proxy address.");
289 ret = connection_destroy(handle);
290 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to destroy connection.");
292 Ewk_Context* pContext = ewk_view_context_get(__pWebFrame);
293 SysAssertf(pContext, "Failed to get context.");
295 if (!pProxy || !strlen(pProxy))
297 ewk_context_proxy_uri_set(pContext, null);
301 ewk_context_proxy_uri_set(pContext, pProxy);
304 SysLog(NID_WEB_CTRL, "The current value of proxy is %s", pProxy);
316 _EflWebkit::GetWebEvasObject(void) const
322 }}} // Tizen::Web::Controls