Name: wrt-plugins-tizen
Summary: JavaScript plugins for WebRuntime
Version: 0.4.12
-Release: 0
+Release: 1
Group: Development/Libraries
License: Apache License, Version 2.0
Source0: %{name}-%{version}.tar.gz
#include <Logger.h>
#include <FilesystemUtils.h>
+#include "DownloadState.h"
+#include "DownloadNetworkType.h"
#include "DownloadManager.h"
namespace DeviceAPI {
return msg;
}
-
typedef struct {
int downloadId;
download_state_e state;
std::string url = request->getUrl();
std::string destination = request->getDestination();
std::string fileName = request->getFileName();
+ std::string networkType = request->getNetworkType();
+ std::map<std::string, std::string> httpHeader = request->getHttpHeader();
LogDebug("url <%s>, destination <%s>, fileName <%s>", url.c_str(), destination.c_str(), fileName.c_str());
throw UnknownException(("Platform error while setting progress callback. " + _get_download_error(ret)).c_str());
}
+ if (!networkType.empty()) {
+ ret = DOWNLOAD_ERROR_NONE;
+ if (networkType == TIZEN_ENUM_DOWNLOAD_NETWORK_TYPE_CELLULAR) {
+ ret = download_set_network_type(downloadId, DOWNLOAD_NETWORK_DATA_NETWORK);
+ } else if (networkType == TIZEN_ENUM_DOWNLOAD_NETWORK_TYPE_WIFI) {
+ ret = download_set_network_type(downloadId, DOWNLOAD_NETWORK_WIFI);
+ } else if (networkType == TIZEN_ENUM_DOWNLOAD_NETWORK_TYPE_ALL) {
+ ret = download_set_network_type(downloadId, DOWNLOAD_NETWORK_ALL);
+ } else {
+ throw TypeMismatchException("Wrong DownloadNetworkType.");
+ }
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ throw UnknownException(("Platform error while setting network type. " + _get_download_error(ret)).c_str());
+ }
+ }
+
+ std::map<std::string, std::string>::const_iterator iter;
+ for (iter = httpHeader.begin(); iter != httpHeader.end(); ++iter) {
+ ret = download_add_http_header_field(downloadId, iter->first.c_str(), iter->second.c_str());
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ throw UnknownException(("Platform error while setting http header fields. " + _get_download_error(ret)).c_str());
+ }
+ }
+
ret = download_start(downloadId);
if (ret != DOWNLOAD_ERROR_NONE) {
throw UnknownException(("Platform error while starting download. " + _get_download_error(ret)).c_str());
DownloadRequest* DownloadManager::getDownloadRequest(long downloadId)
{
int ret;
+ int i;
char *url = NULL;
char *destination = NULL;
char *fileName = NULL;
+ download_network_type_e networkTypeValue = DOWNLOAD_NETWORK_ALL;
+ char **fieldNames = NULL;
+ char *fieldValue = NULL;
+ int fieldLength = 0;
LogDebug("entered. downloadId = %d", downloadId);
throw UnknownException(("Platform error while getting fileName. " + _get_download_error(ret)).c_str());
}
+ ret = download_get_network_type(downloadId, &networkTypeValue);
+ if (ret != DOWNLOAD_ERROR_NONE && ret != DOWNLOAD_ERROR_NO_DATA) {
+ if (ret == DOWNLOAD_ERROR_ID_NOT_FOUND) {
+ throw NotFoundException("download id could not found.");
+ } else if (ret == DOWNLOAD_ERROR_INVALID_PARAMETER) {
+ throw InvalidValuesException("download id is not valid.");
+ }
+ throw UnknownException(("Platform error while getting network type. " + _get_download_error(ret)).c_str());
+ }
+
+ ret = download_get_http_header_field_list(downloadId, &fieldNames, &fieldLength);
+ if (ret != DOWNLOAD_ERROR_NONE && ret != DOWNLOAD_ERROR_NO_DATA) {
+ if (ret == DOWNLOAD_ERROR_ID_NOT_FOUND) {
+ throw NotFoundException("download id could not found.");
+ } else if (ret == DOWNLOAD_ERROR_INVALID_PARAMETER) {
+ throw InvalidValuesException("download id is not valid.");
+ }
+ throw UnknownException(("Platform error while getting http header fields. " + _get_download_error(ret)).c_str());
+ }
+
+ std::map<std::string, std::string> httpHeader;
+ for (i = 0; i < fieldLength; i++) {
+ ret = download_get_http_header_field(downloadId, fieldNames[i], &fieldValue);
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LogWarning("Platform error while getting http header field. " << _get_download_error(ret));
+ }
+ httpHeader.insert(make_pair(std::string(fieldNames[i]), std::string(fieldValue)));
+ free(fieldNames[i]);
+ free(fieldValue);
+ }
+ free(fieldNames);
+
DownloadRequest *request = new DownloadRequest();
if (url) {
free(fileName);
}
+ switch(networkTypeValue) {
+ case DOWNLOAD_NETWORK_DATA_NETWORK:
+ request->setNetworkType(TIZEN_ENUM_DOWNLOAD_NETWORK_TYPE_CELLULAR);
+ break;
+ case DOWNLOAD_NETWORK_WIFI:
+ request->setNetworkType(TIZEN_ENUM_DOWNLOAD_NETWORK_TYPE_WIFI);
+ break;
+ default:
+ request->setNetworkType(TIZEN_ENUM_DOWNLOAD_NETWORK_TYPE_ALL);
+ break;
+ }
+
+ if (fieldLength) {
+ request->setHttpHeader(httpHeader);
+ }
+
+
return request;
}
#include "DownloadRequest.h"
#include "DownloadCallback.h"
-#include "DownloadState.h"
namespace DeviceAPI {
namespace Download {
--- /dev/null
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef __TIZEN_DOWNLOAD_NETWORK_TYPE_H__
+#define __TIZEN_DOWNLOAD_NETWORK_TYPE_H__
+
+namespace DeviceAPI {
+namespace Download {
+
+#define TIZEN_ENUM_DOWNLOAD_NETWORK_TYPE_CELLULAR "CELLULAR"
+#define TIZEN_ENUM_DOWNLOAD_NETWORK_TYPE_WIFI "WIFI"
+#define TIZEN_ENUM_DOWNLOAD_NETWORK_TYPE_ALL "ALL"
+
+} // Download
+} // DeviceAPI
+
+#endif // __TIZEN_DOWNLOAD_NETWORK_TYPE_H__
DownloadRequest::DownloadRequest():
m_url(""),
m_destination(""),
- m_fileName("")
+ m_fileName(""),
+ m_networkType("")
{
-}
-
-DownloadRequest::DownloadRequest(std::string url, std::string destination, std::string fileName)
-{
- m_url = url;
- m_destination = destination;
- m_fileName = fileName;
+ m_httpHeader.clear();
}
DownloadRequest::~DownloadRequest()
m_fileName = fileName;
}
+std::string DownloadRequest::getNetworkType() const
+{
+ return m_networkType;
+}
+
+void DownloadRequest::setNetworkType(std::string networkType)
+{
+ m_networkType = networkType;
+}
+
+std::map<std::string, std::string> DownloadRequest::getHttpHeader() const
+{
+ return m_httpHeader;
+}
+
+void DownloadRequest::setHttpHeader(std::map<std::string, std::string> httpHeader)
+{
+ m_httpHeader = httpHeader;
+}
} // Download
-} // DeviceAPI
\ No newline at end of file
+} // DeviceAPI
#ifndef __TIZEN_DOWNLOAD_REQUEST_H__
#define __TIZEN_DOWNLOAD_REQUEST_H__
+#include <map>
#include <string>
namespace DeviceAPI {
{
public:
DownloadRequest();
- DownloadRequest(std::string url, std::string destination, std::string fileName);
virtual ~DownloadRequest();
std::string getUrl() const;
std::string getFileName() const;
void setFileName(std::string fileName);
+ std::string getNetworkType() const;
+ void setNetworkType(std::string networkType);
+
+ std::map<std::string, std::string> getHttpHeader() const;
+ void setHttpHeader(std::map<std::string, std::string> httpHeader);
+
+
private:
std::string m_url;
std::string m_destination;
std::string m_fileName;
+ std::string m_networkType;
+ std::map<std::string, std::string> m_httpHeader;
};
} // Download
} // DeviceAPI
-#endif // __TIZEN_DOWNLOAD_REQUEST_H__
\ No newline at end of file
+#endif // __TIZEN_DOWNLOAD_REQUEST_H__
#include "DownloadRequest.h"
#include "DownloadCallback.h"
+#include <Logger.h>
+
using namespace WrtDeviceApis::Commons;
using namespace DeviceAPI::Common;
// downloadRequest
JSObjectRef downloadRequestObj = validator.toObject(0, JSDownloadRequest::getClassRef());
- DownloadRequest *downloadRequest = static_cast<DownloadRequest*>(JSObjectGetPrivate(downloadRequestObj));
+ DownloadRequest *downloadRequest = JSDownloadRequest::getPrivateObject(context, downloadRequestObj);
if (!downloadRequest) {
throw TypeMismatchException("DownloadRequest's private object is NULL.");
}
long downloadId = validator.toLong(0);
// perform
+ JSObjectRef obj = JSObjectMake(context, JSDownloadRequest::getClassRef(), NULL);
DownloadRequest *priv = downloadManager->getDownloadRequest(downloadId);
+ JSDownloadRequest::setPrivateObject(context, obj, priv);
- return JSObjectMake(context, JSDownloadRequest::getClassRef(), static_cast<void*>(priv));
+ return obj;
} catch (const BasePlatformException &err) {
return JSWebAPIError::throwException(context, exception, err);
} catch (...) {
#define TIZEN_DOWNLOAD_REQUEST_URL "url"
#define TIZEN_DOWNLOAD_REQUEST_DESTINATION "destination"
#define TIZEN_DOWNLOAD_REQUEST_FILE_NAME "fileName"
+#define TIZEN_DOWNLOAD_REQUEST_NETWORK_TYPE "networkType"
+#define TIZEN_DOWNLOAD_REQUEST_HTTP_HEADER "httpHeader"
using namespace DeviceAPI::Common;
kJSClassAttributeNone,
"DownloadRequest",
NULL, //parentClass
- m_property,
NULL, //staticValues,
+ NULL, //staticFunctions,
initialize,
finalize,
NULL, //hasProperty,
NULL, //convertToType,
};
-JSStaticValue JSDownloadRequest::m_property[] = {
- { TIZEN_DOWNLOAD_REQUEST_URL, getProperty, setProperty, kJSPropertyAttributeNone },
- { TIZEN_DOWNLOAD_REQUEST_DESTINATION, getProperty, setProperty, kJSPropertyAttributeNone },
- { TIZEN_DOWNLOAD_REQUEST_FILE_NAME, getProperty, setProperty, kJSPropertyAttributeNone },
-
- { 0, 0, 0, 0 }
-};
JSClassRef JSDownloadRequest::m_jsClassRef = JSClassCreate(JSDownloadRequest::getClassInfo());
{
ArgumentValidator validator(context, argumentCount, arguments);
+ JSObjectRef obj = JSObjectMake(context, getClassRef(), NULL);
+
+ // constructor
+ JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+ JSObjectSetProperty(context, obj, ctorName, constructor,
+ kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+ JSStringRelease(ctorName);
+
DownloadRequest *priv = new DownloadRequest();
- JSObjectRef obj = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
try {
priv->setUrl(validator.toString(0, true, ""));
try {
priv->setDestination(validator.toString(1, true, ""));
} catch (const BasePlatformException& err) {
- LogWarning("destination convertion is failed. %s", err.getMessage().c_str());
+ LogWarning("url destination is failed. %s", err.getMessage().c_str());
}
try {
priv->setFileName(validator.toString(2, true, ""));
} catch (const BasePlatformException& err) {
- LogWarning("fileName convertion is failed. %s", err.getMessage().c_str());
+ LogWarning("url fileName is failed. %s", err.getMessage().c_str());
}
- JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
- JSObjectSetProperty(context, obj, ctorName, constructor, kJSPropertyAttributeReadOnly, NULL);
- JSStringRelease(ctorName);
+ try {
+ priv->setNetworkType(validator.toString(3, true, ""));
+ } catch (const BasePlatformException& err) {
+ LogWarning("url networkType is failed. %s", err.getMessage().c_str());
+ }
+
+ try {
+ priv->setHttpHeader(validator.toStringMap(4, true));
+ } catch (const BasePlatformException& err) {
+ LogWarning("url networkType is failed. %s", err.getMessage().c_str());
+ }
+
+ setPrivateObject(context, obj, priv);
return obj;
}
-JSValueRef JSDownloadRequest::getProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
+DownloadRequest* JSDownloadRequest::getPrivateObject(JSContextRef context, JSObjectRef object)
{
- try {
- DownloadRequest *priv = static_cast<DownloadRequest*>(JSObjectGetPrivate(object));
- if (!priv) {
- throw TypeMismatchException("Private object is NULL");
- }
+ DownloadRequest *priv = static_cast<DownloadRequest*>(JSObjectGetPrivate(object));
+ if (!priv) {
+ throw TypeMismatchException("DownloadRequest's private object is NULL.");
+ }
- if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_URL)) {
- return JSUtil::toJSValueRef(context, priv->getUrl());
- }
- else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_DESTINATION)) {
- return JSUtil::toJSValueRef(context, priv->getDestination());
- }
- else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_FILE_NAME)) {
- return JSUtil::toJSValueRef(context, priv->getFileName());
- }
- } catch (const BasePlatformException &err) {
- LogWarning("Getting property is failed. %s", err.getMessage().c_str());
- }
+ // url
+ JSValueRef url = JSUtil::getProperty(context, object, TIZEN_DOWNLOAD_REQUEST_URL);
+ priv->setUrl(JSUtil::JSValueToString(context, url));
+
+ // destination
+ JSValueRef destination = JSUtil::getProperty(context, object, TIZEN_DOWNLOAD_REQUEST_DESTINATION);
+ priv->setDestination(JSUtil::JSValueToString(context, destination));
- return NULL;
+ // fileName
+ JSValueRef fileName = JSUtil::getProperty(context, object, TIZEN_DOWNLOAD_REQUEST_FILE_NAME);
+ priv->setFileName(JSUtil::JSValueToString(context, fileName));
+
+ // networkType
+ JSValueRef networkType = JSUtil::getProperty(context, object, TIZEN_DOWNLOAD_REQUEST_NETWORK_TYPE);
+ priv->setNetworkType(JSUtil::JSValueToString(context, networkType));
+
+ // httpHeader
+ JSValueRef httpHeader = JSUtil::getProperty(context, object, TIZEN_DOWNLOAD_REQUEST_HTTP_HEADER);
+ priv->setHttpHeader(JSUtil::JSValueToStringMap(context, httpHeader));
+
+ return priv;
}
-bool JSDownloadRequest::setProperty(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef value,
- JSValueRef* exception)
+void JSDownloadRequest::setPrivateObject(JSContextRef context, JSObjectRef object, DownloadRequest* priv)
{
- try {
- DownloadRequest *priv = static_cast<DownloadRequest*>(JSObjectGetPrivate(object));
- if (!priv) {
- throw TypeMismatchException("Private object is NULL");
- }
-
- if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_URL)) {
- priv->setUrl(JSUtil::JSValueToString(context, value));
- return true;
- }
- else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_DESTINATION)) {
- priv->setDestination(JSUtil::JSValueToString(context, value));
- return true;
- }
- else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_FILE_NAME)) {
- priv->setFileName(JSUtil::JSValueToString(context, value));
- return true;
- }
- } catch (const BasePlatformException &err) {
- LogWarning("Setting property is failed. %s", err.getMessage().c_str());
+ if (priv) {
+ JSObjectSetPrivate(object, static_cast<void*>(priv));
}
- return false;
+ // url
+ JSUtil::setProperty(context, object, TIZEN_DOWNLOAD_REQUEST_URL,
+ JSUtil::toJSValueRef(context, priv->getUrl()), kJSPropertyAttributeNone);
+
+ // destination
+ JSUtil::setProperty(context, object, TIZEN_DOWNLOAD_REQUEST_DESTINATION,
+ JSUtil::toJSValueRef(context, priv->getDestination()), kJSPropertyAttributeNone);
+
+ // fileName
+ JSUtil::setProperty(context, object, TIZEN_DOWNLOAD_REQUEST_FILE_NAME,
+ JSUtil::toJSValueRef(context, priv->getFileName()), kJSPropertyAttributeNone);
+
+ // networkType
+ JSUtil::setProperty(context, object, TIZEN_DOWNLOAD_REQUEST_NETWORK_TYPE,
+ JSUtil::toJSValueRef(context, priv->getNetworkType()), kJSPropertyAttributeNone);
+
+ // httpHeader
+ JSUtil::setProperty(context, object, TIZEN_DOWNLOAD_REQUEST_HTTP_HEADER,
+ JSUtil::toJSValueRef(context, priv->getHttpHeader()), kJSPropertyAttributeNone);
}
} // Download
#include <string>
#include <JavaScriptCore/JavaScript.h>
+#include "DownloadRequest.h"
+
namespace DeviceAPI {
namespace Download {
const JSValueRef arguments[],
JSValueRef* exception);
+ static DownloadRequest* getPrivateObject(JSContextRef context, JSObjectRef object);
+ static void setPrivateObject(JSContextRef context, JSObjectRef object, DownloadRequest* priv);
+
private:
/**