Merge "fixed tc error in GetEvasFromUiApp" into tizen_2.2
[framework/osp/web.git] / src / controls / FWebCtrlWebSetting.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FWebCtrlWebSetting.cpp
20  * @brief               The file contains the definition of WebSetting class.
21  *
22  * The file contains the definition of WebSetting class.
23  */
24 #include <new>
25 #include <FBaseResult.h>
26 #include <FBaseSysLog.h>
27 #include <FWebCtrlWebSetting.h>
28 #include <FSec_AccessController.h>
29 #include "FWebCtrl_WebSettingImpl.h"
30
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Security;
34 using namespace Tizen::Ui::Controls;
35
36
37 namespace Tizen { namespace Web { namespace Controls
38 {
39
40
41 WebSetting::WebSetting(void)
42         : __pWebSettingImpl(new (std::nothrow) _WebSettingImpl())
43 {
44         SysTryReturnVoidResult(NID_WEB_CTRL, __pWebSettingImpl, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
45 }
46
47
48 WebSetting::WebSetting(const WebSetting& setting)
49         : __pWebSettingImpl(new (std::nothrow) _WebSettingImpl(*_WebSettingImpl::GetInstance(&setting)))
50 {
51         SysTryReturnVoidResult(NID_WEB_CTRL, __pWebSettingImpl, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
52 }
53
54
55 WebSetting&
56 WebSetting::operator =(const WebSetting& setting)
57 {
58         if (&setting == this)
59         {
60                 return *this;
61         }
62
63         Object::operator =(setting);
64         _WebSettingImpl* pImpl = _WebSettingImpl::GetInstance(this);
65         if (pImpl)
66         {
67                 *pImpl = *_WebSettingImpl::GetInstance(&setting);
68         }
69
70         return *this;
71 }
72
73
74 WebSetting::~WebSetting(void)
75 {
76         delete __pWebSettingImpl;
77         __pWebSettingImpl = null;
78 }
79
80
81 void
82 WebSetting::SetCacheControl(CacheMode mode)
83 {
84         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
85
86         ClearLastResult();
87         result r = E_SUCCESS;
88
89         r = _AccessController::CheckUserPrivilege(_PRV_WEB_SERVICE);
90         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
91         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
92
93         __pWebSettingImpl->SetCacheControl(mode);
94
95         SysLog(NID_WEB_CTRL, "The current value of mode is %d", mode);
96 }
97
98
99 CacheMode
100 WebSetting::GetCacheControl(void) const
101 {
102         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
103
104         return __pWebSettingImpl->GetCacheControl();
105 }
106
107
108 void
109 WebSetting::SetFontSize(int fontSize)
110 {
111         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
112
113         __pWebSettingImpl->SetFontSize(fontSize);
114
115         SysLog(NID_WEB_CTRL, "The current value of fontSize is %d", fontSize);
116 }
117
118
119 int
120 WebSetting::GetFontSize(void) const
121 {
122         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
123
124         return __pWebSettingImpl->GetFontSize();
125 }
126
127
128 void
129 WebSetting::SetDefaultTextEncoding(const String& encoding)
130 {
131         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
132
133         __pWebSettingImpl->SetDefaultTextEncoding(encoding);
134
135         SysLog(NID_WEB_CTRL, "The current value of encoding is %ls", encoding.GetPointer());
136 }
137
138
139 String
140 WebSetting::GetDefaultTextEncoding(void) const
141 {
142         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
143
144         return __pWebSettingImpl->GetDefaultTextEncoding();
145 }
146
147
148 void
149 WebSetting::SetJavascriptEnabled(bool enable)
150 {
151         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
152
153         __pWebSettingImpl->SetJavascriptEnabled(enable);
154
155         SysLog(NID_WEB_CTRL, "The current value of enable is %d", enable);
156 }
157
158
159 void
160 WebSetting::SetAutoImageLoadEnabled(bool enable)
161 {
162         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
163
164         __pWebSettingImpl->SetAutoImageLoadEnabled(enable);
165
166         SysLog(NID_WEB_CTRL, "The current value of enable is %d", enable);
167 }
168
169
170 bool
171 WebSetting::IsJavascriptEnabled(void) const
172 {
173         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
174
175         return __pWebSettingImpl->IsJavascriptEnabled();
176 }
177
178
179 bool
180 WebSetting::IsAutoImageLoadEnabled(void) const
181 {
182         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
183
184         return __pWebSettingImpl->IsAutoImageLoadEnabled();
185 }
186
187
188 void
189 WebSetting::SetInputStyle(InputStyle inputStyle)
190 {
191         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
192
193         __pWebSettingImpl->SetInputStyle(inputStyle);
194
195         SysLog(NID_WEB_CTRL, "The current value of inputStyle is %d", inputStyle);
196 }
197
198
199 InputStyle
200 WebSetting::GetInputStyle(void) const
201 {
202         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
203
204         return __pWebSettingImpl->GetInputStyle();
205 }
206
207
208 void
209 WebSetting::SetCertificateErrorHandlingMode(CertificateErrorHandlingMode mode)
210 {
211         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
212
213         ClearLastResult();
214         result r = E_SUCCESS;
215
216         r = _AccessController::CheckUserPrivilege(_PRV_WEB_SERVICE);
217         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
218         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
219
220         __pWebSettingImpl->SetCertificateErrorHandlingMode(mode);
221
222         SysLog(NID_WEB_CTRL, "The current value of mode is %d", mode);
223 }
224
225
226 CertificateErrorHandlingMode
227 WebSetting::GetCertificateErrorHandlingMode(void) const
228 {
229         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
230
231         return __pWebSettingImpl->GetCertificateErrorHandlingMode();
232 }
233
234
235 void
236 WebSetting::SetUserAgent(const String& agent)
237 {
238         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
239
240         __pWebSettingImpl->SetUserAgent(agent);
241
242         SysLog(NID_WEB_CTRL, "The current value of agent is %ls", agent.GetPointer());
243 }
244
245
246 String
247 WebSetting::GetUserAgent(void) const
248 {
249         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
250
251         return __pWebSettingImpl->GetUserAgent();
252 }
253
254
255 void
256 WebSetting::SetAutoFittingEnabled(bool enable)
257 {
258         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
259
260         __pWebSettingImpl->SetAutoFittingEnabled(enable);
261
262         SysLog(NID_WEB_CTRL, "The current value of enable is %d", enable);
263 }
264
265
266 bool
267 WebSetting::IsAutoFittingEnabled(void) const
268 {
269         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
270
271         return __pWebSettingImpl->IsAutoFittingEnabled();
272 }
273
274
275 void 
276 WebSetting::SetJavaScriptPopupEnabled(bool enable)
277 {
278         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
279
280         __pWebSettingImpl->SetJavaScriptPopupEnabled(enable);
281
282         SysLog(NID_WEB_CTRL, "The current value of enable is %d", enable);
283 }
284
285
286 bool
287 WebSetting::IsJavaScriptPopupEnabled(void) const
288 {
289         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
290
291         return __pWebSettingImpl->IsJavaScriptPopupEnabled();
292 }
293
294
295 void
296 WebSetting::SetGeolocationEnabled(bool enable)
297 {
298         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
299
300         ClearLastResult();
301         result r = E_SUCCESS;
302
303         r = _AccessController::CheckUserPrivilege(_PRV_WEB_SERVICE);
304         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
305         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
306
307         __pWebSettingImpl->SetGeolocationEnabled(enable);
308
309         SysLog(NID_WEB_CTRL, "The current value of enable is %d", enable);
310 }
311
312
313 bool
314 WebSetting::IsGeolocationEnabled(void) const
315 {
316         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
317
318         return __pWebSettingImpl->IsGeolocationEnabled();
319 }
320
321
322 void
323 WebSetting::SetAutoFormDataShowEnabled(bool enable)
324 {
325         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
326
327         ClearLastResult();
328         result r = E_SUCCESS;
329
330         r = _AccessController::CheckUserPrivilege(_PRV_WEB_SERVICE);
331         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
332         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
333
334         __pWebSettingImpl->SetAutoFormDataShowEnabled(enable);
335
336         SysLog(NID_WEB_CTRL, "The current value of enable is %d", enable);
337 }
338
339
340 bool
341 WebSetting::IsAutoFormDataShowEnabled(void) const
342 {
343         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
344
345         return __pWebSettingImpl->IsAutoFormDataShowEnabled();
346 }
347
348
349 void
350 WebSetting::SetAutoLoginFormFillEnabled(bool enable)
351 {
352         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
353
354         ClearLastResult();
355         result r = E_SUCCESS;
356
357         r = _AccessController::CheckUserPrivilege(_PRV_WEB_SERVICE);
358         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
359         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
360
361         __pWebSettingImpl->SetAutoLoginFormFillEnabled(enable);
362
363         SysLog(NID_WEB_CTRL, "The current value of enable is %d", enable);
364 }
365
366
367 bool
368 WebSetting::IsAutoLoginFormFillEnabled(void) const
369 {
370         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
371
372         return __pWebSettingImpl->IsAutoLoginFormFillEnabled();
373 }
374
375
376 bool
377 WebSetting::Equals(const Object& obj) const
378 {
379         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
380
381         const WebSetting* pRhs = dynamic_cast< const WebSetting* >(&obj);
382         if (pRhs == null)
383         {
384                 return false;
385         }
386
387         return __pWebSettingImpl->Equals(*pRhs->__pWebSettingImpl);
388 }
389
390
391 int
392 WebSetting::GetHashCode(void) const
393 {
394         SysAssertf(__pWebSettingImpl != null, "Not yet constructed. Construct() should be called before use.");
395
396         return __pWebSettingImpl->GetHashCode();
397 }
398
399
400 }}} // Tizen::Web::Controls