Source code formating unification
[platform/framework/web/wrt.git] / src / view / common / view_logic_user_agent_support.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    view_logic_user_agent_support.cpp
18  * @author  Jaroslaw Osmanski (j.osmanski@samsung.com)
19  * @brief   Implementation file of UserAgent API used by ViewLogic
20  */
21
22 #include "view_logic_user_agent_support.h"
23
24 #include <vconf.h>
25 #include <vconf-keys.h>
26
27 #include <string>
28 #include <dpl/log/log.h>
29 #include <dpl/wrt-dao-ro/global_dao_read_only.h>
30
31 namespace {
32 // TODO: remove this after ua is fixed...
33 const std::string USERAGENT_KEY = VCONFKEY_BROWSER_BROWSER_USER_AGENT;
34 const std::string SYSTEM_USER_AGENT = "System user agent";
35 };
36
37 namespace ViewModule {
38 namespace UserAgentSupport {
39 std::string getUserAgentFromVconf()
40 {
41     using namespace WrtDB;
42     char* vconfValue = vconf_get_str(USERAGENT_KEY.c_str());
43     std::string userAgentName;
44
45     if (!vconfValue) {
46         userAgentName = "Tizen";
47     } else {
48         userAgentName = vconfValue;
49     }
50
51     LogDebug("userAgentName: " << userAgentName);
52     std::string userAgent;
53
54     if (userAgentName == SYSTEM_USER_AGENT) {
55         char* adminUAgent = NULL;
56         adminUAgent = vconf_get_str(VCONFKEY_BROWSER_USER_AGENT);
57
58         if (NULL == adminUAgent || 0 == strlen(adminUAgent)) {
59             LogError("Fail to get agent value. Default agent will be set");
60             userAgentName = "Tizen";
61             DPL::String value =
62                 GlobalDAOReadOnly::GetUserAgentValue(
63                     DPL::FromUTF8String(userAgentName));
64             userAgent = DPL::ToUTF8String(value);
65         } else {
66             userAgent = adminUAgent;
67         }
68     } else {
69         DPL::String value =
70             GlobalDAOReadOnly::GetUserAgentValue(DPL::FromUTF8String(
71                                                      userAgentName));
72         userAgent = DPL::ToUTF8String(value);
73         LogDebug("value : " << value);
74     }
75     LogDebug("UA:[" << userAgentName << "] UA string:[" << userAgent);
76     free(vconfValue);
77     return userAgent;
78 }
79 } // namespace ViewModule
80 } // namespace UserAgentSupport