Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: extensions/common/manifest_handlers/file_handler_info.cc

Issue 598173003: Run clang-modernize -use-nullptr over src/extensions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "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/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 16 matching lines...) Expand all
27 FileHandlerInfo::~FileHandlerInfo() {} 27 FileHandlerInfo::~FileHandlerInfo() {}
28 28
29 FileHandlers::FileHandlers() {} 29 FileHandlers::FileHandlers() {}
30 FileHandlers::~FileHandlers() {} 30 FileHandlers::~FileHandlers() {}
31 31
32 // static 32 // static
33 const FileHandlersInfo* FileHandlers::GetFileHandlers( 33 const FileHandlersInfo* FileHandlers::GetFileHandlers(
34 const Extension* extension) { 34 const Extension* extension) {
35 FileHandlers* info = static_cast<FileHandlers*>( 35 FileHandlers* info = static_cast<FileHandlers*>(
36 extension->GetManifestData(keys::kFileHandlers)); 36 extension->GetManifestData(keys::kFileHandlers));
37 return info ? &info->file_handlers : NULL; 37 return info ? &info->file_handlers : nullptr;
38 } 38 }
39 39
40 FileHandlersParser::FileHandlersParser() { 40 FileHandlersParser::FileHandlersParser() {
41 } 41 }
42 42
43 FileHandlersParser::~FileHandlersParser() { 43 FileHandlersParser::~FileHandlersParser() {
44 } 44 }
45 45
46 bool LoadFileHandler(const std::string& handler_id, 46 bool LoadFileHandler(const std::string& handler_id,
47 const base::DictionaryValue& handler_info, 47 const base::DictionaryValue& handler_info,
48 FileHandlersInfo* file_handlers, 48 FileHandlersInfo* file_handlers,
49 base::string16* error, 49 base::string16* error,
50 std::vector<InstallWarning>* install_warnings) { 50 std::vector<InstallWarning>* install_warnings) {
51 DCHECK(error); 51 DCHECK(error);
52 FileHandlerInfo handler; 52 FileHandlerInfo handler;
53 53
54 handler.id = handler_id; 54 handler.id = handler_id;
55 55
56 const base::ListValue* mime_types = NULL; 56 const base::ListValue* mime_types = nullptr;
57 if (handler_info.HasKey(keys::kFileHandlerTypes) && 57 if (handler_info.HasKey(keys::kFileHandlerTypes) &&
58 !handler_info.GetList(keys::kFileHandlerTypes, &mime_types)) { 58 !handler_info.GetList(keys::kFileHandlerTypes, &mime_types)) {
59 *error = ErrorUtils::FormatErrorMessageUTF16( 59 *error = ErrorUtils::FormatErrorMessageUTF16(
60 errors::kInvalidFileHandlerType, handler_id); 60 errors::kInvalidFileHandlerType, handler_id);
61 return false; 61 return false;
62 } 62 }
63 63
64 const base::ListValue* file_extensions = NULL; 64 const base::ListValue* file_extensions = nullptr;
65 if (handler_info.HasKey(keys::kFileHandlerExtensions) && 65 if (handler_info.HasKey(keys::kFileHandlerExtensions) &&
66 !handler_info.GetList(keys::kFileHandlerExtensions, &file_extensions)) { 66 !handler_info.GetList(keys::kFileHandlerExtensions, &file_extensions)) {
67 *error = ErrorUtils::FormatErrorMessageUTF16( 67 *error = ErrorUtils::FormatErrorMessageUTF16(
68 errors::kInvalidFileHandlerExtension, handler_id); 68 errors::kInvalidFileHandlerExtension, handler_id);
69 return false; 69 return false;
70 } 70 }
71 71
72 if ((!mime_types || mime_types->empty()) && 72 if ((!mime_types || mime_types->empty()) &&
73 (!file_extensions || file_extensions->empty())) { 73 (!file_extensions || file_extensions->empty())) {
74 *error = ErrorUtils::FormatErrorMessageUTF16( 74 *error = ErrorUtils::FormatErrorMessageUTF16(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 keys::kFileHandlers, 117 keys::kFileHandlers,
118 it.key())); 118 it.key()));
119 } 119 }
120 } 120 }
121 121
122 return true; 122 return true;
123 } 123 }
124 124
125 bool FileHandlersParser::Parse(Extension* extension, base::string16* error) { 125 bool FileHandlersParser::Parse(Extension* extension, base::string16* error) {
126 scoped_ptr<FileHandlers> info(new FileHandlers); 126 scoped_ptr<FileHandlers> info(new FileHandlers);
127 const base::DictionaryValue* all_handlers = NULL; 127 const base::DictionaryValue* all_handlers = nullptr;
128 if (!extension->manifest()->GetDictionary(keys::kFileHandlers, 128 if (!extension->manifest()->GetDictionary(keys::kFileHandlers,
129 &all_handlers)) { 129 &all_handlers)) {
130 *error = base::ASCIIToUTF16(errors::kInvalidFileHandlers); 130 *error = base::ASCIIToUTF16(errors::kInvalidFileHandlers);
131 return false; 131 return false;
132 } 132 }
133 133
134 std::vector<InstallWarning> install_warnings; 134 std::vector<InstallWarning> install_warnings;
135 for (base::DictionaryValue::Iterator iter(*all_handlers); 135 for (base::DictionaryValue::Iterator iter(*all_handlers);
136 !iter.IsAtEnd(); 136 !iter.IsAtEnd();
137 iter.Advance()) { 137 iter.Advance()) {
138 const base::DictionaryValue* handler = NULL; 138 const base::DictionaryValue* handler = nullptr;
139 if (iter.value().GetAsDictionary(&handler)) { 139 if (iter.value().GetAsDictionary(&handler)) {
140 if (!LoadFileHandler(iter.key(), 140 if (!LoadFileHandler(iter.key(),
141 *handler, 141 *handler,
142 &info->file_handlers, 142 &info->file_handlers,
143 error, 143 error,
144 &install_warnings)) 144 &install_warnings))
145 return false; 145 return false;
146 } else { 146 } else {
147 *error = base::ASCIIToUTF16(errors::kInvalidFileHandlers); 147 *error = base::ASCIIToUTF16(errors::kInvalidFileHandlers);
148 return false; 148 return false;
(...skipping 17 matching lines...) Expand all
166 extension->SetManifestData(keys::kFileHandlers, info.release()); 166 extension->SetManifestData(keys::kFileHandlers, info.release());
167 extension->AddInstallWarnings(install_warnings); 167 extension->AddInstallWarnings(install_warnings);
168 return true; 168 return true;
169 } 169 }
170 170
171 const std::vector<std::string> FileHandlersParser::Keys() const { 171 const std::vector<std::string> FileHandlersParser::Keys() const {
172 return SingleKey(keys::kFileHandlers); 172 return SingleKey(keys::kFileHandlers);
173 } 173 }
174 174
175 } // namespace extensions 175 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698