fix bug for geolocation and contents download
[framework/osp/web.git] / src / controls / FWebCtrl_WebSettingImpl.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 <unique_ptr.h>
25 #include <vconf.h>
26 #include <FBaseBoolean.h>
27 #include <FBaseInteger.h>
28 #include <FWebCtrlWebSetting.h>
29 #include <FBaseSysLog.h>
30 #include "FWebCtrl_WebSettingImpl.h"
31
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Ui::Controls;
35
36
37 namespace Tizen { namespace Web { namespace Controls
38 {
39
40
41 static const wchar_t* DEFAULT_ENCODING_MODE = L"UTF-8";
42 static const int DEFAULT_FONT_SIZE = 17;
43 static const float DEFAULT_ZOOM_LEVEL = 2.0f;
44 static const wchar_t* DEFAULT_USER_AGENT = L"Mozilla/5.0 (Linux; U; Tizen 2.0; en-us) AppleWebKit/537.1 (KHTML, like Gecko) Version/2.0 Mobile";
45
46
47 _WebSettingImpl::_WebSettingImpl(void)
48         : __cacheMode(WEB_CACHE_VALIDATED)
49         , __encoding(DEFAULT_ENCODING_MODE)
50         , __fontSize(DEFAULT_FONT_SIZE)
51         , __javascriptEnabled(true)
52         , __autoImageEnabled(true)
53         , __isScrollEnabled(true)
54         , __isPrivateBrowsingEnabled(false)
55         , __isCookieEnabled(true)
56         , __zoomLevel(DEFAULT_ZOOM_LEVEL)
57         , __inputStyle(INPUT_STYLE_FULLSCREEN)
58         , __certificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM)
59         , __autoFittingEnabled(true)
60         , __javaScriptPopupEnabled(true)
61         , __geolocationEnabled(true)
62         , __autoFormDataEnabled(true)
63         , __autoLoginFormEnabled(true)
64 {
65         char* pUserAgent = vconf_get_str(VCONFKEY_BROWSER_USER_AGENT);
66
67         if(pUserAgent)
68         {
69                 __userAgent = pUserAgent;
70                 free(pUserAgent);
71         }
72         else
73         {
74                 __userAgent = DEFAULT_USER_AGENT;
75         }
76 }
77
78
79 _WebSettingImpl::~_WebSettingImpl(void)
80 {
81 }
82
83
84 void
85 _WebSettingImpl::SetCacheControl(CacheMode mode)
86 {
87         __cacheMode = mode;
88 }
89
90
91 CacheMode
92 _WebSettingImpl::GetCacheControl(void) const
93 {
94         return __cacheMode;
95 }
96
97
98 void
99 _WebSettingImpl::SetFontSize(int fontSize)
100 {
101         __fontSize = fontSize;
102 }
103
104
105 int
106 _WebSettingImpl::GetFontSize(void) const
107 {
108         return __fontSize;
109 }
110
111
112 void
113 _WebSettingImpl::SetDefaultTextEncoding(const Tizen::Base::String& encoding)
114 {
115         __encoding = encoding;
116 }
117
118
119 Tizen::Base::String
120 _WebSettingImpl::GetDefaultTextEncoding(void) const
121 {
122         return __encoding;
123 }
124
125
126 void
127 _WebSettingImpl::SetJavascriptEnabled(bool enable)
128 {
129         __javascriptEnabled = enable;
130 }
131
132
133 void
134 _WebSettingImpl::SetAutoImageLoadEnabled(bool enable)
135 {
136         __autoImageEnabled = enable;
137 }
138
139
140 bool
141 _WebSettingImpl::IsJavascriptEnabled(void) const
142 {
143         return __javascriptEnabled;
144 }
145
146
147 bool
148 _WebSettingImpl::IsAutoImageLoadEnabled(void) const
149 {
150         return __autoImageEnabled;
151 }
152
153
154 void
155 _WebSettingImpl::SetInputStyle(Tizen::Ui::Controls::InputStyle inputStyle)
156 {
157         __inputStyle = inputStyle;
158 }
159
160
161 Tizen::Ui::Controls::InputStyle
162 _WebSettingImpl::GetInputStyle(void) const
163 {
164         return __inputStyle;
165 }
166
167
168 void
169 _WebSettingImpl::SetCertificateErrorHandlingMode(CertificateErrorHandlingMode mode)
170 {
171         __certificateErrorHandlingMode = mode;
172 }
173
174
175 CertificateErrorHandlingMode
176 _WebSettingImpl::GetCertificateErrorHandlingMode(void) const
177 {
178         return __certificateErrorHandlingMode;
179 }
180
181
182 void
183 _WebSettingImpl::SetUserAgent(const Tizen::Base::String& agent)
184 {
185         __userAgent = agent;
186 }
187
188
189 Tizen::Base::String
190 _WebSettingImpl::GetUserAgent(void) const
191 {
192         return __userAgent;
193 }
194
195
196 void
197 _WebSettingImpl::SetScrollEnabled(bool enable)
198 {
199         __isScrollEnabled = enable;
200 }
201
202
203 bool
204 _WebSettingImpl::IsScrollEnabled(void) const
205 {
206         return __isScrollEnabled;
207 }
208
209
210 void
211 _WebSettingImpl::SetPrivateBrowsingEnabled(bool enable)
212 {
213         __isPrivateBrowsingEnabled = enable;
214 }
215
216
217 bool
218 _WebSettingImpl::IsPrivateBrowsingEnabled(void) const
219 {
220         return __isPrivateBrowsingEnabled;
221 }
222
223
224 void
225 _WebSettingImpl::SetCookiEnabled(bool enable)
226 {
227         __isCookieEnabled = enable;
228 }
229
230
231 bool
232 _WebSettingImpl::IsCookieEnabled(void) const
233 {
234         return __isCookieEnabled;
235 }
236
237
238 void
239 _WebSettingImpl::SetZoomLevel(float level)
240 {
241         __zoomLevel = level;
242 }
243
244
245 float
246 _WebSettingImpl::GetZoomLevel(void) const
247 {
248         return __zoomLevel;
249 }
250
251
252 void
253 _WebSettingImpl::SetAutoFittingEnabled(bool enable)
254 {
255         __autoFittingEnabled = enable;
256 }
257
258
259 bool
260 _WebSettingImpl::IsAutoFittingEnabled(void) const
261 {
262         return __autoFittingEnabled;
263 }
264
265
266 void 
267 _WebSettingImpl::SetJavaScriptPopupEnabled(bool enable)
268 {
269         __javaScriptPopupEnabled = enable;
270 }
271
272
273 bool
274 _WebSettingImpl::IsJavaScriptPopupEnabled(void) const
275 {
276         return __javaScriptPopupEnabled;
277 }
278
279
280 void
281 _WebSettingImpl::SetGeolocationEnabled(bool enable)
282 {
283         __geolocationEnabled = enable;
284 }
285
286
287 bool
288 _WebSettingImpl::IsGeolocationEnabled(void) const
289 {
290         return __geolocationEnabled;
291 }
292
293
294 void
295 _WebSettingImpl::SetAutoFormDataShowEnabled(bool enable)
296 {
297         __autoFormDataEnabled = enable;
298 }
299
300
301 bool
302 _WebSettingImpl::IsAutoFormDataShowEnabled(void) const
303 {
304         return __autoFormDataEnabled;
305 }
306
307
308 void
309 _WebSettingImpl::SetAutoLoginFormFillEnabled(bool enable)
310 {
311         __autoLoginFormEnabled = enable;
312 }
313
314
315 bool
316 _WebSettingImpl::IsAutoLoginFormFillEnabled(void) const
317 {
318         return __autoLoginFormEnabled;
319 }
320
321
322 bool
323 _WebSettingImpl::Equals(const Object& obj) const
324 {
325         const _WebSettingImpl* pRhs = dynamic_cast< const _WebSettingImpl* >(&obj);
326         if (pRhs == null)
327         {
328                 return false;
329         }
330
331         return __cacheMode == pRhs->__cacheMode && __encoding == pRhs->__encoding && __fontSize == pRhs->__fontSize
332                    && __javascriptEnabled == pRhs->__javascriptEnabled && __autoImageEnabled == pRhs->__autoImageEnabled
333                    && __isScrollEnabled == pRhs->__isScrollEnabled && __inputStyle == pRhs->__inputStyle
334                    && __certificateErrorHandlingMode == pRhs->__certificateErrorHandlingMode && __userAgent == pRhs->__userAgent
335                    && __autoFittingEnabled == pRhs->__autoFittingEnabled && __javaScriptPopupEnabled == pRhs->__javaScriptPopupEnabled
336                    && __geolocationEnabled == pRhs->__geolocationEnabled && __autoFormDataEnabled == pRhs->__autoFormDataEnabled
337                    && __autoLoginFormEnabled == pRhs->__autoLoginFormEnabled;
338 }
339
340
341 int
342 _WebSettingImpl::GetHashCode(void) const
343 {
344         return Integer(__cacheMode).GetHashCode() + __encoding.GetHashCode() + Integer(__fontSize).GetHashCode()
345                    + Boolean(__javascriptEnabled).GetHashCode() + Boolean(__autoImageEnabled).GetHashCode()
346                    + Boolean(__isScrollEnabled).GetHashCode() + Integer(__inputStyle).GetHashCode()
347                    + Integer(__certificateErrorHandlingMode).GetHashCode() + __userAgent.GetHashCode()
348                    + Boolean(__autoFittingEnabled).GetHashCode() + Boolean(__javaScriptPopupEnabled).GetHashCode()
349                    + Boolean(__geolocationEnabled).GetHashCode() + Boolean(__autoFormDataEnabled).GetHashCode()
350                    + Boolean(__autoLoginFormEnabled).GetHashCode();
351 }
352
353
354 _WebSettingImpl*
355 _WebSettingImpl::GetInstance(WebSetting* pWebSetting)
356 {
357         return pWebSetting->__pWebSettingImpl;
358 }
359
360
361 const _WebSettingImpl*
362 _WebSettingImpl::GetInstance(const WebSetting* pWebSetting)
363 {
364         return pWebSetting->__pWebSettingImpl;
365 }
366
367
368 }}} // Tizen::Web::Controls