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 "chrome/browser/content_settings/content_settings_utils.h" | 8 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | |
| 12 #include "content/public/browser/dom_storage_context.h" | |
| 13 #include "content/public/browser/storage_partition.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 10 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
| 16 #include "extensions/browser/extension_registry.h" | |
| 17 #include "extensions/common/constants.h" | |
| 18 #include "extensions/common/extension.h" | |
| 11 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/base/l10n/time_format.h" | 21 #include "ui/base/l10n/time_format.h" |
| 14 #include "ui/base/text/bytes_formatting.h" | 22 #include "ui/base/text/bytes_formatting.h" |
| 15 | 23 |
| 16 namespace { | 24 namespace { |
| 17 | 25 |
| 18 const int kHttpPort = 80; | 26 const int kHttpPort = 80; |
| 19 const int kHttpsPort = 443; | 27 const int kHttpsPort = 443; |
| 20 const char kPreferencesSource[] = "preference"; | 28 const char kPreferencesSource[] = "preference"; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 46 {"websitesLabelGeolocation", IDS_WEBSITE_SETTINGS_TYPE_LOCATION}, | 54 {"websitesLabelGeolocation", IDS_WEBSITE_SETTINGS_TYPE_LOCATION}, |
| 47 {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, | 55 {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, |
| 48 {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, | 56 {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, |
| 49 {"websitesLabelStorage", IDS_WEBSITE_SETTINGS_TYPE_STORAGE}, | 57 {"websitesLabelStorage", IDS_WEBSITE_SETTINGS_TYPE_STORAGE}, |
| 50 {"websitesLocationDescription", | 58 {"websitesLocationDescription", |
| 51 IDS_WEBSITE_SETTINGS_LOCATION_DESCRIPTION}, | 59 IDS_WEBSITE_SETTINGS_LOCATION_DESCRIPTION}, |
| 52 {"websitesMediastreamDescription", | 60 {"websitesMediastreamDescription", |
| 53 IDS_WEBSITE_SETTINGS_MEDIASTREAM_DESCRIPTION}, | 61 IDS_WEBSITE_SETTINGS_MEDIASTREAM_DESCRIPTION}, |
| 54 {"websitesNotificationsDescription", | 62 {"websitesNotificationsDescription", |
| 55 IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION}, | 63 IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION}, |
| 64 {"websitesButtonClear", IDS_WEBSITE_SETTINGS_STORAGE_CLEAR_BUTTON}, | |
| 56 }; | 65 }; |
| 57 | 66 |
| 58 RegisterStrings(localized_strings, resources, arraysize(resources)); | 67 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 59 RegisterTitle( | 68 RegisterTitle( |
| 60 localized_strings, "websiteSettingsPage", IDS_WEBSITE_SETTINGS_TITLE); | 69 localized_strings, "websiteSettingsPage", IDS_WEBSITE_SETTINGS_TITLE); |
| 61 } | 70 } |
| 62 | 71 |
| 63 void WebsiteSettingsHandler::InitializeHandler() { | 72 void WebsiteSettingsHandler::InitializeHandler() { |
| 64 Profile* profile = Profile::FromWebUI(web_ui()); | 73 Profile* profile = Profile::FromWebUI(web_ui()); |
| 65 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | 74 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 89 | 98 |
| 90 web_ui()->RegisterMessageCallback( | 99 web_ui()->RegisterMessageCallback( |
| 91 "setOriginPermission", | 100 "setOriginPermission", |
| 92 base::Bind(&WebsiteSettingsHandler::HandleSetOriginPermission, | 101 base::Bind(&WebsiteSettingsHandler::HandleSetOriginPermission, |
| 93 base::Unretained(this))); | 102 base::Unretained(this))); |
| 94 | 103 |
| 95 web_ui()->RegisterMessageCallback( | 104 web_ui()->RegisterMessageCallback( |
| 96 "maybeShowEditPage", | 105 "maybeShowEditPage", |
| 97 base::Bind(&WebsiteSettingsHandler::HandleMaybeShowEditPage, | 106 base::Bind(&WebsiteSettingsHandler::HandleMaybeShowEditPage, |
| 98 base::Unretained(this))); | 107 base::Unretained(this))); |
| 108 | |
| 109 web_ui()->RegisterMessageCallback( | |
| 110 "deleteLocalStorage", | |
| 111 base::Bind(&WebsiteSettingsHandler::HandleDeleteLocalStorage, | |
| 112 base::Unretained(this))); | |
| 113 | |
| 114 web_ui()->RegisterMessageCallback( | |
| 115 "stopOrigin", | |
| 116 base::Bind(&WebsiteSettingsHandler::HandleStopOrigin, | |
| 117 base::Unretained(this))); | |
| 99 } | 118 } |
| 100 | 119 |
| 101 // content_settings::Observer implementation. | 120 // content_settings::Observer implementation. |
| 102 void WebsiteSettingsHandler::OnContentSettingChanged( | 121 void WebsiteSettingsHandler::OnContentSettingChanged( |
| 103 const ContentSettingsPattern& primary_pattern, | 122 const ContentSettingsPattern& primary_pattern, |
| 104 const ContentSettingsPattern& secondary_pattern, | 123 const ContentSettingsPattern& secondary_pattern, |
| 105 ContentSettingsType content_type, | 124 ContentSettingsType content_type, |
| 106 std::string resource_identifier) { | 125 std::string resource_identifier) { |
| 107 Update(); | 126 Update(); |
| 108 } | 127 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 | 176 |
| 158 last_site_ = last_site; | 177 last_site_ = last_site; |
| 159 base::StringValue site_value(site); | 178 base::StringValue site_value(site); |
| 160 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.showEditPage", | 179 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.showEditPage", |
| 161 site_value); | 180 site_value); |
| 162 } | 181 } |
| 163 | 182 |
| 164 void WebsiteSettingsHandler::OnLocalStorageFetched(const std::list< | 183 void WebsiteSettingsHandler::OnLocalStorageFetched(const std::list< |
| 165 BrowsingDataLocalStorageHelper::LocalStorageInfo>& storage) { | 184 BrowsingDataLocalStorageHelper::LocalStorageInfo>& storage) { |
| 166 local_storage_list_ = storage; | 185 local_storage_list_ = storage; |
| 167 UpdateLocalStorage(); | 186 Update(); |
| 187 GetInfoForOrigin(last_site_, false); | |
| 168 } | 188 } |
| 169 | 189 |
| 170 void WebsiteSettingsHandler::Update() { | 190 void WebsiteSettingsHandler::Update() { |
| 171 DCHECK(!last_setting_.empty()); | 191 DCHECK(!last_setting_.empty()); |
| 172 if (last_setting_ == kStorage) | 192 if (last_setting_ == kStorage) |
| 173 UpdateLocalStorage(); | 193 UpdateLocalStorage(); |
| 174 else | 194 else |
| 175 UpdateOrigins(); | 195 UpdateOrigins(); |
| 176 } | 196 } |
| 177 | 197 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 | 269 |
| 250 void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) { | 270 void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) { |
| 251 std::string url; | 271 std::string url; |
| 252 bool rv = args->GetString(0, &url); | 272 bool rv = args->GetString(0, &url); |
| 253 DCHECK(rv); | 273 DCHECK(rv); |
| 254 GURL origin(url); | 274 GURL origin(url); |
| 255 | 275 |
| 256 if (!origin.is_valid()) | 276 if (!origin.is_valid()) |
| 257 return; | 277 return; |
| 258 | 278 |
| 259 GetInfoForOrigin(origin); | 279 GetInfoForOrigin(origin, true); |
| 260 } | 280 } |
| 261 | 281 |
| 262 void WebsiteSettingsHandler::HandleSetOriginPermission( | 282 void WebsiteSettingsHandler::HandleSetOriginPermission( |
| 263 const base::ListValue* args) { | 283 const base::ListValue* args) { |
| 264 std::string setting_name; | 284 std::string setting_name; |
| 265 bool rv = args->GetString(0, &setting_name); | 285 bool rv = args->GetString(0, &setting_name); |
| 266 DCHECK(rv); | 286 DCHECK(rv); |
| 267 ContentSettingsType settings_type; | 287 ContentSettingsType settings_type; |
| 268 rv = content_settings::GetTypeFromName(setting_name, &settings_type); | 288 rv = content_settings::GetTypeFromName(setting_name, &settings_type); |
| 269 DCHECK(rv); | 289 DCHECK(rv); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 scoped_ptr<base::Value> v(map->GetWebsiteSetting( | 337 scoped_ptr<base::Value> v(map->GetWebsiteSetting( |
| 318 last_site_, last_site_, settings_type, std::string(), &info)); | 338 last_site_, last_site_, settings_type, std::string(), &info)); |
| 319 map->SetNarrowestWebsiteSetting(primary_pattern, | 339 map->SetNarrowestWebsiteSetting(primary_pattern, |
| 320 secondary_pattern, | 340 secondary_pattern, |
| 321 settings_type, | 341 settings_type, |
| 322 std::string(), | 342 std::string(), |
| 323 setting, | 343 setting, |
| 324 info); | 344 info); |
| 325 } | 345 } |
| 326 | 346 |
| 327 void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url) { | 347 void WebsiteSettingsHandler::HandleDeleteLocalStorage( |
| 348 const base::ListValue* args) { | |
| 349 DCHECK(!last_site_.is_empty()); | |
| 350 DeleteLocalStorage(last_site_); | |
| 351 } | |
| 352 | |
| 353 void WebsiteSettingsHandler::HandleStopOrigin(const base::ListValue* args) { | |
| 354 DCHECK(!last_site_.is_empty()); | |
| 355 StopOrigin(last_site_); | |
| 356 } | |
| 357 | |
| 358 void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url, | |
| 359 bool show_page) { | |
| 328 Profile* profile = Profile::FromWebUI(web_ui()); | 360 Profile* profile = Profile::FromWebUI(web_ui()); |
| 329 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 361 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
| 330 | 362 |
| 331 double storage = 0.0; | 363 double storage = 0.0; |
| 332 for (LocalStorageList::const_iterator it = local_storage_list_.begin(); | 364 for (LocalStorageList::const_iterator it = local_storage_list_.begin(); |
| 333 it != local_storage_list_.end(); | 365 it != local_storage_list_.end(); |
| 334 it++) { | 366 it++) { |
| 335 if (it->origin_url == site_url) { | 367 if (it->origin_url == site_url) { |
| 336 storage = static_cast<double>(it->size); | 368 storage = static_cast<double>(it->size); |
| 337 break; | 369 break; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 permission_info->SetWithoutPathExpansion("options", options); | 421 permission_info->SetWithoutPathExpansion("options", options); |
| 390 permission_info->SetBooleanWithoutPathExpansion( | 422 permission_info->SetBooleanWithoutPathExpansion( |
| 391 "editable", info.source == content_settings::SETTING_SOURCE_USER); | 423 "editable", info.source == content_settings::SETTING_SOURCE_USER); |
| 392 permissions->SetWithoutPathExpansion( | 424 permissions->SetWithoutPathExpansion( |
| 393 content_settings::GetTypeName(permission_type), permission_info); | 425 content_settings::GetTypeName(permission_type), permission_info); |
| 394 } | 426 } |
| 395 | 427 |
| 396 base::Value* storage_used = new base::StringValue(l10n_util::GetStringFUTF16( | 428 base::Value* storage_used = new base::StringValue(l10n_util::GetStringFUTF16( |
| 397 IDS_WEBSITE_SETTINGS_STORAGE_USED, ui::FormatBytes(storage))); | 429 IDS_WEBSITE_SETTINGS_STORAGE_USED, ui::FormatBytes(storage))); |
| 398 | 430 |
| 399 web_ui()->CallJavascriptFunction( | 431 web_ui()->CallJavascriptFunction("WebsiteSettingsEditor.populateOrigin", |
| 400 "WebsiteSettingsEditor.populateOrigin", *storage_used, *permissions); | 432 *storage_used, |
| 433 *permissions, | |
| 434 base::FundamentalValue(show_page)); | |
| 401 } | 435 } |
| 402 | 436 |
| 403 void WebsiteSettingsHandler::UpdateLocalStorage() { | 437 void WebsiteSettingsHandler::UpdateLocalStorage() { |
| 404 base::DictionaryValue local_storage_map; | 438 base::DictionaryValue local_storage_map; |
| 405 for (LocalStorageList::const_iterator it = local_storage_list_.begin(); | 439 for (LocalStorageList::const_iterator it = local_storage_list_.begin(); |
| 406 it != local_storage_list_.end(); | 440 it != local_storage_list_.end(); |
| 407 it++) { | 441 it++) { |
| 408 std::string origin = it->origin_url.spec(); | 442 std::string origin = it->origin_url.spec(); |
| 409 | 443 |
| 410 if (origin.find(last_filter_) == base::string16::npos) | 444 if (origin.find(last_filter_) == base::string16::npos) |
| 411 continue; | 445 continue; |
| 412 | 446 |
| 413 base::DictionaryValue* origin_entry = new base::DictionaryValue(); | 447 base::DictionaryValue* origin_entry = new base::DictionaryValue(); |
| 414 origin_entry->SetWithoutPathExpansion( | 448 origin_entry->SetWithoutPathExpansion( |
| 415 "usage", new base::FundamentalValue(static_cast<double>(it->size))); | 449 "usage", new base::FundamentalValue(static_cast<double>(it->size))); |
| 416 origin_entry->SetWithoutPathExpansion( | 450 origin_entry->SetWithoutPathExpansion( |
| 417 "usageString", new base::StringValue(ui::FormatBytes(it->size))); | 451 "usageString", new base::StringValue(ui::FormatBytes(it->size))); |
| 418 local_storage_map.SetWithoutPathExpansion(origin, origin_entry); | 452 local_storage_map.SetWithoutPathExpansion(origin, origin_entry); |
| 419 } | 453 } |
| 420 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", | 454 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", |
| 421 local_storage_map); | 455 local_storage_map); |
| 422 } | 456 } |
| 423 | 457 |
| 458 void WebsiteSettingsHandler::StopOrigin(const GURL& site_url) { | |
| 459 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 460 if (site_url.SchemeIs(extensions::kExtensionScheme)) { | |
| 461 const extensions::Extension* extension = | |
| 462 extensions::ExtensionRegistry::Get(profile) | |
| 463 ->enabled_extensions() | |
| 464 .GetHostedAppByURL(site_url); | |
| 465 if (extension) { | |
| 466 apps::AppWindowRegistry::Get(profile) | |
| 467 ->CloseAllAppWindowsForApp(extension->id()); | |
| 468 } | |
| 469 } | |
| 470 | |
| 471 for (TabContentsIterator it; !it.done(); it.Next()) { | |
| 472 if (it->GetLastCommittedURL().GetOrigin() == site_url && | |
| 473 profile == Profile::FromBrowserContext(it->GetBrowserContext())) { | |
|
Bernhard Bauer
2014/08/22 20:42:39
How does this interact with incognito?
Daniel Nishi
2014/08/22 21:45:25
Incognito isn't affected. I'm pretty sure it is be
Bernhard Bauer
2014/08/22 21:54:36
Yeah, I was more wondering whether that's somethin
Daniel Nishi
2014/08/22 22:12:47
I did a little experiment -- you can see OTR conte
Bernhard Bauer
2014/08/22 22:41:27
Yeah, I think so. We could probably mark them up d
| |
| 474 it->Close(); | |
|
Bernhard Bauer
2014/08/22 20:42:39
This closes the tabs completely, right? Is that th
Daniel Nishi
2014/08/22 21:45:25
Ooh. I didn't know about the Discard functionality
| |
| 475 } | |
| 476 } | |
| 477 } | |
| 478 | |
| 479 void WebsiteSettingsHandler::DeleteLocalStorage(const GURL& site_url) { | |
| 480 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 481 content::DOMStorageContext* dom_storage_context_ = | |
| 482 content::BrowserContext::GetDefaultStoragePartition(profile) | |
| 483 ->GetDOMStorageContext(); | |
| 484 dom_storage_context_->DeleteLocalStorage(site_url); | |
| 485 | |
| 486 // Load a new BrowsingDataLocalStorageHelper to update. | |
| 487 local_storage_ = NULL; | |
|
Bernhard Bauer
2014/08/22 20:42:39
Is this assignment really necessary?
Daniel Nishi
2014/08/22 21:45:25
Hmm. I think I misunderstood a comment in the scop
| |
| 488 local_storage_ = new BrowsingDataLocalStorageHelper(profile); | |
| 489 | |
| 490 local_storage_->StartFetching( | |
| 491 base::Bind(&WebsiteSettingsHandler::OnLocalStorageFetched, | |
| 492 weak_ptr_factory_.GetWeakPtr())); | |
| 493 } | |
| 494 | |
| 424 } // namespace options | 495 } // namespace options |
| OLD | NEW |