| 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"; |
| 27 const char kAddTo[] = "add_to"; |
| 28 const char kPackWith[] = "pack_with"; |
| 29 const char kShareWith[] = "share_with"; |
| 30 |
| 31 } // namespace file_handler_verbs |
| 32 |
| 24 namespace { | 33 namespace { |
| 34 |
| 25 const int kMaxTypeAndExtensionHandlers = 200; | 35 const int kMaxTypeAndExtensionHandlers = 200; |
| 26 const char kNotRecognized[] = "'%s' is not a recognized file handler property."; | 36 const char kNotRecognized[] = "'%s' is not a recognized file handler property."; |
| 37 |
| 38 bool IsSupportedVerb(const std::string& verb) { |
| 39 return verb == file_handler_verbs::kOpenWith || |
| 40 verb == file_handler_verbs::kAddTo || |
| 41 verb == file_handler_verbs::kPackWith || |
| 42 verb == file_handler_verbs::kShareWith; |
| 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 21 matching lines...) Expand all Loading... |
| 116 handler.extensions.insert(file_extension); | 144 handler.extensions.insert(file_extension); |
| 117 } | 145 } |
| 118 } | 146 } |
| 119 | 147 |
| 120 file_handlers->push_back(handler); | 148 file_handlers->push_back(handler); |
| 121 | 149 |
| 122 // Check for unknown keys. | 150 // Check for unknown keys. |
| 123 for (base::DictionaryValue::Iterator it(handler_info); !it.IsAtEnd(); | 151 for (base::DictionaryValue::Iterator it(handler_info); !it.IsAtEnd(); |
| 124 it.Advance()) { | 152 it.Advance()) { |
| 125 if (it.key() != keys::kFileHandlerExtensions && | 153 if (it.key() != keys::kFileHandlerExtensions && |
| 126 it.key() != keys::kFileHandlerTypes) { | 154 it.key() != keys::kFileHandlerTypes && |
| 155 it.key() != keys::kFileHandlerVerb) { |
| 127 install_warnings->push_back( | 156 install_warnings->push_back( |
| 128 InstallWarning(base::StringPrintf(kNotRecognized, it.key().c_str()), | 157 InstallWarning(base::StringPrintf(kNotRecognized, it.key().c_str()), |
| 129 keys::kFileHandlers, | 158 keys::kFileHandlers, |
| 130 it.key())); | 159 it.key())); |
| 131 } | 160 } |
| 132 } | 161 } |
| 133 | 162 |
| 134 return true; | 163 return true; |
| 135 } | 164 } |
| 136 | 165 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 extension->SetManifestData(keys::kFileHandlers, info.release()); | 207 extension->SetManifestData(keys::kFileHandlers, info.release()); |
| 179 extension->AddInstallWarnings(install_warnings); | 208 extension->AddInstallWarnings(install_warnings); |
| 180 return true; | 209 return true; |
| 181 } | 210 } |
| 182 | 211 |
| 183 const std::vector<std::string> FileHandlersParser::Keys() const { | 212 const std::vector<std::string> FileHandlersParser::Keys() const { |
| 184 return SingleKey(keys::kFileHandlers); | 213 return SingleKey(keys::kFileHandlers); |
| 185 } | 214 } |
| 186 | 215 |
| 187 } // namespace extensions | 216 } // namespace extensions |
| OLD | NEW |