| 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/extension_web_ui.h" | 5 #include "chrome/browser/extensions/extension_web_ui.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // Iterates over |list| and: | 58 // Iterates over |list| and: |
| 59 // - Converts any entries of the form <entry> to | 59 // - Converts any entries of the form <entry> to |
| 60 // { 'entry': <entry>, 'active': true }. | 60 // { 'entry': <entry>, 'active': true }. |
| 61 // - Removes any duplicate entries. | 61 // - Removes any duplicate entries. |
| 62 // We do the conversion because we previously stored these values as strings | 62 // We do the conversion because we previously stored these values as strings |
| 63 // rather than objects. | 63 // rather than objects. |
| 64 // TODO(devlin): Remove the conversion once everyone's updated. | 64 // TODO(devlin): Remove the conversion once everyone's updated. |
| 65 void InitializeOverridesList(base::ListValue* list) { | 65 void InitializeOverridesList(base::ListValue* list) { |
| 66 base::ListValue migrated; | 66 base::ListValue migrated; |
| 67 std::set<std::string> seen_entries; | 67 std::set<std::string> seen_entries; |
| 68 for (base::Value* val : *list) { | 68 for (const auto& val : *list) { |
| 69 std::unique_ptr<base::DictionaryValue> new_dict( | 69 std::unique_ptr<base::DictionaryValue> new_dict( |
| 70 new base::DictionaryValue()); | 70 new base::DictionaryValue()); |
| 71 std::string entry_name; | 71 std::string entry_name; |
| 72 base::DictionaryValue* existing_dict = nullptr; | 72 base::DictionaryValue* existing_dict = nullptr; |
| 73 if (val->GetAsDictionary(&existing_dict)) { | 73 if (val->GetAsDictionary(&existing_dict)) { |
| 74 bool success = existing_dict->GetString(kEntry, &entry_name); | 74 bool success = existing_dict->GetString(kEntry, &entry_name); |
| 75 if (!success) // See comment about CHECK(success) in ForEachOverrideList. | 75 if (!success) // See comment about CHECK(success) in ForEachOverrideList. |
| 76 continue; | 76 continue; |
| 77 new_dict->Swap(existing_dict); | 77 new_dict->Swap(existing_dict); |
| 78 } else if (val->GetAsString(&entry_name)) { | 78 } else if (val->GetAsString(&entry_name)) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 list->Swap(&migrated); | 92 list->Swap(&migrated); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Adds |override| to |list|, or, if there's already an entry for the override, | 95 // Adds |override| to |list|, or, if there's already an entry for the override, |
| 96 // marks it as active. | 96 // marks it as active. |
| 97 void AddOverridesToList(base::ListValue* list, | 97 void AddOverridesToList(base::ListValue* list, |
| 98 const std::string& override) { | 98 const std::string& override) { |
| 99 for (base::Value* val : *list) { | 99 for (const auto& val : *list) { |
| 100 base::DictionaryValue* dict = nullptr; | 100 base::DictionaryValue* dict = nullptr; |
| 101 std::string entry; | 101 std::string entry; |
| 102 if (!val->GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) { | 102 if (!val->GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) { |
| 103 NOTREACHED(); | 103 NOTREACHED(); |
| 104 continue; | 104 continue; |
| 105 } | 105 } |
| 106 if (entry == override) { | 106 if (entry == override) { |
| 107 dict->SetBoolean(kActive, true); | 107 dict->SetBoolean(kActive, true); |
| 108 return; // All done! | 108 return; // All done! |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 112 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 113 dict->SetString(kEntry, override); | 113 dict->SetString(kEntry, override); |
| 114 dict->SetBoolean(kActive, true); | 114 dict->SetBoolean(kActive, true); |
| 115 // Add the entry to the front of the list. | 115 // Add the entry to the front of the list. |
| 116 list->Insert(0, dict.release()); | 116 list->Insert(0, dict.release()); |
| 117 } | 117 } |
| 118 | 118 |
| 119 // Validates that each entry in |list| contains a valid url and points to an | 119 // Validates that each entry in |list| contains a valid url and points to an |
| 120 // extension contained in |all_extensions| (and, if not, removes it). | 120 // extension contained in |all_extensions| (and, if not, removes it). |
| 121 void ValidateOverridesList(const extensions::ExtensionSet* all_extensions, | 121 void ValidateOverridesList(const extensions::ExtensionSet* all_extensions, |
| 122 base::ListValue* list) { | 122 base::ListValue* list) { |
| 123 base::ListValue migrated; | 123 base::ListValue migrated; |
| 124 for (base::Value* val : *list) { | 124 for (const auto& val : *list) { |
| 125 base::DictionaryValue* dict = nullptr; | 125 base::DictionaryValue* dict = nullptr; |
| 126 std::string entry; | 126 std::string entry; |
| 127 if (!val->GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) { | 127 if (!val->GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) { |
| 128 NOTREACHED(); | 128 NOTREACHED(); |
| 129 continue; | 129 continue; |
| 130 } | 130 } |
| 131 std::unique_ptr<base::DictionaryValue> new_dict( | 131 std::unique_ptr<base::DictionaryValue> new_dict( |
| 132 new base::DictionaryValue()); | 132 new base::DictionaryValue()); |
| 133 new_dict->Swap(dict); | 133 new_dict->Swap(dict); |
| 134 GURL override_url(entry); | 134 GURL override_url(entry); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 UPDATE_REMOVE, // Remove the entry from the list. | 169 UPDATE_REMOVE, // Remove the entry from the list. |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 // Updates the entry (if any) for |override_url| in |overrides_list| according | 172 // Updates the entry (if any) for |override_url| in |overrides_list| according |
| 173 // to |behavior|. Returns true if anything changed. | 173 // to |behavior|. Returns true if anything changed. |
| 174 bool UpdateOverridesList(base::ListValue* overrides_list, | 174 bool UpdateOverridesList(base::ListValue* overrides_list, |
| 175 const std::string& override_url, | 175 const std::string& override_url, |
| 176 UpdateBehavior behavior) { | 176 UpdateBehavior behavior) { |
| 177 base::ListValue::iterator iter = | 177 base::ListValue::iterator iter = |
| 178 std::find_if(overrides_list->begin(), overrides_list->end(), | 178 std::find_if(overrides_list->begin(), overrides_list->end(), |
| 179 [&override_url](const base::Value* value) { | 179 [&override_url](const std::unique_ptr<base::Value>& value) { |
| 180 std::string entry; | 180 std::string entry; |
| 181 const base::DictionaryValue* dict = nullptr; | 181 const base::DictionaryValue* dict = nullptr; |
| 182 return value->GetAsDictionary(&dict) && | 182 return value->GetAsDictionary(&dict) && |
| 183 dict->GetString(kEntry, &entry) && | 183 dict->GetString(kEntry, &entry) && |
| 184 entry == override_url; | 184 entry == override_url; |
| 185 }); | 185 }); |
| 186 if (iter != overrides_list->end()) { | 186 if (iter != overrides_list->end()) { |
| 187 switch (behavior) { | 187 switch (behavior) { |
| 188 case UPDATE_DEACTIVATE: { | 188 case UPDATE_DEACTIVATE: { |
| 189 base::DictionaryValue* dict = nullptr; | 189 base::DictionaryValue* dict = nullptr; |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, | 558 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, |
| 559 gfx::Size(pixel_size, pixel_size), | 559 gfx::Size(pixel_size, pixel_size), |
| 560 resource_scale_factor)); | 560 resource_scale_factor)); |
| 561 } | 561 } |
| 562 | 562 |
| 563 // LoadImagesAsync actually can run callback synchronously. We want to force | 563 // LoadImagesAsync actually can run callback synchronously. We want to force |
| 564 // async. | 564 // async. |
| 565 extensions::ImageLoader::Get(profile)->LoadImagesAsync( | 565 extensions::ImageLoader::Get(profile)->LoadImagesAsync( |
| 566 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); | 566 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); |
| 567 } | 567 } |
| OLD | NEW |