| 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 <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); | 225 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); |
| 226 std::string page = url->host(); | 226 std::string page = url->host(); |
| 227 const ListValue* url_list; | 227 const ListValue* url_list; |
| 228 if (!overrides || !overrides->GetList(page, &url_list)) | 228 if (!overrides || !overrides->GetList(page, &url_list)) |
| 229 return false; | 229 return false; |
| 230 | 230 |
| 231 ExtensionService* service = profile->GetExtensionService(); | 231 ExtensionService* service = profile->GetExtensionService(); |
| 232 | 232 |
| 233 size_t i = 0; | 233 size_t i = 0; |
| 234 while (i < url_list->GetSize()) { | 234 while (i < url_list->GetSize()) { |
| 235 Value* val = NULL; | 235 const Value* val = NULL; |
| 236 url_list->Get(i, &val); | 236 url_list->Get(i, &val); |
| 237 | 237 |
| 238 // Verify that the override value is good. If not, unregister it and find | 238 // Verify that the override value is good. If not, unregister it and find |
| 239 // the next one. | 239 // the next one. |
| 240 std::string override; | 240 std::string override; |
| 241 if (!val->GetAsString(&override)) { | 241 if (!val->GetAsString(&override)) { |
| 242 NOTREACHED(); | 242 NOTREACHED(); |
| 243 UnregisterChromeURLOverride(page, profile, val); | 243 UnregisterChromeURLOverride(page, profile, val); |
| 244 continue; | 244 continue; |
| 245 } | 245 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // Insert the override at the front of the list. Last registered override | 358 // Insert the override at the front of the list. Last registered override |
| 359 // wins. | 359 // wins. |
| 360 page_overrides->Insert(0, new StringValue(iter->second.spec())); | 360 page_overrides->Insert(0, new StringValue(iter->second.spec())); |
| 361 } | 361 } |
| 362 } | 362 } |
| 363 | 363 |
| 364 // static | 364 // static |
| 365 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page, | 365 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page, |
| 366 Profile* profile, | 366 Profile* profile, |
| 367 ListValue* list, | 367 ListValue* list, |
| 368 Value* override) { | 368 const Value* override) { |
| 369 size_t index = 0; | 369 size_t index = 0; |
| 370 bool found = list->Remove(*override, &index); | 370 bool found = list->Remove(*override, &index); |
| 371 if (found && index == 0) { | 371 if (found && index == 0) { |
| 372 // This is the active override, so we need to find all existing | 372 // This is the active override, so we need to find all existing |
| 373 // tabs for this override and get them to reload the original URL. | 373 // tabs for this override and get them to reload the original URL. |
| 374 base::Callback<void(WebContents*)> callback = | 374 base::Callback<void(WebContents*)> callback = |
| 375 base::Bind(&UnregisterAndReplaceOverrideForWebContents, page, profile); | 375 base::Bind(&UnregisterAndReplaceOverrideForWebContents, page, profile); |
| 376 ExtensionTabUtil::ForEachTab(callback); | 376 ExtensionTabUtil::ForEachTab(callback); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 | 379 |
| 380 // static | 380 // static |
| 381 void ExtensionWebUI::UnregisterChromeURLOverride(const std::string& page, | 381 void ExtensionWebUI::UnregisterChromeURLOverride(const std::string& page, |
| 382 Profile* profile, Value* override) { | 382 Profile* profile, |
| 383 const Value* override) { |
| 383 if (!override) | 384 if (!override) |
| 384 return; | 385 return; |
| 385 PrefService* prefs = profile->GetPrefs(); | 386 PrefService* prefs = profile->GetPrefs(); |
| 386 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides); | 387 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides); |
| 387 DictionaryValue* all_overrides = update.Get(); | 388 DictionaryValue* all_overrides = update.Get(); |
| 388 ListValue* page_overrides; | 389 ListValue* page_overrides; |
| 389 if (!all_overrides->GetList(page, &page_overrides)) { | 390 if (!all_overrides->GetList(page, &page_overrides)) { |
| 390 // If it's being unregistered, it should already be in the list. | 391 // If it's being unregistered, it should already be in the list. |
| 391 NOTREACHED(); | 392 NOTREACHED(); |
| 392 return; | 393 return; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 420 } | 421 } |
| 421 | 422 |
| 422 // static | 423 // static |
| 423 void ExtensionWebUI::GetFaviconForURL(Profile* profile, | 424 void ExtensionWebUI::GetFaviconForURL(Profile* profile, |
| 424 FaviconService::GetFaviconRequest* request, const GURL& page_url) { | 425 FaviconService::GetFaviconRequest* request, const GURL& page_url) { |
| 425 // tracker deletes itself when done. | 426 // tracker deletes itself when done. |
| 426 ExtensionWebUIImageLoadingTracker* tracker = | 427 ExtensionWebUIImageLoadingTracker* tracker = |
| 427 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); | 428 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); |
| 428 tracker->Init(); | 429 tracker->Init(); |
| 429 } | 430 } |
| OLD | NEW |