New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 627842 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Jul 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug

Blocking:
issue 609258



Sign in to add a comment

Pass service worker origin to NotificationPlatformBridge#Display()

Project Member Reported by pkotw...@chromium.org, Jul 13 2016

Issue description

Currently we check whether a notifications's Notification::origin_url() falls with a WebAPK's scope to determine whether a notification should be shown as coming from the WebAPK in the Android UI.

The scope of the WebAPK may be a sub origin. (e.g. www.google.com/maps vs www.google.com) The WebAPK's scope is taken from the Web App Manifest (https://www.w3.org/TR/appmanifest/#scope-member) 

Unfortunately Notification::origin_url() gives the top level scope. This means notifications are not attributed to a WebAPK unless the WebAPK's scope is also a top level scope
 
Cc: pkotw...@chromium.org yfried...@chromium.org hanxi@chromium.org
Components: Mobile>WebAPKs
Labels: OS-Android
Owner: peter@chromium.org
Status: Assigned (was: Untriaged)
Assigning to Peter Beverloo for implementation advice

Comment 3 by peter@chromium.org, Jul 13 2016

Cc: miguelg@chromium.org
It sounds like you'd want to know the URL that displayed the notification, which could be either a page or a Service Worker. (The ExecutionContext's complete URL.) That would have to be plumbed up all the way from Blink.

Today we pass the origin in a WebSecurityOrigin that doesn't hold the data either, so you'd have to change that to a WebURL.

Two options:
  (1) Change the WebSecurityOrigin arguments to a WebURL, make sure we call GURL::GetOrigin() when doing the necessary permission checks. I don't know if this is OK given that SecurityOrigins are distinct entities throughout Blink.
  (2) Pass the displaying WebURL separately in the WebNotificationData/PlatformNotificationData object, figure out some way to teach the message_center::Notification about this.

Intuitively I'd opt for (2), but maybe Miguel has other ideas?
For WebAPKs we only need to know the service worker origin for persistent notifications only PlatformNotificationServiceImpl::DisplayPersistentNotification(). My understanding is that non-persistent notifications created via Notification::create() are disabled on Android. I am not sure if that makes the implementation simpler.'

We plumb the service worker ID all the way up to PushMessagingNotificationManager::CheckForMissedNotification()
For WebAPKs we only need to know the service worker scope for persistent notifications only (PlatformNotificationServiceImpl::DisplayPersistentNotification()). My understanding is that non-persistent notifications created via Notification::create() are disabled on Android. I am not sure if that makes the implementation simpler.

We plumb the service worker ID all the way up to PushMessagingNotificationManager::CheckForMissedNotification()

Comment 6 by peter@chromium.org, Jul 13 2016

If the URL of the Service Worker scope is sufficient for you, as opposed to the document which may have shown the notification, you could add code in NotificationMessageFilter::OnShowPersistentNotification() which runs on the right thread and has the necessary information.

(The class you're looking at is largely unrelated to any of this, as it exists to display a default notification in case the developer forgets, which, fortunately, is very rare.)

It still leaves passing it to Android undefined— my suggestion would be to add it to //chrome/browser/notifications/notification.h for now.

In the near term, we'd like to remove the dependency on the message center for Android and other platforms that don't use it, thus move to a data-only structure instead of the Notification class, but it makes no sense to block you on that :-).
Just to make sure that I understand:

On Android are there ways to show a notification other than via a service worker?

Is there a "document which has shown the notification" for notifications which were shown by a service worker? My understanding is that there isn't one because a service worker can receive push messages (and send a notification as a result of the push message) even when Chrome is not running
Not right now but we are planning (at some point) to enable in page notifications as toasts.

I agree with Peter that the easiest would be to pass it to the notification.h object. You still need to do all the java plumbing though since we don't keep that object during JNI
Owner: pkotw...@chromium.org
Assigning to myself given that I am going to implement this :)
Blocking: 609258
Project Member

Comment 11 by bugdroid1@chromium.org, Jul 20 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/1f71208bc7377d187085071782ca34c6de8e2c1e

commit 1f71208bc7377d187085071782ca34c6de8e2c1e
Author: pkotwicz <pkotwicz@chromium.org>
Date: Wed Jul 20 16:09:39 2016

This CL plumbs the service worker scope to
PlatformNotificationServiceImpl::DisplayPersistentNotification()

The service worker scope is used to determine whether the notification
should be displayed using a WebAPK as the source or using Chrome as the
source. On Android, the notification source is displayed when a user
long-presses on a notification.

A WebAPK is used as the source of the notification if the "service
worker scope" falls within the "WebAPK scope". The "WebAPK scope"
is determined by the "scope" attribute in the WebAPK's Web Manifest
(http://html5doctor.com/web-manifest-specification/)

BUG= 627842 
TEST=PlatformNotificationServiceBrowserTest.PersistentNotificationServiceWorkerScope

Review-Url: https://codereview.chromium.org/2151993002
Cr-Commit-Position: refs/heads/master@{#406570}

[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/chrome/browser/notifications/notification.cc
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/chrome/browser/notifications/notification.h
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/chrome/browser/notifications/notification_platform_bridge_android.cc
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/chrome/browser/notifications/platform_notification_service_impl.cc
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/chrome/browser/notifications/platform_notification_service_impl.h
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/chrome/browser/notifications/platform_notification_service_interactive_uitest.cc
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/chrome/browser/notifications/platform_notification_service_unittest.cc
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/chrome/browser/push_messaging/push_messaging_notification_manager.cc
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/content/browser/notifications/notification_message_filter.cc
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/content/browser/notifications/notification_message_filter.h
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/content/browser/renderer_host/render_process_host_impl.cc
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/content/public/browser/platform_notification_service.h
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/content/shell/browser/layout_test/layout_test_notification_manager.cc
[modify] https://crrev.com/1f71208bc7377d187085071782ca34c6de8e2c1e/content/shell/browser/layout_test/layout_test_notification_manager.h

Status: Fixed (was: Assigned)

Sign in to add a comment