2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file view_logic_user_agent_support.cpp
18 * @author Jihoon Chung (jihoon.chung@samsung.com)
22 #include "view_logic_user_agent_support.h"
26 #include <dpl/log/secure_log.h>
27 #include <dpl/string.h>
28 #include <widget_model.h>
31 #include <Elementary.h>
34 namespace ViewModule {
36 void setCustomUA(std::string customUA);
37 bool setAppInfo(WidgetModel* model, Evas_Object* wkView);
38 void printUA(Evas_Object* wkView);
40 bool setCustomUA(WidgetModel* model, Evas_Object* wkView)
42 std::string customUserAgent = model->SettingList.Get().getUserAgent();
43 if (customUserAgent.empty()) {
46 ewk_view_user_agent_set(wkView, customUserAgent.c_str());
52 bool setAppInfo(WidgetModel* model, Evas_Object* wkView)
54 std::string appInfo; // appname/appversion
56 if (app_get_name(&name) == APP_ERROR_NONE) {
60 _W("Fail to get app name");
67 DPL::OptionalString version = model->Version.Get();
68 if (!version.IsNull()) {
69 std::string versionStr = DPL::ToUTF8String(*version);
70 if (versionStr.empty()) {
72 // skip to set version field
75 appInfo += versionStr;
78 if (ewk_view_application_name_for_user_agent_set(wkView, appInfo.c_str())
83 ewk_view_application_name_for_user_agent_get(wkView);
84 if (!info || !strlen(info) || appInfo != info) {
85 _W("Fail to verify app info in the UA");
90 _W("Fail to set app info to UA");
95 void printUA(Evas_Object* wkView)
97 const char* ua = ewk_view_user_agent_get(wkView);
100 } // anonymous namespace
102 void UserAgentSupport::setUserAgent(WidgetModel* model, Evas_Object* wkView)
108 if (setCustomUA(model, wkView)) {
113 // In case of default UA, add appname/appversion
114 if (setAppInfo(model, wkView)) {