| OLD | NEW |
| 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/string_number_conversions.h" | 8 #include "base/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 "extensions/common/error_utils.h" | 13 #include "extensions/common/error_utils.h" |
| 13 | 14 |
| 14 namespace extensions { | 15 namespace extensions { |
| 15 | 16 |
| 16 FileHandlerInfo::FileHandlerInfo() {} | 17 FileHandlerInfo::FileHandlerInfo() {} |
| 17 FileHandlerInfo::~FileHandlerInfo() {} | 18 FileHandlerInfo::~FileHandlerInfo() {} |
| 18 | 19 |
| 19 FileHandlers::FileHandlers() {} | 20 FileHandlers::FileHandlers() {} |
| 20 FileHandlers::~FileHandlers() {} | 21 FileHandlers::~FileHandlers() {} |
| 21 | 22 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 std::string(base::IntToString(i))); | 68 std::string(base::IntToString(i))); |
| 68 return false; | 69 return false; |
| 69 } | 70 } |
| 70 handler.types.insert(type); | 71 handler.types.insert(type); |
| 71 } | 72 } |
| 72 | 73 |
| 73 file_handlers->push_back(handler); | 74 file_handlers->push_back(handler); |
| 74 return true; | 75 return true; |
| 75 } | 76 } |
| 76 | 77 |
| 77 bool FileHandlersParser::Parse(const base::Value* value, | 78 bool FileHandlersParser::Parse(Extension* extension, string16* error) { |
| 78 Extension* extension, | |
| 79 string16* error) { | |
| 80 scoped_ptr<FileHandlers> info(new FileHandlers); | 79 scoped_ptr<FileHandlers> info(new FileHandlers); |
| 81 const DictionaryValue* all_handlers = NULL; | 80 const DictionaryValue* all_handlers = NULL; |
| 82 if (!value->GetAsDictionary(&all_handlers)) { | 81 if (!extension->manifest()->GetDictionary( |
| 82 extension_manifest_keys::kFileHandlers, &all_handlers)) { |
| 83 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidFileHandlers); | 83 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidFileHandlers); |
| 84 return false; | 84 return false; |
| 85 } | 85 } |
| 86 | 86 |
| 87 DCHECK(extension->is_platform_app()); | 87 DCHECK(extension->is_platform_app()); |
| 88 | 88 |
| 89 for (DictionaryValue::key_iterator iter(all_handlers->begin_keys()); | 89 for (DictionaryValue::key_iterator iter(all_handlers->begin_keys()); |
| 90 iter != all_handlers->end_keys(); ++iter) { | 90 iter != all_handlers->end_keys(); ++iter) { |
| 91 // A file handler entry is a title and a list of MIME types to handle. | 91 // A file handler entry is a title and a list of MIME types to handle. |
| 92 const DictionaryValue* handler = NULL; | 92 const DictionaryValue* handler = NULL; |
| 93 if (all_handlers->GetDictionaryWithoutPathExpansion(*iter, &handler)) { | 93 if (all_handlers->GetDictionaryWithoutPathExpansion(*iter, &handler)) { |
| 94 if (!LoadFileHandler(*iter, *handler, &info->file_handlers, error)) | 94 if (!LoadFileHandler(*iter, *handler, &info->file_handlers, error)) |
| 95 return false; | 95 return false; |
| 96 } else { | 96 } else { |
| 97 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidFileHandlers); | 97 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidFileHandlers); |
| 98 return false; | 98 return false; |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 extension->SetManifestData(extension_manifest_keys::kFileHandlers, | 102 extension->SetManifestData(extension_manifest_keys::kFileHandlers, |
| 103 info.release()); | 103 info.release()); |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace extensions | 107 } // namespace extensions |
| OLD | NEW |