Update change log and spec for wrt-plugins-tizen_0.4.12-1
authorDongjin Choi <milkelf.choi@samsung.com>
Thu, 28 Mar 2013 04:50:58 +0000 (13:50 +0900)
committerDongjin Choi <milkelf.choi@samsung.com>
Thu, 28 Mar 2013 04:50:58 +0000 (13:50 +0900)
[Issue#] ORANGE-246
[Problem] N/A
[Cause] N/A
[Solution] Add new feature about http header field and network type selection.

[SCMRequest] N/A

packaging/wrt-plugins-tizen.spec
src/Download/DownloadManager.cpp
src/Download/DownloadManager.h
src/Download/DownloadNetworkType.h [new file with mode: 0644]
src/Download/DownloadRequest.cpp
src/Download/DownloadRequest.h
src/Download/JSDownloadManager.cpp
src/Download/JSDownloadRequest.cpp
src/Download/JSDownloadRequest.h

index 60bebfa..daef2ff 100755 (executable)
@@ -1,7 +1,7 @@
 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
index 74bd6fb..8542b43 100644 (file)
@@ -22,6 +22,8 @@
 #include <Logger.h>
 #include <FilesystemUtils.h>
 
+#include "DownloadState.h"
+#include "DownloadNetworkType.h"
 #include "DownloadManager.h"
 
 namespace DeviceAPI {
@@ -116,7 +118,6 @@ static std::string _get_download_error(int err)
     return msg;
 }
 
-
 typedef struct {
        int downloadId;
        download_state_e state;
@@ -324,6 +325,8 @@ long DownloadManager::start(DownloadRequest *request, DownloadCallback *download
        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());
 
@@ -374,6 +377,30 @@ long DownloadManager::start(DownloadRequest *request, DownloadCallback *download
                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());
@@ -487,10 +514,15 @@ std::string DownloadManager::getState(long downloadId)
 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);
 
@@ -524,6 +556,38 @@ DownloadRequest* DownloadManager::getDownloadRequest(long 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) {
@@ -548,6 +612,23 @@ DownloadRequest* DownloadManager::getDownloadRequest(long downloadId)
                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;
 }
 
index f4ac1ce..5fd77d3 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "DownloadRequest.h"
 #include "DownloadCallback.h"
-#include "DownloadState.h"
 
 namespace DeviceAPI {
 namespace Download {
diff --git a/src/Download/DownloadNetworkType.h b/src/Download/DownloadNetworkType.h
new file mode 100644 (file)
index 0000000..f8e4931
--- /dev/null
@@ -0,0 +1,31 @@
+//
+// 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__
index 573004a..cfb3565 100644 (file)
@@ -25,15 +25,10 @@ namespace Download {
 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()
@@ -70,6 +65,25 @@ void DownloadRequest::setFileName(std::string fileName)
        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
index 84e029f..8f7172d 100644 (file)
@@ -18,6 +18,7 @@
 #ifndef __TIZEN_DOWNLOAD_REQUEST_H__
 #define __TIZEN_DOWNLOAD_REQUEST_H__
 
+#include <map>
 #include <string>
 
 namespace DeviceAPI {
@@ -27,7 +28,6 @@ class DownloadRequest
 {
 public:
        DownloadRequest();
-       DownloadRequest(std::string url, std::string destination, std::string fileName);
        virtual ~DownloadRequest();
 
        std::string getUrl() const;
@@ -39,13 +39,22 @@ public:
        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__
index 67e6256..0a1d2ad 100644 (file)
@@ -30,6 +30,8 @@
 #include "DownloadRequest.h"
 #include "DownloadCallback.h"
 
+#include <Logger.h>
+
 using namespace WrtDeviceApis::Commons;
 using namespace DeviceAPI::Common;
 
@@ -125,7 +127,7 @@ JSValueRef JSDownloadManager::startDownload(JSContextRef context,
 
         // 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.");
         }
@@ -330,9 +332,11 @@ JSValueRef JSDownloadManager::getDownloadRequest(JSContextRef context,
         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 (...) {
index 2fe335e..7cbfd60 100755 (executable)
@@ -30,6 +30,8 @@
 #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;
 
@@ -41,8 +43,8 @@ JSClassDefinition JSDownloadRequest::m_classInfo = {
     kJSClassAttributeNone,
     "DownloadRequest",
     NULL, //parentClass
-    m_property,
     NULL, //staticValues,
+    NULL, //staticFunctions,
     initialize,
     finalize,
     NULL, //hasProperty,
@@ -56,13 +58,6 @@ JSClassDefinition JSDownloadRequest::m_classInfo = {
     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());
 
@@ -106,8 +101,15 @@ JSObjectRef JSDownloadRequest::constructor(JSContextRef context,
 {
        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, ""));
@@ -118,78 +120,87 @@ JSObjectRef JSDownloadRequest::constructor(JSContextRef context,
        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
index 9e62e4a..2e735fe 100644 (file)
@@ -21,6 +21,8 @@
 #include <string>
 #include <JavaScriptCore/JavaScript.h>
 
+#include "DownloadRequest.h"
+
 namespace DeviceAPI {
 namespace Download {
 
@@ -38,6 +40,9 @@ public:
             const JSValueRef arguments[],
             JSValueRef* exception);
 
+    static DownloadRequest* getPrivateObject(JSContextRef context, JSObjectRef object);
+    static void setPrivateObject(JSContextRef context, JSObjectRef object, DownloadRequest* priv);
+
 private:
 
     /**