Upstream version 8.36.169.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / application_file_util.cc
index 798c911..df07360 100644 (file)
@@ -25,6 +25,7 @@
 #include "net/base/file_stream.h"
 #include "third_party/libxml/src/include/libxml/tree.h"
 #include "ui/base/l10n/l10n_util.h"
+#include "xwalk/application/common/installer/package.h"
 #include "xwalk/application/common/application_data.h"
 #include "xwalk/application/common/application_manifest_constants.h"
 #include "xwalk/application/common/constants.h"
@@ -55,6 +56,12 @@ const char kDirRTLKey[] = "rtl";
 const char kDirLROKey[] = "lro";
 const char kDirRLOKey[] = "rlo";
 
+const char* kSingletonElements[] = {
+  "allow-navigation",
+  "content-security-policy-report-only",
+  "content-security-policy"
+};
+
 inline char* ToCharPointer(void* ptr) {
   return reinterpret_cast<char *>(ptr);
 }
@@ -151,6 +158,34 @@ inline bool IsElementSupportSpanAndDir(xmlNode* root) {
   return false;
 }
 
+bool GetPackageType(const base::FilePath& path,
+                    xwalk::application::Package::Type* package_type,
+                    std::string* error) {
+  base::FilePath manifest_path;
+
+  manifest_path = path.Append(xwalk::application::kManifestXpkFilename);
+  if (base::PathExists(manifest_path)) {
+    *package_type = xwalk::application::Package::XPK;
+    return true;
+  }
+
+  manifest_path = path.Append(xwalk::application::kManifestWgtFilename);
+  if (base::PathExists(manifest_path)) {
+    *package_type = xwalk::application::Package::WGT;
+    return true;
+  }
+
+  *error = base::StringPrintf("%s", errors::kManifestUnreadable);
+  return false;
+}
+
+bool IsSingletonElement(const std::string& name) {
+  for (int i = 0; i < arraysize(kSingletonElements); ++i)
+    if (kSingletonElements[i] == name)
+      return true;
+  return false;
+}
+
 }  // namespace
 
 namespace xwalk {
@@ -228,6 +263,8 @@ base::DictionaryValue* LoadXMLNode(
     if (!value->HasKey(sub_node_name)) {
       value->Set(sub_node_name, sub_value);
       continue;
+    } else if (IsSingletonElement(sub_node_name)) {
+      continue;
     }
 
     base::Value* temp;
@@ -273,17 +310,22 @@ scoped_refptr<ApplicationData> LoadApplication(
     const base::FilePath& application_path,
     Manifest::SourceType source_type,
     std::string* error) {
+  Package::Type package_type;
+  if (!GetPackageType(application_path, &package_type, error))
+    return NULL;
+
   return LoadApplication(application_path, std::string(),
-                         source_type, error);
+                         source_type, package_type, error);
 }
 
 scoped_refptr<ApplicationData> LoadApplication(
     const base::FilePath& application_path,
     const std::string& application_id,
     Manifest::SourceType source_type,
+    Package::Type package_type,
     std::string* error) {
   scoped_ptr<base::DictionaryValue> manifest(
-      LoadManifest(application_path, error));
+      LoadManifest(application_path, package_type, error));
   if (!manifest.get())
     return NULL;
 
@@ -299,8 +341,8 @@ scoped_refptr<ApplicationData> LoadApplication(
   std::vector<InstallWarning> warnings;
   ManifestHandlerRegistry* registry =
       manifest->HasKey(widget_keys::kWidgetKey)
-      ? ManifestHandlerRegistry::GetInstance(Manifest::TYPE_WGT)
-      : ManifestHandlerRegistry::GetInstance(Manifest::TYPE_XPK);
+      ? ManifestHandlerRegistry::GetInstance(Package::WGT)
+      : ManifestHandlerRegistry::GetInstance(Package::XPK);
 
   if (!registry->ValidateAppManifest(application, error, &warnings))
     return NULL;
@@ -368,15 +410,16 @@ static base::DictionaryValue* LoadManifestWgt(
 }
 
 base::DictionaryValue* LoadManifest(const base::FilePath& application_path,
-      std::string* error) {
+                                    Package::Type package_type,
+                                    std::string* error) {
   base::FilePath manifest_path;
 
   manifest_path = application_path.Append(kManifestXpkFilename);
-  if (base::PathExists(manifest_path))
+  if (package_type == Package::XPK)
     return LoadManifestXpk(manifest_path, error);
 
   manifest_path = application_path.Append(kManifestWgtFilename);
-  if (base::PathExists(manifest_path))
+  if (package_type == Package::WGT)
     return LoadManifestWgt(manifest_path, error);
 
   *error = base::StringPrintf("%s", errors::kManifestUnreadable);