Upstream version 7.35.141.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / manifest_handlers / csp_handler.cc
index 8346e7d..48863e0 100644 (file)
@@ -9,10 +9,11 @@
 #include "xwalk/application/common/application_manifest_constants.h"
 
 namespace xwalk {
-
-namespace keys = application_manifest_keys;
-
 namespace application {
+namespace {
+const char directive_separator = ';';
+const char value_separator = ' ';
+}  // namespace
 
 CSPInfo::CSPInfo() {
 }
@@ -20,28 +21,33 @@ CSPInfo::CSPInfo() {
 CSPInfo::~CSPInfo() {
 }
 
-CSPHandler::CSPHandler() {
+CSPHandler::CSPHandler(Package::Type type)
+    : package_type_(type) {
 }
 
 CSPHandler::~CSPHandler() {
 }
 
 bool CSPHandler::Parse(scoped_refptr<ApplicationData> application,
-                       string16* error) {
+                       base::string16* error) {
+  if (package_type_ != application->GetPackageType())
+    return false;
   scoped_ptr<CSPInfo> csp_info(new CSPInfo);
   std::string policies_str;
-  if (application->GetManifest()->HasKey(keys::kCSPKey) &&
-      !application->GetManifest()->GetString(keys::kCSPKey, &policies_str)) {
-    *error = ASCIIToUTF16("Invalid value of Content Security Policy (CSP).");
+  const char* csp_key = GetCSPKey(package_type_);
+  if (application->GetManifest()->HasPath(csp_key) &&
+      !application->GetManifest()->GetString(csp_key, &policies_str)) {
+    *error = base::ASCIIToUTF16(
+        "Invalid value of Content Security Policy (CSP).");
     return false;
   }
 
   std::vector<std::string> policies;
-  base::SplitString(policies_str, ';', &policies);
+  base::SplitString(policies_str, directive_separator, &policies);
   for (size_t i = 0; i < policies.size(); ++i) {
-    size_t found = policies[i].find(' ');
+    size_t found = policies[i].find(value_separator);
     if (found == std::string::npos) {
-      *error = ASCIIToUTF16("Invalid value of directive: " + policies[i]);
+      *error = base::ASCIIToUTF16("Invalid value of directive: " + policies[i]);
       return false;
     }
     const std::string& directive_name = policies[i].substr(0, found);
@@ -50,17 +56,17 @@ bool CSPHandler::Parse(scoped_refptr<ApplicationData> application,
     base::SplitStringAlongWhitespace(directive_value_str, &directive_value);
     csp_info->SetDirective(directive_name, directive_value);
   }
-  application->SetManifestData(keys::kCSPKey, csp_info.release());
+  application->SetManifestData(csp_key, csp_info.release());
 
   return true;
 }
 
 bool CSPHandler::AlwaysParseForType(Manifest::Type type) const {
-  return true;
+  return package_type_ == Package::XPK;
 }
 
 std::vector<std::string> CSPHandler::Keys() const {
-  return std::vector<std::string>(1, keys::kCSPKey);
+  return std::vector<std::string>(1, GetCSPKey(package_type_));
 }
 
 }  // namespace application