From: Przemyslaw Ciezkowski
Date: Thu, 13 Dec 2012 15:23:29 +0000 (+0100)
Subject: [Custom handler] Content listener
X-Git-Tag: 2.1b_release~22^2~156
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dc21d3643ea599e2fae8ff5d3050582a36dca456;p=platform%2Fframework%2Fweb%2Fwrt.git
[Custom handler] Content listener
[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
---
diff --git a/src/view/common/view_logic_uri_support.cpp b/src/view/common/view_logic_uri_support.cpp
index df23dfc..2072bb9 100644
--- a/src/view/common/view_logic_uri_support.cpp
+++ b/src/view/common/view_logic_uri_support.cpp
@@ -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("");
}