Commit 5b6c23a4 authored by Anita Woodruff's avatar Anita Woodruff Committed by Commit Bot

[Notifications] Enable mojo for service worker notifications

- Enables the mojo pathway by default and removes the legacy IPC
code path for persistent notifications.

- Removes the NotificationsWithMojo feature flag which previously
guarded this code-path during incremental development.

R=kinuko@chromium.org

Bug: 796991
Change-Id: Ia4dac0ab4b98b7a6df342b7df1b424e3af67bf05
Reviewed-on: https://chromium-review.googlesource.com/1027843Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Anita Woodruff <awdf@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557486}
parent 47084bae
......@@ -1007,132 +1007,3 @@ IN_PROC_BROWSER_TEST_F(
// notification should be shown without an image.
EXPECT_TRUE(notifications[0].image().IsEmpty());
}
class PlatformNotificationServiceMojoEnabledBrowserTest
: public PlatformNotificationServiceBrowserTest {
public:
// InProcessBrowserTest overrides.
void SetUpInProcessBrowserTestFixture() override {
scoped_feature_list_.InitWithFeatures({features::kNotificationsWithMojo},
{});
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceMojoEnabledBrowserTest,
DisplayPersistentNotificationWithPermission) {
RequestAndAcceptPermission();
std::string script_result;
ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_none')",
&script_result));
EXPECT_EQ("ok", script_result);
std::vector<message_center::Notification> notifications =
GetDisplayedNotifications(true /* is_persistent */);
ASSERT_EQ(1u, notifications.size());
}
IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceMojoEnabledBrowserTest,
PersistentNotificationServiceWorkerScope) {
RequestAndAcceptPermission();
// Creates a simple notification.
std::string script_result;
ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result));
std::vector<message_center::Notification> notifications =
GetDisplayedNotifications(true /* is_persistent */);
ASSERT_EQ(1u, notifications.size());
EXPECT_EQ(
TestPageUrl(),
PersistentNotificationMetadata::From(
display_service_tester_->GetMetadataForNotification(notifications[0]))
->service_worker_scope);
}
IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceMojoEnabledBrowserTest,
GetDisplayedNotifications) {
RequestAndAcceptPermission();
std::string script_result;
std::string script_message;
ASSERT_TRUE(RunScript("DisplayNonPersistentNotification('NonPersistent')",
&script_result));
EXPECT_EQ("ok", script_result);
ASSERT_TRUE(RunScript("DisplayPersistentNotification('PersistentI')",
&script_result));
EXPECT_EQ("ok", script_result);
ASSERT_TRUE(RunScript("DisplayPersistentNotification('PersistentII')",
&script_result));
EXPECT_EQ("ok", script_result);
// Only the persistent ones should show.
ASSERT_TRUE(RunScript("GetDisplayedNotifications()", &script_result));
EXPECT_EQ("ok", script_result);
ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_message));
std::vector<std::string> notification_ids = base::SplitString(
script_message, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
ASSERT_EQ(2u, notification_ids.size());
const std::string first_id = notification_ids[0];
std::vector<message_center::Notification> notifications =
GetDisplayedNotifications(true /* is_persistent */);
ASSERT_EQ(notification_ids.size(), notifications.size());
// Now remove one of the notifications straight from the ui manager
// without going through the database.
const message_center::Notification& notification = notifications[1];
// p# is the prefix for persistent notifications. See
// content/browser/notifications/notification_id_generator.{h,cc} for details
ASSERT_TRUE(
base::StartsWith(notification.id(), "p#", base::CompareCase::SENSITIVE));
display_service_tester_->RemoveNotification(
NotificationHandler::Type::WEB_PERSISTENT, notification.id(),
false /* by_user */, true /* silent */);
ASSERT_TRUE(RunScript("GetDisplayedNotifications()", &script_result));
EXPECT_EQ("ok", script_result);
ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_message));
notification_ids = base::SplitString(
script_message, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
// The list of displayed notification Ids should have been updated.
ASSERT_EQ(1u, notification_ids.size());
ASSERT_EQ(notification_ids[0], first_id);
}
IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceMojoEnabledBrowserTest,
CloseDisplayedPersistentNotification) {
ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
std::string script_result;
ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_close')",
&script_result));
EXPECT_EQ("ok", script_result);
std::vector<message_center::Notification> notifications =
GetDisplayedNotifications(true /* is_persistent */);
ASSERT_EQ(1u, notifications.size());
display_service_tester_->SimulateClick(
NotificationHandler::Type::WEB_PERSISTENT, notifications[0].id(),
base::nullopt /* action_index */, base::nullopt /* reply */);
ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
EXPECT_EQ("action_close", script_result);
notifications = GetDisplayedNotifications(true /* is_persistent */);
ASSERT_EQ(0u, notifications.size());
}
......@@ -1175,8 +1175,6 @@ jumbo_source_set("browser") {
"notifications/notification_event_dispatcher_impl.h",
"notifications/notification_id_generator.cc",
"notifications/notification_id_generator.h",
"notifications/notification_message_filter.cc",
"notifications/notification_message_filter.h",
"notifications/platform_notification_context_impl.cc",
"notifications/platform_notification_context_impl.h",
"origin_manifest/origin_manifest_parser.cc",
......
......@@ -9,7 +9,6 @@
#include "base/callback_helpers.h"
#include "base/optional.h"
#include "build/build_config.h"
#include "content/browser/notifications/notification_message_filter.h"
#include "content/browser/notifications/platform_notification_context_impl.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_registration.h"
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_
#define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_
#include <stdint.h>
#include <vector>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "content/common/service_worker/service_worker_status_code.h"
#include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/notification_database_data.h"
#include "third_party/blink/public/platform/modules/permissions/permission_status.mojom.h"
class GURL;
namespace content {
class BrowserContext;
class NotificationIdGenerator;
struct NotificationResources;
class PlatformNotificationContextImpl;
struct PlatformNotificationData;
class PlatformNotificationService;
class ResourceContext;
class ServiceWorkerContextWrapper;
class ServiceWorkerRegistration;
class NotificationMessageFilter : public BrowserMessageFilter {
public:
NotificationMessageFilter(
int process_id,
PlatformNotificationContextImpl* notification_context,
ResourceContext* resource_context,
const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context,
BrowserContext* browser_context);
// BrowserMessageFilter implementation. Called on the UI thread.
void OnDestruct() const override;
bool OnMessageReceived(const IPC::Message& message) override;
protected:
~NotificationMessageFilter() override;
private:
friend class base::DeleteHelper<NotificationMessageFilter>;
friend class BrowserThread;
void OnShowPersistentNotification(
int request_id,
int64_t service_worker_registration_id,
const GURL& origin,
const PlatformNotificationData& notification_data,
const NotificationResources& notification_resources);
void OnGetNotifications(int request_id,
int64_t service_worker_registration_id,
const GURL& origin,
const std::string& filter_tag);
void OnClosePersistentNotification(const GURL& origin,
const std::string& tag,
const std::string& notification_id);
// Callback to be invoked by the notification context when the notification
// data for the persistent notification may have been written, as indicated by
// |success|. Will present the notification to the user when successful.
void DidWritePersistentNotificationData(
int request_id,
int64_t service_worker_registration_id,
const GURL& origin,
const PlatformNotificationData& notification_data,
const NotificationResources& notification_resources,
bool success,
const std::string& notification_id);
// Callback to be invoked by the service worker context when the service
// worker registration was retrieved. Will present the notification to the
// user when successful.
void DidFindServiceWorkerRegistration(
int request_id,
const GURL& origin,
const PlatformNotificationData& notification_data,
const NotificationResources& notification_resources,
const std::string& notification_id,
content::ServiceWorkerStatusCode service_worker_status,
scoped_refptr<ServiceWorkerRegistration> registration);
// Callback to be invoked when all notifications belonging to a Service Worker
// registration have been read from the database. The |success| argument
// indicates whether the data could be read successfully, whereas the actual
// notifications will be stored in |notifications|.
void DidGetNotifications(
int request_id,
const std::string& filter_tag,
bool success,
const std::vector<NotificationDatabaseData>& notifications);
// Callback to be invoked when the data associated with a persistent
// notification has been removed by the database, unless an error occurred,
// which will be indicated by |success|.
void DidDeletePersistentNotificationData(bool success);
// Returns the permission status for |origin|. Must only be used on the IO
// thread. If the PlatformNotificationService is unavailable, permission will
// assumed to be denied.
blink::mojom::PermissionStatus GetPermissionForOriginOnIO(
const GURL& origin) const;
// Verifies that Web Notification permission has been granted for |origin| in
// cases where the renderer shouldn't send messages if it weren't the case.
bool VerifyNotificationPermissionGranted(PlatformNotificationService* service,
const GURL& origin);
// Returns the NotificationIdGenerator instance owned by the context.
NotificationIdGenerator* GetNotificationIdGenerator() const;
int process_id_;
scoped_refptr<PlatformNotificationContextImpl> notification_context_;
ResourceContext* resource_context_;
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
BrowserContext* browser_context_;
base::WeakPtrFactory<NotificationMessageFilter> weak_factory_io_;
DISALLOW_COPY_AND_ASSIGN(NotificationMessageFilter);
};
} // namespace content
#endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_
......@@ -103,7 +103,6 @@
#include "content/browser/media/midi_host.h"
#include "content/browser/memory/memory_coordinator_impl.h"
#include "content/browser/mime_registry_impl.h"
#include "content/browser/notifications/notification_message_filter.h"
#include "content/browser/payments/payment_manager.h"
#include "content/browser/permissions/permission_service_context.h"
#include "content/browser/permissions/permission_service_impl.h"
......@@ -1865,10 +1864,6 @@ void RenderProcessHostImpl::CreateMessageFilters() {
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context(
static_cast<ServiceWorkerContextWrapper*>(
storage_partition_impl_->GetServiceWorkerContext()));
notification_message_filter_ = new NotificationMessageFilter(
GetID(), storage_partition_impl_->GetPlatformNotificationContext(),
resource_context, service_worker_context, browser_context);
AddFilter(notification_message_filter_.get());
}
void RenderProcessHostImpl::BindCacheStorage(
......
......@@ -75,7 +75,6 @@ class ChildConnection;
class GpuClientImpl;
class IndexedDBDispatcherHost;
class InProcessChildThreadParams;
class NotificationMessageFilter;
class PermissionServiceContext;
class PeerConnectionTrackerHost;
class PushMessagingManager;
......@@ -334,10 +333,6 @@ class CONTENT_EXPORT RenderProcessHostImpl
return render_frame_message_filter_.get();
}
NotificationMessageFilter* notification_message_filter() const {
return notification_message_filter_.get();
}
void SetBrowserPluginMessageFilterSubFilterForTesting(
scoped_refptr<BrowserMessageFilter> message_filter) const;
......@@ -684,10 +679,6 @@ class CONTENT_EXPORT RenderProcessHostImpl
scoped_refptr<RenderFrameMessageFilter> render_frame_message_filter_;
// The filter for Web Notification messages coming from the renderer. Holds a
// closure per notification that must be freed when the notification closes.
scoped_refptr<NotificationMessageFilter> notification_message_filter_;
// The filter for messages coming from the browser plugin.
scoped_refptr<BrowserPluginMessageFilter> bp_message_filter_;
......
......@@ -326,9 +326,6 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
WebRuntimeFeatures::EnableGenericSensorExtraClasses(true);
}
if (base::FeatureList::IsEnabled(features::kNotificationsWithMojo))
WebRuntimeFeatures::EnableNotificationsWithMojo(true);
if (base::FeatureList::IsEnabled(network::features::kOutOfBlinkCORS))
WebRuntimeFeatures::EnableOutOfBlinkCORS(true);
......
......@@ -17,19 +17,10 @@
#include "content/public/common/platform_notification_data.h"
#include "ipc/ipc_message_macros.h"
// Singly-included section for type definitions.
#ifndef INTERNAL_CONTENT_COMMON_PLATFORM_NOTIFICATION_MESSAGES_H_
#define INTERNAL_CONTENT_COMMON_PLATFORM_NOTIFICATION_MESSAGES_H_
// Defines the pair of [notification id] => [notification data] used when
// getting the notifications for a given Service Worker registration.
using PersistentNotificationInfo =
std::pair<std::string, content::PlatformNotificationData>;
#endif // INTERNAL_CONTENT_COMMON_PLATFORM_NOTIFICATION_MESSAGES_H_
#define IPC_MESSAGE_START PlatformNotificationMsgStart
// TODO(https://crbug.com/841329): Delete this legacy IPC code, use a pure
// mojo struct instead from ServiceWorkerEventDispatcher mojo interface.
IPC_ENUM_TRAITS_MAX_VALUE(
content::PlatformNotificationData::Direction,
content::PlatformNotificationData::DIRECTION_LAST)
......@@ -63,48 +54,4 @@ IPC_STRUCT_TRAITS_BEGIN(content::PlatformNotificationData)
IPC_STRUCT_TRAITS_MEMBER(actions)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(content::NotificationResources)
IPC_STRUCT_TRAITS_MEMBER(image)
IPC_STRUCT_TRAITS_MEMBER(notification_icon)
IPC_STRUCT_TRAITS_MEMBER(badge)
IPC_STRUCT_TRAITS_MEMBER(action_icons)
IPC_STRUCT_TRAITS_END()
// Messages sent from the browser to the renderer.
// Reply to PlatformNotificationHostMsg_ShowPersistent indicating that a
// persistent notification has been shown on the platform (if |success| is
// true), or that an unspecified error occurred.
IPC_MESSAGE_CONTROL2(PlatformNotificationMsg_DidShowPersistent,
int /* request_id */,
bool /* success */)
// Reply to PlatformNotificationHostMsg_GetNotifications sharing a vector of
// available notifications per the request's constraints.
IPC_MESSAGE_CONTROL2(PlatformNotificationMsg_DidGetNotifications,
int /* request_id */,
std::vector<PersistentNotificationInfo>
/* notifications */)
// Messages sent from the renderer to the browser.
IPC_MESSAGE_CONTROL5(
PlatformNotificationHostMsg_ShowPersistent,
int /* request_id */,
int64_t /* service_worker_registration_id */,
GURL /* origin */,
content::PlatformNotificationData /* notification_data */,
content::NotificationResources /* notification_resources */)
IPC_MESSAGE_CONTROL4(PlatformNotificationHostMsg_GetNotifications,
int /* request_id */,
int64_t /* service_worker_registration_id */,
GURL /* origin */,
std::string /* filter_tag */)
IPC_MESSAGE_CONTROL3(PlatformNotificationHostMsg_ClosePersistent,
GURL /* origin */,
std::string /* tag */,
std::string /* notification_id */)
#endif // CONTENT_COMMON_PLATFORM_NOTIFICATION_MESSAGES_H_
......@@ -233,10 +233,6 @@ const base::Feature kNetworkServiceInProcess{"NetworkServiceInProcess",
const base::Feature kNotificationContentImage{"NotificationContentImage",
base::FEATURE_ENABLED_BY_DEFAULT};
// Use Mojo IPC for notifications.
const base::Feature kNotificationsWithMojo{"NotificationsWithMojo",
base::FEATURE_DISABLED_BY_DEFAULT};
// Off-main-thread WebSocket. See https://crbug.com/825740
const base::Feature kOffMainThreadWebSocket{"OffMainThreadWebSocket",
base::FEATURE_ENABLED_BY_DEFAULT};
......
......@@ -60,7 +60,6 @@ CONTENT_EXPORT extern const base::Feature kMojoSessionStorage;
CONTENT_EXPORT extern const base::Feature kMojoVideoCapture;
CONTENT_EXPORT extern const base::Feature kNetworkServiceInProcess;
CONTENT_EXPORT extern const base::Feature kNotificationContentImage;
CONTENT_EXPORT extern const base::Feature kNotificationsWithMojo;
CONTENT_EXPORT extern const base::Feature kOffMainThreadWebSocket;
CONTENT_EXPORT extern const base::Feature kOriginManifest;
CONTENT_EXPORT extern const base::Feature kOriginTrials;
......
......@@ -494,10 +494,6 @@ target(link_target_type, "renderer") {
"net_info_helper.h",
"notifications/notification_data_conversions.cc",
"notifications/notification_data_conversions.h",
"notifications/notification_dispatcher.cc",
"notifications/notification_dispatcher.h",
"notifications/notification_manager.cc",
"notifications/notification_manager.h",
"p2p/empty_network_manager.cc",
"p2p/empty_network_manager.h",
"p2p/filtering_network_manager.cc",
......
......@@ -19,66 +19,6 @@ using blink::WebString;
namespace content {
PlatformNotificationData ToPlatformNotificationData(
const WebNotificationData& web_data) {
PlatformNotificationData platform_data;
platform_data.title = web_data.title.Utf16();
switch (web_data.direction) {
case WebNotificationData::kDirectionLeftToRight:
platform_data.direction =
PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT;
break;
case WebNotificationData::kDirectionRightToLeft:
platform_data.direction =
PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT;
break;
case WebNotificationData::kDirectionAuto:
platform_data.direction = PlatformNotificationData::DIRECTION_AUTO;
break;
}
platform_data.lang = web_data.lang.Utf8(
WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
platform_data.body = web_data.body.Utf16();
platform_data.tag = web_data.tag.Utf8(
WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
platform_data.image = WebStringToGURL(web_data.image.GetString());
platform_data.icon = WebStringToGURL(web_data.icon.GetString());
platform_data.badge = WebStringToGURL(web_data.badge.GetString());
platform_data.vibration_pattern.assign(web_data.vibrate.begin(),
web_data.vibrate.end());
platform_data.timestamp = base::Time::FromJsTime(web_data.timestamp);
platform_data.renotify = web_data.renotify;
platform_data.silent = web_data.silent;
platform_data.require_interaction = web_data.require_interaction;
platform_data.data.assign(web_data.data.begin(), web_data.data.end());
platform_data.actions.resize(web_data.actions.size());
for (size_t i = 0; i < web_data.actions.size(); ++i) {
switch (web_data.actions[i].type) {
case blink::WebNotificationAction::kButton:
platform_data.actions[i].type =
PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON;
break;
case blink::WebNotificationAction::kText:
platform_data.actions[i].type = PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT;
break;
default:
NOTREACHED() << "Unknown notification action type: "
<< web_data.actions[i].type;
}
platform_data.actions[i].action = web_data.actions[i].action.Utf8(
WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
platform_data.actions[i].title = web_data.actions[i].title.Utf16();
platform_data.actions[i].icon =
WebStringToGURL(web_data.actions[i].icon.GetString());
platform_data.actions[i].placeholder =
WebString::ToNullableString16(web_data.actions[i].placeholder);
}
return platform_data;
}
WebNotificationData ToWebNotificationData(
const PlatformNotificationData& platform_data) {
WebNotificationData web_data;
......
......@@ -11,10 +11,6 @@
namespace content {
// Converts Blink WebNotificationData to PlatformNotificationData.
CONTENT_EXPORT PlatformNotificationData
ToPlatformNotificationData(const blink::WebNotificationData& web_data);
// Converts PlatformNotificationData to Blink WebNotificationData.
CONTENT_EXPORT blink::WebNotificationData ToWebNotificationData(
const PlatformNotificationData& platform_data);
......
......@@ -36,77 +36,6 @@ const char kAction2Name[] = "btn2";
const char kAction2Title[] = "Button 2";
const char kAction2IconUrl[] = "https://example.com/action_icon_2.png";
TEST(NotificationDataConversionsTest, ToPlatformNotificationData) {
blink::WebNotificationData web_data;
web_data.title = blink::WebString::FromUTF8(kNotificationTitle);
web_data.direction = blink::WebNotificationData::kDirectionLeftToRight;
web_data.lang = blink::WebString::FromUTF8(kNotificationLang);
web_data.body = blink::WebString::FromUTF8(kNotificationBody);
web_data.tag = blink::WebString::FromUTF8(kNotificationTag);
web_data.image = blink::WebURL(GURL(kNotificationImageUrl));
web_data.icon = blink::WebURL(GURL(kNotificationIconUrl));
web_data.badge = blink::WebURL(GURL(kNotificationBadgeUrl));
web_data.vibrate = blink::WebVector<int>(
kNotificationVibrationPattern, arraysize(kNotificationVibrationPattern));
web_data.timestamp = kNotificationTimestamp;
web_data.renotify = true;
web_data.silent = true;
web_data.require_interaction = true;
web_data.data =
blink::WebVector<char>(kNotificationData, arraysize(kNotificationData));
web_data.actions =
blink::WebVector<blink::WebNotificationAction>(static_cast<size_t>(2));
web_data.actions[0].type = blink::WebNotificationAction::kButton;
web_data.actions[0].action = blink::WebString::FromUTF8(kAction1Name);
web_data.actions[0].title = blink::WebString::FromUTF8(kAction1Title);
web_data.actions[0].icon = blink::WebURL(GURL(kAction1IconUrl));
web_data.actions[0].placeholder =
blink::WebString::FromUTF8(kAction1Placeholder);
web_data.actions[1].type = blink::WebNotificationAction::kText;
web_data.actions[1].action = blink::WebString::FromUTF8(kAction2Name);
web_data.actions[1].title = blink::WebString::FromUTF8(kAction2Title);
web_data.actions[1].icon = blink::WebURL(GURL(kAction2IconUrl));
web_data.actions[1].placeholder = blink::WebString();
PlatformNotificationData platform_data = ToPlatformNotificationData(web_data);
EXPECT_EQ(base::ASCIIToUTF16(kNotificationTitle), platform_data.title);
EXPECT_EQ(PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT,
platform_data.direction);
EXPECT_EQ(kNotificationLang, platform_data.lang);
EXPECT_EQ(base::ASCIIToUTF16(kNotificationBody), platform_data.body);
EXPECT_EQ(kNotificationTag, platform_data.tag);
EXPECT_EQ(kNotificationImageUrl, platform_data.image.spec());
EXPECT_EQ(kNotificationIconUrl, platform_data.icon.spec());
EXPECT_EQ(kNotificationBadgeUrl, platform_data.badge.spec());
EXPECT_TRUE(platform_data.renotify);
EXPECT_TRUE(platform_data.silent);
EXPECT_TRUE(platform_data.require_interaction);
EXPECT_THAT(platform_data.vibration_pattern,
testing::ElementsAreArray(kNotificationVibrationPattern));
EXPECT_DOUBLE_EQ(kNotificationTimestamp, platform_data.timestamp.ToJsTime());
ASSERT_EQ(web_data.data.size(), platform_data.data.size());
for (size_t i = 0; i < web_data.data.size(); ++i)
EXPECT_EQ(web_data.data[i], platform_data.data[i]);
ASSERT_EQ(web_data.actions.size(), platform_data.actions.size());
EXPECT_EQ(PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON,
platform_data.actions[0].type);
EXPECT_EQ(kAction1Name, platform_data.actions[0].action);
EXPECT_EQ(base::ASCIIToUTF16(kAction1Title), platform_data.actions[0].title);
EXPECT_EQ(kAction1IconUrl, platform_data.actions[0].icon.spec());
EXPECT_EQ(base::ASCIIToUTF16(kAction1Placeholder),
platform_data.actions[0].placeholder.string());
EXPECT_FALSE(platform_data.actions[0].placeholder.is_null());
EXPECT_EQ(PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT,
platform_data.actions[1].type);
EXPECT_EQ(kAction2Name, platform_data.actions[1].action);
EXPECT_EQ(base::ASCIIToUTF16(kAction2Title), platform_data.actions[1].title);
EXPECT_EQ(kAction2IconUrl, platform_data.actions[1].icon.spec());
EXPECT_TRUE(platform_data.actions[1].placeholder.is_null());
}
TEST(NotificationDataConversionsTest, ToWebNotificationData) {
std::vector<int> vibration_pattern(
kNotificationVibrationPattern,
......@@ -180,72 +109,4 @@ TEST(NotificationDataConversionsTest, ToWebNotificationData) {
EXPECT_TRUE(web_data.actions[1].placeholder.IsNull());
}
TEST(NotificationDataConversionsTest, NotificationDataDirectionality) {
std::map<blink::WebNotificationData::Direction,
PlatformNotificationData::Direction> mappings;
mappings[blink::WebNotificationData::kDirectionLeftToRight] =
PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT;
mappings[blink::WebNotificationData::kDirectionRightToLeft] =
PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT;
mappings[blink::WebNotificationData::kDirectionAuto] =
PlatformNotificationData::DIRECTION_AUTO;
for (const auto& pair : mappings) {
{
blink::WebNotificationData web_data;
web_data.direction = pair.first;
PlatformNotificationData platform_data =
ToPlatformNotificationData(web_data);
EXPECT_EQ(pair.second, platform_data.direction);
}
{
PlatformNotificationData platform_data;
platform_data.direction = pair.second;
blink::WebNotificationData web_data =
ToWebNotificationData(platform_data);
EXPECT_EQ(pair.first, web_data.direction);
}
}
}
TEST(NotificationDataConversionsTest, TimeEdgeCaseValueBehaviour) {
{
blink::WebNotificationData web_data;
web_data.timestamp =
static_cast<double>(std::numeric_limits<unsigned long long>::max());
blink::WebNotificationData copied_data =
ToWebNotificationData(ToPlatformNotificationData(web_data));
EXPECT_NE(web_data.timestamp, copied_data.timestamp);
}
{
blink::WebNotificationData web_data;
web_data.timestamp =
static_cast<double>(9211726771200000000ull); // January 1, 293878
blink::WebNotificationData copied_data =
ToWebNotificationData(ToPlatformNotificationData(web_data));
EXPECT_NE(web_data.timestamp, copied_data.timestamp);
}
{
blink::WebNotificationData web_data;
web_data.timestamp = 0;
blink::WebNotificationData copied_data =
ToWebNotificationData(ToPlatformNotificationData(web_data));
EXPECT_EQ(web_data.timestamp, copied_data.timestamp);
}
{
blink::WebNotificationData web_data;
web_data.timestamp = 0;
blink::WebNotificationData copied_data =
ToWebNotificationData(ToPlatformNotificationData(web_data));
EXPECT_EQ(web_data.timestamp, copied_data.timestamp);
}
}
} // namespace content
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/notifications/notification_dispatcher.h"
#include <limits>
#include "content/renderer/notifications/notification_manager.h"
namespace content {
NotificationDispatcher::NotificationDispatcher(
ThreadSafeSender* thread_safe_sender,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner)
: WorkerThreadMessageFilter(thread_safe_sender,
std::move(main_thread_task_runner)) {}
NotificationDispatcher::~NotificationDispatcher() {}
int NotificationDispatcher::GenerateNotificationRequestId(int thread_id) {
base::AutoLock lock(notification_request_id_map_lock_);
CHECK_LT(next_notification_request_id_, std::numeric_limits<int>::max());
notification_request_id_map_[next_notification_request_id_] = thread_id;
return next_notification_request_id_++;
}
bool NotificationDispatcher::ShouldHandleMessage(
const IPC::Message& msg) const {
return IPC_MESSAGE_CLASS(msg) == PlatformNotificationMsgStart;
}
void NotificationDispatcher::OnFilteredMessageReceived(
const IPC::Message& msg) {
NotificationManager::ThreadSpecificInstance(thread_safe_sender(), this)
->OnMessageReceived(msg);
}
bool NotificationDispatcher::GetWorkerThreadIdForMessage(
const IPC::Message& msg,
int* ipc_thread_id) {
int notification_request_id = -1;
const bool success =
base::PickleIterator(msg).ReadInt(&notification_request_id);
DCHECK(success);
base::AutoLock lock(notification_request_id_map_lock_);
auto iterator = notification_request_id_map_.find(notification_request_id);
if (iterator != notification_request_id_map_.end()) {
*ipc_thread_id = iterator->second;
return true;
}
return false;
}
} // namespace content
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_NOTIFICATIONS_NOTIFICATION_DISPATCHER_H_
#define CONTENT_RENDERER_NOTIFICATIONS_NOTIFICATION_DISPATCHER_H_
#include <map>
#include "base/macros.h"
#include "base/single_thread_task_runner.h"
#include "base/synchronization/lock.h"
#include "content/renderer/worker_thread_message_filter.h"
namespace content {
class NotificationDispatcher : public WorkerThreadMessageFilter {
public:
NotificationDispatcher(
ThreadSafeSender* thread_safe_sender,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner);
// Generates and stores a new process-unique notification request ID mapped to
// |thread_id|, and returns the generated request ID. This method can be
// called on any thread.
int GenerateNotificationRequestId(int thread_id);
protected:
~NotificationDispatcher() override;
private:
// WorkerThreadMessageFilter:
bool ShouldHandleMessage(const IPC::Message& msg) const override;
void OnFilteredMessageReceived(const IPC::Message& msg) override;
bool GetWorkerThreadIdForMessage(const IPC::Message& msg,
int* ipc_thread_id) override;
using NotificationRequestIdToThreadId = std::map<int, int>;
base::Lock notification_request_id_map_lock_;
NotificationRequestIdToThreadId notification_request_id_map_;
int next_notification_request_id_ = 0;
DISALLOW_COPY_AND_ASSIGN(NotificationDispatcher);
};
} // namespace content
#endif // CONTENT_RENDERER_NOTIFICATIONS_NOTIFICATION_DISPATCHER_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/notifications/notification_manager.h"
#include <utility>
#include "base/lazy_instance.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_local.h"
#include "content/child/thread_safe_sender.h"
#include "content/public/common/notification_resources.h"
#include "content/public/common/platform_notification_data.h"
#include "content/renderer/notifications/notification_data_conversions.h"
#include "content/renderer/notifications/notification_dispatcher.h"
#include "content/renderer/service_worker/web_service_worker_registration_impl.h"
#include "third_party/blink/public/platform/modules/notifications/notification.mojom.h"
#include "third_party/blink/public/platform/url_conversion.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "url/origin.h"
using blink::WebString;
namespace content {
namespace {
int NotificationWorkerId() {
return WorkerThread::GetCurrentId();
}
NotificationResources ToNotificationResources(
std::unique_ptr<blink::WebNotificationResources> web_resources) {
NotificationResources resources;
resources.image = web_resources->image;
resources.notification_icon = web_resources->icon;
resources.badge = web_resources->badge;
for (const auto& action_icon : web_resources->action_icons)
resources.action_icons.push_back(action_icon);
return resources;
}
} // namespace
static base::LazyInstance<base::ThreadLocalPointer<NotificationManager>>::Leaky
g_notification_manager_tls = LAZY_INSTANCE_INITIALIZER;
NotificationManager::NotificationManager(
ThreadSafeSender* thread_safe_sender,
NotificationDispatcher* notification_dispatcher)
: thread_safe_sender_(thread_safe_sender),
notification_dispatcher_(notification_dispatcher) {
g_notification_manager_tls.Pointer()->Set(this);
}
NotificationManager::~NotificationManager() {
g_notification_manager_tls.Pointer()->Set(nullptr);
}
NotificationManager* NotificationManager::ThreadSpecificInstance(
ThreadSafeSender* thread_safe_sender,
NotificationDispatcher* notification_dispatcher) {
if (g_notification_manager_tls.Pointer()->Get())
return g_notification_manager_tls.Pointer()->Get();
NotificationManager* manager =
new NotificationManager(thread_safe_sender, notification_dispatcher);
if (NotificationWorkerId())
WorkerThread::AddObserver(manager);
return manager;
}
void NotificationManager::WillStopCurrentWorkerThread() {
delete this;
}
void NotificationManager::ShowPersistent(
const blink::WebSecurityOrigin& origin,
const blink::WebNotificationData& notification_data,
std::unique_ptr<blink::WebNotificationResources> notification_resources,
blink::WebServiceWorkerRegistration* service_worker_registration,
std::unique_ptr<blink::WebNotificationShowCallbacks> callbacks) {
DCHECK(service_worker_registration);
DCHECK_EQ(notification_data.actions.size(),
notification_resources->action_icons.size());
int64_t service_worker_registration_id =
static_cast<WebServiceWorkerRegistrationImpl*>(
service_worker_registration)
->RegistrationId();
// Verify that the author-provided payload size does not exceed our limit.
// This is an implementation-defined limit to prevent abuse of notification
// data as a storage mechanism. A UMA histogram records the requested sizes,
// which enables us to track how much data authors are attempting to store.
//
// If the size exceeds this limit, reject the showNotification() promise. This
// is outside of the boundaries set by the specification, but it gives authors
// an indication that something has gone wrong.
size_t author_data_size = notification_data.data.size();
UMA_HISTOGRAM_COUNTS_1000("Notifications.AuthorDataSize", author_data_size);
if (author_data_size >
blink::mojom::NotificationData::kMaximumDeveloperDataSize) {
callbacks->OnError();
return;
}
int request_id = notification_dispatcher_->GenerateNotificationRequestId(
NotificationWorkerId());
pending_show_notification_requests_.AddWithID(std::move(callbacks),
request_id);
// TODO(mkwst): This is potentially doing the wrong thing with unique
// origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See
// https://crbug.com/490074 for detail.
thread_safe_sender_->Send(new PlatformNotificationHostMsg_ShowPersistent(
request_id, service_worker_registration_id, url::Origin(origin).GetURL(),
ToPlatformNotificationData(notification_data),
ToNotificationResources(std::move(notification_resources))));
}
void NotificationManager::GetNotifications(
const blink::WebString& filter_tag,
blink::WebServiceWorkerRegistration* service_worker_registration,
std::unique_ptr<blink::WebNotificationGetCallbacks> callbacks) {
DCHECK(service_worker_registration);
DCHECK(callbacks);
WebServiceWorkerRegistrationImpl* service_worker_registration_impl =
static_cast<WebServiceWorkerRegistrationImpl*>(
service_worker_registration);
GURL origin = GURL(service_worker_registration_impl->Scope()).GetOrigin();
int64_t service_worker_registration_id =
service_worker_registration_impl->RegistrationId();
int request_id = notification_dispatcher_->GenerateNotificationRequestId(
NotificationWorkerId());
pending_get_notification_requests_.AddWithID(std::move(callbacks),
request_id);
thread_safe_sender_->Send(new PlatformNotificationHostMsg_GetNotifications(
request_id, service_worker_registration_id, origin,
filter_tag.Utf8(
WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD)));
}
void NotificationManager::ClosePersistent(
const blink::WebSecurityOrigin& origin,
const blink::WebString& tag,
const blink::WebString& notification_id) {
thread_safe_sender_->Send(new PlatformNotificationHostMsg_ClosePersistent(
// TODO(mkwst): This is potentially doing the wrong thing with unique
// origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See
// https://crbug.com/490074 for detail.
url::Origin(origin).GetURL(),
tag.Utf8(WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD),
notification_id.Utf8(
WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD)));
}
bool NotificationManager::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(NotificationManager, message)
IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShowPersistent,
OnDidShowPersistent)
IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidGetNotifications,
OnDidGetNotifications)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void NotificationManager::OnDidShowPersistent(int request_id, bool success) {
blink::WebNotificationShowCallbacks* callbacks =
pending_show_notification_requests_.Lookup(request_id);
DCHECK(callbacks);
if (!callbacks)
return;
if (success)
callbacks->OnSuccess();
else
callbacks->OnError();
pending_show_notification_requests_.Remove(request_id);
}
void NotificationManager::OnDidGetNotifications(
int request_id,
const std::vector<PersistentNotificationInfo>& notification_infos) {
blink::WebNotificationGetCallbacks* callbacks =
pending_get_notification_requests_.Lookup(request_id);
DCHECK(callbacks);
if (!callbacks)
return;
blink::WebVector<blink::WebPersistentNotificationInfo> notifications(
notification_infos.size());
for (size_t i = 0; i < notification_infos.size(); ++i) {
blink::WebPersistentNotificationInfo web_notification_info;
web_notification_info.notification_id =
blink::WebString::FromUTF8(notification_infos[i].first);
web_notification_info.data =
ToWebNotificationData(notification_infos[i].second);
notifications[i] = web_notification_info;
}
callbacks->OnSuccess(notifications);
pending_get_notification_requests_.Remove(request_id);
}
} // namespace content
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_NOTIFICATIONS_NOTIFICATION_MANAGER_H_
#define CONTENT_RENDERER_NOTIFICATIONS_NOTIFICATION_MANAGER_H_
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <set>
#include <vector>
#include "base/containers/id_map.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "content/common/platform_notification_messages.h"
#include "content/public/renderer/worker_thread.h"
#include "content/renderer/notifications/notification_dispatcher.h"
#include "third_party/blink/public/platform/modules/notifications/web_notification_manager.h"
namespace content {
class ThreadSafeSender;
class NotificationManager : public blink::WebNotificationManager,
public WorkerThread::Observer {
public:
~NotificationManager() override;
// |thread_safe_sender| and |notification_dispatcher| are used if
// calling this leads to construction.
static NotificationManager* ThreadSpecificInstance(
ThreadSafeSender* thread_safe_sender,
NotificationDispatcher* notification_dispatcher);
// WorkerThread::Observer implementation.
void WillStopCurrentWorkerThread() override;
void ShowPersistent(
const blink::WebSecurityOrigin& origin,
const blink::WebNotificationData& notification_data,
std::unique_ptr<blink::WebNotificationResources> notification_resources,
blink::WebServiceWorkerRegistration* service_worker_registration,
std::unique_ptr<blink::WebNotificationShowCallbacks> callbacks) override;
void GetNotifications(
const blink::WebString& filter_tag,
blink::WebServiceWorkerRegistration* service_worker_registration,
std::unique_ptr<blink::WebNotificationGetCallbacks> callbacks) override;
void ClosePersistent(const blink::WebSecurityOrigin& origin,
const blink::WebString& tag,
const blink::WebString& notification_id) override;
// Called by the NotificationDispatcher.
bool OnMessageReceived(const IPC::Message& message);
private:
NotificationManager(ThreadSafeSender* thread_safe_sender,
NotificationDispatcher* notification_dispatcher);
// IPC message handlers.
void OnDidShowPersistent(int request_id, bool success);
void OnDidGetNotifications(
int request_id,
const std::vector<PersistentNotificationInfo>& notification_infos);
scoped_refptr<ThreadSafeSender> thread_safe_sender_;
scoped_refptr<NotificationDispatcher> notification_dispatcher_;
// Tracks pending requests for getting a list of notifications.
base::IDMap<std::unique_ptr<blink::WebNotificationGetCallbacks>>
pending_get_notification_requests_;
// Tracks pending requests for displaying persistent notifications.
base::IDMap<std::unique_ptr<blink::WebNotificationShowCallbacks>>
pending_show_notification_requests_;
DISALLOW_COPY_AND_ASSIGN(NotificationManager);
};
} // namespace content
#endif // CONTENT_RENDERER_NOTIFICATIONS_NOTIFICATION_MANAGER_H_
......@@ -104,7 +104,6 @@
#include "content/renderer/mus/render_widget_window_tree_client_factory.h"
#include "content/renderer/mus/renderer_window_tree_client.h"
#include "content/renderer/net_info_helper.h"
#include "content/renderer/notifications/notification_dispatcher.h"
#include "content/renderer/render_frame_proxy.h"
#include "content/renderer/render_process_impl.h"
#include "content/renderer/render_view_impl.h"
......@@ -803,10 +802,6 @@ void RenderThreadImpl::Init(
: mojom::kBrowserServiceName,
GetIOTaskRunner());
notification_dispatcher_ = new NotificationDispatcher(
thread_safe_sender(), GetWebMainThreadScheduler()->IPCTaskRunner());
AddFilter(notification_dispatcher_->GetFilter());
resource_dispatcher_.reset(new ResourceDispatcher());
url_loader_throttle_provider_ =
GetContentClient()->renderer()->CreateURLLoaderThrottleProvider(
......
......@@ -138,7 +138,6 @@ class FrameSwapMessageQueue;
class GpuVideoAcceleratorFactoriesImpl;
class IndexedDBDispatcher;
class MidiMessageFilter;
class NotificationDispatcher;
class P2PSocketDispatcher;
class PeerConnectionDependencyFactory;
class PeerConnectionTracker;
......@@ -377,10 +376,6 @@ class CONTENT_EXPORT RenderThreadImpl
return vc_manager_.get();
}
NotificationDispatcher* notification_dispatcher() const {
return notification_dispatcher_.get();
}
mojom::RenderFrameMessageFilter* render_frame_message_filter();
mojom::RenderMessageFilter* render_message_filter();
......@@ -655,8 +650,6 @@ class CONTENT_EXPORT RenderThreadImpl
// Used on the render thread.
std::unique_ptr<VideoCaptureImplManager> vc_manager_;
scoped_refptr<NotificationDispatcher> notification_dispatcher_;
// The count of RenderWidgets running through this thread.
int widget_count_;
......
......@@ -67,8 +67,6 @@
#include "content/renderer/media_capture_from_element/html_video_element_capturer_source.h"
#include "content/renderer/media_recorder/media_recorder_handler.h"
#include "content/renderer/mojo/blink_interface_provider_impl.h"
#include "content/renderer/notifications/notification_dispatcher.h"
#include "content/renderer/notifications/notification_manager.h"
#include "content/renderer/push_messaging/push_provider.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/storage_util.h"
......@@ -295,8 +293,6 @@ RendererBlinkPlatformImpl::RendererBlinkPlatformImpl(
web_idb_factory_.reset(new WebIDBFactoryImpl(
sync_message_filter_,
RenderThreadImpl::current()->GetIOTaskRunner().get()));
notification_dispatcher_ =
RenderThreadImpl::current()->notification_dispatcher();
} else {
service_manager::mojom::ConnectorRequest request;
connector_ = service_manager::Connector::Create(&request);
......@@ -1294,18 +1290,6 @@ blink::WebPushProvider* RendererBlinkPlatformImpl::PushProvider() {
//------------------------------------------------------------------------------
blink::WebNotificationManager*
RendererBlinkPlatformImpl::GetWebNotificationManager() {
if (!thread_safe_sender_.get() || !notification_dispatcher_.get())
return nullptr;
return NotificationManager::ThreadSpecificInstance(
thread_safe_sender_.get(),
notification_dispatcher_.get());
}
//------------------------------------------------------------------------------
void RendererBlinkPlatformImpl::DidStartWorkerThread() {
WorkerThreadRegistry::Instance()->DidStartCurrentWorkerThread();
}
......
......@@ -58,7 +58,6 @@ namespace content {
class BlinkInterfaceProviderImpl;
class ChildURLLoaderFactoryBundle;
class LocalStorageCachedAreas;
class NotificationDispatcher;
class PlatformEventObserverBase;
class ThreadSafeSender;
class WebDatabaseObserverImpl;
......@@ -206,7 +205,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
const blink::WebString& sample) override;
void RecordRapporURL(const char* metric, const blink::WebURL& url) override;
blink::WebPushProvider* PushProvider() override;
blink::WebNotificationManager* GetWebNotificationManager() override;
void DidStartWorkerThread() override;
void WillStopWorkerThread() override;
void WorkerContextCreated(const v8::Local<v8::Context>& worker) override;
......@@ -333,8 +331,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
blink::mojom::WebDatabaseHostPtrInfo web_database_host_info_;
scoped_refptr<blink::mojom::ThreadSafeWebDatabaseHostPtr> web_database_host_;
scoped_refptr<NotificationDispatcher> notification_dispatcher_;
THREAD_CHECKER(main_thread_checker_);
DISALLOW_COPY_AND_ASSIGN(RendererBlinkPlatformImpl);
......
......@@ -349,11 +349,6 @@
"--enable-threaded-compositing",
"--disable-smooth-scrolling"]
},
{
"prefix": "mojo-notifications",
"base": "http/tests/notifications",
"args": ["--enable-blink-features=NotificationsWithMojo"]
},
{
"prefix": "scalefactor150",
"base": "fast/events/synthetic-events",
......
......@@ -155,7 +155,6 @@ source_set("blink_headers") {
"platform/modules/notifications/web_notification_action.h",
"platform/modules/notifications/web_notification_constants.h",
"platform/modules/notifications/web_notification_data.h",
"platform/modules/notifications/web_notification_manager.h",
"platform/modules/notifications/web_notification_resources.h",
"platform/modules/payments/web_payment_currency_amount.h",
"platform/modules/payments/web_payment_details_modifier.h",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_NOTIFICATIONS_WEB_NOTIFICATION_MANAGER_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_NOTIFICATIONS_WEB_NOTIFICATION_MANAGER_H_
#include <stdint.h>
#include <memory>
#include "third_party/blink/public/platform/modules/notifications/web_notification_data.h"
#include "third_party/blink/public/platform/modules/notifications/web_notification_resources.h"
#include "third_party/blink/public/platform/web_callbacks.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_vector.h"
namespace blink {
class WebSecurityOrigin;
class WebServiceWorkerRegistration;
// Structure representing the info associated with a persistent notification.
struct WebPersistentNotificationInfo {
WebString notification_id;
WebNotificationData data;
};
using WebNotificationGetCallbacks =
WebCallbacks<const WebVector<WebPersistentNotificationInfo>&, void>;
using WebNotificationShowCallbacks = WebCallbacks<void, void>;
// Provides the services to show platform notifications to the user.
class WebNotificationManager {
public:
virtual ~WebNotificationManager() = default;
// Shows a persistent notification on the user's system. These notifications
// will have their events delivered to a Service Worker rather than the
// object's delegate. Will take ownership of the WebNotificationShowCallbacks
// object.
virtual void ShowPersistent(
const WebSecurityOrigin&,
const WebNotificationData&,
std::unique_ptr<WebNotificationResources>,
WebServiceWorkerRegistration*,
std::unique_ptr<WebNotificationShowCallbacks>) = 0;
// Asynchronously gets the persistent notifications belonging to the Service
// Worker Registration. If |filterTag| is not an empty string, only the
// notification with the given tag will be considered. Will take ownership of
// the WebNotificationGetCallbacks object.
virtual void GetNotifications(
const WebString& filter_tag,
WebServiceWorkerRegistration*,
std::unique_ptr<WebNotificationGetCallbacks>) = 0;
// Closes a persistent notification identified by its notification Id.
virtual void ClosePersistent(const WebSecurityOrigin&,
const WebString& tag,
const WebString& notification_id) = 0;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_NOTIFICATIONS_WEB_NOTIFICATION_MANAGER_H_
......@@ -104,7 +104,6 @@ class WebRuntimeFeatures {
BLINK_PLATFORM_EXPORT static void EnableNotificationConstructor(bool);
BLINK_PLATFORM_EXPORT static void EnableNotificationContentImage(bool);
BLINK_PLATFORM_EXPORT static void EnableNotifications(bool);
BLINK_PLATFORM_EXPORT static void EnableNotificationsWithMojo(bool);
BLINK_PLATFORM_EXPORT static void EnableOnDeviceChange(bool);
BLINK_PLATFORM_EXPORT static void EnableOrientationEvent(bool);
BLINK_PLATFORM_EXPORT static void EnableOriginManifest(bool);
......
......@@ -33,10 +33,7 @@
#include "base/unguessable_token.h"
#include "third_party/blink/public/platform/modules/notifications/web_notification_action.h"
#include "third_party/blink/public/platform/modules/notifications/web_notification_constants.h"
#include "third_party/blink/public/platform/modules/notifications/web_notification_manager.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/renderer/bindings/core/v8/exception_state.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value_factory.h"
#include "third_party/blink/renderer/bindings/core/v8/source_location.h"
......@@ -63,13 +60,6 @@
#include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink {
namespace {
WebNotificationManager* GetWebNotificationManager() {
return Platform::Current()->GetWebNotificationManager();
}
} // namespace
Notification* Notification::Create(ExecutionContext* context,
const String& title,
......@@ -167,7 +157,6 @@ Notification::Notification(ExecutionContext* context,
state_(State::kLoading),
data_(data),
listener_binding_(this) {
DCHECK(GetWebNotificationManager());
}
Notification::~Notification() = default;
......@@ -231,17 +220,8 @@ void Notification::close() {
state_ = State::kClosed;
if (RuntimeEnabledFeatures::NotificationsWithMojoEnabled()) {
NotificationManager::From(GetExecutionContext())
->ClosePersistentNotification(notification_id_);
return;
}
const SecurityOrigin* origin = GetExecutionContext()->GetSecurityOrigin();
DCHECK(origin);
GetWebNotificationManager()->ClosePersistent(WebSecurityOrigin(origin),
data_.tag, notification_id_);
NotificationManager::From(GetExecutionContext())
->ClosePersistentNotification(notification_id_);
}
void Notification::OnShow() {
......
......@@ -6,7 +6,6 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_NOTIFICATIONS_NOTIFICATION_MANAGER_H_
#include "third_party/blink/public/platform/modules/notifications/notification_service.mojom-blink.h"
#include "third_party/blink/public/platform/modules/notifications/web_notification_manager.h"
#include "third_party/blink/public/platform/modules/permissions/permission.mojom-blink.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_notification_permission_callback.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
......@@ -18,6 +17,7 @@ namespace blink {
class ScriptPromise;
class ScriptPromiseResolver;
class ScriptState;
class WebServiceWorkerRegistration;
struct WebNotificationData;
// The notification manager, unique to the execution context, is responsible for
......
......@@ -9,11 +9,9 @@
#include "third_party/blink/public/platform/modules/notifications/web_notification_data.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/renderer/bindings/core/v8/callback_promise_adapter.h"
#include "third_party/blink/renderer/bindings/core/v8/exception_state.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/modules/notifications/get_notification_options.h"
#include "third_party/blink/renderer/modules/notifications/notification.h"
#include "third_party/blink/renderer/modules/notifications/notification_data.h"
#include "third_party/blink/renderer/modules/notifications/notification_manager.h"
#include "third_party/blink/renderer/modules/notifications/notification_options.h"
......@@ -25,32 +23,6 @@
#include "third_party/blink/renderer/platform/wtf/assertions.h"
namespace blink {
namespace {
// Allows using a CallbackPromiseAdapter with a WebVector to resolve the
// getNotifications() promise with a HeapVector owning Notifications.
class NotificationArray {
public:
using WebType = const WebVector<WebPersistentNotificationInfo>&;
static HeapVector<Member<Notification>> Take(
ScriptPromiseResolver* resolver,
const WebVector<WebPersistentNotificationInfo>& notification_infos) {
HeapVector<Member<Notification>> notifications;
for (const WebPersistentNotificationInfo& notification_info :
notification_infos)
notifications.push_back(Notification::Create(
resolver->GetExecutionContext(), notification_info.notification_id,
notification_info.data, true /* showing */));
return notifications;
}
private:
NotificationArray() = delete;
};
} // namespace
ServiceWorkerRegistrationNotifications::ServiceWorkerRegistrationNotifications(
ExecutionContext* context,
......@@ -115,23 +87,10 @@ ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(
ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
ScriptPromise promise = resolver->Promise();
if (RuntimeEnabledFeatures::NotificationsWithMojoEnabled()) {
ExecutionContext* execution_context = ExecutionContext::From(script_state);
NotificationManager::From(execution_context)
->GetNotifications(registration.WebRegistration(), options.tag(),
WrapPersistent(resolver));
} else {
auto callbacks =
std::make_unique<CallbackPromiseAdapter<NotificationArray, void>>(
resolver);
WebNotificationManager* notification_manager =
Platform::Current()->GetWebNotificationManager();
DCHECK(notification_manager);
notification_manager->GetNotifications(
options.tag(), registration.WebRegistration(), std::move(callbacks));
}
ExecutionContext* execution_context = ExecutionContext::From(script_state);
NotificationManager::From(execution_context)
->GetNotifications(registration.WebRegistration(), options.tag(),
WrapPersistent(resolver));
return promise;
}
......@@ -186,23 +145,10 @@ void ServiceWorkerRegistrationNotifications::DidLoadResources(
NotificationResourcesLoader* loader) {
DCHECK(loaders_.Contains(loader));
if (RuntimeEnabledFeatures::NotificationsWithMojoEnabled()) {
NotificationManager::From(GetExecutionContext())
->DisplayPersistentNotification(registration_->WebRegistration(), data,
loader->GetResources(),
WrapPersistent(resolver));
} else {
WebNotificationManager* notification_manager =
Platform::Current()->GetWebNotificationManager();
DCHECK(notification_manager);
std::unique_ptr<WebNotificationShowCallbacks> callbacks =
std::make_unique<CallbackPromiseAdapter<void, void>>(resolver);
notification_manager->ShowPersistent(
WebSecurityOrigin(origin.get()), data, loader->GetResources(),
registration_->WebRegistration(), std::move(callbacks));
}
NotificationManager::From(GetExecutionContext())
->DisplayPersistentNotification(registration_->WebRegistration(), data,
loader->GetResources(),
WrapPersistent(resolver));
loaders_.erase(loader);
}
......
......@@ -7,12 +7,10 @@
#include <memory>
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/public/platform/modules/notifications/web_notification_manager.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/noncopyable.h"
......
......@@ -204,10 +204,6 @@ void WebRuntimeFeatures::EnableNotifications(bool enable) {
RuntimeEnabledFeatures::SetNotificationsEnabled(enable);
}
void WebRuntimeFeatures::EnableNotificationsWithMojo(bool enable) {
RuntimeEnabledFeatures::SetNotificationsWithMojoEnabled(enable);
}
void WebRuntimeFeatures::EnableNavigatorContentUtils(bool enable) {
RuntimeEnabledFeatures::SetNavigatorContentUtilsEnabled(enable);
}
......
......@@ -844,9 +844,6 @@
name: "Notifications",
status: "stable",
},
{
name: "NotificationsWithMojo",
},
{
name: "NullableDocumentDomain",
status: "experimental",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment