Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/notifications/android_settings_provider.h" | |
| 6 | |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "base/android/jni_string.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/strings/string_util.h" | |
| 11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "components/content_settings/core/browser/content_settings_details.h" | |
| 14 #include "components/content_settings/core/browser/content_settings_utils.h" | |
| 15 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
| 16 #include "components/content_settings/core/common/content_settings.h" | |
| 17 #include "components/content_settings/core/common/content_settings_pattern.h" | |
| 18 #include "jni/NotificationSettingsBridge_jni.h" | |
| 19 #include "url/gurl.h" | |
| 20 #include "url/url_constants.h" | |
| 21 | |
| 22 using base::android::AttachCurrentThread; | |
| 23 using base::android::ConvertUTF8ToJavaString; | |
| 24 using base::android::ScopedJavaLocalRef; | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 // A Java counterpart will be generated for this enum. | |
| 29 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.notifications | |
| 30 enum NotificationChannelStatus { ENABLED, BLOCKED, UNAVAILABLE }; | |
| 31 | |
| 32 } // anonymous namespace | |
| 33 | |
| 34 namespace content_settings { | |
| 35 | |
| 36 AndroidSettingsProvider::AndroidSettingsProvider() | |
| 37 : should_use_channels_( | |
| 38 Java_NotificationSettingsBridge_shouldUseChannelSettings( | |
| 39 AttachCurrentThread())) {} | |
| 40 | |
| 41 AndroidSettingsProvider::~AndroidSettingsProvider() {} | |
|
Peter Beverloo
2017/05/15 15:10:08
micro nit: {} -> = default;
awdf
2017/05/16 15:17:35
Done.
| |
| 42 | |
| 43 std::unique_ptr<RuleIterator> AndroidSettingsProvider::GetRuleIterator( | |
| 44 ContentSettingsType content_type, | |
| 45 const ResourceIdentifier& resource_identifier, | |
| 46 bool incognito) const { | |
| 47 // TODO(crbug.com/700377) return rule iterator over all channels | |
| 48 return nullptr; | |
| 49 } | |
| 50 | |
| 51 bool AndroidSettingsProvider::SetWebsiteSetting( | |
| 52 const ContentSettingsPattern& primary_pattern, | |
| 53 const ContentSettingsPattern& secondary_pattern, | |
| 54 ContentSettingsType content_type, | |
| 55 const ResourceIdentifier& resource_identifier, | |
| 56 base::Value* value) { | |
| 57 if (content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS || | |
|
raymes
2017/05/16 01:08:18
Should we just DCHECK that it's only notifications
awdf
2017/05/16 15:17:35
But won't this get all types of content settings u
raymes
2017/05/17 03:13:38
Ah good point, you're right. Sorry for the misguid
| |
| 58 !should_use_channels_) | |
| 59 return false; | |
|
Peter Beverloo
2017/05/15 15:10:08
micro nit: {} (multi-line statement)
awdf
2017/05/16 15:17:35
Done.
| |
| 60 GURL primary_url = GURL(primary_pattern.ToString()); | |
| 61 if (!primary_url.is_valid()) | |
|
Peter Beverloo
2017/05/15 15:10:08
This warrants a comment
raymes
2017/05/16 01:08:18
Would this be better as DCHECK too?
awdf
2017/05/16 15:17:35
Done.
awdf
2017/05/16 15:17:35
hmmm good question.
I agree it might be useful t
raymes
2017/05/17 03:13:38
I guess my thought is that if there are callers pa
awdf
2017/05/17 17:14:40
Okay I have added the DCHECK here and in HCSM on A
| |
| 62 return false; | |
| 63 JNIEnv* env = AttachCurrentThread(); | |
| 64 const std::string origin = primary_url.spec(); | |
| 65 ScopedJavaLocalRef<jstring> jorigin = ConvertUTF8ToJavaString(env, origin); | |
| 66 ContentSetting setting = ValueToContentSetting(value); | |
| 67 switch (setting) { | |
| 68 case CONTENT_SETTING_ALLOW: | |
| 69 case CONTENT_SETTING_BLOCK: { | |
| 70 auto channel_status = static_cast<NotificationChannelStatus>( | |
| 71 Java_NotificationSettingsBridge_getChannelStatus(env, jorigin)); | |
| 72 if (channel_status == NotificationChannelStatus::UNAVAILABLE) { | |
| 73 bool result = Java_NotificationSettingsBridge_createChannel( | |
| 74 env, jorigin, setting == CONTENT_SETTING_ALLOW /* enabled */); | |
| 75 return result; | |
|
Peter Beverloo
2017/05/15 15:10:08
When would creating a channel fail?
awdf
2017/05/16 15:17:35
Well right now it does because I haven't implement
| |
| 76 } | |
|
raymes
2017/05/16 01:08:18
What if there was already a channel created but th
awdf
2017/05/16 15:17:35
Done.
| |
| 77 return true; | |
| 78 } | |
| 79 case CONTENT_SETTING_ASK: | |
|
raymes
2017/05/16 01:08:18
This should never be passed in so I think we can r
awdf
2017/05/16 15:17:35
Done.
| |
| 80 case CONTENT_SETTING_DEFAULT: | |
| 81 Java_NotificationSettingsBridge_deleteChannel(env, jorigin); | |
| 82 return false; | |
| 83 default: | |
| 84 return false; | |
|
raymes
2017/05/16 01:08:17
I'd suggest DCHECKing here too
awdf
2017/05/16 15:17:35
again I wonder about dchecking this earlier on, if
| |
| 85 } | |
| 86 } | |
| 87 | |
| 88 void AndroidSettingsProvider::ClearAllContentSettingsRules( | |
| 89 ContentSettingsType content_type) { | |
| 90 // TODO(crbug.com/700377) delete all channels | |
|
Peter Beverloo
2017/05/15 15:10:08
nit: if |content_type| == NOTIFICATIONS
raymes
2017/05/16 01:08:17
DCHECK here too?
awdf
2017/05/16 15:17:35
again, I don't think I can?
awdf
2017/05/16 15:17:35
Done.
| |
| 91 } | |
| 92 | |
| 93 void AndroidSettingsProvider::ShutdownOnUIThread() { | |
| 94 RemoveAllObservers(); | |
| 95 } | |
| 96 | |
| 97 } // namespace content_settings | |
| OLD | NEW |