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