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

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

Issue 16915006: Convert most of extensions and some other random stuff to using the base namespace for Values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
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 27 matching lines...) Expand all
38 #include "ui/gfx/favicon_size.h" 38 #include "ui/gfx/favicon_size.h"
39 #include "ui/gfx/image/image_skia.h" 39 #include "ui/gfx/image/image_skia.h"
40 40
41 using content::WebContents; 41 using content::WebContents;
42 using extensions::Extension; 42 using extensions::Extension;
43 using extensions::URLOverrides; 43 using extensions::URLOverrides;
44 44
45 namespace { 45 namespace {
46 46
47 // De-dupes the items in |list|. Assumes the values are strings. 47 // De-dupes the items in |list|. Assumes the values are strings.
48 void CleanUpDuplicates(ListValue* list) { 48 void CleanUpDuplicates(base::ListValue* list) {
49 std::set<std::string> seen_values; 49 std::set<std::string> seen_values;
50 50
51 // Loop backwards as we may be removing items. 51 // Loop backwards as we may be removing items.
52 for (size_t i = list->GetSize() - 1; (i + 1) > 0; --i) { 52 for (size_t i = list->GetSize() - 1; (i + 1) > 0; --i) {
53 std::string value; 53 std::string value;
54 if (!list->GetString(i, &value)) { 54 if (!list->GetString(i, &value)) {
55 NOTREACHED(); 55 NOTREACHED();
56 continue; 56 continue;
57 } 57 }
58 58
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 171 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
172 } 172 }
173 173
174 // static 174 // static
175 bool ExtensionWebUI::HandleChromeURLOverride( 175 bool ExtensionWebUI::HandleChromeURLOverride(
176 GURL* url, content::BrowserContext* browser_context) { 176 GURL* url, content::BrowserContext* browser_context) {
177 if (!url->SchemeIs(chrome::kChromeUIScheme)) 177 if (!url->SchemeIs(chrome::kChromeUIScheme))
178 return false; 178 return false;
179 179
180 Profile* profile = Profile::FromBrowserContext(browser_context); 180 Profile* profile = Profile::FromBrowserContext(browser_context);
181 const DictionaryValue* overrides = 181 const base::DictionaryValue* overrides =
182 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); 182 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides);
183 std::string page = url->host(); 183 std::string page = url->host();
184 const ListValue* url_list = NULL; 184 const base::ListValue* url_list = NULL;
185 if (!overrides || !overrides->GetList(page, &url_list)) 185 if (!overrides || !overrides->GetList(page, &url_list))
186 return false; 186 return false;
187 187
188 ExtensionService* service = profile->GetExtensionService(); 188 ExtensionService* service = profile->GetExtensionService();
189 189
190 size_t i = 0; 190 size_t i = 0;
191 while (i < url_list->GetSize()) { 191 while (i < url_list->GetSize()) {
192 const Value* val = NULL; 192 const Value* val = NULL;
193 url_list->Get(i, &val); 193 url_list->Get(i, &val);
194 194
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 *url = extension_url; 237 *url = extension_url;
238 return true; 238 return true;
239 } 239 }
240 return false; 240 return false;
241 } 241 }
242 242
243 // static 243 // static
244 bool ExtensionWebUI::HandleChromeURLOverrideReverse( 244 bool ExtensionWebUI::HandleChromeURLOverrideReverse(
245 GURL* url, content::BrowserContext* browser_context) { 245 GURL* url, content::BrowserContext* browser_context) {
246 Profile* profile = Profile::FromBrowserContext(browser_context); 246 Profile* profile = Profile::FromBrowserContext(browser_context);
247 const DictionaryValue* overrides = 247 const base::DictionaryValue* overrides =
248 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); 248 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides);
249 if (!overrides) 249 if (!overrides)
250 return false; 250 return false;
251 251
252 // Find the reverse mapping based on the given URL. For example this maps the 252 // Find the reverse mapping based on the given URL. For example this maps the
253 // internal URL 253 // internal URL
254 // chrome-extension://eemcgdkfndhakfknompkggombfjjjeno/main.html#1 to 254 // chrome-extension://eemcgdkfndhakfknompkggombfjjjeno/main.html#1 to
255 // chrome://bookmarks/#1 for display in the omnibox. 255 // chrome://bookmarks/#1 for display in the omnibox.
256 for (DictionaryValue::Iterator it(*overrides); !it.IsAtEnd(); it.Advance()) { 256 for (base::DictionaryValue::Iterator it(*overrides); !it.IsAtEnd();
257 const ListValue* url_list = NULL; 257 it.Advance()) {
258 const base::ListValue* url_list = NULL;
258 if (!it.value().GetAsList(&url_list)) 259 if (!it.value().GetAsList(&url_list))
259 continue; 260 continue;
260 261
261 for (ListValue::const_iterator it2 = url_list->begin(); 262 for (base::ListValue::const_iterator it2 = url_list->begin();
262 it2 != url_list->end(); ++it2) { 263 it2 != url_list->end(); ++it2) {
263 std::string override; 264 std::string override;
264 if (!(*it2)->GetAsString(&override)) 265 if (!(*it2)->GetAsString(&override))
265 continue; 266 continue;
266 if (StartsWithASCII(url->spec(), override, true)) { 267 if (StartsWithASCII(url->spec(), override, true)) {
267 GURL original_url(chrome::kChromeUIScheme + std::string("://") + 268 GURL original_url(chrome::kChromeUIScheme + std::string("://") +
268 it.key() + url->spec().substr(override.length())); 269 it.key() + url->spec().substr(override.length()));
269 *url = original_url; 270 *url = original_url;
270 return true; 271 return true;
271 } 272 }
272 } 273 }
273 } 274 }
274 275
275 return false; 276 return false;
276 } 277 }
277 278
278 // static 279 // static
279 void ExtensionWebUI::RegisterChromeURLOverrides( 280 void ExtensionWebUI::RegisterChromeURLOverrides(
280 Profile* profile, const URLOverrides::URLOverrideMap& overrides) { 281 Profile* profile, const URLOverrides::URLOverrideMap& overrides) {
281 if (overrides.empty()) 282 if (overrides.empty())
282 return; 283 return;
283 284
284 PrefService* prefs = profile->GetPrefs(); 285 PrefService* prefs = profile->GetPrefs();
285 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides); 286 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides);
286 DictionaryValue* all_overrides = update.Get(); 287 base::DictionaryValue* all_overrides = update.Get();
287 288
288 // For each override provided by the extension, add it to the front of 289 // For each override provided by the extension, add it to the front of
289 // the override list if it's not already in the list. 290 // the override list if it's not already in the list.
290 URLOverrides::URLOverrideMap::const_iterator iter = overrides.begin(); 291 URLOverrides::URLOverrideMap::const_iterator iter = overrides.begin();
291 for (; iter != overrides.end(); ++iter) { 292 for (; iter != overrides.end(); ++iter) {
292 const std::string& key = iter->first; 293 const std::string& key = iter->first;
293 ListValue* page_overrides = NULL; 294 base::ListValue* page_overrides = NULL;
294 if (!all_overrides->GetList(key, &page_overrides)) { 295 if (!all_overrides->GetList(key, &page_overrides)) {
295 page_overrides = new ListValue(); 296 page_overrides = new base::ListValue();
296 all_overrides->Set(key, page_overrides); 297 all_overrides->Set(key, page_overrides);
297 } else { 298 } else {
298 CleanUpDuplicates(page_overrides); 299 CleanUpDuplicates(page_overrides);
299 300
300 // Verify that the override isn't already in the list. 301 // Verify that the override isn't already in the list.
301 ListValue::iterator i = page_overrides->begin(); 302 base::ListValue::iterator i = page_overrides->begin();
302 for (; i != page_overrides->end(); ++i) { 303 for (; i != page_overrides->end(); ++i) {
303 std::string override_val; 304 std::string override_val;
304 if (!(*i)->GetAsString(&override_val)) { 305 if (!(*i)->GetAsString(&override_val)) {
305 NOTREACHED(); 306 NOTREACHED();
306 continue; 307 continue;
307 } 308 }
308 if (override_val == iter->second.spec()) 309 if (override_val == iter->second.spec())
309 break; 310 break;
310 } 311 }
311 // This value is already in the list, leave it alone. 312 // This value is already in the list, leave it alone.
312 if (i != page_overrides->end()) 313 if (i != page_overrides->end())
313 continue; 314 continue;
314 } 315 }
315 // Insert the override at the front of the list. Last registered override 316 // Insert the override at the front of the list. Last registered override
316 // wins. 317 // wins.
317 page_overrides->Insert(0, new StringValue(iter->second.spec())); 318 page_overrides->Insert(0, new StringValue(iter->second.spec()));
318 } 319 }
319 } 320 }
320 321
321 // static 322 // static
322 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page, 323 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page,
323 Profile* profile, 324 Profile* profile,
324 ListValue* list, 325 base::ListValue* list,
325 const Value* override) { 326 const Value* override) {
326 size_t index = 0; 327 size_t index = 0;
327 bool found = list->Remove(*override, &index); 328 bool found = list->Remove(*override, &index);
328 if (found && index == 0) { 329 if (found && index == 0) {
329 // This is the active override, so we need to find all existing 330 // This is the active override, so we need to find all existing
330 // tabs for this override and get them to reload the original URL. 331 // tabs for this override and get them to reload the original URL.
331 base::Callback<void(WebContents*)> callback = 332 base::Callback<void(WebContents*)> callback =
332 base::Bind(&UnregisterAndReplaceOverrideForWebContents, page, profile); 333 base::Bind(&UnregisterAndReplaceOverrideForWebContents, page, profile);
333 ExtensionTabUtil::ForEachTab(callback); 334 ExtensionTabUtil::ForEachTab(callback);
334 } 335 }
335 } 336 }
336 337
337 // static 338 // static
338 void ExtensionWebUI::UnregisterChromeURLOverride(const std::string& page, 339 void ExtensionWebUI::UnregisterChromeURLOverride(const std::string& page,
339 Profile* profile, 340 Profile* profile,
340 const Value* override) { 341 const Value* override) {
341 if (!override) 342 if (!override)
342 return; 343 return;
343 PrefService* prefs = profile->GetPrefs(); 344 PrefService* prefs = profile->GetPrefs();
344 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides); 345 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides);
345 DictionaryValue* all_overrides = update.Get(); 346 base::DictionaryValue* all_overrides = update.Get();
346 ListValue* page_overrides = NULL; 347 base::ListValue* page_overrides = NULL;
347 if (!all_overrides->GetList(page, &page_overrides)) { 348 if (!all_overrides->GetList(page, &page_overrides)) {
348 // If it's being unregistered, it should already be in the list. 349 // If it's being unregistered, it should already be in the list.
349 NOTREACHED(); 350 NOTREACHED();
350 return; 351 return;
351 } else { 352 } else {
352 UnregisterAndReplaceOverride(page, profile, page_overrides, override); 353 UnregisterAndReplaceOverride(page, profile, page_overrides, override);
353 } 354 }
354 } 355 }
355 356
356 // static 357 // static
357 void ExtensionWebUI::UnregisterChromeURLOverrides( 358 void ExtensionWebUI::UnregisterChromeURLOverrides(
358 Profile* profile, const URLOverrides::URLOverrideMap& overrides) { 359 Profile* profile, const URLOverrides::URLOverrideMap& overrides) {
359 if (overrides.empty()) 360 if (overrides.empty())
360 return; 361 return;
361 PrefService* prefs = profile->GetPrefs(); 362 PrefService* prefs = profile->GetPrefs();
362 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides); 363 DictionaryPrefUpdate update(prefs, kExtensionURLOverrides);
363 DictionaryValue* all_overrides = update.Get(); 364 base::DictionaryValue* all_overrides = update.Get();
364 URLOverrides::URLOverrideMap::const_iterator iter = overrides.begin(); 365 URLOverrides::URLOverrideMap::const_iterator iter = overrides.begin();
365 for (; iter != overrides.end(); ++iter) { 366 for (; iter != overrides.end(); ++iter) {
366 const std::string& page = iter->first; 367 const std::string& page = iter->first;
367 ListValue* page_overrides = NULL; 368 base::ListValue* page_overrides = NULL;
368 if (!all_overrides->GetList(page, &page_overrides)) { 369 if (!all_overrides->GetList(page, &page_overrides)) {
369 // If it's being unregistered, it should already be in the list. 370 // If it's being unregistered, it should already be in the list.
370 NOTREACHED(); 371 NOTREACHED();
371 continue; 372 continue;
372 } else { 373 } else {
373 StringValue override(iter->second.spec()); 374 StringValue override(iter->second.spec());
374 UnregisterAndReplaceOverride(iter->first, profile, 375 UnregisterAndReplaceOverride(iter->first, profile,
375 page_overrides, &override); 376 page_overrides, &override);
376 } 377 }
377 } 378 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, 417 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE,
417 gfx::Size(pixel_size, pixel_size), 418 gfx::Size(pixel_size, pixel_size),
418 scale_factors[i])); 419 scale_factors[i]));
419 } 420 }
420 421
421 // LoadImagesAsync actually can run callback synchronously. We want to force 422 // LoadImagesAsync actually can run callback synchronously. We want to force
422 // async. 423 // async.
423 extensions::ImageLoader::Get(profile)->LoadImagesAsync( 424 extensions::ImageLoader::Get(profile)->LoadImagesAsync(
424 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); 425 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback));
425 } 426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698