Index: chrome/browser/extensions/menu_manager.cc |
diff --git a/chrome/browser/extensions/menu_manager.cc b/chrome/browser/extensions/menu_manager.cc |
index 92154f981e8a0f222515f477b05df60376a12daa..4bace409825e1d6b9f13e3d1612e2f70aa62c5da 100644 |
--- a/chrome/browser/extensions/menu_manager.cc |
+++ b/chrome/browser/extensions/menu_manager.cc |
@@ -203,14 +203,14 @@ MenuItem* MenuItem::Populate(const std::string& extension_id, |
if (!value.GetString(kStringUIDKey, &id.string_uid)) |
return NULL; |
int type_int; |
- Type type; |
+ Type type = NORMAL; |
if (!value.GetInteger(kTypeKey, &type_int)) |
return NULL; |
type = static_cast<Type>(type_int); |
std::string title; |
if (type != SEPARATOR && !value.GetString(kTitleKey, &title)) |
return NULL; |
- bool checked; |
+ bool checked = false; |
if ((type == CHECKBOX || type == RADIO) && |
!value.GetBoolean(kCheckedKey, &checked)) { |
return NULL; |
@@ -228,9 +228,38 @@ MenuItem* MenuItem::Populate(const std::string& extension_id, |
scoped_ptr<MenuItem> result(new MenuItem( |
id, title, checked, enabled, type, contexts)); |
- if (!result->PopulateURLPatterns( |
- value, kDocumentURLPatternsKey, kTargetURLPatternsKey, error)) |
+ std::vector<std::string> document_url_patterns; |
+ if (value.HasKey(kDocumentURLPatternsKey)) { |
not at google - send to devlin
2012/08/07 02:00:11
code is basically repeated. Could you pull this ou
chebert
2012/08/13 22:41:52
Done.
|
+ const ListValue* list = NULL; |
+ if (!value.GetList(kDocumentURLPatternsKey, &list)) |
+ return NULL; |
+ |
+ for (size_t i = 0; i < list->GetSize(); ++i) { |
+ std::string pattern; |
+ if (!list->GetString(i, &pattern)) |
+ return NULL; |
+ document_url_patterns.push_back(pattern); |
+ } |
+ } |
+ |
+ std::vector<std::string> target_url_patterns; |
+ if (value.HasKey(kTargetURLPatternsKey)) { |
+ const ListValue* list = NULL; |
+ if (!value.GetList(kTargetURLPatternsKey, &list)) |
+ return NULL; |
+ |
+ for (size_t i = 0; i < list->GetSize(); ++i) { |
+ std::string pattern; |
+ if (!list->GetString(i, &pattern)) |
+ return NULL; |
+ target_url_patterns.push_back(pattern); |
+ } |
+ } |
+ if (!result->PopulateURLPatterns(&document_url_patterns, |
+ &target_url_patterns, |
+ error)) { |
return NULL; |
+ } |
// parent_id is filled in from the value, but it might not be valid. It's left |
// to be validated upon being added (via AddChildItem) to the menu manager. |
@@ -243,25 +272,19 @@ MenuItem* MenuItem::Populate(const std::string& extension_id, |
return result.release(); |
} |
-bool MenuItem::PopulateURLPatterns(const DictionaryValue& properties, |
- const char* document_url_patterns_key, |
- const char* target_url_patterns_key, |
- std::string* error) { |
- if (properties.HasKey(document_url_patterns_key)) { |
- const ListValue* list = NULL; |
- if (!properties.GetList(document_url_patterns_key, &list)) |
- return false; |
+bool MenuItem::PopulateURLPatterns( |
+ std::vector<std::string>* document_url_patterns, |
+ std::vector<std::string>* target_url_patterns, |
+ std::string* error) { |
+ if (document_url_patterns) { |
if (!document_url_patterns_.Populate( |
- *list, URLPattern::SCHEME_ALL, true, error)) { |
+ *document_url_patterns, URLPattern::SCHEME_ALL, true, error)) { |
return false; |
} |
} |
- if (properties.HasKey(target_url_patterns_key)) { |
- const ListValue* list = NULL; |
- if (!properties.GetList(target_url_patterns_key, &list)) |
- return false; |
+ if (target_url_patterns) { |
if (!target_url_patterns_.Populate( |
- *list, URLPattern::SCHEME_ALL, true, error)) { |
+ *target_url_patterns, URLPattern::SCHEME_ALL, true, error)) { |
return false; |
} |
} |