| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/url_handlers/url_handlers_parser.h" | 5 #include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 bool ParseUrlHandler(const std::string& handler_id, | 91 bool ParseUrlHandler(const std::string& handler_id, |
| 92 const base::DictionaryValue& handler_info, | 92 const base::DictionaryValue& handler_info, |
| 93 std::vector<UrlHandlerInfo>* url_handlers, | 93 std::vector<UrlHandlerInfo>* url_handlers, |
| 94 base::string16* error) { | 94 base::string16* error) { |
| 95 DCHECK(error); | 95 DCHECK(error); |
| 96 | 96 |
| 97 UrlHandlerInfo handler; | 97 UrlHandlerInfo handler; |
| 98 handler.id = handler_id; | 98 handler.id = handler_id; |
| 99 | 99 |
| 100 if (!handler_info.GetString(mkeys::kUrlHandlerTitle, &handler.title)) { | 100 if (!handler_info.GetString(mkeys::kUrlHandlerTitle, &handler.title)) { |
| 101 *error = ASCIIToUTF16(merrors::kInvalidURLHandlerTitle); | 101 *error = base::ASCIIToUTF16(merrors::kInvalidURLHandlerTitle); |
| 102 return false; | 102 return false; |
| 103 } | 103 } |
| 104 | 104 |
| 105 const base::ListValue* manif_patterns = NULL; | 105 const base::ListValue* manif_patterns = NULL; |
| 106 if (!handler_info.GetList(mkeys::kMatches, &manif_patterns) || | 106 if (!handler_info.GetList(mkeys::kMatches, &manif_patterns) || |
| 107 manif_patterns->GetSize() == 0) { | 107 manif_patterns->GetSize() == 0) { |
| 108 *error = ErrorUtils::FormatErrorMessageUTF16( | 108 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 109 merrors::kInvalidURLHandlerPattern, handler_id); | 109 merrors::kInvalidURLHandlerPattern, handler_id); |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 130 url_handlers->push_back(handler); | 130 url_handlers->push_back(handler); |
| 131 | 131 |
| 132 return true; | 132 return true; |
| 133 } | 133 } |
| 134 | 134 |
| 135 bool UrlHandlersParser::Parse(Extension* extension, base::string16* error) { | 135 bool UrlHandlersParser::Parse(Extension* extension, base::string16* error) { |
| 136 scoped_ptr<UrlHandlers> info(new UrlHandlers); | 136 scoped_ptr<UrlHandlers> info(new UrlHandlers); |
| 137 const base::DictionaryValue* all_handlers = NULL; | 137 const base::DictionaryValue* all_handlers = NULL; |
| 138 if (!extension->manifest()->GetDictionary( | 138 if (!extension->manifest()->GetDictionary( |
| 139 mkeys::kUrlHandlers, &all_handlers)) { | 139 mkeys::kUrlHandlers, &all_handlers)) { |
| 140 *error = ASCIIToUTF16(merrors::kInvalidURLHandlers); | 140 *error = base::ASCIIToUTF16(merrors::kInvalidURLHandlers); |
| 141 return false; | 141 return false; |
| 142 } | 142 } |
| 143 | 143 |
| 144 DCHECK(extension->is_platform_app()); | 144 DCHECK(extension->is_platform_app()); |
| 145 | 145 |
| 146 for (base::DictionaryValue::Iterator iter(*all_handlers); !iter.IsAtEnd(); | 146 for (base::DictionaryValue::Iterator iter(*all_handlers); !iter.IsAtEnd(); |
| 147 iter.Advance()) { | 147 iter.Advance()) { |
| 148 // A URL handler entry is a title and a list of URL patterns to handle. | 148 // A URL handler entry is a title and a list of URL patterns to handle. |
| 149 const base::DictionaryValue* handler = NULL; | 149 const base::DictionaryValue* handler = NULL; |
| 150 if (!iter.value().GetAsDictionary(&handler)) { | 150 if (!iter.value().GetAsDictionary(&handler)) { |
| 151 *error = ASCIIToUTF16(merrors::kInvalidURLHandlerPatternElement); | 151 *error = base::ASCIIToUTF16(merrors::kInvalidURLHandlerPatternElement); |
| 152 return false; | 152 return false; |
| 153 } | 153 } |
| 154 | 154 |
| 155 if (!ParseUrlHandler(iter.key(), *handler, &info->handlers, error)) { | 155 if (!ParseUrlHandler(iter.key(), *handler, &info->handlers, error)) { |
| 156 // Text in |error| is set by ParseUrlHandler. | 156 // Text in |error| is set by ParseUrlHandler. |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 extension->SetManifestData(mkeys::kUrlHandlers, info.release()); | 161 extension->SetManifestData(mkeys::kUrlHandlers, info.release()); |
| 162 | 162 |
| 163 return true; | 163 return true; |
| 164 } | 164 } |
| 165 | 165 |
| 166 const std::vector<std::string> UrlHandlersParser::Keys() const { | 166 const std::vector<std::string> UrlHandlersParser::Keys() const { |
| 167 return SingleKey(mkeys::kUrlHandlers); | 167 return SingleKey(mkeys::kUrlHandlers); |
| 168 } | 168 } |
| 169 | 169 |
| 170 } // namespace extensions | 170 } // namespace extensions |
| OLD | NEW |