Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: chrome/browser/extensions/extension_web_ui.cc

Issue 11660016: Move the parsing of "chrome_url_overrides" out of Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: patch-rebased Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/command_line.h" 10 #include "base/command_line.h"
(...skipping 20 matching lines...) Expand all
31 #include "content/public/browser/web_ui.h" 31 #include "content/public/browser/web_ui.h"
32 #include "content/public/common/bindings_policy.h" 32 #include "content/public/common/bindings_policy.h"
33 #include "content/public/common/page_transition_types.h" 33 #include "content/public/common/page_transition_types.h"
34 #include "net/base/file_stream.h" 34 #include "net/base/file_stream.h"
35 #include "third_party/skia/include/core/SkBitmap.h" 35 #include "third_party/skia/include/core/SkBitmap.h"
36 #include "ui/gfx/codec/png_codec.h" 36 #include "ui/gfx/codec/png_codec.h"
37 #include "ui/gfx/favicon_size.h" 37 #include "ui/gfx/favicon_size.h"
38 38
39 using content::WebContents; 39 using content::WebContents;
40 using extensions::Extension; 40 using extensions::Extension;
41 using extensions::URLOverrides;
41 42
42 namespace { 43 namespace {
43 44
44 // De-dupes the items in |list|. Assumes the values are strings. 45 // De-dupes the items in |list|. Assumes the values are strings.
45 void CleanUpDuplicates(ListValue* list) { 46 void CleanUpDuplicates(ListValue* list) {
46 std::set<std::string> seen_values; 47 std::set<std::string> seen_values;
47 48
48 // Loop backwards as we may be removing items. 49 // Loop backwards as we may be removing items.
49 for (size_t i = list->GetSize() - 1; (i + 1) > 0; --i) { 50 for (size_t i = list->GetSize() - 1; (i + 1) > 0; --i) {
50 std::string value; 51 std::string value;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return true; 297 return true;
297 } 298 }
298 } 299 }
299 } 300 }
300 301
301 return false; 302 return false;
302 } 303 }
303 304
304 // static 305 // static
305 void ExtensionWebUI::RegisterChromeURLOverrides( 306 void ExtensionWebUI::RegisterChromeURLOverrides(
306 Profile* profile, const Extension::URLOverrideMap& overrides) { 307 Profile* profile, const URLOverrides::URLOverrideMap& overrides) {
307 if (overrides.empty()) 308 if (overrides.empty())
308 return; 309 return;
309 310
310 PrefService* prefs = profile->GetPrefs(); 311 PrefService* prefs = profile->GetPrefs();
311 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides); 312 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides);
312 DictionaryValue* all_overrides = update.Get(); 313 DictionaryValue* all_overrides = update.Get();
313 314
314 // For each override provided by the extension, add it to the front of 315 // For each override provided by the extension, add it to the front of
315 // the override list if it's not already in the list. 316 // the override list if it's not already in the list.
316 Extension::URLOverrideMap::const_iterator iter = overrides.begin(); 317 URLOverrides::URLOverrideMap::const_iterator iter = overrides.begin();
317 for (; iter != overrides.end(); ++iter) { 318 for (; iter != overrides.end(); ++iter) {
318 const std::string& key = iter->first; 319 const std::string& key = iter->first;
319 ListValue* page_overrides; 320 ListValue* page_overrides;
320 if (!all_overrides->GetList(key, &page_overrides)) { 321 if (!all_overrides->GetList(key, &page_overrides)) {
321 page_overrides = new ListValue(); 322 page_overrides = new ListValue();
322 all_overrides->Set(key, page_overrides); 323 all_overrides->Set(key, page_overrides);
323 } else { 324 } else {
324 CleanUpDuplicates(page_overrides); 325 CleanUpDuplicates(page_overrides);
325 326
326 // Verify that the override isn't already in the list. 327 // Verify that the override isn't already in the list.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // If it's being unregistered, it should already be in the list. 375 // If it's being unregistered, it should already be in the list.
375 NOTREACHED(); 376 NOTREACHED();
376 return; 377 return;
377 } else { 378 } else {
378 UnregisterAndReplaceOverride(page, profile, page_overrides, override); 379 UnregisterAndReplaceOverride(page, profile, page_overrides, override);
379 } 380 }
380 } 381 }
381 382
382 // static 383 // static
383 void ExtensionWebUI::UnregisterChromeURLOverrides( 384 void ExtensionWebUI::UnregisterChromeURLOverrides(
384 Profile* profile, const Extension::URLOverrideMap& overrides) { 385 Profile* profile, const URLOverrides::URLOverrideMap& overrides) {
385 if (overrides.empty()) 386 if (overrides.empty())
386 return; 387 return;
387 PrefService* prefs = profile->GetPrefs(); 388 PrefService* prefs = profile->GetPrefs();
388 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides); 389 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides);
389 DictionaryValue* all_overrides = update.Get(); 390 DictionaryValue* all_overrides = update.Get();
390 Extension::URLOverrideMap::const_iterator iter = overrides.begin(); 391 URLOverrides::URLOverrideMap::const_iterator iter = overrides.begin();
391 for (; iter != overrides.end(); ++iter) { 392 for (; iter != overrides.end(); ++iter) {
392 const std::string& page = iter->first; 393 const std::string& page = iter->first;
393 ListValue* page_overrides; 394 ListValue* page_overrides;
394 if (!all_overrides->GetList(page, &page_overrides)) { 395 if (!all_overrides->GetList(page, &page_overrides)) {
395 // If it's being unregistered, it should already be in the list. 396 // If it's being unregistered, it should already be in the list.
396 NOTREACHED(); 397 NOTREACHED();
397 continue; 398 continue;
398 } else { 399 } else {
399 StringValue override(iter->second.spec()); 400 StringValue override(iter->second.spec());
400 UnregisterAndReplaceOverride(iter->first, profile, 401 UnregisterAndReplaceOverride(iter->first, profile,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, 442 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE,
442 gfx::Size(pixel_size, pixel_size), 443 gfx::Size(pixel_size, pixel_size),
443 scale_factors[i])); 444 scale_factors[i]));
444 } 445 }
445 446
446 // LoadImagesAsync actually can run callback synchronously. We want to force 447 // LoadImagesAsync actually can run callback synchronously. We want to force
447 // async. 448 // async.
448 extensions::ImageLoader::Get(profile)->LoadImagesAsync( 449 extensions::ImageLoader::Get(profile)->LoadImagesAsync(
449 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); 450 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback));
450 } 451 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_web_ui.h ('k') | chrome/browser/extensions/manifest_url_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698