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

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: Created 7 years, 12 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"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h" 13 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_tab_util.h" 15 #include "chrome/browser/extensions/extension_tab_util.h"
16 #include "chrome/browser/extensions/image_loader.h" 16 #include "chrome/browser/extensions/image_loader.h"
17 #include "chrome/browser/favicon/favicon_util.h" 17 #include "chrome/browser/favicon/favicon_util.h"
18 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/prefs/scoped_user_pref_update.h" 19 #include "chrome/browser/prefs/scoped_user_pref_update.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 22 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
23 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/extensions/api/url_overrides/url_overrides_handler.h"
24 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
25 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
26 #include "chrome/common/extensions/extension_icon_set.h" 27 #include "chrome/common/extensions/extension_icon_set.h"
27 #include "chrome/common/extensions/extension_resource.h" 28 #include "chrome/common/extensions/extension_resource.h"
28 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
29 #include "content/public/browser/navigation_controller.h" 30 #include "content/public/browser/navigation_controller.h"
30 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
31 #include "content/public/browser/web_ui.h" 32 #include "content/public/browser/web_ui.h"
32 #include "content/public/common/bindings_policy.h" 33 #include "content/public/common/bindings_policy.h"
33 #include "content/public/common/page_transition_types.h" 34 #include "content/public/common/page_transition_types.h"
34 #include "net/base/file_stream.h" 35 #include "net/base/file_stream.h"
35 #include "third_party/skia/include/core/SkBitmap.h" 36 #include "third_party/skia/include/core/SkBitmap.h"
36 #include "ui/gfx/codec/png_codec.h" 37 #include "ui/gfx/codec/png_codec.h"
37 #include "ui/gfx/favicon_size.h" 38 #include "ui/gfx/favicon_size.h"
38 39
39 using content::WebContents; 40 using content::WebContents;
40 using extensions::Extension; 41 using extensions::Extension;
42 using extensions::URLOverridesInfo;
41 43
42 namespace { 44 namespace {
43 45
44 // De-dupes the items in |list|. Assumes the values are strings. 46 // De-dupes the items in |list|. Assumes the values are strings.
45 void CleanUpDuplicates(ListValue* list) { 47 void CleanUpDuplicates(ListValue* list) {
46 std::set<std::string> seen_values; 48 std::set<std::string> seen_values;
47 49
48 // Loop backwards as we may be removing items. 50 // Loop backwards as we may be removing items.
49 for (size_t i = list->GetSize() - 1; (i + 1) > 0; --i) { 51 for (size_t i = list->GetSize() - 1; (i + 1) > 0; --i) {
50 std::string value; 52 std::string value;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return true; 298 return true;
297 } 299 }
298 } 300 }
299 } 301 }
300 302
301 return false; 303 return false;
302 } 304 }
303 305
304 // static 306 // static
305 void ExtensionWebUI::RegisterChromeURLOverrides( 307 void ExtensionWebUI::RegisterChromeURLOverrides(
306 Profile* profile, const Extension::URLOverrideMap& overrides) { 308 Profile* profile, const URLOverridesInfo::URLOverrideMap& overrides) {
307 if (overrides.empty()) 309 if (overrides.empty())
308 return; 310 return;
309 311
310 PrefService* prefs = profile->GetPrefs(); 312 PrefService* prefs = profile->GetPrefs();
311 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides); 313 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides);
312 DictionaryValue* all_overrides = update.Get(); 314 DictionaryValue* all_overrides = update.Get();
313 315
314 // For each override provided by the extension, add it to the front of 316 // 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. 317 // the override list if it's not already in the list.
316 Extension::URLOverrideMap::const_iterator iter = overrides.begin(); 318 URLOverridesInfo::URLOverrideMap::const_iterator iter = overrides.begin();
317 for (; iter != overrides.end(); ++iter) { 319 for (; iter != overrides.end(); ++iter) {
318 const std::string& key = iter->first; 320 const std::string& key = iter->first;
319 ListValue* page_overrides; 321 ListValue* page_overrides;
320 if (!all_overrides->GetList(key, &page_overrides)) { 322 if (!all_overrides->GetList(key, &page_overrides)) {
321 page_overrides = new ListValue(); 323 page_overrides = new ListValue();
322 all_overrides->Set(key, page_overrides); 324 all_overrides->Set(key, page_overrides);
323 } else { 325 } else {
324 CleanUpDuplicates(page_overrides); 326 CleanUpDuplicates(page_overrides);
325 327
326 // Verify that the override isn't already in the list. 328 // 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. 376 // If it's being unregistered, it should already be in the list.
375 NOTREACHED(); 377 NOTREACHED();
376 return; 378 return;
377 } else { 379 } else {
378 UnregisterAndReplaceOverride(page, profile, page_overrides, override); 380 UnregisterAndReplaceOverride(page, profile, page_overrides, override);
379 } 381 }
380 } 382 }
381 383
382 // static 384 // static
383 void ExtensionWebUI::UnregisterChromeURLOverrides( 385 void ExtensionWebUI::UnregisterChromeURLOverrides(
384 Profile* profile, const Extension::URLOverrideMap& overrides) { 386 Profile* profile, const URLOverridesInfo::URLOverrideMap& overrides) {
385 if (overrides.empty()) 387 if (overrides.empty())
386 return; 388 return;
387 PrefService* prefs = profile->GetPrefs(); 389 PrefService* prefs = profile->GetPrefs();
388 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides); 390 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides);
389 DictionaryValue* all_overrides = update.Get(); 391 DictionaryValue* all_overrides = update.Get();
390 Extension::URLOverrideMap::const_iterator iter = overrides.begin(); 392 URLOverridesInfo::URLOverrideMap::const_iterator iter = overrides.begin();
391 for (; iter != overrides.end(); ++iter) { 393 for (; iter != overrides.end(); ++iter) {
392 const std::string& page = iter->first; 394 const std::string& page = iter->first;
393 ListValue* page_overrides; 395 ListValue* page_overrides;
394 if (!all_overrides->GetList(page, &page_overrides)) { 396 if (!all_overrides->GetList(page, &page_overrides)) {
395 // If it's being unregistered, it should already be in the list. 397 // If it's being unregistered, it should already be in the list.
396 NOTREACHED(); 398 NOTREACHED();
397 continue; 399 continue;
398 } else { 400 } else {
399 StringValue override(iter->second.spec()); 401 StringValue override(iter->second.spec());
400 UnregisterAndReplaceOverride(iter->first, profile, 402 UnregisterAndReplaceOverride(iter->first, profile,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, 443 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE,
442 gfx::Size(pixel_size, pixel_size), 444 gfx::Size(pixel_size, pixel_size),
443 scale_factors[i])); 445 scale_factors[i]));
444 } 446 }
445 447
446 // LoadImagesAsync actually can run callback synchronously. We want to force 448 // LoadImagesAsync actually can run callback synchronously. We want to force
447 // async. 449 // async.
448 extensions::ImageLoader::Get(profile)->LoadImagesAsync( 450 extensions::ImageLoader::Get(profile)->LoadImagesAsync(
449 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); 451 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback));
450 } 452 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698