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

Side by Side Diff: components/content_settings/core/browser/host_content_settings_map.cc

Issue 2886433002: [Android] Adding content settings provider for notification channels (Closed)
Patch Set: Improve comment and fixup site engagement service test Created 3 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
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 "components/content_settings/core/browser/host_content_settings_map.h" 5 #include "components/content_settings/core/browser/host_content_settings_map.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 struct ProviderNamesSourceMapEntry { 48 struct ProviderNamesSourceMapEntry {
49 const char* provider_name; 49 const char* provider_name;
50 content_settings::SettingSource provider_source; 50 content_settings::SettingSource provider_source;
51 }; 51 };
52 52
53 const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = { 53 const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = {
54 {"platform_app", content_settings::SETTING_SOURCE_EXTENSION}, 54 {"platform_app", content_settings::SETTING_SOURCE_EXTENSION},
55 {"policy", content_settings::SETTING_SOURCE_POLICY}, 55 {"policy", content_settings::SETTING_SOURCE_POLICY},
56 {"supervised_user", content_settings::SETTING_SOURCE_SUPERVISED}, 56 {"supervised_user", content_settings::SETTING_SOURCE_SUPERVISED},
57 {"extension", content_settings::SETTING_SOURCE_EXTENSION}, 57 {"extension", content_settings::SETTING_SOURCE_EXTENSION},
58 {"notification_android", content_settings::SETTING_SOURCE_USER},
58 {"preference", content_settings::SETTING_SOURCE_USER}, 59 {"preference", content_settings::SETTING_SOURCE_USER},
59 {"default", content_settings::SETTING_SOURCE_USER}, 60 {"default", content_settings::SETTING_SOURCE_USER},
60 }; 61 };
61 62
62 // Enum describing the status of domain to origin migration of content settings. 63 // Enum describing the status of domain to origin migration of content settings.
63 // Migration will be done twice: once upon construction of the 64 // Migration will be done twice: once upon construction of the
64 // HostContentSettingsMap (before syncing any content settings) and once after 65 // HostContentSettingsMap (before syncing any content settings) and once after
65 // sync has finished. We always migrate before sync to ensure that settings will 66 // sync has finished. We always migrate before sync to ensure that settings will
66 // get migrated even if a user doesn't have sync enabled. We migrate after sync 67 // get migrated even if a user doesn't have sync enabled. We migrate after sync
67 // to ensure that any sync'd settings will be migrated. Once these events have 68 // to ensure that any sync'd settings will be migrated. Once these events have
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } 378 }
378 379
379 void HostContentSettingsMap::SetWebsiteSettingCustomScope( 380 void HostContentSettingsMap::SetWebsiteSettingCustomScope(
380 const ContentSettingsPattern& primary_pattern, 381 const ContentSettingsPattern& primary_pattern,
381 const ContentSettingsPattern& secondary_pattern, 382 const ContentSettingsPattern& secondary_pattern,
382 ContentSettingsType content_type, 383 ContentSettingsType content_type,
383 const std::string& resource_identifier, 384 const std::string& resource_identifier,
384 std::unique_ptr<base::Value> value) { 385 std::unique_ptr<base::Value> value) {
385 DCHECK(SupportsResourceIdentifier(content_type) || 386 DCHECK(SupportsResourceIdentifier(content_type) ||
386 resource_identifier.empty()); 387 resource_identifier.empty());
388 #if defined(OS_ANDROID) && DCHECK_IS_ON()
389 // The notification permission on Android only allows valid origins with a
390 // restricted set of settings, or the global wildcard origin.
391 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS &&
392 !primary_pattern.MatchesAllHosts()) {
393 // The |primary_pattern| must be a valid GURL as it may be presented to the
394 // user: Android Notification Channels may be used on Android O onward.
395 DCHECK(GURL(primary_pattern.ToString()).is_valid());
396
397 ContentSetting setting =
398 content_settings::ValueToContentSetting(value.get());
399
400 // Disallow notification content setting updates for specific origins that
401 // are not ALLOW/BLOCK/DEFAULT on Android.
402 DCHECK(setting == CONTENT_SETTING_ALLOW ||
403 setting == CONTENT_SETTING_BLOCK ||
404 setting == CONTENT_SETTING_DEFAULT);
405 }
406 #endif
raymes 2017/06/06 01:08:14 This is getting complicated and I'm not quite happ
awdf 2017/06/08 14:46:11 I agree there's got to be a nicer way to ensure ou
407
387 UsedContentSettingsProviders(); 408 UsedContentSettingsProviders();
388 409
389 for (const auto& provider_pair : content_settings_providers_) { 410 for (const auto& provider_pair : content_settings_providers_) {
390 if (provider_pair.second->SetWebsiteSetting( 411 if (provider_pair.second->SetWebsiteSetting(
391 primary_pattern, secondary_pattern, content_type, 412 primary_pattern, secondary_pattern, content_type,
392 resource_identifier, value.get())) { 413 resource_identifier, value.get())) {
393 // If successful then ownership is passed to the provider. 414 // If successful then ownership is passed to the provider.
394 ignore_result(value.release()); 415 ignore_result(value.release());
395 return; 416 return;
396 } 417 }
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 return base::WrapUnique(rule.value.get()->DeepCopy()); 924 return base::WrapUnique(rule.value.get()->DeepCopy());
904 } 925 }
905 } 926 }
906 } 927 }
907 return std::unique_ptr<base::Value>(); 928 return std::unique_ptr<base::Value>();
908 } 929 }
909 930
910 void HostContentSettingsMap::SetClockForTesting( 931 void HostContentSettingsMap::SetClockForTesting(
911 std::unique_ptr<base::Clock> clock) { 932 std::unique_ptr<base::Clock> clock) {
912 pref_provider_->SetClockForTesting(std::move(clock)); 933 pref_provider_->SetClockForTesting(std::move(clock));
913 } 934 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698