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

Side by Side Diff: chrome/common/extensions/api/file_handlers/file_handlers_parser.cc

Issue 93793010: Update uses of UTF conversions in chrome/common to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/api/file_handlers/file_handlers_parser.h" 5 #include "chrome/common/extensions/api/file_handlers/file_handlers_parser.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/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 if ((!mime_types || mime_types->GetSize() == 0) && 67 if ((!mime_types || mime_types->GetSize() == 0) &&
68 (!file_extensions || file_extensions->GetSize() == 0)) { 68 (!file_extensions || file_extensions->GetSize() == 0)) {
69 *error = ErrorUtils::FormatErrorMessageUTF16( 69 *error = ErrorUtils::FormatErrorMessageUTF16(
70 errors::kInvalidFileHandlerNoTypeOrExtension, 70 errors::kInvalidFileHandlerNoTypeOrExtension,
71 handler_id); 71 handler_id);
72 return false; 72 return false;
73 } 73 }
74 74
75 if (handler_info.HasKey(keys::kFileHandlerTitle) && 75 if (handler_info.HasKey(keys::kFileHandlerTitle) &&
76 !handler_info.GetString(keys::kFileHandlerTitle, &handler.title)) { 76 !handler_info.GetString(keys::kFileHandlerTitle, &handler.title)) {
77 *error = ASCIIToUTF16(errors::kInvalidFileHandlerTitle); 77 *error = base::ASCIIToUTF16(errors::kInvalidFileHandlerTitle);
78 return false; 78 return false;
79 } 79 }
80 80
81 if (mime_types) { 81 if (mime_types) {
82 std::string type; 82 std::string type;
83 for (size_t i = 0; i < mime_types->GetSize(); ++i) { 83 for (size_t i = 0; i < mime_types->GetSize(); ++i) {
84 if (!mime_types->GetString(i, &type)) { 84 if (!mime_types->GetString(i, &type)) {
85 *error = ErrorUtils::FormatErrorMessageUTF16( 85 *error = ErrorUtils::FormatErrorMessageUTF16(
86 errors::kInvalidFileHandlerTypeElement, 86 errors::kInvalidFileHandlerTypeElement,
87 handler_id, 87 handler_id,
(...skipping 20 matching lines...) Expand all
108 108
109 file_handlers->push_back(handler); 109 file_handlers->push_back(handler);
110 return true; 110 return true;
111 } 111 }
112 112
113 bool FileHandlersParser::Parse(Extension* extension, base::string16* error) { 113 bool FileHandlersParser::Parse(Extension* extension, base::string16* error) {
114 scoped_ptr<FileHandlers> info(new FileHandlers); 114 scoped_ptr<FileHandlers> info(new FileHandlers);
115 const base::DictionaryValue* all_handlers = NULL; 115 const base::DictionaryValue* all_handlers = NULL;
116 if (!extension->manifest()->GetDictionary(keys::kFileHandlers, 116 if (!extension->manifest()->GetDictionary(keys::kFileHandlers,
117 &all_handlers)) { 117 &all_handlers)) {
118 *error = ASCIIToUTF16(errors::kInvalidFileHandlers); 118 *error = base::ASCIIToUTF16(errors::kInvalidFileHandlers);
119 return false; 119 return false;
120 } 120 }
121 121
122 DCHECK(extension->is_platform_app()); 122 DCHECK(extension->is_platform_app());
123 123
124 for (base::DictionaryValue::Iterator iter(*all_handlers); !iter.IsAtEnd(); 124 for (base::DictionaryValue::Iterator iter(*all_handlers); !iter.IsAtEnd();
125 iter.Advance()) { 125 iter.Advance()) {
126 // A file handler entry is a title and a list of MIME types to handle. 126 // A file handler entry is a title and a list of MIME types to handle.
127 const base::DictionaryValue* handler = NULL; 127 const base::DictionaryValue* handler = NULL;
128 if (iter.value().GetAsDictionary(&handler)) { 128 if (iter.value().GetAsDictionary(&handler)) {
129 if (!LoadFileHandler(iter.key(), *handler, &info->file_handlers, error)) 129 if (!LoadFileHandler(iter.key(), *handler, &info->file_handlers, error))
130 return false; 130 return false;
131 } else { 131 } else {
132 *error = ASCIIToUTF16(errors::kInvalidFileHandlers); 132 *error = base::ASCIIToUTF16(errors::kInvalidFileHandlers);
133 return false; 133 return false;
134 } 134 }
135 } 135 }
136 136
137 int filterCount = 0; 137 int filterCount = 0;
138 for (std::vector<FileHandlerInfo>::iterator iter = 138 for (std::vector<FileHandlerInfo>::iterator iter =
139 info->file_handlers.begin(); 139 info->file_handlers.begin();
140 iter < info->file_handlers.end(); 140 iter < info->file_handlers.end();
141 iter++) { 141 iter++) {
142 filterCount += iter->types.size(); 142 filterCount += iter->types.size();
143 filterCount += iter->extensions.size(); 143 filterCount += iter->extensions.size();
144 } 144 }
145 145
146 if (filterCount > kMaxTypeAndExtensionHandlers) { 146 if (filterCount > kMaxTypeAndExtensionHandlers) {
147 *error = ASCIIToUTF16( 147 *error = base::ASCIIToUTF16(
148 errors::kInvalidFileHandlersTooManyTypesAndExtensions); 148 errors::kInvalidFileHandlersTooManyTypesAndExtensions);
149 return false; 149 return false;
150 } 150 }
151 151
152 extension->SetManifestData(keys::kFileHandlers, info.release()); 152 extension->SetManifestData(keys::kFileHandlers, info.release());
153 return true; 153 return true;
154 } 154 }
155 155
156 const std::vector<std::string> FileHandlersParser::Keys() const { 156 const std::vector<std::string> FileHandlersParser::Keys() const {
157 return SingleKey(keys::kFileHandlers); 157 return SingleKey(keys::kFileHandlers);
158 } 158 }
159 159
160 } // namespace extensions 160 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698