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 "chrome/browser/content_settings/content_settings_utils.h" | 7 #include "chrome/browser/content_settings/content_settings_utils.h" |
8 #include "chrome/browser/content_settings/host_content_settings_map.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 using power::OriginPowerMapFactory; | 31 using power::OriginPowerMapFactory; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const char kBattery[] = "battery"; | 35 const char kBattery[] = "battery"; |
36 const int kHttpPort = 80; | 36 const int kHttpPort = 80; |
37 const int kHttpsPort = 443; | 37 const int kHttpsPort = 443; |
38 const char kPreferencesSource[] = "preference"; | 38 const char kPreferencesSource[] = "preference"; |
39 const char kStorage[] = "storage"; | 39 const char kStorage[] = "storage"; |
40 const ContentSettingsType kValidTypes[] = { | 40 const ContentSettingsType kValidTypes[] = { |
| 41 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| 42 CONTENT_SETTINGS_TYPE_COOKIES, |
41 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 43 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 44 CONTENT_SETTINGS_TYPE_IMAGES, |
| 45 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
42 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 46 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
43 CONTENT_SETTINGS_TYPE_MEDIASTREAM, | 47 CONTENT_SETTINGS_TYPE_MEDIASTREAM, |
44 CONTENT_SETTINGS_TYPE_COOKIES}; | 48 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 49 CONTENT_SETTINGS_TYPE_POPUPS}; |
45 const size_t kValidTypesLength = arraysize(kValidTypes); | 50 const size_t kValidTypesLength = arraysize(kValidTypes); |
46 | 51 |
47 } // namespace | 52 } // namespace |
48 | 53 |
49 namespace options { | 54 namespace options { |
50 | 55 |
51 WebsiteSettingsHandler::WebsiteSettingsHandler() | 56 WebsiteSettingsHandler::WebsiteSettingsHandler() |
52 : observer_(this), | 57 : observer_(this), |
53 weak_ptr_factory_(this) { | 58 weak_ptr_factory_(this) { |
54 } | 59 } |
55 | 60 |
56 WebsiteSettingsHandler::~WebsiteSettingsHandler() { | 61 WebsiteSettingsHandler::~WebsiteSettingsHandler() { |
57 } | 62 } |
58 | 63 |
59 void WebsiteSettingsHandler::GetLocalizedValues( | 64 void WebsiteSettingsHandler::GetLocalizedValues( |
60 base::DictionaryValue* localized_strings) { | 65 base::DictionaryValue* localized_strings) { |
61 DCHECK(localized_strings); | 66 DCHECK(localized_strings); |
62 | 67 |
63 static OptionsStringResource resources[] = { | 68 static OptionsStringResource resources[] = { |
64 {"websitesOptionsPageTabTitle", IDS_WEBSITE_SETTINGS_TITLE}, | 69 {"websitesOptionsPageTabTitle", IDS_WEBSITE_SETTINGS_TITLE}, |
65 {"websitesSettingsEditPage", IDS_WEBSITE_SETTINGS_EDIT_TITLE}, | 70 {"websitesSettingsEditPage", IDS_WEBSITE_SETTINGS_EDIT_TITLE}, |
66 {"websitesManage", IDS_WEBSITE_SETTINGS_MANAGE}, | 71 {"websitesManage", IDS_WEBSITE_SETTINGS_MANAGE}, |
67 {"websitesSearch", IDS_WEBSITE_SETTINGS_SEARCH_ORIGINS}, | 72 {"websitesSearch", IDS_WEBSITE_SETTINGS_SEARCH_ORIGINS}, |
68 {"websitesLabelGeolocation", IDS_WEBSITE_SETTINGS_TYPE_LOCATION}, | 73 {"websitesLabelGeolocation", IDS_WEBSITE_SETTINGS_TYPE_LOCATION}, |
69 {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, | 74 {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, |
70 {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, | 75 {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, |
71 {"websitesLabelStorage", IDS_WEBSITE_SETTINGS_TYPE_STORAGE}, | 76 {"websitesLabelStorage", IDS_WEBSITE_SETTINGS_TYPE_STORAGE}, |
72 {"websitesLabelBattery", IDS_WEBSITE_SETTINGS_TYPE_BATTERY}, | 77 {"websitesLabelBattery", IDS_WEBSITE_SETTINGS_TYPE_BATTERY}, |
73 {"websitesCookiesDescription", IDS_WEBSITE_SETTINGS_COOKIES_DESCRIPTION}, | 78 {"websitesCookiesDescription", IDS_WEBSITE_SETTINGS_COOKIES_DESCRIPTION}, |
74 {"websitesLocationDescription", | 79 {"websitesGeolocationDescription", |
75 IDS_WEBSITE_SETTINGS_LOCATION_DESCRIPTION}, | 80 IDS_WEBSITE_SETTINGS_LOCATION_DESCRIPTION}, |
76 {"websitesMediastreamDescription", | 81 {"websitesMediastreamDescription", |
77 IDS_WEBSITE_SETTINGS_MEDIASTREAM_DESCRIPTION}, | 82 IDS_WEBSITE_SETTINGS_MEDIASTREAM_DESCRIPTION}, |
78 {"websitesNotificationsDescription", | 83 {"websitesNotificationsDescription", |
79 IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION}, | 84 IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION}, |
| 85 {"websitesMultipleautomaticdownloadsDescription", |
| 86 IDS_WEBSITE_SETTINGS_DOWNLOAD_DESCRIPTION}, |
| 87 {"websitesPluginsDescription", IDS_WEBSITE_SETTINGS_PLUGINS_DESCRIPTION}, |
| 88 {"websitesPopupsDescription", IDS_WEBSITE_SETTINGS_POPUPS_DESCRIPTION}, |
| 89 {"websitesJavascriptDescription", |
| 90 IDS_WEBSITE_SETTINGS_JAVASCRIPT_DESCRIPTION}, |
| 91 {"websitesImagesDescription", IDS_WEBSITE_SETTINGS_IMAGES_DESCRIPTION}, |
80 {"websitesButtonClear", IDS_WEBSITE_SETTINGS_STORAGE_CLEAR_BUTTON}, | 92 {"websitesButtonClear", IDS_WEBSITE_SETTINGS_STORAGE_CLEAR_BUTTON}, |
81 {"websitesButtonStop", IDS_WEBSITE_SETTINGS_BATTERY_STOP_BUTTON}, | 93 {"websitesButtonStop", IDS_WEBSITE_SETTINGS_BATTERY_STOP_BUTTON}, |
82 }; | 94 }; |
83 | 95 |
84 RegisterStrings(localized_strings, resources, arraysize(resources)); | 96 RegisterStrings(localized_strings, resources, arraysize(resources)); |
85 RegisterTitle( | 97 RegisterTitle( |
86 localized_strings, "websiteSettingsPage", IDS_WEBSITE_SETTINGS_TITLE); | 98 localized_strings, "websiteSettingsPage", IDS_WEBSITE_SETTINGS_TITLE); |
87 } | 99 } |
88 | 100 |
89 void WebsiteSettingsHandler::InitializeHandler() { | 101 void WebsiteSettingsHandler::InitializeHandler() { |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 map->GetDefaultContentSetting(settings_type, NULL); | 352 map->GetDefaultContentSetting(settings_type, NULL); |
341 | 353 |
342 // Users are not allowed to be the source of the "ask" setting. It is an | 354 // Users are not allowed to be the source of the "ask" setting. It is an |
343 // ephemeral setting which is removed once the question is asked. | 355 // ephemeral setting which is removed once the question is asked. |
344 if (setting == CONTENT_SETTING_ASK && setting == default_value) | 356 if (setting == CONTENT_SETTING_ASK && setting == default_value) |
345 setting = CONTENT_SETTING_DEFAULT; | 357 setting = CONTENT_SETTING_DEFAULT; |
346 | 358 |
347 ContentSettingsPattern primary_pattern; | 359 ContentSettingsPattern primary_pattern; |
348 ContentSettingsPattern secondary_pattern; | 360 ContentSettingsPattern secondary_pattern; |
349 switch (settings_type) { | 361 switch (settings_type) { |
350 case CONTENT_SETTINGS_TYPE_COOKIES: | |
351 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); | |
352 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); | |
353 break; | |
354 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 362 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
355 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); | 363 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); |
356 secondary_pattern = ContentSettingsPattern::Wildcard(); | 364 secondary_pattern = ContentSettingsPattern::Wildcard(); |
357 break; | 365 break; |
358 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | |
359 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); | |
360 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); | |
361 break; | |
362 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: | 366 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: |
363 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); | 367 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); |
364 secondary_pattern = ContentSettingsPattern::Wildcard(); | 368 secondary_pattern = ContentSettingsPattern::Wildcard(); |
365 map->SetContentSetting(primary_pattern, | 369 map->SetContentSetting(primary_pattern, |
366 secondary_pattern, | 370 secondary_pattern, |
367 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 371 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
368 std::string(), | 372 std::string(), |
369 setting); | 373 setting); |
370 map->SetContentSetting(primary_pattern, | 374 map->SetContentSetting(primary_pattern, |
371 secondary_pattern, | 375 secondary_pattern, |
372 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 376 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
373 std::string(), | 377 std::string(), |
374 setting); | 378 setting); |
375 return; | 379 return; |
| 380 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: |
| 381 case CONTENT_SETTINGS_TYPE_COOKIES: |
| 382 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 383 case CONTENT_SETTINGS_TYPE_IMAGES: |
| 384 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: |
| 385 case CONTENT_SETTINGS_TYPE_PLUGINS: |
| 386 case CONTENT_SETTINGS_TYPE_POPUPS: |
| 387 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); |
| 388 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); |
| 389 break; |
376 default: | 390 default: |
377 NOTREACHED() << "Content settings type not yet supported."; | 391 NOTREACHED() << "Content settings type not yet supported."; |
378 break; | 392 return; |
379 } | 393 } |
380 | 394 |
381 content_settings::SettingInfo info; | 395 content_settings::SettingInfo info; |
382 scoped_ptr<base::Value> v(map->GetWebsiteSetting( | 396 scoped_ptr<base::Value> v(map->GetWebsiteSetting( |
383 last_site_, last_site_, settings_type, std::string(), &info)); | 397 last_site_, last_site_, settings_type, std::string(), &info)); |
384 map->SetNarrowestWebsiteSetting(primary_pattern, | 398 map->SetNarrowestWebsiteSetting(primary_pattern, |
385 secondary_pattern, | 399 secondary_pattern, |
386 settings_type, | 400 settings_type, |
387 std::string(), | 401 std::string(), |
388 setting, | 402 setting, |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 // If extension is NULL, it was removed and we cannot look up its name. | 621 // If extension is NULL, it was removed and we cannot look up its name. |
608 if (!extension) | 622 if (!extension) |
609 return site_url.spec(); | 623 return site_url.spec(); |
610 | 624 |
611 return extension->name(); | 625 return extension->name(); |
612 } | 626 } |
613 return site_url.spec(); | 627 return site_url.spec(); |
614 } | 628 } |
615 | 629 |
616 } // namespace options | 630 } // namespace options |
OLD | NEW |