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 <dpl/availability.h>
29 #include <widget_model.h>
32 #include <Elementary.h>
35 namespace ViewModule {
37 void setCustomUA(std::string customUA);
38 bool setAppInfo(WidgetModel* model, Evas_Object* wkView);
39 void printUA(Evas_Object* wkView);
41 bool setCustomUA(WidgetModel* model, Evas_Object* wkView)
43 std::string customUserAgent = model->SettingList.Get().getUserAgent();
44 if (customUserAgent.empty()) {
47 ewk_view_user_agent_set(wkView, customUserAgent.c_str());
53 bool setAppInfo(WidgetModel* model, Evas_Object* wkView)
55 DPL_UNUSED_PARAM(model);
56 std::string appInfo; // appname/appversion
58 if (app_get_name(&name) == APP_ERROR_NONE) {
62 _W("Fail to get app name");
69 DPL::OptionalString version = model->Version.Get();
70 if (!version.IsNull()) {
71 std::string versionStr = DPL::ToUTF8String(*version);
72 if (versionStr.empty()) {
74 // skip to set version field
77 appInfo += versionStr;
80 if (ewk_view_application_name_for_user_agent_set(wkView, appInfo.c_str())
85 ewk_view_application_name_for_user_agent_get(wkView);
86 if (!info || !strlen(info) || appInfo != info) {
87 _W("Fail to verify app info in the UA");
92 _W("Fail to set app info to UA");
97 void printUA(Evas_Object* wkView)
99 const char* ua = ewk_view_user_agent_get(wkView);
102 } // anonymous namespace
104 void UserAgentSupport::setUserAgent(WidgetModel* model, Evas_Object* wkView)
110 if (setCustomUA(model, wkView)) {
115 // In case of default UA, add appname/appversion
116 if (setAppInfo(model, wkView)) {