Download non-supported file like wml on loading resource.
authorYunchan Cho <yunchan.cho@samsung.com>
Wed, 8 May 2013 08:48:52 +0000 (17:48 +0900)
committerYunchan Cho <yunchan.cho@samsung.com>
Wed, 29 May 2013 06:27:11 +0000 (15:27 +0900)
[Issue#] N/A
[Problem] when page of non-supported file type is loaded, its source code is display on its window
[Cause] web-provider didn't handle non-supported file type exceptionally
[Solution] web-provider calls downloader to download page of non-supported type when it is requested to be loaded.

Change-Id: Idf8f8e05c3aaddbd02b74a2611ccede5d587d15a

src/Core/Service/AppControl.cpp
src/Core/Service/AppControl.h
src/Core/View/WebView.cpp

index 87cfea6..761dd93 100644 (file)
@@ -66,5 +66,59 @@ bool launchBrowser(std::string& url)
     return true;
 }
 
+bool launchDownloader(std::string& url, std::string& cookie)
+{
+    LogD("enter");
+
+    service_h handle = NULL;
+    int ret = SERVICE_ERROR_NONE;
+
+    if (url.empty()) {
+        LogD("invalid arguments");
+        return false;
+    }
+
+    ret = service_create(&handle);
+    if (ret != SERVICE_ERROR_NONE) {
+        LogD("failed to create service");
+        return false;
+    }
+
+    ret = service_set_operation(handle, SERVICE_OPERATION_DOWNLOAD);
+    if (ret != SERVICE_ERROR_NONE) {
+        LogD("failed to set operation");
+        service_destroy(handle);
+        return false;
+    }
+
+    ret = service_set_uri(handle, url.c_str());
+    if (ret != SERVICE_ERROR_NONE) {
+        LogD("failed to set url");
+        service_destroy(handle);
+        return false;
+    }
+
+    if (!cookie.empty()) {
+        ret = service_add_extra_data(handle, "cookie", cookie.c_str());
+        if (ret != SERVICE_ERROR_NONE) {
+            LogD("failed to set cookie");
+            service_destroy(handle);
+            return false;
+        }
+    }
+
+    ret = service_send_launch_request(handle, NULL, NULL);
+    if (ret != SERVICE_ERROR_NONE) {
+        LogD("failed to request launch");
+        service_destroy(handle);
+        return false;
+    }
+
+    LogD("success to launch downloader");
+    service_destroy(handle);
+
+    return true;
+}
+
 } // AppControl
 } // Service
index 151940f..5693873 100644 (file)
@@ -24,6 +24,7 @@ namespace Service {
 namespace AppControl {
 
 bool launchBrowser(std::string& url);
+bool launchDownloader(std::string& url, std::string& cookie);
 
 }
 } // Service
index 2241906..e96272a 100644 (file)
@@ -24,7 +24,9 @@
 #include <Eina.h>
 #include <ewk_context.h>
 #include <ewk_view.h>
+#include <ewk_policy_decision.h>
 #include <Core/Util/Log.h>
+#include <Core/Service/AppControl.h>
 #include "WebView.h"
 
 // injection javascript file regarding creating js object used by box and pd
@@ -326,6 +328,41 @@ void WebView::pageResponseDecideCallback(
 {
     LogD("enter");
 
+    Ewk_Policy_Decision *policyDecision = static_cast<Ewk_Policy_Decision *>(eventInfo);
+    Ewk_Policy_Decision_Type policyType = ewk_policy_decision_type_get(policyDecision);
+    std::string url(ewk_policy_decision_url_get(policyDecision));
+    std::string cookie(ewk_policy_decision_cookie_get(policyDecision));
+    const char* contentType = ewk_policy_decision_response_mime_get(policyDecision);
+
+    switch (policyType) {
+    case EWK_POLICY_DECISION_USE:
+        LogD("policy use");
+        ewk_policy_decision_use(policyDecision);
+        break;
+
+    case EWK_POLICY_DECISION_DOWNLOAD:
+        LogD("policy download: %s, %s, %s", url.c_str(), cookie.c_str(), contentType);
+        ewk_policy_decision_suspend(policyDecision);
+        Service::AppControl::launchDownloader(url, cookie);
+        ewk_policy_decision_ignore(policyDecision);
+        break;
+
+    case EWK_POLICY_DECISION_IGNORE:
+    default:
+        LogD("policy ignore");
+        ewk_policy_decision_ignore(policyDecision);
+        break;
+    }
+
+    if (policyType == EWK_POLICY_DECISION_DOWNLOAD) {
+        if (ewk_view_back_possible(obj)) {
+            ewk_view_back(obj);
+        } else {
+            // TODO Add handling code in case that new window is opened
+            //ecore_idler_add(windowCloseIdlerCallback, data);
+        }
+    }
+
     WebView* This = static_cast<WebView*>(data);
     This->didPageResponseDecide(obj);
 }