Chromium Code Reviews| 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/file_handler_info.h" | 5 #include "extensions/common/manifest_handlers/file_handler_info.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "extensions/common/error_utils.h" | 15 #include "extensions/common/error_utils.h" |
| 16 #include "extensions/common/manifest.h" | 16 #include "extensions/common/manifest.h" |
| 17 #include "extensions/common/manifest_constants.h" | 17 #include "extensions/common/manifest_constants.h" |
| 18 | 18 |
| 19 namespace extensions { | 19 namespace extensions { |
| 20 | 20 |
| 21 namespace keys = manifest_keys; | 21 namespace keys = manifest_keys; |
| 22 namespace errors = manifest_errors; | 22 namespace errors = manifest_errors; |
| 23 | 23 |
| 24 namespace file_handler_verbs { | |
| 25 | |
| 26 const char kOpenWith[] = "Open with"; | |
|
Devlin
2016/05/16 16:17:32
manifest constants are almost always all_lowercase
cmihail
2016/05/18 02:35:31
Done.
| |
| 27 const char kAddTo[] = "Add to"; | |
| 28 const char kPackWith[] = "Pack with"; | |
| 29 | |
| 30 } // namespace file_handler_verbs | |
| 31 | |
| 24 namespace { | 32 namespace { |
| 33 | |
| 25 const int kMaxTypeAndExtensionHandlers = 200; | 34 const int kMaxTypeAndExtensionHandlers = 200; |
| 26 const char kNotRecognized[] = "'%s' is not a recognized file handler property."; | 35 const char kNotRecognized[] = "'%s' is not a recognized file handler property."; |
| 36 | |
| 37 bool IsSupportedVerb(const std::string& verb) { | |
| 38 std::set<std::string> supported_verbs; | |
| 39 supported_verbs.emplace(file_handler_verbs::kOpenWith); | |
| 40 supported_verbs.emplace(file_handler_verbs::kAddTo); | |
| 41 supported_verbs.emplace(file_handler_verbs::kPackWith); | |
| 42 return supported_verbs.find(verb) != supported_verbs.end(); | |
|
Devlin
2016/05/16 16:17:32
This results in the construction of a set and thre
cmihail
2016/05/18 02:35:31
Done.
| |
| 27 } | 43 } |
| 28 | 44 |
| 29 FileHandlerInfo::FileHandlerInfo() : include_directories(false) {} | 45 } // namespace |
| 46 | |
| 47 FileHandlerInfo::FileHandlerInfo() | |
| 48 : include_directories(false), verb(file_handler_verbs::kOpenWith) {} | |
| 30 FileHandlerInfo::FileHandlerInfo(const FileHandlerInfo& other) = default; | 49 FileHandlerInfo::FileHandlerInfo(const FileHandlerInfo& other) = default; |
| 31 FileHandlerInfo::~FileHandlerInfo() {} | 50 FileHandlerInfo::~FileHandlerInfo() {} |
| 32 | 51 |
| 33 FileHandlers::FileHandlers() {} | 52 FileHandlers::FileHandlers() {} |
| 34 FileHandlers::~FileHandlers() {} | 53 FileHandlers::~FileHandlers() {} |
| 35 | 54 |
| 36 // static | 55 // static |
| 37 const FileHandlersInfo* FileHandlers::GetFileHandlers( | 56 const FileHandlersInfo* FileHandlers::GetFileHandlers( |
| 38 const Extension* extension) { | 57 const Extension* extension) { |
| 39 FileHandlers* info = static_cast<FileHandlers*>( | 58 FileHandlers* info = static_cast<FileHandlers*>( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 | 94 |
| 76 handler.include_directories = false; | 95 handler.include_directories = false; |
| 77 if (handler_info.HasKey("include_directories") && | 96 if (handler_info.HasKey("include_directories") && |
| 78 !handler_info.GetBoolean("include_directories", | 97 !handler_info.GetBoolean("include_directories", |
| 79 &handler.include_directories)) { | 98 &handler.include_directories)) { |
| 80 *error = ErrorUtils::FormatErrorMessageUTF16( | 99 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 81 errors::kInvalidFileHandlerIncludeDirectories, handler_id); | 100 errors::kInvalidFileHandlerIncludeDirectories, handler_id); |
| 82 return false; | 101 return false; |
| 83 } | 102 } |
| 84 | 103 |
| 104 handler.verb = file_handler_verbs::kOpenWith; | |
| 105 if (handler_info.HasKey(keys::kFileHandlerVerb) && | |
| 106 !handler_info.GetString(keys::kFileHandlerVerb, &handler.verb) && | |
| 107 !IsSupportedVerb(handler.verb)) { | |
| 108 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 109 errors::kInvalidFileHandlerVerb, handler_id); | |
| 110 return false; | |
| 111 } | |
| 112 | |
| 85 if ((!mime_types || mime_types->empty()) && | 113 if ((!mime_types || mime_types->empty()) && |
| 86 (!file_extensions || file_extensions->empty()) && | 114 (!file_extensions || file_extensions->empty()) && |
| 87 !handler.include_directories) { | 115 !handler.include_directories) { |
| 88 *error = ErrorUtils::FormatErrorMessageUTF16( | 116 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 89 errors::kInvalidFileHandlerNoTypeOrExtension, | 117 errors::kInvalidFileHandlerNoTypeOrExtension, |
| 90 handler_id); | 118 handler_id); |
| 91 return false; | 119 return false; |
| 92 } | 120 } |
| 93 | 121 |
| 94 if (mime_types) { | 122 if (mime_types) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 extension->SetManifestData(keys::kFileHandlers, info.release()); | 206 extension->SetManifestData(keys::kFileHandlers, info.release()); |
| 179 extension->AddInstallWarnings(install_warnings); | 207 extension->AddInstallWarnings(install_warnings); |
| 180 return true; | 208 return true; |
| 181 } | 209 } |
| 182 | 210 |
| 183 const std::vector<std::string> FileHandlersParser::Keys() const { | 211 const std::vector<std::string> FileHandlersParser::Keys() const { |
| 184 return SingleKey(keys::kFileHandlers); | 212 return SingleKey(keys::kFileHandlers); |
| 185 } | 213 } |
| 186 | 214 |
| 187 } // namespace extensions | 215 } // namespace extensions |
| OLD | NEW |