Init Tizen 2.2.1
[framework/osp/web.git] / src / controls / FWebCtrl_EflWebkit.cpp
index 014bd33..aeedd30 100755 (executable)
 #include <FAppApp.h>
 #include <FGrpPoint.h>
 #include <FGrpRectangle.h>
-#include <FIoDbEnumerator.h>
 #include <FSysVibrator.h>
 #include <FUiAnimVisualElement.h>
-#include <FApp_AppInfo.h>
 #include <FBaseSysLog.h>
 #include <FBase_StringConverter.h>
 #include <FGrp_CoordinateSystem.h>
-#include <FIo_DirectoryImpl.h>
-#include <FIo_DatabaseImpl.h>
-#include <FIo_FileImpl.h>
 #include <FSecCert_CertService.h>
-#include <FSys_VibratorImpl.h>
 #include <FUi_Control.h>
 #include <FUi_Window.h>
 #include "FUiAnim_EflNode.h"
@@ -64,16 +58,8 @@ namespace Tizen { namespace Web { namespace Controls
 
 static const char PLUGIN_DIRECTORY_PATH[] =  "/usr/lib/osp/browser-plugin/";
 
-
-extern const wchar_t CUSTOM_DB_DIRECTORY_PATH[] = L"data/.webkit/customDatabase/";
-extern const wchar_t USER_CONFIRM_DB_NAME[] = L"userConfirm.db";
-extern const wchar_t GEOLOCATION_TABLE_NAME[] = L"geolocationPermission";
-extern const wchar_t CUSTOM_PROTOCOL_TABLE_NAME[] = L"customProtocol";
-extern const wchar_t CUSTOM_CONTENT_TABLE_NAME[] = L"customContent";
-extern const wchar_t CERTIFICATE_TABLE_NAME[] = L"certificate";
-
-
-static const int CUSTOM_DB_TABLE_COUNT= 4;
+static const wchar_t ICON_DB_DIRECTORY_PATH[] = L"data/.webkit/iconDatabase/";
+static const wchar_t ICON_DB_FILE_NAME[] = L"icon.db";
 
 
 _EflWebkit::_EflWebkit(void)
@@ -90,10 +76,15 @@ _EflWebkit::~_EflWebkit(void)
        {
                __pContainerVisualElement->SetSurface(null);
        }
+
        delete __pSurface;
-//     evas_object_smart_member_del(__pWebFrame);
-       evas_object_del(__pWebFrame);
-       __pWebFrame = null;
+       __pSurface = null;
+
+       if (__pWebFrame)
+       {
+               evas_object_del(__pWebFrame);
+               __pWebFrame = null;
+       }
 }
 
 
@@ -162,19 +153,16 @@ _EflWebkit::SetWebConfiguration(void) const
        ewk_context_additional_plugin_path_set(pContext, PLUGIN_DIRECTORY_PATH);
 
        String certPath(_CertService::GetCertificateCrtFilePath());
-       std::unique_ptr<char[]> pcertPath(_StringConverter::CopyToCharArrayN(certPath));
-       SysTryReturn(NID_WEB_CTRL, pcertPath.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       std::unique_ptr<char[]> pCertPath(_StringConverter::CopyToCharArrayN(certPath));
+       SysTryReturn(NID_WEB_CTRL, pCertPath.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       ewk_context_certificate_file_set(pContext, pcertPath.get());
+       ewk_context_certificate_file_set(pContext, pCertPath.get());
 
-       r = CreateResourceDirectory();
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       String iconPath(App::App::GetInstance()->GetAppRootPath() + ICON_DB_DIRECTORY_PATH + ICON_DB_FILE_NAME);
+       std::unique_ptr<char[]> pIconPath(_StringConverter::CopyToCharArrayN(iconPath));
+       SysTryReturn(NID_WEB_CTRL, pIconPath.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       r = InitializeCustomDb();
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       r = SetProxyAddress();
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       ewk_context_icon_database_path_set(pContext, pIconPath.get());
 
        InitializeCustomHeader();
 
@@ -183,116 +171,8 @@ _EflWebkit::SetWebConfiguration(void) const
 
 
 result
-_EflWebkit::CreateResourceDirectory(void) const
+_EflWebkit::SetProxyAddress(char* pProxy) const
 {
-       String html5FeaturesPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH);
-
-       if (!_FileImpl::IsFileExist(html5FeaturesPath))
-       {
-               result r = E_SUCCESS;
-
-               r = _DirectoryImpl::Create(html5FeaturesPath, true);
-               SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. create html5 features directory.");
-       }
-
-       return E_SUCCESS;
-}
-
-
-result
-_EflWebkit::InitializeCustomDb(void) const
-{
-       result r = E_SUCCESS;
-
-       _DatabaseImpl db;
-       String path(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
-       String geolocationTable(GEOLOCATION_TABLE_NAME);
-       String protocolTable(CUSTOM_PROTOCOL_TABLE_NAME);
-       String contentTable(CUSTOM_CONTENT_TABLE_NAME);
-       String certificateTable(CERTIFICATE_TABLE_NAME);
-
-       r = db.Construct(path, "a+", null);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       std::unique_ptr<DbEnumerator>   pEnum(db.QueryN(L"Select count(name) from sqlite_master Where type='table' And name in ('" + geolocationTable + L"', '" + protocolTable + L"', '" + contentTable + L"', '" + certificateTable + L"')"));
-       if (pEnum.get())
-       {
-               int count = 0;
-
-               r = pEnum->MoveNext();
-               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
-
-               r = pEnum->GetIntAt(0, count);
-               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
-
-               if (count == CUSTOM_DB_TABLE_COUNT)
-               {
-                       return E_SUCCESS;
-               }
-       }
-
-       pEnum.reset();
-       pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + geolocationTable + L"'"));
-       if (!pEnum.get())
-       {
-               r = db.ExecuteSql(
-                       L"CREATE TABLE IF NOT EXISTS " + geolocationTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, origin TEXT, permission INTEGER)",
-                       true);
-               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-       }
-
-       pEnum.reset();
-       pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + protocolTable + L"'"));
-       if (!pEnum.get())
-       {
-               r = db.ExecuteSql(
-                       L"CREATE TABLE IF NOT EXISTS " + protocolTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, baseUrl TEXT, url TEXT, mime TEXT, allow INTEGER)",
-                       true);
-               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-       }
-
-       pEnum.reset();
-       pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + contentTable + L"'"));
-       if (!pEnum.get())
-       {
-               r = db.ExecuteSql(
-                       L"CREATE TABLE IF NOT EXISTS " + contentTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, baseUrl TEXT, url TEXT, mime TEXT, allow INTEGER)",
-                       true);
-               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-       }
-
-       pEnum.reset();
-       pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + certificateTable + L"'"));
-       if (!pEnum.get())
-       {
-               r = db.ExecuteSql(
-                       L"CREATE TABLE IF NOT EXISTS " + certificateTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, pem TEXT, allow INTEGER)",
-                       true);
-               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-       }
-
-       return E_SUCCESS;
-}
-
-
-result
-_EflWebkit::SetProxyAddress(void) const
-{
-       int ret = -1;
-       connection_h handle = null;
-
-       ret = connection_create(&handle);
-       SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to create connection.");
-
-       char* pProxy = null;
-       connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
-
-       ret = connection_get_proxy(handle, family, &pProxy);
-       SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to get proxy address.");
-
-       ret = connection_destroy(handle);
-       SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to destroy connection.");
-
        Ewk_Context* pContext = ewk_view_context_get(__pWebFrame);
        SysAssertf(pContext, "Failed to get context.");
 
@@ -307,11 +187,6 @@ _EflWebkit::SetProxyAddress(void) const
 
        SysLog(NID_WEB_CTRL, "The current value of proxy is %s", pProxy);
 
-       if (pProxy)
-       {
-               free(pProxy);
-       }
-
        return E_SUCCESS;
 }
 
