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