implement of content element processing 27/42827/17
authorJoonghyun Cho <jh5.cho@samsung.com>
Fri, 3 Jul 2015 01:11:01 +0000 (10:11 +0900)
committeryons.kim <yons.kim@samsung.com>
Mon, 20 Jul 2015 01:50:15 +0000 (10:50 +0900)
Change-Id: Ie44a9fb78b409813237777d85bffcbb9232a8942

src/common/file_utils.cc
src/common/file_utils.h
src/common/resource_manager.cc
src/common/string_utils.cc
src/common/string_utils.h

index e92edba..bbfc443 100755 (executable)
@@ -19,6 +19,7 @@
 #include <unistd.h>
 #include <libgen.h>
 #include <string>
+#include <algorithm>
 
 namespace wrt {
 namespace utils {
@@ -46,5 +47,16 @@ std::string SchemeName(const std::string& uri) {
   }
 }
 
+std::string ExtName(const std::string& path) {
+  size_t last_dot = path.find_last_of(".");
+  if (last_dot != 0 && last_dot != std::string::npos) {
+    std::string ext = path.substr(last_dot);
+    std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
+    return ext;
+  } else {
+    return std::string();
+  }
+}
+
 }  // namespace utils
 }  // namespace wrt
index 4d9b068..d7d5565 100755 (executable)
@@ -30,6 +30,8 @@ std::string DirName(const std::string& path);
 
 std::string SchemeName(const std::string& uri);
 
+std::string ExtName(const std::string& path);
+
 
 }  // namespace utils
 }  // namespace wrt
index df68bf3..18b634b 100755 (executable)
@@ -188,31 +188,45 @@ ResourceManager::ResourceManager(ApplicationData* application_data,
 
 std::unique_ptr<ResourceManager::Resource>
 ResourceManager::GetDefaultResource() {
-  std::string default_src;
+  std::string src;
   std::string type;
   std::string encoding = kDefaultEncoding;
-
   auto content_info = application_data_->content_info();
   if (content_info) {
-    default_src = content_info->src();
+    src = content_info->src();
     type = content_info->type();
-    encoding = (!content_info->encoding().empty())
-               ? content_info->encoding() : kDefaultEncoding;
+    encoding = content_info->encoding();
+    LOGGER(DEBUG) << "src: " << src;
+    LOGGER(DEBUG) << "type: " << type;
+    LOGGER(DEBUG) << "encoding: " << encoding;
+  }
+  else
+    LOGGER(DEBUG) << "content_info is null";
+
+  // Check that tizen:content src is external page
+  if (content_info && content_info->is_tizen_content()
+      && (utils::StartsWith(src, kSchemeTypeHttp) ||
+          utils::StartsWith(src, kSchemeTypeHttps))) {
+    LOGGER(DEBUG) << "tizen content_info's src is an external page";
+    return std::unique_ptr<Resource>(new Resource(src, type, encoding));
   }
 
-  if (!default_src.empty()) {
-    default_src = InsertPrefixPath(default_src);
-  } else {
-    // if there is no content src, find reserved index files
+  // Find based on default start files list, if src is empty or invald
+  if (!content_info || !utils::Exists(resource_base_path_+src)) {
     for (auto& start_file : kDefaultStartFiles) {
       if (utils::Exists(resource_base_path_ + start_file)) {
-        default_src = InsertPrefixPath(start_file);
-        break;
+        src = InsertPrefixPath(start_file);
+        LOGGER(DEBUG) << "start file: " << src;
+        return std::unique_ptr<Resource>(new Resource(src, type, encoding));
       }
     }
+    // shouldn't be entered here
+    LOGGER(ERROR) << "it can't enter here. can't find any default start file";
+    return std::unique_ptr<Resource>(new Resource(src, type, encoding));
   }
 
-  return std::unique_ptr<Resource>(new Resource(default_src, type, encoding));
+  return std::unique_ptr<Resource>(new Resource(InsertPrefixPath(src),
+                                                type, encoding));
 }
 
 std::unique_ptr<ResourceManager::Resource> ResourceManager::GetMatchedResource(
@@ -222,7 +236,6 @@ std::unique_ptr<ResourceManager::Resource> ResourceManager::GetMatchedResource(
       InsertPrefixPath(app_control_info.src()),
                        app_control_info.onreset() == "disable" ? false : true));
   }
-
   return GetDefaultResource();
 }
 
index 80c443b..cdab154 100755 (executable)
@@ -20,6 +20,7 @@
 #include <math.h>
 #include <uuid/uuid.h>
 #include <string>
+#include <vector>
 #include <sstream>
 #include <iomanip>
 #include <algorithm>
index 5f3187e..8268808 100755 (executable)
@@ -17,6 +17,7 @@
 #ifndef WRT_COMMON_STRING_UTILS_H_
 #define WRT_COMMON_STRING_UTILS_H_
 
+#include <vector>
 #include <string>
 
 namespace wrt {