Index: chrome/browser/notifications/notification_channels_provider_android.cc |
diff --git a/chrome/browser/notifications/notification_channels_provider_android.cc b/chrome/browser/notifications/notification_channels_provider_android.cc |
index f865fb126b9e95ab59de07953c75cbdbf6426046..d58f600b277cb9d98ed6b6382de0e3217d6f665b 100644 |
--- a/chrome/browser/notifications/notification_channels_provider_android.cc |
+++ b/chrome/browser/notifications/notification_channels_provider_android.cc |
@@ -11,6 +11,7 @@ |
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
#include "chrome/browser/profiles/profile.h" |
#include "components/content_settings/core/browser/content_settings_details.h" |
+#include "components/content_settings/core/browser/content_settings_rule.h" |
#include "components/content_settings/core/browser/content_settings_utils.h" |
#include "components/content_settings/core/browser/host_content_settings_map.h" |
#include "components/content_settings/core/common/content_settings.h" |
@@ -56,6 +57,62 @@ class NotificationChannelsBridgeImpl |
Java_NotificationSettingsBridge_deleteChannel( |
env, ConvertUTF8ToJavaString(env, origin)); |
} |
+ |
+ std::vector<NotificationChannel> GetChannels() override { |
+ JNIEnv* env = AttachCurrentThread(); |
+ ScopedJavaLocalRef<jobjectArray> raw_channels = |
+ Java_NotificationSettingsBridge_getSiteChannels(env); |
+ jsize num_channels = env->GetArrayLength(raw_channels.obj()); |
+ std::vector<NotificationChannel> channels; |
+ for (jsize i = 0; i < num_channels; ++i) { |
+ jobject jchannel = env->GetObjectArrayElement(raw_channels.obj(), i); |
+ channels.emplace_back( |
+ ConvertJavaStringToUTF8(Java_SiteChannel_getOrigin(env, jchannel)), |
+ static_cast<NotificationChannelStatus>( |
+ Java_SiteChannel_getStatus(env, jchannel))); |
+ } |
+ return channels; |
+ } |
+}; |
+ |
+ContentSetting ChannelStatusToContentSetting(NotificationChannelStatus status) { |
+ switch (status) { |
+ case NotificationChannelStatus::ENABLED: |
+ return CONTENT_SETTING_ALLOW; |
+ case NotificationChannelStatus::BLOCKED: |
+ return CONTENT_SETTING_BLOCK; |
+ case NotificationChannelStatus::UNAVAILABLE: |
+ return CONTENT_SETTING_DEFAULT; |
raymes
2017/06/04 23:51:21
Arguably UNAVAILABLE doesn't really map to a conte
awdf
2017/06/05 16:29:26
Done.
|
+ } |
+ NOTREACHED(); |
+ return CONTENT_SETTING_DEFAULT; |
+} |
+ |
+class ChannelsRuleIterator : public content_settings::RuleIterator { |
+ public: |
+ explicit ChannelsRuleIterator(std::vector<NotificationChannel> channels) |
+ : channels_(std::move(channels)), index_(0) {} |
+ |
+ ~ChannelsRuleIterator() override {} |
Peter Beverloo
2017/06/05 12:40:24
micro nit: {} -> = default;
|
+ |
+ bool HasNext() const override { return index_ < channels_.size(); } |
+ |
+ content_settings::Rule Next() override { |
+ DCHECK(HasNext()); |
+ DCHECK_NE(channels_[index_].status_, |
+ NotificationChannelStatus::UNAVAILABLE); |
+ content_settings::Rule rule = content_settings::Rule( |
+ ContentSettingsPattern::FromString(channels_[index_].origin_), |
+ ContentSettingsPattern(), |
raymes
2017/06/04 23:51:21
I think returning ContentSettingsPattern::Wildcard
awdf
2017/06/05 16:29:26
Done.
|
+ new base::Value( |
+ ChannelStatusToContentSetting(channels_[index_].status_))); |
+ index_++; |
+ return rule; |
+ } |
+ |
+ private: |
+ std::vector<NotificationChannel> channels_; |
+ size_t index_; |
}; |
Peter Beverloo
2017/06/05 12:40:24
nit: DISALLOW_COPY_AND_ASSIGN
awdf
2017/06/05 16:29:26
Done.
|
} // anonymous namespace |
@@ -77,8 +134,14 @@ NotificationChannelsProviderAndroid::GetRuleIterator( |
ContentSettingsType content_type, |
const content_settings::ResourceIdentifier& resource_identifier, |
bool incognito) const { |
- // TODO(crbug.com/700377) return rule iterator over all channels |
- return nullptr; |
+ if (content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS || incognito || |
Peter Beverloo
2017/06/05 12:40:24
nit: please document what this means
We don't ena
awdf
2017/06/05 16:29:26
Right. But I have two questions:
1. Since this is
Peter Beverloo
2017/06/05 17:12:50
To be frank: I don't know whether we'd inherit the
awdf
2017/06/05 17:33:36
Re:
raymes
2017/06/06 01:39:04
If incognito is true, this should just return sett
awdf
2017/06/08 15:53:46
Thanks. Added a TODO for now, will discuss with Pe
|
+ !should_use_channels_) { |
+ return nullptr; |
+ } |
+ std::vector<NotificationChannel> channels = bridge_->GetChannels(); |
+ return channels.empty() |
+ ? nullptr |
+ : base::MakeUnique<ChannelsRuleIterator>(std::move(channels)); |
} |
bool NotificationChannelsProviderAndroid::SetWebsiteSetting( |