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/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); | 178 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); |
179 std::string page = url->host(); | 179 std::string page = url->host(); |
180 const base::ListValue* url_list = NULL; | 180 const base::ListValue* url_list = NULL; |
181 if (!overrides || !overrides->GetList(page, &url_list)) | 181 if (!overrides || !overrides->GetList(page, &url_list)) |
182 return false; | 182 return false; |
183 | 183 |
184 ExtensionService* service = profile->GetExtensionService(); | 184 ExtensionService* service = profile->GetExtensionService(); |
185 | 185 |
186 size_t i = 0; | 186 size_t i = 0; |
187 while (i < url_list->GetSize()) { | 187 while (i < url_list->GetSize()) { |
188 const Value* val = NULL; | 188 const base::Value* val = NULL; |
189 url_list->Get(i, &val); | 189 url_list->Get(i, &val); |
190 | 190 |
191 // Verify that the override value is good. If not, unregister it and find | 191 // Verify that the override value is good. If not, unregister it and find |
192 // the next one. | 192 // the next one. |
193 std::string override; | 193 std::string override; |
194 if (!val->GetAsString(&override)) { | 194 if (!val->GetAsString(&override)) { |
195 NOTREACHED(); | 195 NOTREACHED(); |
196 UnregisterChromeURLOverride(page, profile, val); | 196 UnregisterChromeURLOverride(page, profile, val); |
197 continue; | 197 continue; |
198 } | 198 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 } | 304 } |
305 if (override_val == iter->second.spec()) | 305 if (override_val == iter->second.spec()) |
306 break; | 306 break; |
307 } | 307 } |
308 // This value is already in the list, leave it alone. | 308 // This value is already in the list, leave it alone. |
309 if (i != page_overrides->end()) | 309 if (i != page_overrides->end()) |
310 continue; | 310 continue; |
311 } | 311 } |
312 // Insert the override at the front of the list. Last registered override | 312 // Insert the override at the front of the list. Last registered override |
313 // wins. | 313 // wins. |
314 page_overrides->Insert(0, new StringValue(iter->second.spec())); | 314 page_overrides->Insert(0, new base::StringValue(iter->second.spec())); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 // static | 318 // static |
319 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page, | 319 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page, |
320 Profile* profile, | 320 Profile* profile, |
321 base::ListValue* list, | 321 base::ListValue* list, |
322 const Value* override) { | 322 const base::Value* override) { |
323 size_t index = 0; | 323 size_t index = 0; |
324 bool found = list->Remove(*override, &index); | 324 bool found = list->Remove(*override, &index); |
325 if (found && index == 0) { | 325 if (found && index == 0) { |
326 // This is the active override, so we need to find all existing | 326 // This is the active override, so we need to find all existing |
327 // tabs for this override and get them to reload the original URL. | 327 // tabs for this override and get them to reload the original URL. |
328 base::Callback<void(WebContents*)> callback = | 328 base::Callback<void(WebContents*)> callback = |
329 base::Bind(&UnregisterAndReplaceOverrideForWebContents, page, profile); | 329 base::Bind(&UnregisterAndReplaceOverrideForWebContents, page, profile); |
330 extensions::ExtensionTabUtil::ForEachTab(callback); | 330 extensions::ExtensionTabUtil::ForEachTab(callback); |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 // static | 334 // static |
335 void ExtensionWebUI::UnregisterChromeURLOverride(const std::string& page, | 335 void ExtensionWebUI::UnregisterChromeURLOverride(const std::string& page, |
336 Profile* profile, | 336 Profile* profile, |
337 const Value* override) { | 337 const base::Value* override) { |
338 if (!override) | 338 if (!override) |
339 return; | 339 return; |
340 PrefService* prefs = profile->GetPrefs(); | 340 PrefService* prefs = profile->GetPrefs(); |
341 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides); | 341 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides); |
342 base::DictionaryValue* all_overrides = update.Get(); | 342 base::DictionaryValue* all_overrides = update.Get(); |
343 base::ListValue* page_overrides = NULL; | 343 base::ListValue* page_overrides = NULL; |
344 if (!all_overrides->GetList(page, &page_overrides)) { | 344 if (!all_overrides->GetList(page, &page_overrides)) { |
345 // If it's being unregistered, it should already be in the list. | 345 // If it's being unregistered, it should already be in the list. |
346 NOTREACHED(); | 346 NOTREACHED(); |
347 return; | 347 return; |
(...skipping 12 matching lines...) Expand all Loading... |
360 base::DictionaryValue* all_overrides = update.Get(); | 360 base::DictionaryValue* all_overrides = update.Get(); |
361 URLOverrides::URLOverrideMap::const_iterator iter = overrides.begin(); | 361 URLOverrides::URLOverrideMap::const_iterator iter = overrides.begin(); |
362 for (; iter != overrides.end(); ++iter) { | 362 for (; iter != overrides.end(); ++iter) { |
363 const std::string& page = iter->first; | 363 const std::string& page = iter->first; |
364 base::ListValue* page_overrides = NULL; | 364 base::ListValue* page_overrides = NULL; |
365 if (!all_overrides->GetList(page, &page_overrides)) { | 365 if (!all_overrides->GetList(page, &page_overrides)) { |
366 // If it's being unregistered, it should already be in the list. | 366 // If it's being unregistered, it should already be in the list. |
367 NOTREACHED(); | 367 NOTREACHED(); |
368 continue; | 368 continue; |
369 } else { | 369 } else { |
370 StringValue override(iter->second.spec()); | 370 base::StringValue override(iter->second.spec()); |
371 UnregisterAndReplaceOverride(iter->first, profile, | 371 UnregisterAndReplaceOverride(iter->first, profile, |
372 page_overrides, &override); | 372 page_overrides, &override); |
373 } | 373 } |
374 } | 374 } |
375 } | 375 } |
376 | 376 |
377 // static | 377 // static |
378 void ExtensionWebUI::GetFaviconForURL( | 378 void ExtensionWebUI::GetFaviconForURL( |
379 Profile* profile, | 379 Profile* profile, |
380 const GURL& page_url, | 380 const GURL& page_url, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, | 413 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, |
414 gfx::Size(pixel_size, pixel_size), | 414 gfx::Size(pixel_size, pixel_size), |
415 scale_factors[i])); | 415 scale_factors[i])); |
416 } | 416 } |
417 | 417 |
418 // LoadImagesAsync actually can run callback synchronously. We want to force | 418 // LoadImagesAsync actually can run callback synchronously. We want to force |
419 // async. | 419 // async. |
420 extensions::ImageLoader::Get(profile)->LoadImagesAsync( | 420 extensions::ImageLoader::Get(profile)->LoadImagesAsync( |
421 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); | 421 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); |
422 } | 422 } |
OLD | NEW |