| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/extensions/webview_handler.h" | 5 #include "chrome/common/extensions/webview_handler.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 WebviewHandler::~WebviewHandler() { | 66 WebviewHandler::~WebviewHandler() { |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool WebviewHandler::Parse(Extension* extension, base::string16* error) { | 69 bool WebviewHandler::Parse(Extension* extension, base::string16* error) { |
| 70 scoped_ptr<WebviewInfo> info(new WebviewInfo()); | 70 scoped_ptr<WebviewInfo> info(new WebviewInfo()); |
| 71 | 71 |
| 72 const base::DictionaryValue* dict_value = NULL; | 72 const base::DictionaryValue* dict_value = NULL; |
| 73 if (!extension->manifest()->GetDictionary(keys::kWebview, | 73 if (!extension->manifest()->GetDictionary(keys::kWebview, |
| 74 &dict_value)) { | 74 &dict_value)) { |
| 75 *error = ASCIIToUTF16(errors::kInvalidWebview); | 75 *error = base::ASCIIToUTF16(errors::kInvalidWebview); |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 | 78 |
| 79 const base::ListValue* url_list = NULL; | 79 const base::ListValue* url_list = NULL; |
| 80 if (!dict_value->GetList(keys::kWebviewAccessibleResources, | 80 if (!dict_value->GetList(keys::kWebviewAccessibleResources, |
| 81 &url_list)) { | 81 &url_list)) { |
| 82 *error = ASCIIToUTF16(errors::kInvalidWebviewAccessibleResourcesList); | 82 *error = base::ASCIIToUTF16(errors::kInvalidWebviewAccessibleResourcesList); |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 for (size_t i = 0; i < url_list->GetSize(); ++i) { | 86 for (size_t i = 0; i < url_list->GetSize(); ++i) { |
| 87 std::string relative_path; | 87 std::string relative_path; |
| 88 if (!url_list->GetString(i, &relative_path)) { | 88 if (!url_list->GetString(i, &relative_path)) { |
| 89 *error = ErrorUtils::FormatErrorMessageUTF16( | 89 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 90 errors::kInvalidWebviewAccessibleResource, base::IntToString(i)); | 90 errors::kInvalidWebviewAccessibleResource, base::IntToString(i)); |
| 91 return false; | 91 return false; |
| 92 } | 92 } |
| 93 URLPattern pattern(URLPattern::SCHEME_EXTENSION); | 93 URLPattern pattern(URLPattern::SCHEME_EXTENSION); |
| 94 if (pattern.Parse(extension->url().spec()) != URLPattern::PARSE_SUCCESS) { | 94 if (pattern.Parse(extension->url().spec()) != URLPattern::PARSE_SUCCESS) { |
| 95 *error = ErrorUtils::FormatErrorMessageUTF16( | 95 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 96 errors::kInvalidURLPatternError, extension->url().spec()); | 96 errors::kInvalidURLPatternError, extension->url().spec()); |
| 97 return false; | 97 return false; |
| 98 } | 98 } |
| 99 while (relative_path[0] == '/') | 99 while (relative_path[0] == '/') |
| 100 relative_path = relative_path.substr(1, relative_path.length() - 1); | 100 relative_path = relative_path.substr(1, relative_path.length() - 1); |
| 101 pattern.SetPath(pattern.path() + relative_path); | 101 pattern.SetPath(pattern.path() + relative_path); |
| 102 info->webview_accessible_resources_.AddPattern(pattern); | 102 info->webview_accessible_resources_.AddPattern(pattern); |
| 103 } | 103 } |
| 104 | 104 |
| 105 const base::ListValue* partition_list = NULL; | 105 const base::ListValue* partition_list = NULL; |
| 106 if (!dict_value->GetList(keys::kWebviewPrivilegedPartitions, | 106 if (!dict_value->GetList(keys::kWebviewPrivilegedPartitions, |
| 107 &partition_list)) { | 107 &partition_list)) { |
| 108 *error = ASCIIToUTF16(errors::kInvalidWebviewPrivilegedPartitionList); | 108 *error = base::ASCIIToUTF16(errors::kInvalidWebviewPrivilegedPartitionList); |
| 109 return false; | 109 return false; |
| 110 } | 110 } |
| 111 for (size_t i = 0; i < partition_list->GetSize(); ++i) { | 111 for (size_t i = 0; i < partition_list->GetSize(); ++i) { |
| 112 std::string partition_wildcard; | 112 std::string partition_wildcard; |
| 113 if (!partition_list->GetString(i, &partition_wildcard)) { | 113 if (!partition_list->GetString(i, &partition_wildcard)) { |
| 114 *error = ErrorUtils::FormatErrorMessageUTF16( | 114 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 115 errors::kInvalidWebviewPrivilegedPartition, base::IntToString(i)); | 115 errors::kInvalidWebviewPrivilegedPartition, base::IntToString(i)); |
| 116 return false; | 116 return false; |
| 117 } | 117 } |
| 118 info->webview_privileged_partitions_.push_back(partition_wildcard); | 118 info->webview_privileged_partitions_.push_back(partition_wildcard); |
| 119 } | 119 } |
| 120 extension->SetManifestData(keys::kWebviewAccessibleResources, info.release()); | 120 extension->SetManifestData(keys::kWebviewAccessibleResources, info.release()); |
| 121 return true; | 121 return true; |
| 122 } | 122 } |
| 123 | 123 |
| 124 const std::vector<std::string> WebviewHandler::Keys() const { | 124 const std::vector<std::string> WebviewHandler::Keys() const { |
| 125 return SingleKey(keys::kWebview); | 125 return SingleKey(keys::kWebview); |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace extensions | 128 } // namespace extensions |
| OLD | NEW |