Commit 7a6336bc authored by Kyle Milka's avatar Kyle Milka Committed by Commit Bot

Remove STTS dependencies on browser/init

Refactor SendTabToSelfNotificationReceiver out of NotificationManager.

Bug: 1090917

Change-Id: I8cd10e739af093dc35138a8ac4478d4f251ce639
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261174
Commit-Queue: Kyle Milka <kmilka@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784305}
parent 5d267906
......@@ -2909,6 +2909,7 @@ generate_jni("chrome_jni_headers") {
"java/src/org/chromium/chrome/browser/about_settings/AboutSettingsBridge.java",
"java/src/org/chromium/chrome/browser/accessibility/FontSizePrefs.java",
"java/src/org/chromium/chrome/browser/announcement/AnnouncementNotificationManager.java",
"java/src/org/chromium/chrome/browser/app/send_tab_to_self/SendTabToSelfNotificationReceiver.java",
"java/src/org/chromium/chrome/browser/app/tab_activity_glue/ReparentingTask.java",
"java/src/org/chromium/chrome/browser/autofill/AutofillExpirationDateFixFlowBridge.java",
"java/src/org/chromium/chrome/browser/autofill/AutofillLogger.java",
......
......@@ -77,6 +77,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/app/appmenu/AppMenuPropertiesDelegateImpl.java",
"java/src/org/chromium/chrome/browser/app/appmenu/UpdateMenuItemViewBinder.java",
"java/src/org/chromium/chrome/browser/app/flags/ChromeCachedFlags.java",
"java/src/org/chromium/chrome/browser/app/send_tab_to_self/SendTabToSelfNotificationReceiver.java",
"java/src/org/chromium/chrome/browser/app/tab_activity_glue/ActivityTabWebContentsDelegateAndroid.java",
"java/src/org/chromium/chrome/browser/app/tab_activity_glue/ReparentingDelegateFactory.java",
"java/src/org/chromium/chrome/browser/app/tab_activity_glue/ReparentingTask.java",
......
......@@ -824,6 +824,9 @@
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.announcement.AnnouncementNotificationManager$Receiver"/>
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.app.send_tab_to_self.SendTabToSelfNotificationReceiver"/>
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.bookmarkswidget.BookmarkWidgetProxy"/>
......@@ -866,9 +869,6 @@
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.omaha.UpdateNotificationController$UpdateNotificationReceiver"/>
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.send_tab_to_self.NotificationManager$SendTabToSelfNotificationReceiver"/>
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.sharing.click_to_call.ClickToCallMessageHandler$TapReceiver"/>
......
......@@ -767,6 +767,9 @@
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.announcement.AnnouncementNotificationManager$Receiver"/>
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.app.send_tab_to_self.SendTabToSelfNotificationReceiver"/>
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.bookmarkswidget.BookmarkWidgetProxy"/>
......@@ -809,9 +812,6 @@
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.omaha.UpdateNotificationController$UpdateNotificationReceiver"/>
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.send_tab_to_self.NotificationManager$SendTabToSelfNotificationReceiver"/>
<receiver
android:exported="false"
android:name="org.chromium.chrome.browser.sharing.click_to_call.ClickToCallMessageHandler$TapReceiver"/>
......
......@@ -1115,7 +1115,7 @@ by a child template that "extends" this file.
<receiver android:name="org.chromium.chrome.browser.notifications.scheduler.DisplayAgent$Receiver"
android:exported="false"/>
<receiver android:name="org.chromium.chrome.browser.send_tab_to_self.NotificationManager$SendTabToSelfNotificationReceiver"
<receiver android:name="org.chromium.chrome.browser.app.send_tab_to_self.SendTabToSelfNotificationReceiver"
android:exported="false"/>
<receiver android:name="org.chromium.chrome.browser.sharing.click_to_call.ClickToCallMessageHandler$TapReceiver"
......
// Copyright 2020 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.
package org.chromium.chrome.browser.app.send_tab_to_self;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.init.BrowserParts;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.init.EmptyBrowserParts;
import org.chromium.chrome.browser.send_tab_to_self.NotificationManager;
/** Handles changes to notifications based on user action or timeout. */
public class SendTabToSelfNotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final BrowserParts parts = new EmptyBrowserParts() {
@Override
public void finishNativeInitialization() {
NotificationManager.handleIntent(intent);
}
};
// Try to load native.
ChromeBrowserInitializer.getInstance().handlePreNativeStartup(parts);
ChromeBrowserInitializer.getInstance().handlePostNativeStartup(true, parts);
}
@CalledByNative
public static Class<?> getSendTabToSelfNotificationReciever() {
return SendTabToSelfNotificationReceiver.class;
}
}
......@@ -25,9 +25,6 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.init.BrowserParts;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.init.EmptyBrowserParts;
import org.chromium.chrome.browser.notifications.NotificationBuilderFactory;
import org.chromium.chrome.browser.notifications.NotificationConstants;
import org.chromium.chrome.browser.notifications.NotificationUmaTracker;
......@@ -51,43 +48,6 @@ public class NotificationManager {
private static final String NOTIFICATION_ACTION_DISMISS = "send_tab_to_self.dismiss";
private static final String NOTIFICATION_ACTION_TIMEOUT = "send_tab_to_self.timeout";
/** Handles changes to notifications based on user action or timeout. */
public static final class SendTabToSelfNotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final BrowserParts parts = new EmptyBrowserParts() {
@Override
public void finishNativeInitialization() {
final String action = intent.getAction();
final String guid =
IntentUtils.safeGetStringExtra(intent, NOTIFICATION_GUID_EXTRA);
// If this feature ever supports incognito mode, we need to modify
// this method to obtain the current profile, rather than the last-used
// regular profile.
final Profile profile = Profile.getLastUsedRegularProfile();
switch (action) {
case NOTIFICATION_ACTION_TAP:
openUrl(intent.getData());
hideNotification(guid);
SendTabToSelfAndroidBridge.deleteEntry(profile, guid);
break;
case NOTIFICATION_ACTION_DISMISS:
hideNotification(guid);
SendTabToSelfAndroidBridge.dismissEntry(profile, guid);
break;
case NOTIFICATION_ACTION_TIMEOUT:
SendTabToSelfAndroidBridge.dismissEntry(profile, guid);
break;
}
}
};
// Try to load native.
ChromeBrowserInitializer.getInstance().handlePreNativeStartup(parts);
ChromeBrowserInitializer.getInstance().handlePostNativeStartup(true, parts);
}
}
/**
* Open the URL specified within Chrome.
*
......@@ -106,6 +66,29 @@ public class NotificationManager {
context.startActivity(intent);
}
public static void handleIntent(Intent intent) {
final String action = intent.getAction();
final String guid = IntentUtils.safeGetStringExtra(intent, NOTIFICATION_GUID_EXTRA);
// If this feature ever supports incognito mode, we need to modify
// this method to obtain the current profile, rather than the last-used
// regular profile.
final Profile profile = Profile.getLastUsedRegularProfile();
switch (action) {
case NOTIFICATION_ACTION_TAP:
openUrl(intent.getData());
hideNotification(guid);
SendTabToSelfAndroidBridge.deleteEntry(profile, guid);
break;
case NOTIFICATION_ACTION_DISMISS:
hideNotification(guid);
SendTabToSelfAndroidBridge.dismissEntry(profile, guid);
break;
case NOTIFICATION_ACTION_TIMEOUT:
SendTabToSelfAndroidBridge.dismissEntry(profile, guid);
break;
}
}
/**
* Hides a notification.
*
......@@ -138,7 +121,8 @@ public class NotificationManager {
*/
@CalledByNative
private static boolean showNotification(String guid, @NonNull String url, String title,
String deviceName, long timeoutAtMillis) {
String deviceName, long timeoutAtMillis,
Class<? extends BroadcastReceiver> broadcastReceiver) {
// A notification associated with this Share entry already exists. Don't display a new one.
if (NotificationSharedPrefManager.findActiveNotification(guid) != null) {
return false;
......@@ -151,13 +135,13 @@ public class NotificationManager {
int nextId = NotificationSharedPrefManager.getNextNotificationId();
Uri uri = Uri.parse(url);
PendingIntentProvider contentIntent = PendingIntentProvider.getBroadcast(context, nextId,
new Intent(context, SendTabToSelfNotificationReceiver.class)
new Intent(context, broadcastReceiver)
.setData(uri)
.setAction(NOTIFICATION_ACTION_TAP)
.putExtra(NOTIFICATION_GUID_EXTRA, guid),
0);
PendingIntentProvider deleteIntent = PendingIntentProvider.getBroadcast(context, nextId,
new Intent(context, SendTabToSelfNotificationReceiver.class)
new Intent(context, broadcastReceiver)
.setData(uri)
.setAction(NOTIFICATION_ACTION_DISMISS)
.putExtra(NOTIFICATION_GUID_EXTRA, guid),
......@@ -199,7 +183,7 @@ public class NotificationManager {
if (timeoutAtMillis != Long.MAX_VALUE) {
AlarmManager alarmManager =
(AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent timeoutIntent = new Intent(context, SendTabToSelfNotificationReceiver.class)
Intent timeoutIntent = new Intent(context, broadcastReceiver)
.setData(Uri.parse(url))
.setAction(NOTIFICATION_ACTION_TIMEOUT)
.putExtra(NOTIFICATION_GUID_EXTRA, guid);
......
......@@ -11,10 +11,12 @@
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/android/chrome_jni_headers/NotificationManager_jni.h"
#include "chrome/android/chrome_jni_headers/SendTabToSelfNotificationReceiver_jni.h"
#include "components/send_tab_to_self/send_tab_to_self_entry.h"
using base::android::AttachCurrentThread;
using base::android::ConvertUTF8ToJavaString;
using base::android::ScopedJavaLocalRef;
namespace send_tab_to_self {
......@@ -27,12 +29,20 @@ void AndroidNotificationHandler::DisplayNewEntries(
base::Time expiraton_time =
entry->GetSharedTime() + base::TimeDelta::FromDays(10);
ScopedJavaLocalRef<jclass> send_tab_to_self_notification_receiver_class =
// base::android::GetClass(env,
// "org/chromium/chrome/browser/send_tab_to_self/"
// "SendTabToSelfNotificationReceiver");
Java_SendTabToSelfNotificationReceiver_getSendTabToSelfNotificationReciever(
env);
Java_NotificationManager_showNotification(
env, ConvertUTF8ToJavaString(env, entry->GetGUID()),
ConvertUTF8ToJavaString(env, entry->GetURL().spec()),
ConvertUTF8ToJavaString(env, entry->GetTitle()),
ConvertUTF8ToJavaString(env, entry->GetDeviceName()),
expiraton_time.ToJavaTime());
expiraton_time.ToJavaTime(),
send_tab_to_self_notification_receiver_class);
}
}
......
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