| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/common/manifest_handlers/webview_info.h" | 5 #include "extensions/common/manifest_handlers/webview_info.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <utility> | 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/strings/pattern.h" | 12 #include "base/strings/pattern.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "extensions/common/error_utils.h" | 17 #include "extensions/common/error_utils.h" |
| 18 #include "extensions/common/manifest.h" | 18 #include "extensions/common/manifest.h" |
| 19 #include "extensions/common/manifest_constants.h" | 19 #include "extensions/common/manifest_constants.h" |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 if (item->Matches(partition_id) && | 79 if (item->Matches(partition_id) && |
| 80 extension->ResourceMatches(item->accessible_resources(), | 80 extension->ResourceMatches(item->accessible_resources(), |
| 81 relative_path)) { | 81 relative_path)) { |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 return false; | 86 return false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void WebviewInfo::AddPartitionItem(scoped_ptr<PartitionItem> item) { | 89 void WebviewInfo::AddPartitionItem(std::unique_ptr<PartitionItem> item) { |
| 90 partition_items_.push_back(std::move(item)); | 90 partition_items_.push_back(std::move(item)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 WebviewHandler::WebviewHandler() { | 93 WebviewHandler::WebviewHandler() { |
| 94 } | 94 } |
| 95 | 95 |
| 96 WebviewHandler::~WebviewHandler() { | 96 WebviewHandler::~WebviewHandler() { |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool WebviewHandler::Parse(Extension* extension, base::string16* error) { | 99 bool WebviewHandler::Parse(Extension* extension, base::string16* error) { |
| 100 scoped_ptr<WebviewInfo> info(new WebviewInfo(extension->id())); | 100 std::unique_ptr<WebviewInfo> info(new WebviewInfo(extension->id())); |
| 101 | 101 |
| 102 const base::DictionaryValue* dict_value = NULL; | 102 const base::DictionaryValue* dict_value = NULL; |
| 103 if (!extension->manifest()->GetDictionary(keys::kWebview, | 103 if (!extension->manifest()->GetDictionary(keys::kWebview, |
| 104 &dict_value)) { | 104 &dict_value)) { |
| 105 *error = base::ASCIIToUTF16(errors::kInvalidWebview); | 105 *error = base::ASCIIToUTF16(errors::kInvalidWebview); |
| 106 return false; | 106 return false; |
| 107 } | 107 } |
| 108 | 108 |
| 109 const base::ListValue* partition_list = NULL; | 109 const base::ListValue* partition_list = NULL; |
| 110 if (!dict_value->GetList(keys::kWebviewPartitions, &partition_list)) { | 110 if (!dict_value->GetList(keys::kWebviewPartitions, &partition_list)) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 141 return false; | 141 return false; |
| 142 } | 142 } |
| 143 | 143 |
| 144 // The URL list should have at least one entry. | 144 // The URL list should have at least one entry. |
| 145 if (url_list->GetSize() == 0) { | 145 if (url_list->GetSize() == 0) { |
| 146 *error = base::ASCIIToUTF16( | 146 *error = base::ASCIIToUTF16( |
| 147 errors::kInvalidWebviewAccessibleResourcesList); | 147 errors::kInvalidWebviewAccessibleResourcesList); |
| 148 return false; | 148 return false; |
| 149 } | 149 } |
| 150 | 150 |
| 151 scoped_ptr<PartitionItem> partition_item( | 151 std::unique_ptr<PartitionItem> partition_item( |
| 152 new PartitionItem(partition_pattern)); | 152 new PartitionItem(partition_pattern)); |
| 153 | 153 |
| 154 for (size_t i = 0; i < url_list->GetSize(); ++i) { | 154 for (size_t i = 0; i < url_list->GetSize(); ++i) { |
| 155 std::string relative_path; | 155 std::string relative_path; |
| 156 if (!url_list->GetString(i, &relative_path)) { | 156 if (!url_list->GetString(i, &relative_path)) { |
| 157 *error = ErrorUtils::FormatErrorMessageUTF16( | 157 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 158 errors::kInvalidWebviewAccessibleResource, base::SizeTToString(i)); | 158 errors::kInvalidWebviewAccessibleResource, base::SizeTToString(i)); |
| 159 return false; | 159 return false; |
| 160 } | 160 } |
| 161 URLPattern pattern(URLPattern::SCHEME_EXTENSION, | 161 URLPattern pattern(URLPattern::SCHEME_EXTENSION, |
| 162 Extension::GetResourceURL(extension->url(), | 162 Extension::GetResourceURL(extension->url(), |
| 163 relative_path).spec()); | 163 relative_path).spec()); |
| 164 partition_item->AddPattern(pattern); | 164 partition_item->AddPattern(pattern); |
| 165 } | 165 } |
| 166 info->AddPartitionItem(std::move(partition_item)); | 166 info->AddPartitionItem(std::move(partition_item)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 extension->SetManifestData(keys::kWebviewAccessibleResources, info.release()); | 169 extension->SetManifestData(keys::kWebviewAccessibleResources, info.release()); |
| 170 return true; | 170 return true; |
| 171 } | 171 } |
| 172 | 172 |
| 173 const std::vector<std::string> WebviewHandler::Keys() const { | 173 const std::vector<std::string> WebviewHandler::Keys() const { |
| 174 return SingleKey(keys::kWebview); | 174 return SingleKey(keys::kWebview); |
| 175 } | 175 } |
| 176 | 176 |
| 177 } // namespace extensions | 177 } // namespace extensions |
| OLD | NEW |