Support security origin for W3C Web storage usage
authorJihoon Chung <jihoon.chung@samsung.com>
Fri, 23 Nov 2012 08:06:11 +0000 (17:06 +0900)
committerJihoon Chung <jihoon.chung@samsung.com>
Fri, 23 Nov 2012 12:16:01 +0000 (21:16 +0900)
[Issue#] N/A
[Problem] Support security origin for create web storage
[Cause] N/A
[Solution] Implement security origin stored database after user
makes decision on the asking popup
[SCMRequest] N/A

Change-Id: I876ec13f82d67e93c5a831a4f614196a09f669e3

src/view/webkit/CMakeLists.txt
src/view/webkit/view_logic.cpp
src/view/webkit/view_logic.h
src/view/webkit/view_logic_web_storage_support.cpp [new file with mode: 0644]
src/view/webkit/view_logic_web_storage_support.h [new file with mode: 0644]

index 2bd9031..08d310e 100644 (file)
@@ -43,6 +43,7 @@ SET(VIEW_MODULE_SOURCES
     ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_filesystem_support.cpp
     ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_scheme_support.cpp
     ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_geolocation_support_webkit2.cpp
+    ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_web_storage_support.cpp
     ${PROJECT_SOURCE_DIR}/src/view/webkit/bundles/plugin_module_support.cpp
     ${VIEW_MODULE_SOURCES}
 )
index 12908ad..4c2d2fd 100644 (file)
@@ -52,6 +52,7 @@
 #include <view_logic_scheme_support.h>
 #include <view_logic_filesystem_support.h>
 #include <view_logic_geolocation_support_webkit2.h>
+#include <view_logic_web_storage_support.h>
 #include "bundles/plugin_module_support.h"
 
 #include <EWebKit2.h>
@@ -109,9 +110,6 @@ const char * const EWK_FILESYSTEM_PERMISSION_REQUEST = "filesystem,permission,re
 const char * const EWK_FULLSCREEN_ENTER = "fullscreen,enterfullscreen";
 const char * const EWK_FULLSCREEN_EXIT = "fullscreen,exitfullscreen";
 
-// DataBase Use Ask Title
-const char * const DATABASE_USE_ASK_TITLE = "Increase Database Size?";
-
 // IME Callback
 const char * const EWK_INPUTMETHOD_CHANGED = "inputmethod,changed";
 const char * const EWK_EDITORCLIENT_IME_CLOSED = "editorclient,ime,closed";
@@ -1617,54 +1615,15 @@ void ViewLogic::databaseUsagePermissionRequestCallback(
     LogDebug("databaseUsagePermissionRequestCallback called");
     Assert(data);
     ViewLogic* This = static_cast<ViewLogic*>(data);
-    This->databaseUsagePermissionRequest(eventInfo);
-    return;
- }
 
-void ViewLogic::databaseUsagePermissionRequest(
-    void* eventInfo)
-{
-    LogDebug("databaseUsagePermissionRequest called");
     Assert(eventInfo);
-    Ewk_Context_Exceeded_Quota* exceededQuota =
-        static_cast<Ewk_Context_Exceeded_Quota*>(eventInfo);
-
-    bool state = askUserForDatabaseExceedPermission(
-        exceededQuota);
-
-    if (true == state) {
-        LogDebug("permit");
-        ewk_context_web_database_exceeded_quota_new_quota_set(
-            exceededQuota,
-            ewk_context_web_database_exceeded_quota_expected_usage_get(
-                exceededQuota)
-            + 10*(1024*1024)); //10MB
-    } else {
-        LogDebug("deny");
-    }
+    ViewModule::WebStorageSupport::webStorageCreatePermissionRequest(
+        This->m_window,
+        This->m_securityOriginSupport->getSecurityOriginDAO(),
+        eventInfo);
     return;
  }
 
-bool ViewLogic::askUserForDatabaseExceedPermission(
-    Ewk_Context_Exceeded_Quota* exceededQuota)
-{
-    LogDebug("askUserForDatabaseExceedPermission called");
-    Ewk_Security_Origin* origin =
-        ewk_context_web_database_exceeded_quota_security_origin_get(
-        exceededQuota);
-    char databaseUseAskTitle[180];
-
-    snprintf(databaseUseAskTitle, sizeof(databaseUseAskTitle),
-            "Do you want to allow %s to use up to %dMB of storage?",
-            ewk_security_origin_host_get(origin),
-            static_cast<int>(ewk_context_web_database_exceeded_quota_expected_usage_get(
-                    exceededQuota) / (1024 * 1024)));
-
-    return Wrt::PopupInvoker().askYesNo(
-        DATABASE_USE_ASK_TITLE,
-        databaseUseAskTitle);
-}
-
 void ViewLogic::fileSystemPermissionRequestCallback(
     void* data,
     Evas_Object* /*obj*/,
index 4527a4d..b5a1484 100644 (file)
@@ -231,11 +231,6 @@ class ViewLogic : public ViewModule::IViewModule
         void* data,
         Evas_Object* obj,
         void* eventInfo);
-    void databaseUsagePermissionRequest(
-           void* eventInfo);
-    bool askUserForDatabaseExceedPermission(
-        Ewk_Context_Exceeded_Quota* exceededQuota);
-
     // file System Permission Request Callback
     static void fileSystemPermissionRequestCallback(
         void* data,
diff --git a/src/view/webkit/view_logic_web_storage_support.cpp b/src/view/webkit/view_logic_web_storage_support.cpp
new file mode 100644 (file)
index 0000000..f1bf7d2
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file    view_logic_web_storage_support.cpp
+ * @author  Jihoon Chung (jihoon.chung@samsung.com)
+ */
+
+#include "view_logic_web_storage_support.h"
+
+#include <string>
+#include <sstream>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <wrt-commons/security-origin-dao/security_origin_dao_types.h>
+#include <wrt-commons/security-origin-dao/security_origin_dao.h>
+#include <EWebKit2.h>
+#include <common/view_logic_security_origin_support.h>
+#include <Elementary.h>
+
+namespace ViewModule {
+
+using namespace SecurityOriginDB;
+using namespace ViewModule::SecurityOriginSupportUtil;
+
+namespace {
+const char* const WEB_STORAGE_CREATE_ASK_BODY_PREFIX = "Do you want to allow ";
+const char* const WEB_STORAGE_CREATE_ASK_BODY =
+    " to use up to ";
+const char* const WEB_STORAGE_CREATE_ASK_BODY_POSTFIX =
+    "MB of storage?";
+const char* const WEB_STORAGE_CREATE_ASK_CHECK = "Don't ask again";
+
+// function declare
+void askUserForWebStorageCreatePermission(
+    Evas_Object* window,
+    PermissionData* data);
+static void popupCallback(void* data, Evas_Object* obj, void* eventInfo);
+
+void askUserForWebStorageCreatePermission(
+    Evas_Object* window,
+    PermissionData* data)
+{
+    LogDebug("askUserForWebStorageCreatePermission called");
+    PermissionData* permData = static_cast<PermissionData*>(data);
+    Ewk_Context_Exceeded_Quota* exceededQuota =
+            static_cast<Ewk_Context_Exceeded_Quota*>(permData->m_data);
+
+    std::ostringstream size;
+    size << ewk_context_web_database_exceeded_quota_expected_usage_get(exceededQuota) /
+        (1024 * 1024);
+
+    std::string body =
+        WEB_STORAGE_CREATE_ASK_BODY_PREFIX +
+        DPL::ToUTF8String(data->m_originData.origin.host) +
+        WEB_STORAGE_CREATE_ASK_BODY +
+        size.str() +
+        WEB_STORAGE_CREATE_ASK_BODY_POSTFIX;
+
+    Evas_Object* popup = createPopup(window,
+                                     body.c_str(),
+                                     WEB_STORAGE_CREATE_ASK_CHECK,
+                                     popupCallback,
+                                     data);
+
+    if (popup == NULL) {
+        LogError("Fail to create popup object");
+        delete data;
+        return;
+    } else {
+        evas_object_show(popup);
+    }
+}
+
+void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/)
+{
+    LogDebug("popupCallback");
+    Assert(data);
+    PermissionData* permData = static_cast<PermissionData*>(data);
+    Ewk_Context_Exceeded_Quota* exceededQuota =
+            static_cast<Ewk_Context_Exceeded_Quota*>(permData->m_data);
+
+    Evas_Object* popup = getPopup(obj);
+    Result result = getResult(obj);
+
+    if (result != RESULT_UNKNOWN) {
+        permData->m_originDao->setSecurityOriginData(permData->m_originData, result);
+    }
+    if  (result == RESULT_ALLOW_ALWAYS || result == RESULT_ALLOW_ONCE) {
+        ewk_context_web_database_exceeded_quota_new_quota_set(
+            exceededQuota,
+            ewk_context_web_database_exceeded_quota_expected_usage_get(
+                exceededQuota) +
+            10*(1024*1024)); //10MB
+    }
+
+    delete permData;
+    evas_object_hide(popup);
+    evas_object_del(popup);
+}
+} // namespace
+
+void WebStorageSupport::webStorageCreatePermissionRequest(
+    Evas_Object* window,
+    SecurityOriginDAO* securityOriginDAO,
+    void* data)
+{
+    LogDebug("webStorageCreatePermissionRequest called");
+    Assert(securityOriginDAO);
+    Assert(data);
+    Ewk_Context_Exceeded_Quota* exceededQuota =
+        static_cast<Ewk_Context_Exceeded_Quota*>(data);
+    Ewk_Security_Origin* ewkOrigin =
+        ewk_context_web_database_exceeded_quota_security_origin_get(
+            exceededQuota);
+    Assert(ewkOrigin);
+
+    SecurityOriginData securityOriginData(
+        FEATURE_WEB_DATABASE,
+        Origin(
+            DPL::FromUTF8String(ewk_security_origin_protocol_get(ewkOrigin)),
+            DPL::FromUTF8String(ewk_security_origin_host_get(ewkOrigin)),
+            ewk_security_origin_port_get(ewkOrigin)));
+
+    // check cache database
+    Result result = securityOriginDAO->getResult(securityOriginData);
+    if (RESULT_ALLOW_ONCE == result || RESULT_ALLOW_ALWAYS == result) {
+        LogDebug("allow");
+        ewk_context_web_database_exceeded_quota_new_quota_set(
+                exceededQuota,
+                ewk_context_web_database_exceeded_quota_expected_usage_get(
+                    exceededQuota) +
+                10*(1024*1024)); //10MB
+        return;
+    } else if (RESULT_DENY_ONCE == result || RESULT_DENY_ALWAYS == result) {
+        LogDebug("deny");
+        return;
+    }
+
+    // ask to user
+    PermissionData* permissionData =
+        new PermissionData(securityOriginDAO,
+                           securityOriginData,
+                           exceededQuota);
+    askUserForWebStorageCreatePermission(window, permissionData);
+    return;
+}
+} // namespace ViewModule
diff --git a/src/view/webkit/view_logic_web_storage_support.h b/src/view/webkit/view_logic_web_storage_support.h
new file mode 100644 (file)
index 0000000..537489d
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file    view_logic_web_storage_support.h
+ * @author  Jihoon Chung (jihoon.chung@samsung.com)
+ */
+
+#ifndef VIEW_LOGIC_WEB_STORAGE_SUPPORT_H_
+#define VIEW_LOGIC_WEB_STORAGE_SUPPORT_H_
+
+#include <memory.h>
+#include <Elementary.h>
+
+namespace SecurityOriginDB {
+    class SecurityOriginDAO;
+}
+
+namespace ViewModule {
+namespace WebStorageSupport {
+
+void webStorageCreatePermissionRequest(
+        Evas_Object* window,
+        SecurityOriginDB::SecurityOriginDAO* securityOriginDAO,
+        void* data);
+
+} // namespace WebStorageSupport
+} // namespace ViewModule
+
+#endif // VIEW_LOGIC_WEB_STORAGE_SUPPORT_H_
\ No newline at end of file