| 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/browser/extensions/menu_manager.h" | 5 #include "chrome/browser/extensions/menu_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 return NULL; | 212 return NULL; |
| 213 bool checked; | 213 bool checked; |
| 214 if ((type == CHECKBOX || type == RADIO) && | 214 if ((type == CHECKBOX || type == RADIO) && |
| 215 !value.GetBoolean(kCheckedKey, &checked)) { | 215 !value.GetBoolean(kCheckedKey, &checked)) { |
| 216 return NULL; | 216 return NULL; |
| 217 } | 217 } |
| 218 bool enabled = true; | 218 bool enabled = true; |
| 219 if (!value.GetBoolean(kEnabledKey, &enabled)) | 219 if (!value.GetBoolean(kEnabledKey, &enabled)) |
| 220 return NULL; | 220 return NULL; |
| 221 ContextList contexts; | 221 ContextList contexts; |
| 222 Value* contexts_value = NULL; | 222 const Value* contexts_value = NULL; |
| 223 if (!value.Get(kContextsKey, &contexts_value)) | 223 if (!value.Get(kContextsKey, &contexts_value)) |
| 224 return NULL; | 224 return NULL; |
| 225 if (!contexts.Populate(*contexts_value)) | 225 if (!contexts.Populate(*contexts_value)) |
| 226 return NULL; | 226 return NULL; |
| 227 | 227 |
| 228 scoped_ptr<MenuItem> result(new MenuItem( | 228 scoped_ptr<MenuItem> result(new MenuItem( |
| 229 id, title, checked, enabled, type, contexts)); | 229 id, title, checked, enabled, type, contexts)); |
| 230 | 230 |
| 231 if (!result->PopulateURLPatterns( | 231 if (!result->PopulateURLPatterns( |
| 232 value, kDocumentURLPatternsKey, kTargetURLPatternsKey, error)) | 232 value, kDocumentURLPatternsKey, kTargetURLPatternsKey, error)) |
| 233 return NULL; | 233 return NULL; |
| 234 | 234 |
| 235 // parent_id is filled in from the value, but it might not be valid. It's left | 235 // parent_id is filled in from the value, but it might not be valid. It's left |
| 236 // to be validated upon being added (via AddChildItem) to the menu manager. | 236 // to be validated upon being added (via AddChildItem) to the menu manager. |
| 237 scoped_ptr<Id> parent_id(new Id(incognito, extension_id)); | 237 scoped_ptr<Id> parent_id(new Id(incognito, extension_id)); |
| 238 if (value.HasKey(kParentUIDKey)) { | 238 if (value.HasKey(kParentUIDKey)) { |
| 239 if (!value.GetString(kParentUIDKey, &parent_id->string_uid)) | 239 if (!value.GetString(kParentUIDKey, &parent_id->string_uid)) |
| 240 return NULL; | 240 return NULL; |
| 241 result->parent_id_.swap(parent_id); | 241 result->parent_id_.swap(parent_id); |
| 242 } | 242 } |
| 243 return result.release(); | 243 return result.release(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 bool MenuItem::PopulateURLPatterns(const DictionaryValue& properties, | 246 bool MenuItem::PopulateURLPatterns(const DictionaryValue& properties, |
| 247 const char* document_url_patterns_key, | 247 const char* document_url_patterns_key, |
| 248 const char* target_url_patterns_key, | 248 const char* target_url_patterns_key, |
| 249 std::string* error) { | 249 std::string* error) { |
| 250 if (properties.HasKey(document_url_patterns_key)) { | 250 if (properties.HasKey(document_url_patterns_key)) { |
| 251 ListValue* list = NULL; | 251 const ListValue* list = NULL; |
| 252 if (!properties.GetList(document_url_patterns_key, &list)) | 252 if (!properties.GetList(document_url_patterns_key, &list)) |
| 253 return false; | 253 return false; |
| 254 if (!document_url_patterns_.Populate( | 254 if (!document_url_patterns_.Populate( |
| 255 *list, URLPattern::SCHEME_ALL, true, error)) { | 255 *list, URLPattern::SCHEME_ALL, true, error)) { |
| 256 return false; | 256 return false; |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 if (properties.HasKey(target_url_patterns_key)) { | 259 if (properties.HasKey(target_url_patterns_key)) { |
| 260 ListValue* list = NULL; | 260 const ListValue* list = NULL; |
| 261 if (!properties.GetList(target_url_patterns_key, &list)) | 261 if (!properties.GetList(target_url_patterns_key, &list)) |
| 262 return false; | 262 return false; |
| 263 if (!target_url_patterns_.Populate( | 263 if (!target_url_patterns_.Populate( |
| 264 *list, URLPattern::SCHEME_ALL, true, error)) { | 264 *list, URLPattern::SCHEME_ALL, true, error)) { |
| 265 return false; | 265 return false; |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 return true; | 268 return true; |
| 269 } | 269 } |
| 270 | 270 |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 if (uid < other.uid) | 817 if (uid < other.uid) |
| 818 return true; | 818 return true; |
| 819 if (uid == other.uid) | 819 if (uid == other.uid) |
| 820 return string_uid < other.string_uid; | 820 return string_uid < other.string_uid; |
| 821 } | 821 } |
| 822 } | 822 } |
| 823 return false; | 823 return false; |
| 824 } | 824 } |
| 825 | 825 |
| 826 } // namespace extensions | 826 } // namespace extensions |
| OLD | NEW |