Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/webui/options/website_settings_handler.h" | 5 #include "chrome/browser/ui/webui/options/website_settings_handler.h" |
| 6 | 6 |
| 7 #include "apps/app_window_registry.h" | 7 #include "apps/app_window_registry.h" |
| 8 #include "chrome/browser/content_settings/content_settings_utils.h" | 8 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_iterator.h" | 13 #include "chrome/browser/ui/browser_iterator.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "content/public/browser/dom_storage_context.h" | 15 #include "content/public/browser/dom_storage_context.h" |
| 15 #include "content/public/browser/storage_partition.h" | 16 #include "content/public/browser/storage_partition.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
| 18 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 20 #include "extensions/browser/extension_system.h" | |
| 19 #include "extensions/common/constants.h" | 21 #include "extensions/common/constants.h" |
| 20 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
| 21 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/l10n/time_format.h" | 25 #include "ui/base/l10n/time_format.h" |
| 24 #include "ui/base/text/bytes_formatting.h" | 26 #include "ui/base/text/bytes_formatting.h" |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 const int kHttpPort = 80; | 30 const int kHttpPort = 80; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 base::DictionaryValue* origin_entry = new base::DictionaryValue(); | 256 base::DictionaryValue* origin_entry = new base::DictionaryValue(); |
| 255 origin_entry->SetDoubleWithoutPathExpansion("usage", | 257 origin_entry->SetDoubleWithoutPathExpansion("usage", |
| 256 last_usage.ToDoubleT()); | 258 last_usage.ToDoubleT()); |
| 257 base::string16 usage_string; | 259 base::string16 usage_string; |
| 258 if (last_usage.ToDoubleT()) { | 260 if (last_usage.ToDoubleT()) { |
| 259 usage_string = ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, | 261 usage_string = ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, |
| 260 ui::TimeFormat::LENGTH_SHORT, | 262 ui::TimeFormat::LENGTH_SHORT, |
| 261 base::Time::Now() - last_usage); | 263 base::Time::Now() - last_usage); |
| 262 } | 264 } |
| 263 origin_entry->SetStringWithoutPathExpansion("usageString", usage_string); | 265 origin_entry->SetStringWithoutPathExpansion("usageString", usage_string); |
| 266 origin_entry->SetStringWithoutPathExpansion("readableName", | |
| 267 GetReadableName(origin_url)); | |
| 264 | 268 |
| 265 origins.SetWithoutPathExpansion(origin, origin_entry); | 269 origins.SetWithoutPathExpansion(origin, origin_entry); |
| 266 } | 270 } |
| 267 | 271 |
| 268 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", | 272 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", |
| 269 origins); | 273 origins); |
| 270 } | 274 } |
| 271 | 275 |
| 272 void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) { | 276 void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) { |
| 273 std::string url; | 277 std::string url; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 std::string origin = it->origin_url.spec(); | 448 std::string origin = it->origin_url.spec(); |
| 445 | 449 |
| 446 if (origin.find(last_filter_) == base::string16::npos) | 450 if (origin.find(last_filter_) == base::string16::npos) |
| 447 continue; | 451 continue; |
| 448 | 452 |
| 449 base::DictionaryValue* origin_entry = new base::DictionaryValue(); | 453 base::DictionaryValue* origin_entry = new base::DictionaryValue(); |
| 450 origin_entry->SetWithoutPathExpansion( | 454 origin_entry->SetWithoutPathExpansion( |
| 451 "usage", new base::FundamentalValue(static_cast<double>(it->size))); | 455 "usage", new base::FundamentalValue(static_cast<double>(it->size))); |
| 452 origin_entry->SetWithoutPathExpansion( | 456 origin_entry->SetWithoutPathExpansion( |
| 453 "usageString", new base::StringValue(ui::FormatBytes(it->size))); | 457 "usageString", new base::StringValue(ui::FormatBytes(it->size))); |
| 458 origin_entry->SetStringWithoutPathExpansion( | |
| 459 "readableName", GetReadableName(it->origin_url)); | |
| 454 local_storage_map.SetWithoutPathExpansion(origin, origin_entry); | 460 local_storage_map.SetWithoutPathExpansion(origin, origin_entry); |
| 455 } | 461 } |
| 456 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", | 462 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", |
| 457 local_storage_map); | 463 local_storage_map); |
| 458 } | 464 } |
| 459 | 465 |
| 460 void WebsiteSettingsHandler::StopOrigin(const GURL& site_url) { | 466 void WebsiteSettingsHandler::StopOrigin(const GURL& site_url) { |
| 461 Profile* profile = Profile::FromWebUI(web_ui()); | 467 Profile* profile = Profile::FromWebUI(web_ui()); |
| 462 if (site_url.SchemeIs(extensions::kExtensionScheme)) { | 468 if (site_url.SchemeIs(extensions::kExtensionScheme)) { |
| 463 const extensions::Extension* extension = | 469 const extensions::Extension* extension = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 dom_storage_context_->DeleteLocalStorage(site_url); | 504 dom_storage_context_->DeleteLocalStorage(site_url); |
| 499 | 505 |
| 500 // Load a new BrowsingDataLocalStorageHelper to update. | 506 // Load a new BrowsingDataLocalStorageHelper to update. |
| 501 local_storage_ = new BrowsingDataLocalStorageHelper(profile); | 507 local_storage_ = new BrowsingDataLocalStorageHelper(profile); |
| 502 | 508 |
| 503 local_storage_->StartFetching( | 509 local_storage_->StartFetching( |
| 504 base::Bind(&WebsiteSettingsHandler::OnLocalStorageFetched, | 510 base::Bind(&WebsiteSettingsHandler::OnLocalStorageFetched, |
| 505 weak_ptr_factory_.GetWeakPtr())); | 511 weak_ptr_factory_.GetWeakPtr())); |
| 506 } | 512 } |
| 507 | 513 |
| 514 const std::string& WebsiteSettingsHandler::GetReadableName( | |
| 515 const GURL& site_url) { | |
| 516 if (site_url.SchemeIs(extensions::kExtensionScheme)) { | |
| 517 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 518 ExtensionService* extension_service = | |
| 519 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 520 if (!extension_service) | |
|
Bernhard Bauer
2014/08/26 07:44:31
When is this NULL?
Daniel Nishi
2014/08/26 17:22:33
Hmm. Looking at it, it looks like this situation s
| |
| 521 return site_url.spec(); | |
| 522 | |
| 523 const extensions::Extension* extension = | |
| 524 extension_service->extensions()->GetExtensionOrAppByURL(site_url); | |
| 525 if (!extension) | |
|
Bernhard Bauer
2014/08/26 07:44:31
And this?
Daniel Nishi
2014/08/26 17:22:33
This is NULL if for some reason an chrome-extensio
Bernhard Bauer
2014/08/26 17:25:58
Makes sense. Can you add a comment that explains t
Daniel Nishi
2014/08/26 17:48:54
Done.
| |
| 526 return site_url.spec(); | |
| 527 | |
| 528 return extension->name(); | |
| 529 } | |
| 530 return site_url.spec(); | |
| 531 } | |
| 532 | |
| 508 } // namespace options | 533 } // namespace options |
| OLD | NEW |