| 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/ui/webui/options/content_settings_handler.h" | 5 #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 // Here we only subscribe to the HostZoomMap for the default storage partition | 730 // Here we only subscribe to the HostZoomMap for the default storage partition |
| 731 // since we don't allow the user to manage the zoom levels for apps. | 731 // since we don't allow the user to manage the zoom levels for apps. |
| 732 // We're only interested in zoom-levels that are persisted, since the user | 732 // We're only interested in zoom-levels that are persisted, since the user |
| 733 // is given the opportunity to view/delete these in the content-settings page. | 733 // is given the opportunity to view/delete these in the content-settings page. |
| 734 host_zoom_map_subscription_ = | 734 host_zoom_map_subscription_ = |
| 735 content::HostZoomMap::GetDefaultForBrowserContext(context) | 735 content::HostZoomMap::GetDefaultForBrowserContext(context) |
| 736 ->AddZoomLevelChangedCallback( | 736 ->AddZoomLevelChangedCallback( |
| 737 base::Bind(&ContentSettingsHandler::OnZoomLevelChanged, | 737 base::Bind(&ContentSettingsHandler::OnZoomLevelChanged, |
| 738 base::Unretained(this))); | 738 base::Unretained(this))); |
| 739 | 739 |
| 740 if (!switches::IsEnableWebviewBasedSignin()) { | |
| 741 // The legacy signin page uses a different storage partition, so we need to | |
| 742 // add a subscription for its HostZoomMap separately. | |
| 743 GURL signin_url(chrome::kChromeUIChromeSigninURL); | |
| 744 content::StoragePartition* signin_partition = | |
| 745 content::BrowserContext::GetStoragePartitionForSite( | |
| 746 GetBrowserContext(web_ui()), signin_url); | |
| 747 content::HostZoomMap* signin_host_zoom_map = | |
| 748 signin_partition->GetHostZoomMap(); | |
| 749 signin_host_zoom_map_subscription_ = | |
| 750 signin_host_zoom_map->AddZoomLevelChangedCallback( | |
| 751 base::Bind(&ContentSettingsHandler::OnZoomLevelChanged, | |
| 752 base::Unretained(this))); | |
| 753 } | |
| 754 | |
| 755 flash_settings_manager_.reset(new PepperFlashSettingsManager(this, context)); | 740 flash_settings_manager_.reset(new PepperFlashSettingsManager(this, context)); |
| 756 | 741 |
| 757 Profile* profile = Profile::FromWebUI(web_ui()); | 742 Profile* profile = Profile::FromWebUI(web_ui()); |
| 758 observer_.Add(HostContentSettingsMapFactory::GetForProfile(profile)); | 743 observer_.Add(HostContentSettingsMapFactory::GetForProfile(profile)); |
| 759 if (profile->HasOffTheRecordProfile()) { | 744 if (profile->HasOffTheRecordProfile()) { |
| 760 auto map = HostContentSettingsMapFactory::GetForProfile( | 745 auto map = HostContentSettingsMapFactory::GetForProfile( |
| 761 profile->GetOffTheRecordProfile()); | 746 profile->GetOffTheRecordProfile()); |
| 762 if (!observer_.IsObserving(map)) | 747 if (!observer_.IsObserving(map)) |
| 763 observer_.Add(map); | 748 observer_.Add(map); |
| 764 } | 749 } |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 for (auto& one_provider_exceptions : all_provider_exceptions) { | 1181 for (auto& one_provider_exceptions : all_provider_exceptions) { |
| 1197 for (auto& exception : one_provider_exceptions) | 1182 for (auto& exception : one_provider_exceptions) |
| 1198 exceptions.Append(exception.Pass()); | 1183 exceptions.Append(exception.Pass()); |
| 1199 } | 1184 } |
| 1200 | 1185 |
| 1201 base::StringValue type_string(chooser_type.name); | 1186 base::StringValue type_string(chooser_type.name); |
| 1202 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", type_string, | 1187 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", type_string, |
| 1203 exceptions); | 1188 exceptions); |
| 1204 } | 1189 } |
| 1205 | 1190 |
| 1206 void ContentSettingsHandler::AdjustZoomLevelsListForSigninPageIfNecessary( | |
| 1207 content::HostZoomMap::ZoomLevelVector* zoom_levels) { | |
| 1208 if (switches::IsEnableWebviewBasedSignin()) | |
| 1209 return; | |
| 1210 | |
| 1211 GURL signin_url(chrome::kChromeUIChromeSigninURL); | |
| 1212 content::HostZoomMap* signin_host_zoom_map = | |
| 1213 content::BrowserContext::GetStoragePartitionForSite( | |
| 1214 GetBrowserContext(web_ui()), signin_url)->GetHostZoomMap(); | |
| 1215 | |
| 1216 // Since zoom levels set for scheme + host are not persisted, and since the | |
| 1217 // signin page zoom levels need to be persisted, they are stored without | |
| 1218 // a scheme. We use an empty scheme string to indicate this. | |
| 1219 std::string scheme; | |
| 1220 std::string host = signin_url.host(); | |
| 1221 | |
| 1222 // If there's a WebView signin zoom level, remove it. | |
| 1223 content::HostZoomMap::ZoomLevelVector::iterator it = | |
| 1224 std::find_if(zoom_levels->begin(), zoom_levels->end(), | |
| 1225 [&host](content::HostZoomMap::ZoomLevelChange change) { | |
| 1226 return change.host == host; | |
| 1227 }); | |
| 1228 if (it != zoom_levels->end()) | |
| 1229 zoom_levels->erase(it); | |
| 1230 | |
| 1231 // If there's a non-WebView signin zoom level, add it. | |
| 1232 if (signin_host_zoom_map->HasZoomLevel(scheme, host)) { | |
| 1233 content::HostZoomMap::ZoomLevelChange change = { | |
| 1234 content::HostZoomMap::ZOOM_CHANGED_FOR_HOST, | |
| 1235 host, | |
| 1236 scheme, | |
| 1237 signin_host_zoom_map->GetZoomLevelForHostAndScheme(scheme, host)}; | |
| 1238 zoom_levels->push_back(change); | |
| 1239 } | |
| 1240 } | |
| 1241 | |
| 1242 void ContentSettingsHandler::UpdateZoomLevelsExceptionsView() { | 1191 void ContentSettingsHandler::UpdateZoomLevelsExceptionsView() { |
| 1243 base::ListValue zoom_levels_exceptions; | 1192 base::ListValue zoom_levels_exceptions; |
| 1244 | 1193 |
| 1245 content::HostZoomMap* host_zoom_map = | 1194 content::HostZoomMap* host_zoom_map = |
| 1246 content::HostZoomMap::GetDefaultForBrowserContext( | 1195 content::HostZoomMap::GetDefaultForBrowserContext( |
| 1247 GetBrowserContext(web_ui())); | 1196 GetBrowserContext(web_ui())); |
| 1248 content::HostZoomMap::ZoomLevelVector zoom_levels( | 1197 content::HostZoomMap::ZoomLevelVector zoom_levels( |
| 1249 host_zoom_map->GetAllZoomLevels()); | 1198 host_zoom_map->GetAllZoomLevels()); |
| 1250 | 1199 |
| 1251 AdjustZoomLevelsListForSigninPageIfNecessary(&zoom_levels); | |
| 1252 | |
| 1253 // Sort ZoomLevelChanges by host and scheme | 1200 // Sort ZoomLevelChanges by host and scheme |
| 1254 // (a.com < http://a.com < https://a.com < b.com). | 1201 // (a.com < http://a.com < https://a.com < b.com). |
| 1255 std::sort(zoom_levels.begin(), zoom_levels.end(), | 1202 std::sort(zoom_levels.begin(), zoom_levels.end(), |
| 1256 [](const content::HostZoomMap::ZoomLevelChange& a, | 1203 [](const content::HostZoomMap::ZoomLevelChange& a, |
| 1257 const content::HostZoomMap::ZoomLevelChange& b) { | 1204 const content::HostZoomMap::ZoomLevelChange& b) { |
| 1258 return a.host == b.host ? a.scheme < b.scheme : a.host < b.host; | 1205 return a.host == b.host ? a.scheme < b.scheme : a.host < b.host; |
| 1259 }); | 1206 }); |
| 1260 | 1207 |
| 1261 for (content::HostZoomMap::ZoomLevelVector::const_iterator i = | 1208 for (content::HostZoomMap::ZoomLevelVector::const_iterator i = |
| 1262 zoom_levels.begin(); | 1209 zoom_levels.begin(); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 std::string pattern; | 1464 std::string pattern; |
| 1518 rv = args->GetString(2, &pattern); | 1465 rv = args->GetString(2, &pattern); |
| 1519 DCHECK(rv); | 1466 DCHECK(rv); |
| 1520 | 1467 |
| 1521 if (pattern == | 1468 if (pattern == |
| 1522 l10n_util::GetStringUTF8(IDS_ZOOMLEVELS_CHROME_ERROR_PAGES_LABEL)) { | 1469 l10n_util::GetStringUTF8(IDS_ZOOMLEVELS_CHROME_ERROR_PAGES_LABEL)) { |
| 1523 pattern = content::kUnreachableWebDataURL; | 1470 pattern = content::kUnreachableWebDataURL; |
| 1524 } | 1471 } |
| 1525 | 1472 |
| 1526 content::HostZoomMap* host_zoom_map; | 1473 content::HostZoomMap* host_zoom_map; |
| 1527 if (switches::IsEnableWebviewBasedSignin() || | 1474 host_zoom_map = |
| 1528 pattern != chrome::kChromeUIChromeSigninHost) { | 1475 content::HostZoomMap::GetDefaultForBrowserContext( |
| 1529 host_zoom_map = | 1476 GetBrowserContext(web_ui())); |
| 1530 content::HostZoomMap::GetDefaultForBrowserContext( | |
| 1531 GetBrowserContext(web_ui())); | |
| 1532 } else { | |
| 1533 host_zoom_map = | |
| 1534 content::BrowserContext::GetStoragePartitionForSite( | |
| 1535 GetBrowserContext(web_ui()), GURL(chrome::kChromeUIChromeSigninURL)) | |
| 1536 ->GetHostZoomMap(); | |
| 1537 } | |
| 1538 double default_level = host_zoom_map->GetDefaultZoomLevel(); | 1477 double default_level = host_zoom_map->GetDefaultZoomLevel(); |
| 1539 host_zoom_map->SetZoomLevelForHost(pattern, default_level); | 1478 host_zoom_map->SetZoomLevelForHost(pattern, default_level); |
| 1540 } | 1479 } |
| 1541 | 1480 |
| 1542 void ContentSettingsHandler::RemoveChooserException( | 1481 void ContentSettingsHandler::RemoveChooserException( |
| 1543 const ChooserTypeNameEntry* chooser_type, | 1482 const ChooserTypeNameEntry* chooser_type, |
| 1544 const base::ListValue* args) { | 1483 const base::ListValue* args) { |
| 1545 std::string mode; | 1484 std::string mode; |
| 1546 bool rv = args->GetString(1, &mode); | 1485 bool rv = args->GetString(1, &mode); |
| 1547 DCHECK(rv); | 1486 DCHECK(rv); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1862 | 1801 |
| 1863 // Exceptions apply only when the feature is enabled. | 1802 // Exceptions apply only when the feature is enabled. |
| 1864 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); | 1803 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); |
| 1865 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); | 1804 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); |
| 1866 web_ui()->CallJavascriptFunction( | 1805 web_ui()->CallJavascriptFunction( |
| 1867 "ContentSettings.enableProtectedContentExceptions", | 1806 "ContentSettings.enableProtectedContentExceptions", |
| 1868 base::FundamentalValue(enable_exceptions)); | 1807 base::FundamentalValue(enable_exceptions)); |
| 1869 } | 1808 } |
| 1870 | 1809 |
| 1871 } // namespace options | 1810 } // namespace options |
| OLD | NEW |