Add to ewk api for setting/getting the User Agent by using system info library.
authordaehyun81.yoo <daehyun81.yoo@samsung.com>
Wed, 17 Apr 2013 08:28:09 +0000 (17:28 +0900)
committerdaehyun81.yoo <daehyun81.yoo@samsung.com>
Thu, 8 Aug 2013 04:08:22 +0000 (13:08 +0900)
[Title] Add to ewk api for setting/getting the User Agent by using system info library.
[Issue#] N/A
[Problem] Currently the UA was managed by Browser with hard coded string.
[Cause] UA issue is decided recently.
[Solution] Access the system info for User Agent by using capi-system-info and modify the ewk api.

Change-Id: Ie393928f6d4597da3dc3f96a149abbf9fe83a096

Source/WebKit2/Platform/tizen/AboutData/AboutDataTizen.cpp
Source/WebKit2/PlatformTizen.cmake
Source/WebKit2/UIProcess/API/efl/EwkViewImpl.h
Source/WebKit2/UIProcess/API/efl/ewk_view.cpp
Source/WebKit2/UIProcess/API/efl/ewk_view.h
Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp
Source/cmake/FindCAPI.cmake
Source/cmake/OptionsTizen.cmake
packaging/webkit2-efl.spec

index dbcecaa..d9ce44c 100755 (executable)
@@ -618,8 +618,12 @@ static String versionPage()
 
     // TODO : More information(OS version, JavaScript Core version) will be added. 
     page.append(helpTextToRow("WebKit", String::format("%d.%d", WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION)));
-    // FIXME : User Agent should be obtained from a page OBJECT. This will be fixed after refactoring 'about:' implementation itself.
-     page.append(helpTextToRow("User Agent", "Mozilla/5.0 (Linux; Tizen 2.2; sdk) AppleWebKit/537.3 (KHTML, like Gecko) Version/2.2 Mobile Safari/537.3"));
+
+    HashSet<Page*>::iterator begin = allPages->begin();
+    HashSet<Page*>::iterator end = allPages->end();
+    KURL unused;
+    if (begin != end)
+        page.append(helpTextToRow("User Agent", header((*begin)->mainFrame()->loader()->userAgent(unused))));
 
     page.append(footer());
 
index 433b9c6..4b27604 100755 (executable)
@@ -26,6 +26,7 @@ LIST(APPEND WebKit2StaticForDebug_INCLUDE_DIRECTORIES
     "${WEBKIT2_DIR}/WebProcess/WebCoreSupport/efl/tizen"
     "${WEBKIT2_DIR}/WebProcess/WebPage/efl/tizen"
     "${WTF_DIR}"
+    ${CAPI_INCLUDE_DIRS}
     ${ELEMENTARY_INCLUDE_DIRS}
     ${GLES_INCLUDE_DIRS} #FIXME
     ${TTS_INCLUDE_DIRS}
@@ -35,6 +36,7 @@ LIST(APPEND WebKit2StaticForDebug_INCLUDE_DIRECTORIES
 )
 
 LIST(APPEND WebKit2_LIBRARIES
+    ${CAPI_LIBRARIES}
     ${ELEMENTARY_LIBRARIES}
     ${GLES20_LIBRARIES} #FIXME
     ${TTS_LIBRARIES}
index dfe660f..fd78c49 100755 (executable)
@@ -367,6 +367,10 @@ public:
 
     WKEinaSharedString userAgent;
 
+#if OS(TIZEN)
+    WKEinaSharedString applicationName;
+#endif
+
 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
     WKEinaSharedString webAppIconURL;
     Eina_List* webAppIconURLs;
index fb60c13..cc62359 100755 (executable)
@@ -2870,6 +2870,14 @@ const char* ewk_view_user_agent_get(const Evas_Object* ewkView)
     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
 
+#if OS(TIZEN)
+    WKRetainPtr<WKStringRef> userAgentString(AdoptWK, WKPageCopyUserAgent(toAPI(impl->pageProxy.get())));
+
+    int length = WKStringGetMaximumUTF8CStringSize(userAgentString.get());
+    OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
+    WKStringGetUTF8CString(userAgentString.get(), buffer.get(), length);
+    impl->userAgent = buffer.get();
+#else
     if (!impl->userAgent) {
         WKRetainPtr<WKStringRef> userAgentString(AdoptWK, WKPageCopyUserAgent(toAPI(impl->pageProxy.get())));
 
@@ -2878,9 +2886,41 @@ const char* ewk_view_user_agent_get(const Evas_Object* ewkView)
         WKStringGetUTF8CString(userAgentString.get(), buffer.get(), length);
         impl->userAgent = buffer.get();
     }
+#endif
 
     return impl->userAgent;
 }
+
+#if OS(TIZEN)
+Eina_Bool ewk_view_application_name_for_user_agent_set(Evas_Object* ewkView, const char* applicationName)
+{
+    EINA_SAFETY_ON_NULL_RETURN_VAL(applicationName, false);
+
+    EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
+    EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
+
+    WKRetainPtr<WKStringRef> applicationNameString(AdoptWK, WKStringCreateWithUTF8CString(applicationName));
+    WKPageSetApplicationNameForUserAgent(toAPI(impl->pageProxy.get()), applicationNameString.get());
+
+    return true;
+}
+
+const char* ewk_view_application_name_for_user_agent_get(const Evas_Object* ewkView)
+{
+    EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
+    EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
+
+    WKRetainPtr<WKStringRef> applicationNameString(AdoptWK, WKPageCopyApplicationNameForUserAgent(toAPI(impl->pageProxy.get())));
+
+    int length = WKStringGetMaximumUTF8CStringSize(applicationNameString.get());
+    OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
+    WKStringGetUTF8CString(applicationNameString.get(), buffer.get(), length);
+    impl->applicationName = buffer.get();
+
+    return impl->applicationName;
+}
+#endif
+
 Eina_Bool ewk_view_custom_header_add(const Evas_Object* ewkView, const char* name, const char* value)
 {
 #if ENABLE(TIZEN_CUSTOM_HEADERS)
index c01947f..44caf45 100644 (file)
@@ -899,6 +899,29 @@ EAPI Eina_Bool ewk_view_user_agent_set(Evas_Object* o, const char* user_agent);
 * @return @c user agent string
 */
 EAPI const char* ewk_view_user_agent_get(const Evas_Object* o);
+
+// #if OS(TIZEN)
+/**
+* Request to set the user agent with application name.
+*
+* @param o view object to set the user agent with application name
+*
+* @param application_name string to set the user agent
+*
+* @return @c EINA_TRUE on success or @c EINA_FALSE on failure
+*/
+EAPI Eina_Bool ewk_view_application_name_for_user_agent_set(Evas_Object* o, const char* application_name);
+
+/**
+* Returns application name string.
+*
+* @param o view object to get the application name
+*
+* @return @c application name
+*/
+EAPI const char* ewk_view_application_name_for_user_agent_get(const Evas_Object* o);
+// #endif
+
 //#if ENABLE(TIZEN_CUSTOM_HEADERS)
 /**
 * add custom header
index 3d7b14d..e4b88c9 100755 (executable)
@@ -66,6 +66,9 @@
 #include <WebCore/ContentSecurityPolicy.h>
 #endif
 
+#include <system_info.h>
+#include "WebKitVersion.h"
+
 using namespace WebCore;
 #endif
 
@@ -79,7 +82,43 @@ Evas_Object* WebPageProxy::viewWidget()
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
 #if OS(TIZEN)
-    return String::fromUTF8("Mozilla/5.0 (Linux; Tizen 2.2; sdk) AppleWebKit/537.3 (KHTML, like Gecko) Version/2.2 Mobile Safari/537.3");
+    WTF::String appleWebkitVer = makeString(String::number(WEBKIT_MAJOR_VERSION), '.', String::number(WEBKIT_MINOR_VERSION));
+
+    char* versionName = NULL;
+    WTF::String platformVer;
+    int ret = system_info_get_value_string(SYSTEM_INFO_KEY_TIZEN_VERSION, &versionName);
+    if (ret == SYSTEM_INFO_ERROR_NONE) {
+        char* versionNameCopy = NULL;
+        versionNameCopy = strdup(versionName);
+
+        char* majorVersion = NULL;
+        char* minorVersion = NULL;
+        majorVersion = strtok(versionNameCopy, ".");
+        minorVersion = strtok(NULL, ".");
+
+        if (majorVersion == NULL || minorVersion == NULL) {
+            platformVer = String("2.2");
+        } else {
+            WTF::String platformVerMajor;
+            WTF::String platformVerMinor;
+            platformVerMajor = String(majorVersion);
+            platformVerMinor = String(minorVersion);
+            platformVer = makeString(platformVerMajor, ".", platformVerMinor);
+        }
+        free(versionNameCopy);
+    }
+
+    if (versionName)
+        free(versionName);
+
+    WTF::String userAgentString = makeString("Mozilla/5.0 (Linux; Tizen ", platformVer, "; sdk) AppleWebKit/", appleWebkitVer, " (KHTML, like Gecko)");
+    if (applicationNameForUserAgent.isEmpty())
+        userAgentString.append(makeString("Version/", platformVer));
+    else
+        userAgentString.append(applicationNameForUserAgent);
+    userAgentString.append(makeString(" Mobile Safari/", appleWebkitVer));
+
+    return userAgentString;
 #endif
 
     WTF::String platform;
index 8273286..f27bcb7 100755 (executable)
@@ -40,6 +40,7 @@ PKG_CHECK_MODULES(PC_CAPI
     capi-system-sensor
     capi-telephony-network-info
     capi-system-power
+    capi-system-info
 )
 
 FIND_PATH(APPFW_APPLICATION_INCLUDE_DIRS NAMES app.h
@@ -84,6 +85,13 @@ FIND_LIBRARY(SYSTEM_POWER_LIBRARIES NAMES capi-system-power
     HINTS ${PC_CAPI_LIBRARY_DIRS} ${PC_CAPI_LIBDIR}
 )
 
+FIND_PATH(SYSTEM_INFO_INCLUDE_DIRS NAMES system_info.h
+    HINTS ${PC_CAPI_INCLUDE_DIRS} ${PC_CAPI_INCLUDEDIR}
+)
+FIND_LIBRARY(SYSTEM_INFO_LIBRARIES NAMES capi-system-info
+    HINTS ${PC_CAPI_LIBRARY_DIRS} ${PC_CAPI_LIBDIR}
+)
+
 SET(CAPI_INCLUDE_DIRS
     ${APPFW_APPLICATION_INCLUDE_DIRS}
     ${NETWORK_CONNECTION_INCLUDE_DIRS}
@@ -91,6 +99,7 @@ SET(CAPI_INCLUDE_DIRS
     ${SYSTEM_SENSOR_INCLUDE_DIRS}
     ${TELEPHONY_NETWORK_INCLUDE_DIRS}
     ${SYSTEM_POWER_INCLUDE_DIRS}
+    ${SYSTEM_INFO_INCLUDE_DIRS}
 )
 SET(CAPI_LIBRARIES
     ${APPFW_APPLICATION_LIBRARIES}
@@ -99,6 +108,7 @@ SET(CAPI_LIBRARIES
     ${SYSTEM_SENSOR_LIBRARIES}
     ${TELEPHONY_NETWORK_LIBRARIES}
     ${SYSTEM_POWER_LIBRARIES}
+    ${SYSTEM_INFO_LIBRARIES}
 )
 
 INCLUDE(FindPackageHandleStandardArgs)
index 196e5a1..0cc47ae 100644 (file)
@@ -9,7 +9,7 @@ SET(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_
 # version up.
 # -----------------------------------------------------------------------------
 SET(WEBKIT_USER_AGENT_MAJOR_VERSION 537)
-SET(WEBKIT_USER_AGENT_MINOR_VERSION 2)
+SET(WEBKIT_USER_AGENT_MINOR_VERSION 3)
 
 ADD_DEFINITIONS(-DWEBCORE_NAVIGATOR_VENDOR="Tizen")
 ADD_DEFINITIONS(-DBUILDING_EFL__=1)
index e4a9417..dad5c42 100644 (file)
@@ -59,6 +59,7 @@ BuildRequires: pkgconfig(libavcodec)
 BuildRequires: pkgconfig(gles20)
 BuildRequires: pkgconfig(tts)
 BuildRequires: pkgconfig(capi-system-power)
+BuildRequires: pkgconfig(capi-system-info)
 
 
 %description