[Custom handler] Protocol listener
authorPrzemyslaw Ciezkowski <p.ciezkowski@samsung.com>
Thu, 13 Dec 2012 13:14:49 +0000 (14:14 +0100)
committerGerrit Code Review <gerrit2@kim11>
Mon, 17 Dec 2012 10:33:56 +0000 (19:33 +0900)
[Issue#] N/A
[Feature] Handle protocol from custom handlers.
[Problem] N/A
[Cause] N/A
[Solution] Added protocol listener. It will check if widget
was run by appservice and will look for proper page to show.
[ScmRequest] wrt-commons
This patch depends on:
https://tizendev.org/gerrit/#/c/20791/

[Verification] Run manual test from wrt-extra:
1. Run sh registered_handler_register.sh to add widget to appsvc and to custom handlers.
2. Install register_handler.wgt
3. Run scheme_test_tizen.wgt
4. Run mailto link, verify that mailto.html from register_handler.wgt was run.

Change-Id: I3ea18d251999d15df5aaf3fd9d8b3405e3f36bba

src/view/common/CMakeLists.txt
src/view/common/view_logic_uri_support.cpp

index 58bd3a1..d4df698 100644 (file)
@@ -19,6 +19,7 @@
 SET(TARGET_VIEW_COMMON_LIB_STATIC "wrt-view-common")
 
 PKG_CHECK_MODULES(SYS_VIEW_COMMON_DEP
+    wrt-commons-custom-handler-dao-ro
     appsvc
     cert-svc-vcore
     capi-appfw-app-manager
index bee3d18..df23dfc 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "view_logic_uri_support.h"
 #include <string>
+#include <vector>
 #include <list>
 #include <dpl/string.h>
 #include <dpl/log/log.h>
@@ -29,6 +30,9 @@
 #include <bundle.h>
 #include <appsvc.h>
 #include <application_data.h>
+#include <wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h>
+#include <wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h>
+#include <stdio.h>
 
 namespace ViewModule {
 namespace UriSupport {
@@ -61,6 +65,24 @@ std::list<std::string> parsingMimeData(std::string origin, std::string token)
     return parsedData;
 }
 
+/**
+ * Parses scheme from appsvc. From mailto:test@wacapps.net
+ * it will return list:
+ * 0: mailto
+ * 1: test@wacapps.net
+ */
+std::vector<std::string> parseScheme(const std::string &scheme)
+{
+    std::vector<std::string> schemeParts;
+    std::string::size_type pos = scheme.find(":");
+    if (pos != std::string::npos) {
+        schemeParts.push_back(scheme.substr(0, pos));
+        schemeParts.push_back(
+                scheme.substr(pos + 1, scheme.length() - pos - 1));
+    }
+    return schemeParts;
+}
+
 bool compareServiceData(ServiceDataType type,
                         std::string origin,
                         std::string other)
@@ -108,6 +130,33 @@ bool compareServiceData(ServiceDataType type,
 }
 }
 
+std::string getCustomHandlerProtocolUri(
+        WidgetModel *widgetModel,
+        const std::string &schemeType,
+        const std::string &schemeValue)
+{
+    CustomHandlerDB::Interface::attachDatabaseRO();
+    CustomHandlerDB::CustomHandlerDAOReadOnly handlersDao(widgetModel->TizenId);
+    CustomHandlerDB::CustomHandlerPtr handler =
+            handlersDao.getActivProtocolHandler(
+                DPL::FromASCIIString(schemeType));
+    CustomHandlerDB::Interface::detachDatabase();
+    if (handler) {
+        LogDebug("Found handler, url: " << handler->url);
+        std::string url = DPL::ToUTF8String(handler->base_url) +
+                DPL::ToUTF8String(handler->url);
+        if (url.find("file://") == 0) {
+            url.erase(0, 6);
+        }
+        //replace %s in url with given from appservice
+        int size = snprintf(NULL, 0, url.c_str(), schemeValue.c_str()) + 1;
+        char buffer[size];
+        snprintf(buffer, size, url.c_str(), schemeValue.c_str());
+        return std::string(buffer);
+    }
+    return "";
+}
+
 std::string getAppServiceUri(bundle *bundle, WidgetModel *widgetModel)
 {
     if(!bundle)
@@ -148,6 +197,13 @@ std::string getAppServiceUri(bundle *bundle, WidgetModel *widgetModel)
             return DPL::ToUTF8String(appServiceIt->src);
         }
     }
+    std::vector<std::string> schemeParts = parseScheme(scheme);
+    if (schemeParts.size() > 1) {
+        LogDebug("Scheme parts: " << schemeParts[0] << ", " << schemeParts[1]);
+        return getCustomHandlerProtocolUri(
+                widgetModel, schemeParts[0], schemeParts[1]);
+    }
+
     LogDebug("no matching result");
     return std::string("");
 }
@@ -156,7 +212,7 @@ std::string getUri(WidgetModel *widgetModel, const std::string &defaultUri)
 {
     DPL::String uri;
     std::string startUri;
-
+    LogDebug("default uri: " << defaultUri);
     bundle *originBundle = ApplicationDataSingleton::Instance().getBundle();
     // search application service
     startUri = getAppServiceUri(originBundle, widgetModel).c_str();