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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 (base::Value* val : *list) { |
69 scoped_ptr<base::DictionaryValue> new_dict(new base::DictionaryValue()); | 69 std::unique_ptr<base::DictionaryValue> new_dict( |
| 70 new base::DictionaryValue()); |
70 std::string entry_name; | 71 std::string entry_name; |
71 base::DictionaryValue* existing_dict = nullptr; | 72 base::DictionaryValue* existing_dict = nullptr; |
72 if (val->GetAsDictionary(&existing_dict)) { | 73 if (val->GetAsDictionary(&existing_dict)) { |
73 bool success = existing_dict->GetString(kEntry, &entry_name); | 74 bool success = existing_dict->GetString(kEntry, &entry_name); |
74 if (!success) // See comment about CHECK(success) in ForEachOverrideList. | 75 if (!success) // See comment about CHECK(success) in ForEachOverrideList. |
75 continue; | 76 continue; |
76 new_dict->Swap(existing_dict); | 77 new_dict->Swap(existing_dict); |
77 } else if (val->GetAsString(&entry_name)) { | 78 } else if (val->GetAsString(&entry_name)) { |
78 new_dict->SetString(kEntry, entry_name); | 79 new_dict->SetString(kEntry, entry_name); |
79 new_dict->SetBoolean(kActive, true); | 80 new_dict->SetBoolean(kActive, true); |
(...skipping 21 matching lines...) Expand all Loading... |
101 if (!val->GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) { | 102 if (!val->GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) { |
102 NOTREACHED(); | 103 NOTREACHED(); |
103 continue; | 104 continue; |
104 } | 105 } |
105 if (entry == override) { | 106 if (entry == override) { |
106 dict->SetBoolean(kActive, true); | 107 dict->SetBoolean(kActive, true); |
107 return; // All done! | 108 return; // All done! |
108 } | 109 } |
109 } | 110 } |
110 | 111 |
111 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 112 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
112 dict->SetString(kEntry, override); | 113 dict->SetString(kEntry, override); |
113 dict->SetBoolean(kActive, true); | 114 dict->SetBoolean(kActive, true); |
114 // Add the entry to the front of the list. | 115 // Add the entry to the front of the list. |
115 list->Insert(0, dict.release()); | 116 list->Insert(0, dict.release()); |
116 } | 117 } |
117 | 118 |
118 // 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 |
119 // extension contained in |all_extensions| (and, if not, removes it). | 120 // extension contained in |all_extensions| (and, if not, removes it). |
120 void ValidateOverridesList(const extensions::ExtensionSet* all_extensions, | 121 void ValidateOverridesList(const extensions::ExtensionSet* all_extensions, |
121 base::ListValue* list) { | 122 base::ListValue* list) { |
122 base::ListValue migrated; | 123 base::ListValue migrated; |
123 for (base::Value* val : *list) { | 124 for (base::Value* val : *list) { |
124 base::DictionaryValue* dict = nullptr; | 125 base::DictionaryValue* dict = nullptr; |
125 std::string entry; | 126 std::string entry; |
126 if (!val->GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) { | 127 if (!val->GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) { |
127 NOTREACHED(); | 128 NOTREACHED(); |
128 continue; | 129 continue; |
129 } | 130 } |
130 scoped_ptr<base::DictionaryValue> new_dict(new base::DictionaryValue()); | 131 std::unique_ptr<base::DictionaryValue> new_dict( |
| 132 new base::DictionaryValue()); |
131 new_dict->Swap(dict); | 133 new_dict->Swap(dict); |
132 GURL override_url(entry); | 134 GURL override_url(entry); |
133 if (!override_url.is_valid()) | 135 if (!override_url.is_valid()) |
134 continue; | 136 continue; |
135 | 137 |
136 if (!all_extensions->GetByID(override_url.host())) | 138 if (!all_extensions->GetByID(override_url.host())) |
137 continue; | 139 continue; |
138 | 140 |
139 migrated.Append(std::move(new_dict)); | 141 migrated.Append(std::move(new_dict)); |
140 } | 142 } |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 return false; | 478 return false; |
477 } | 479 } |
478 | 480 |
479 // static | 481 // static |
480 void ExtensionWebUI::InitializeChromeURLOverrides(Profile* profile) { | 482 void ExtensionWebUI::InitializeChromeURLOverrides(Profile* profile) { |
481 ForEachOverrideList(profile, base::Bind(&InitializeOverridesList)); | 483 ForEachOverrideList(profile, base::Bind(&InitializeOverridesList)); |
482 } | 484 } |
483 | 485 |
484 // static | 486 // static |
485 void ExtensionWebUI::ValidateChromeURLOverrides(Profile* profile) { | 487 void ExtensionWebUI::ValidateChromeURLOverrides(Profile* profile) { |
486 scoped_ptr<extensions::ExtensionSet> all_extensions = | 488 std::unique_ptr<extensions::ExtensionSet> all_extensions = |
487 extensions::ExtensionRegistry::Get(profile)-> | 489 extensions::ExtensionRegistry::Get(profile) |
488 GenerateInstalledExtensionsSet(); | 490 ->GenerateInstalledExtensionsSet(); |
489 | 491 |
490 ForEachOverrideList(profile, | 492 ForEachOverrideList(profile, |
491 base::Bind(&ValidateOverridesList, all_extensions.get())); | 493 base::Bind(&ValidateOverridesList, all_extensions.get())); |
492 } | 494 } |
493 | 495 |
494 // static | 496 // static |
495 void ExtensionWebUI::RegisterOrActivateChromeURLOverrides( | 497 void ExtensionWebUI::RegisterOrActivateChromeURLOverrides( |
496 Profile* profile, | 498 Profile* profile, |
497 const URLOverrides::URLOverrideMap& overrides) { | 499 const URLOverrides::URLOverrideMap& overrides) { |
498 if (overrides.empty()) | 500 if (overrides.empty()) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, | 558 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, |
557 gfx::Size(pixel_size, pixel_size), | 559 gfx::Size(pixel_size, pixel_size), |
558 resource_scale_factor)); | 560 resource_scale_factor)); |
559 } | 561 } |
560 | 562 |
561 // LoadImagesAsync actually can run callback synchronously. We want to force | 563 // LoadImagesAsync actually can run callback synchronously. We want to force |
562 // async. | 564 // async. |
563 extensions::ImageLoader::Get(profile)->LoadImagesAsync( | 565 extensions::ImageLoader::Get(profile)->LoadImagesAsync( |
564 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); | 566 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); |
565 } | 567 } |
OLD | NEW |