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

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

Issue 12253022: Manifest handler for all keys background-related. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/common/extensions/extension_manifest_constants.h" 11 #include "chrome/common/extensions/extension_manifest_constants.h"
12 #include "chrome/common/extensions/manifest.h" 12 #include "chrome/common/extensions/manifest.h"
13 #include "extensions/common/error_utils.h" 13 #include "extensions/common/error_utils.h"
14 14
15 namespace keys = extension_manifest_keys;
16
15 namespace extensions { 17 namespace extensions {
16 18
17 FileHandlerInfo::FileHandlerInfo() {} 19 FileHandlerInfo::FileHandlerInfo() {}
18 FileHandlerInfo::~FileHandlerInfo() {} 20 FileHandlerInfo::~FileHandlerInfo() {}
19 21
20 FileHandlers::FileHandlers() {} 22 FileHandlers::FileHandlers() {}
21 FileHandlers::~FileHandlers() {} 23 FileHandlers::~FileHandlers() {}
22 24
23 // static 25 // static
24 const std::vector<FileHandlerInfo>* FileHandlers::GetFileHandlers( 26 const std::vector<FileHandlerInfo>* FileHandlers::GetFileHandlers(
(...skipping 13 matching lines...) Expand all
38 const DictionaryValue& handler_info, 40 const DictionaryValue& handler_info,
39 std::vector<FileHandlerInfo>* file_handlers, 41 std::vector<FileHandlerInfo>* file_handlers,
40 string16* error) { 42 string16* error) {
41 DCHECK(error); 43 DCHECK(error);
42 FileHandlerInfo handler; 44 FileHandlerInfo handler;
43 45
44 handler.id = handler_id; 46 handler.id = handler_id;
45 47
46 const ListValue* mime_types = NULL; 48 const ListValue* mime_types = NULL;
47 // TODO(benwells): handle file extensions. 49 // TODO(benwells): handle file extensions.
48 if (!handler_info.HasKey(extension_manifest_keys::kFileHandlerTypes) || 50 if (!handler_info.HasKey(keys::kFileHandlerTypes) ||
49 !handler_info.GetList(extension_manifest_keys::kFileHandlerTypes, 51 !handler_info.GetList(keys::kFileHandlerTypes, &mime_types) ||
50 &mime_types) || mime_types->GetSize() == 0) { 52 mime_types->GetSize() == 0) {
51 *error = ErrorUtils::FormatErrorMessageUTF16( 53 *error = ErrorUtils::FormatErrorMessageUTF16(
52 extension_manifest_errors::kInvalidFileHandlerType, handler_id); 54 extension_manifest_errors::kInvalidFileHandlerType, handler_id);
53 return false; 55 return false;
54 } 56 }
55 57
56 if (handler_info.HasKey(extension_manifest_keys::kFileHandlerTitle) && 58 if (handler_info.HasKey(keys::kFileHandlerTitle) &&
57 !handler_info.GetString(extension_manifest_keys::kFileHandlerTitle, 59 !handler_info.GetString(keys::kFileHandlerTitle, &handler.title)) {
58 &handler.title)) {
59 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidFileHandlerTitle); 60 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidFileHandlerTitle);
60 return false; 61 return false;
61 } 62 }
62 63
63 std::string type; 64 std::string type;
64 for (size_t i = 0; i < mime_types->GetSize(); ++i) { 65 for (size_t i = 0; i < mime_types->GetSize(); ++i) {
65 if (!mime_types->GetString(i, &type)) { 66 if (!mime_types->GetString(i, &type)) {
66 *error = ErrorUtils::FormatErrorMessageUTF16( 67 *error = ErrorUtils::FormatErrorMessageUTF16(
67 extension_manifest_errors::kInvalidFileHandlerTypeElement, handler_id, 68 extension_manifest_errors::kInvalidFileHandlerTypeElement, handler_id,
68 std::string(base::IntToString(i))); 69 std::string(base::IntToString(i)));
69 return false; 70 return false;
70 } 71 }
71 handler.types.insert(type); 72 handler.types.insert(type);
72 } 73 }
73 74
74 file_handlers->push_back(handler); 75 file_handlers->push_back(handler);
75 return true; 76 return true;
76 } 77 }
77 78
78 bool FileHandlersParser::Parse(Extension* extension, string16* error) { 79 bool FileHandlersParser::Parse(Extension* extension, string16* error) {
79 scoped_ptr<FileHandlers> info(new FileHandlers); 80 scoped_ptr<FileHandlers> info(new FileHandlers);
80 const DictionaryValue* all_handlers = NULL; 81 const DictionaryValue* all_handlers = NULL;
81 if (!extension->manifest()->GetDictionary( 82 if (!extension->manifest()->GetDictionary(keys::kFileHandlers,
82 extension_manifest_keys::kFileHandlers, &all_handlers)) { 83 &all_handlers)) {
83 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidFileHandlers); 84 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidFileHandlers);
84 return false; 85 return false;
85 } 86 }
86 87
87 DCHECK(extension->is_platform_app()); 88 DCHECK(extension->is_platform_app());
88 89
89 for (DictionaryValue::key_iterator iter(all_handlers->begin_keys()); 90 for (DictionaryValue::key_iterator iter(all_handlers->begin_keys());
90 iter != all_handlers->end_keys(); ++iter) { 91 iter != all_handlers->end_keys(); ++iter) {
91 // A file handler entry is a title and a list of MIME types to handle. 92 // A file handler entry is a title and a list of MIME types to handle.
92 const DictionaryValue* handler = NULL; 93 const DictionaryValue* handler = NULL;
93 if (all_handlers->GetDictionaryWithoutPathExpansion(*iter, &handler)) { 94 if (all_handlers->GetDictionaryWithoutPathExpansion(*iter, &handler)) {
94 if (!LoadFileHandler(*iter, *handler, &info->file_handlers, error)) 95 if (!LoadFileHandler(*iter, *handler, &info->file_handlers, error))
95 return false; 96 return false;
96 } else { 97 } else {
97 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidFileHandlers); 98 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidFileHandlers);
98 return false; 99 return false;
99 } 100 }
100 } 101 }
101 102
102 extension->SetManifestData(extension_manifest_keys::kFileHandlers, 103 extension->SetManifestData(keys::kFileHandlers, info.release());
103 info.release());
104 return true; 104 return true;
105 } 105 }
106 106
107 const std::vector<std::string> FileHandlersParser::Keys() const {
108 return SingleKey(keys::kFileHandlers);
109 }
110
107 } // namespace extensions 111 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698