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>
27 #include <net_connection.h>
29 #include <FGrpPoint.h>
30 #include <FGrpRectangle.h>
31 #include <FSysVibrator.h>
32 #include <FUiAnimVisualElement.h>
33 #include <FBaseSysLog.h>
34 #include <FBase_StringConverter.h>
35 #include <FGrp_CoordinateSystem.h>
36 #include <FSecCert_CertService.h>
37 #include <FUi_Control.h>
38 #include <FUi_Window.h>
39 #include "FUiAnim_EflNode.h"
40 #include "FUiAnim_VisualElementImpl.h"
41 #include "FUiAnim_VisualElementSurfaceImpl.h"
42 #include "FWebCtrl_EflWebkit.h"
43 #include "FWebCtrl_Utility.h"
44 #include "FWebCtrl_WebImpl.h"
47 using namespace Tizen::Base;
48 using namespace Tizen::Graphics;
49 using namespace Tizen::Io;
50 using namespace Tizen::Security::Cert;
51 using namespace Tizen::Ui;
52 using namespace Tizen::Ui::Animations;
55 namespace Tizen { namespace Web { namespace Controls
59 static const char PLUGIN_DIRECTORY_PATH[] = "/usr/lib/osp/browser-plugin/";
61 static const wchar_t ICON_DB_DIRECTORY_PATH[] = L"data/.webkit/iconDatabase/";
62 static const wchar_t ICON_DB_FILE_NAME[] = L"icon.db";
65 _EflWebkit::_EflWebkit(void)
67 , __pContainerVisualElement(null)
73 _EflWebkit::~_EflWebkit(void)
75 if (__pContainerVisualElement)
77 __pContainerVisualElement->SetSurface(null);
85 evas_object_del(__pWebFrame);
92 _EflWebkit::Construct(const Rectangle& rect, VisualElement& containerVisualElement, _Control* pControl)
96 const _VisualElementImpl* pWebVisualElementImpl = _VisualElementImpl::GetInstance(containerVisualElement);
97 SysAssertf(pWebVisualElementImpl, "Failed to get VisualElement of Web control.");
99 _EflNode* pEflNode = dynamic_cast< _EflNode* >(pWebVisualElementImpl->GetNativeNode());
100 SysAssertf(pEflNode, "Failed to get native node.");
102 Evas* pEvas = pEflNode->GetEvas();
103 SysAssertf(pEvas, "Failed to get Evas.");
105 __pWebFrame = ewk_view_add(pEvas);
106 SysTryReturnResult(NID_WEB_CTRL, __pWebFrame, E_SYSTEM, "A system error has been occurred. Failed to create webkit instance.");
108 evas_object_pass_events_set(__pWebFrame, EINA_TRUE);
110 r = SetWebConfiguration();
111 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
113 _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetTransformer();
114 SysAssertf(pXformer, "Failed to get coordinate transformer.");
116 evas_object_resize(__pWebFrame, pXformer->TransformHorizontal(rect.width), pXformer->TransformVertical(rect.height));
117 evas_object_move(__pWebFrame, pXformer->TransformHorizontal(rect.x), pXformer->TransformVertical(rect.y));
120 pEflNode->AddNativeSmartObject(containerVisualElement, __pWebFrame);
122 __pContainerVisualElement = &containerVisualElement;
124 DisplayContext* pDisplayContext = pControl->GetRootWindow()->GetDisplayContext();
125 SysTryReturn(NID_WEB_CTRL, pDisplayContext, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
127 __pSurface = _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(*pDisplayContext, (Handle)__pWebFrame, Dimension(rect.width, rect.height));
128 SysTryReturn(NID_WEB_CTRL, __pSurface, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
130 containerVisualElement.SetSurface(__pSurface);
138 _EflWebkit::SetWebConfiguration(void) const
140 result r = E_SUCCESS;
142 Ewk_Context* pContext = ewk_view_context_get(__pWebFrame);
143 SysAssertf(pContext, "Failed to request.");
145 Ewk_Settings* pSettings = ewk_view_settings_get(__pWebFrame);
146 SysAssertf(pSettings, "Failed to get webkit instance.");
148 ewk_context_cache_model_set(pContext, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
150 ewk_settings_text_selection_enabled_set(pSettings, EINA_FALSE);
151 ewk_settings_uses_keypad_without_user_action_set(pSettings, EINA_FALSE);
153 ewk_context_additional_plugin_path_set(pContext, PLUGIN_DIRECTORY_PATH);
155 String certPath(_CertService::GetCertificateCrtFilePath());
156 std::unique_ptr<char[]> pCertPath(_StringConverter::CopyToCharArrayN(certPath));
157 SysTryReturn(NID_WEB_CTRL, pCertPath.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
159 ewk_context_certificate_file_set(pContext, pCertPath.get());
161 String iconPath(App::App::GetInstance()->GetAppRootPath() + ICON_DB_DIRECTORY_PATH + ICON_DB_FILE_NAME);
162 std::unique_ptr<char[]> pIconPath(_StringConverter::CopyToCharArrayN(iconPath));
163 SysTryReturn(NID_WEB_CTRL, pIconPath.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
165 ewk_context_icon_database_path_set(pContext, pIconPath.get());
167 InitializeCustomHeader();
174 _EflWebkit::SetProxyAddress(char* pProxy) const
176 Ewk_Context* pContext = ewk_view_context_get(__pWebFrame);
177 SysAssertf(pContext, "Failed to get context.");
179 if (!pProxy || !strlen(pProxy))
181 ewk_context_proxy_uri_set(pContext, null);
185 ewk_context_proxy_uri_set(pContext, pProxy);
188 SysLog(NID_WEB_CTRL, "The current value of proxy is %s", pProxy);
195 _EflWebkit::InitializeCustomHeader(void) const
197 char pAcceptLang[6] = {0, };
198 char* pLangSet = vconf_get_str(VCONFKEY_LANGSET);
199 const char name[] = "Accept-Language";
201 if (pLangSet && strlen(pLangSet))
203 strncpy(pAcceptLang, pLangSet, 2);
205 char *pRawData = strchr(pLangSet, '_');
206 if (pRawData && strlen(pLangSet) >= 5)
208 strcat(pAcceptLang, "-");
209 strncat(pAcceptLang, pRawData + 1, 2);
214 strcat(pAcceptLang, "en");
218 ewk_view_custom_header_add(__pWebFrame, name, pAcceptLang);
223 _EflWebkit::GetWebEvasObject(void) const
229 }}} // Tizen::Web::Controls