Index: chrome/browser/extensions/extension_dom_ui.cc |
diff --git a/chrome/browser/extensions/extension_dom_ui.cc b/chrome/browser/extensions/extension_dom_ui.cc |
index 40f11f1f2636523d85e4aad2cb56ee71d92e33d1..531407830b337aa3839c07d8416ef33536cdf26b 100644 |
--- a/chrome/browser/extensions/extension_dom_ui.cc |
+++ b/chrome/browser/extensions/extension_dom_ui.cc |
@@ -4,6 +4,8 @@ |
#include "chrome/browser/extensions/extension_dom_ui.h" |
+#include <set> |
+ |
#include "base/file_path.h" |
#include "base/file_util.h" |
#include "net/base/file_stream.h" |
@@ -23,8 +25,6 @@ |
#include "chrome/common/url_constants.h" |
namespace { |
-const wchar_t kExtensionURLOverrides[] = L"extensions.chrome_url_overrides"; |
- |
// Returns a piece of memory with the contents of the file |path|. |
RefCountedMemory* ReadFileData(const FilePath& path) { |
// TODO(arv): We currently read this on the UI thread since extension objects |
@@ -45,8 +45,30 @@ RefCountedMemory* ReadFileData(const FilePath& path) { |
return result; |
} |
+// De-dupes the items in |list|. Assumes the values are strings. |
Erik does not do reviews
2010/04/14 20:48:42
Add comment referencing bug and mention that this
|
+void CleanUpDuplicates(ListValue* list) { |
+ std::set<std::string> seen_values; |
+ |
+ // Loop backwards as we may be removing items. |
Erik does not do reviews
2010/04/14 20:48:42
this also has the cool side effect of preserving p
|
+ for (size_t i = list->GetSize() - 1; (i + 1) > 0; --i) { |
+ std::string value; |
+ if (!list->GetString(i, &value)) { |
+ NOTREACHED(); |
+ continue; |
+ } |
+ |
+ if (seen_values.find(value) == seen_values.end()) |
+ seen_values.insert(value); |
+ else |
+ list->Remove(i, NULL); |
+ } |
+} |
+ |
} // namespace |
+const wchar_t ExtensionDOMUI::kExtensionURLOverrides[] = |
+ L"extensions.chrome_url_overrides"; |
+ |
ExtensionDOMUI::ExtensionDOMUI(TabContents* tab_contents) |
: DOMUI(tab_contents) { |
should_hide_url_ = true; |
@@ -222,6 +244,8 @@ void ExtensionDOMUI::RegisterChromeURLOverrides( |
page_overrides = new ListValue(); |
all_overrides->Set(key, page_overrides); |
} else { |
+ CleanUpDuplicates(page_overrides); |
+ |
// Verify that the override isn't already in the list. |
ListValue::iterator i = page_overrides->begin(); |
for (; i != page_overrides->end(); ++i) { |
@@ -230,7 +254,7 @@ void ExtensionDOMUI::RegisterChromeURLOverrides( |
NOTREACHED(); |
continue; |
} |
- if (override_val == (*iter).first) |
+ if (override_val == (*iter).second.spec()) |
break; |
} |
// This value is already in the list, leave it alone. |