Implement Storage quota exceed callback
authorSeungkeun Lee <sngn.lee@samsung.com>
Thu, 30 Apr 2015 07:05:02 +0000 (16:05 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Thu, 30 Apr 2015 07:05:02 +0000 (16:05 +0900)
Change-Id: I39784702f70b6c8d163cf17b712678953ca42a72

src/runtime/web_application.cc
src/runtime/web_application.h
src/runtime/web_view.h
src/runtime/web_view_impl.cc

index 72bd68d..5230003 100755 (executable)
@@ -62,6 +62,8 @@ namespace {
       "http://tizen.org/privilege/notification";
   const char* kLocationPrivilege =
       "http://tizen.org/privilege/location";
+  const char* kStoragePrivilege =
+      "http://tizen.org/privilege/unlimitedstorage";
 
 bool FindPrivilege(wrt::ApplicationData* app_data,
                    const std::string& privilege) {
@@ -484,5 +486,26 @@ void WebApplication::OnGeolocationPermissionRequest(
 }
 
 
+void WebApplication::OnQuotaExceed(
+    WebView* view,
+    const std::string& url,
+    std::function<void(bool)> result_handler) {
+  // TODO(sngn.lee): check from DB url was already allowed
+  // if(check already allow or denied) {
+  //   result_handler(true);
+  //   return;
+  // }
+  // Local Domain: Grant permission if defined, otherwise Popup user prompt.
+  // Remote Domain: Popup user prompt.
+  if (utils::StartsWith(url, "file://") &&
+      FindPrivilege(app_data_.get(), kStoragePrivilege)) {
+    result_handler(true);
+    return;
+  }
+
+  // TODO(sngn.lee): create popup and show
+}
+
+
 
 }  // namespace wrt
index c194823..aaf529f 100755 (executable)
@@ -63,6 +63,10 @@ class WebApplication : public WebView::EventListener {
       WebView* view,
       const std::string& url,
       std::function<void(bool)> result_handler);
+  virtual void OnQuotaExceed(
+      WebView* view,
+      const std::string& url,
+      std::function<void(bool)> result_handler);
 
 
   std::string uuid() const { return uuid_; }
index c79e379..4d71744 100755 (executable)
@@ -51,6 +51,10 @@ class WebView {
         WebView* /*view*/,
         const std::string& /*url*/,
         std::function<void(bool)> /*result_handler*/) {}
+    virtual void OnQuotaExceed(
+        WebView* /*view*/,
+        const std::string& /*url*/,
+        std::function<void(bool)> /*result_handler*/) {}
   };
 
   WebView(wrt::NativeWindow* window, Ewk_Context* context);
index f976080..db78800 100755 (executable)
@@ -289,61 +289,91 @@ void WebViewImpl::InitQuotaExceededCallback() {
                                        Ewk_Security_Origin* origin,
                                        const char*,
                                        uint64_t,
-                                       void*) -> Eina_Bool {
-    std::string protocol(ewk_security_origin_protocol_get(origin));
-    if (protocol == "file" || protocol == "app") {
-      // Allow for local origin
-      ewk_view_exceeded_database_quota_reply(view, EINA_TRUE);
-    } else {
-      // Deny for remote origin
-      ewk_view_exceeded_database_quota_reply(view, EINA_FALSE);
-    }
+                                       void* user_data) -> Eina_Bool {
+    WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
+    if (self == NULL || self->listener_ == NULL)
+      return EINA_TRUE;
+
+    auto result_handler = [view](bool result) {
+      LoggerD("database quota Permission Result : %d", result);
+      ewk_view_exceeded_database_quota_reply(view, result);
+    };
+    std::stringstream url;
+    url << ewk_security_origin_protocol_get(origin)
+        << "://"
+        << ewk_security_origin_host_get(origin)
+        << ":"
+        << ewk_security_origin_port_get(origin);
+    self->listener_->OnQuotaExceed(
+        self->view_,
+        url.str(),
+        result_handler);
     return EINA_TRUE;
   };
   ewk_view_exceeded_database_quota_callback_set(
     ewk_view_,
     database_exceeded_callback,
-    NULL);
+    this);
 
   // callback for indexed database quota exceeded
   auto indexed_db_exceeded_callback = [](Evas_Object* view,
                                        Ewk_Security_Origin* origin,
                                        int64_t,
-                                       void*) -> Eina_Bool {
-    std::string protocol(ewk_security_origin_protocol_get(origin));
-    if (protocol == "file://" || protocol == "app://") {
-      // Allow for local origin
-      ewk_view_exceeded_indexed_database_quota_reply(view, EINA_TRUE);
-    } else {
-      // Deny for remote origin
-      ewk_view_exceeded_indexed_database_quota_reply(view, EINA_FALSE);
-    }
+                                       void* user_data) -> Eina_Bool {
+    WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
+    if (self == NULL || self->listener_ == NULL)
+      return EINA_TRUE;
+
+    auto result_handler = [view](bool result) {
+      LoggerD("indexed db quota Permission Result : %d", result);
+      ewk_view_exceeded_indexed_database_quota_reply(view, result);
+    };
+    std::stringstream url;
+    url << ewk_security_origin_protocol_get(origin)
+        << "://"
+        << ewk_security_origin_host_get(origin)
+        << ":"
+        << ewk_security_origin_port_get(origin);
+    self->listener_->OnQuotaExceed(
+        self->view_,
+        url.str(),
+        result_handler);
     return EINA_TRUE;
   };
   ewk_view_exceeded_indexed_database_quota_callback_set(
     ewk_view_,
     indexed_db_exceeded_callback,
-    NULL);
+    this);
 
   // callback for localfile quota exceeded
   auto localfile_exceeded_callback = [](Evas_Object* view,
                                        Ewk_Security_Origin* origin,
                                        int64_t,
-                                       void*) -> Eina_Bool {
-    std::string protocol(ewk_security_origin_protocol_get(origin));
-    if (protocol == "file://" || protocol == "app://") {
-      // Allow for local origin
-      ewk_view_exceeded_local_file_system_quota_reply(view, EINA_TRUE);
-    } else {
-      // Deny for remote origin
-      ewk_view_exceeded_local_file_system_quota_reply(view, EINA_FALSE);
-    }
+                                       void* user_data) -> Eina_Bool {
+    WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
+    if (self == NULL || self->listener_ == NULL)
+      return EINA_TRUE;
+
+    auto result_handler = [view](bool result) {
+      LoggerD("local file quota Permission Result : %d", result);
+      ewk_view_exceeded_local_file_system_quota_reply(view, result);
+    };
+    std::stringstream url;
+    url << ewk_security_origin_protocol_get(origin)
+        << "://"
+        << ewk_security_origin_host_get(origin)
+        << ":"
+        << ewk_security_origin_port_get(origin);
+    self->listener_->OnQuotaExceed(
+        self->view_,
+        url.str(),
+        result_handler);
     return EINA_TRUE;
   };
   ewk_view_exceeded_local_file_system_quota_callback_set(
     ewk_view_,
     localfile_exceeded_callback,
-    NULL);
+    this);
 }
 
 void WebViewImpl::InitIPCMessageCallback() {