@@ -319,33 +194,28 @@ _EflWebkit::SetProxyAddress(void) const
 void
 _EflWebkit::InitializeCustomHeader(void) const
 {
-       std::unique_ptr<char[]> pLang(vconf_get_str(VCONFKEY_LANGSET));
-       std::unique_ptr<char[]> pRegion(vconf_get_str(VCONFKEY_LANGSET));
+       char pAcceptLang[6] = {0, };
+       char* pLangSet = vconf_get_str(VCONFKEY_LANGSET);
        const char name[] = "Accept-Language";
-       String value(L"");
 
-       if (pLang.get())
+       if (pLangSet && strlen(pLangSet))
        {
-               if (pRegion.get())
-               {
-                       value.Append(pLang.get());
-                       value.Append(L"_");
-                       value.Append(pRegion.get());
-               }
-               else
+               strncpy(pAcceptLang, pLangSet, 2);
+
+               char *pRawData = strchr(pLangSet, '_');
+               if (pRawData && strlen(pLangSet) >= 5)
                {
-                       value.Append(pLang.get());
+                       strcat(pAcceptLang, "-");
+                       strncat(pAcceptLang, pRawData + 1, 2);
                }
        }
        else
        {
-               value = L"en";
+               strcat(pAcceptLang, "en");
        }
+       free(pLangSet);
 
-       std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(value));
-       SysTryReturnVoidResult(NID_WEB_CTRL, pValue.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-       ewk_view_custom_header_add(__pWebFrame, name, pValue.get());
+       ewk_view_custom_header_add(__pWebFrame, name, pAcceptLang);
 }