summaryrefslogtreecommitdiff
path: root/src/controls/FWebCtrl_EflWebkit.cpp
blob: 1485ca90d1cdbf1fee53bfbeef4588d007dc5a7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//
// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

/**
 * @file		FWebCtrl_EflWebkit.cpp
 * @brief		The file contains the definition of _EflWebkit class.
 *
 * The file contains the definition of _EflWebkit class.
 */
#include <unique_ptr.h>
#include <EWebKit2.h>
#include <net_connection.h>
#include <vconf.h>
#include <FAppApp.h>
#include <FGrpPoint.h>
#include <FGrpRectangle.h>
#include <FIoDbEnumerator.h>
#include <FUiAnimVisualElement.h>
#include <FApp_AppInfo.h>
#include <FBaseSysLog.h>
#include <FBase_StringConverter.h>
#include <FGrp_CoordinateSystem.h>
#include <FIo_DirectoryImpl.h>
#include <FIo_DatabaseImpl.h>
#include <FIo_FileImpl.h>
#include <FSecCert_CertService.h>
#include "FUiAnim_EflNode.h"
#include "FUiAnim_VisualElementImpl.h"
#include "FWebCtrl_EflWebkit.h"
#include "FWebCtrl_Utility.h"
#include "FWebCtrl_WebImpl.h"


using namespace Tizen::Base;
using namespace Tizen::Graphics;
using namespace Tizen::Io;
using namespace Tizen::Security::Cert;
using namespace Tizen::Ui;
using namespace Tizen::Ui::Animations;


namespace Tizen { namespace Web { namespace Controls
{


_EflWebkit::_EflWebkit(void)
	: __pWebFrame(null)
{
}


_EflWebkit::~_EflWebkit(void)
{
//	evas_object_smart_member_del(__pWebFrame);
	evas_object_del(__pWebFrame);
	__pWebFrame = null;
}


result
_EflWebkit::Construct(const Rectangle& rect, VisualElement& containerVisualElement)
{
	result r = E_SUCCESS;

	const _VisualElementImpl* pWebVisualElementImpl = _VisualElementImpl::GetInstance(containerVisualElement);
	SysAssertf(pWebVisualElementImpl, "Failed to get VisualElement of Web control.");

	_EflNode* pEflNode = dynamic_cast< _EflNode* >(pWebVisualElementImpl->GetNativeNode());
	SysAssertf(pEflNode, "Failed to get native node.");

	Evas* pEvas = pEflNode->GetEvas();
	SysAssertf(pEvas, "Failed to get Evas.");

	__pWebFrame = ewk_view_add(pEvas);
	SysTryReturnResult(NID_WEB_CTRL, __pWebFrame, E_SYSTEM, "A system error has been occurred. Failed to create webkit instance.");

	pEflNode->AddNativeSmartObject(containerVisualElement, __pWebFrame);

	evas_object_pass_events_set(__pWebFrame, EINA_TRUE);

	r = SetWebConfiguration();
	SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));

	_ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetTransformer();
	SysAssertf(pXformer, "Failed to get coordinate transformer.");

	evas_object_resize(__pWebFrame, pXformer->TransformHorizontal(rect.width), pXformer->TransformVertical(rect.height));
	evas_object_move(__pWebFrame, pXformer->TransformHorizontal(rect.x), pXformer->TransformVertical(rect.y));

	return E_SUCCESS;
}


result
_EflWebkit::SetWebConfiguration(void) const
{
	result r = E_SUCCESS;

	Ewk_Context* pContext = ewk_view_context_get(__pWebFrame);
	SysAssertf(pContext, "Failed to request.");

	ewk_view_text_selection_enable_set(__pWebFrame, EINA_FALSE);

	ewk_context_additional_plugin_path_set(pContext, PLUGIN_DIRECTORY_PATH);

	String certPath(_CertService::GetCertificateCrtFilePath());
	std::unique_ptr<char[]> pcertPath(_StringConverter::CopyToCharArrayN(certPath));
	SysTryReturn(NID_WEB_CTRL, pcertPath.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));

	ewk_context_certificate_file_set(pContext, pcertPath.get());

	r = CreateResourceDirectory();
	SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));

	r = InitializeGeolocationDb();
	SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));

	r = SetProxyAddress();
	SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));

	return E_SUCCESS;
}


result
_EflWebkit::CreateResourceDirectory(void) const
{
	String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + GEOLOCATION_DIRECTORY_PATH);
	String parentPath(L"");

	if (!_FileImpl::IsFileExist(geolocationPath))
	{
		result r = E_SUCCESS;

		r = _DirectoryImpl::Create(geolocationPath, true);
		SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. create geolocation directory.");
	}

	return E_SUCCESS;
}


result
_EflWebkit::InitializeGeolocationDb(void) const
{
	result r = E_SUCCESS;

	_DatabaseImpl db;
	String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + GEOLOCATION_DIRECTORY_PATH + GEOLOCATION_DB_NAME);
	String table(GEOLOCATION_TABLE_NAME);

	r = db.Construct(geolocationPath, "a+", null);
	SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));

	std::unique_ptr<DbEnumerator>	pEnum(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + table + L"'"));
	if (!pEnum.get())
	{
		r = db.ExecuteSql(
			L"CREATE TABLE IF NOT EXISTS " + table + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, origin TEXT, permission INTEGER)",
			true);
		SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
	}

	return E_SUCCESS;
}


result
_EflWebkit::SetProxyAddress(void) const
{
	int ret = -1;
	connection_h handle = null;

	ret = connection_create(&handle);
	SysTryReturnResult(NID_WEB_CTRL, ret >= 0, E_SYSTEM, "A system error has been occurred. Failed to create connection.");

	char* pProxy = null;
	connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;

	ret = connection_get_proxy(handle, family, &pProxy);
	SysTryReturnResult(NID_WEB_CTRL, ret >= 0, E_SYSTEM, "A system error has been occurred. Failed to get proxy address.");

	ret = connection_destroy(handle);
	SysTryReturnResult(NID_WEB_CTRL, ret >= 0, E_SYSTEM, "A system error has been occurred. Failed to destroy connection.");

	Ewk_Context* pContext = ewk_view_context_get(__pWebFrame);
	SysAssertf(pContext, "Failed to get context.");

	if (!pProxy || !strlen(pProxy))
	{
		ewk_context_proxy_uri_set(pContext, null);
	}
	else
	{
		ewk_context_proxy_uri_set(pContext, pProxy);
	}

	SysLog(NID_WEB_CTRL, "The current value of proxy is %s", pProxy);

	if (pProxy)
	{
		free(pProxy);
	}

	return E_SUCCESS;
}


Evas_Object*
_EflWebkit::GetWebEvasObject(void) const
{
	return __pWebFrame;
}


}}} // Tizen::Web::Controls