[Custom handler] Content listener
authorPrzemyslaw Ciezkowski <p.ciezkowski@samsung.com>
Thu, 13 Dec 2012 15:23:29 +0000 (16:23 +0100)
committerGerrit Code Review <gerrit2@kim11>
Mon, 17 Dec 2012 10:39:38 +0000 (19:39 +0900)
[Issue#] N/A
[Feature] Handle content (mime type) from custom handlers.
[Problem] N/A
[Cause] N/A
[Solution] Added content (mime) 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 wrt-appsvc-test
4. Verify that custom.html from register_handler.wgt was run with proper file in uri.

Change-Id: Ib0434a9f3409896681e7a536eaed4ad42af0bb7c

src/view/common/view_logic_uri_support.cpp

index df23dfc..2072bb9 100644 (file)
@@ -130,6 +130,19 @@ bool compareServiceData(ServiceDataType type,
 }
 }
 
+std::string prepareUrl(const std::string &url, const std::string &insert)
+{
+    std::string urlFixed = url;
+    if (urlFixed.find("file://") == 0) {
+        urlFixed.erase(0, 6);
+    }
+    //replace %s in url with given from appservice
+    int size = snprintf(NULL, 0, urlFixed.c_str(), insert.c_str()) + 1;
+    char buffer[size];
+    snprintf(buffer, size, urlFixed.c_str(), insert.c_str());
+    return std::string(buffer);
+}
+
 std::string getCustomHandlerProtocolUri(
         WidgetModel *widgetModel,
         const std::string &schemeType,
@@ -143,16 +156,27 @@ std::string getCustomHandlerProtocolUri(
     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 prepareUrl(DPL::ToUTF8String(handler->base_url) +
+                DPL::ToUTF8String(handler->url), schemeValue);
+    }
+    return "";
+}
+
+std::string getCustomHandlerContentUri(
+        WidgetModel *widgetModel,
+        const std::string &mime,
+        const std::string &mimeValue)
+{
+    CustomHandlerDB::Interface::attachDatabaseRO();
+    CustomHandlerDB::CustomHandlerDAOReadOnly handlersDao(widgetModel->TizenId);
+    CustomHandlerDB::CustomHandlerPtr handler =
+            handlersDao.getActivContentHandler(
+                DPL::FromASCIIString(mime));
+    CustomHandlerDB::Interface::detachDatabase();
+    if (handler) {
+        LogDebug("Found handler, url: " << handler->url);
+        return prepareUrl(DPL::ToUTF8String(handler->base_url) +
+                DPL::ToUTF8String(handler->url), mimeValue);
     }
     return "";
 }
@@ -203,7 +227,16 @@ std::string getAppServiceUri(bundle *bundle, WidgetModel *widgetModel)
         return getCustomHandlerProtocolUri(
                 widgetModel, schemeParts[0], schemeParts[1]);
     }
-
+    if (mime != "") {
+        value = appsvc_get_data(bundle, APPSVC_DATA_SELECTED);
+        if (value != NULL) {
+            LogDebug("Use mime type for: " << value);
+            return getCustomHandlerContentUri(
+                    widgetModel, mime, std::string(value));
+        } else {
+            LogError("Selected file for mime is null, nothind to do");
+        }
+    }
     LogDebug("no matching result");
     return std::string("");
 }