-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle incoming Shared Clipboard messages on Android.
Bug: 992345 Change-Id: I825496fc0a0da3084f741c420a8abcea84e5daf6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1745473 Commit-Queue: Michael van Ouwerkerk <mvanouwerkerk@chromium.org> Reviewed-by: Michael van Ouwerkerk <mvanouwerkerk@chromium.org> Reviewed-by: Peter Beverloo <peter@chromium.org> Reviewed-by: Theresa <twellington@chromium.org> Reviewed-by: Alexei Svitkine <asvitkine@chromium.org> Reviewed-by: Richard Knoll <knollr@chromium.org> Cr-Commit-Position: refs/heads/master@{#686382}
- Loading branch information
Showing
20 changed files
with
256 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
chrome/android/java/src/org/chromium/chrome/browser/sharing/SharingNotificationUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2019 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.sharing; | ||
|
||
import android.app.Notification; | ||
import android.content.Context; | ||
import android.content.res.Resources; | ||
import android.support.annotation.DrawableRes; | ||
import android.support.v4.app.NotificationCompat; | ||
|
||
import org.chromium.base.ApiCompatibilityUtils; | ||
import org.chromium.base.ContextUtils; | ||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.notifications.ChromeNotification; | ||
import org.chromium.chrome.browser.notifications.ChromeNotificationBuilder; | ||
import org.chromium.chrome.browser.notifications.NotificationBuilderFactory; | ||
import org.chromium.chrome.browser.notifications.NotificationManagerProxyImpl; | ||
import org.chromium.chrome.browser.notifications.NotificationMetadata; | ||
import org.chromium.chrome.browser.notifications.NotificationUmaTracker; | ||
import org.chromium.chrome.browser.notifications.NotificationUmaTracker.SystemNotificationType; | ||
import org.chromium.chrome.browser.notifications.PendingIntentProvider; | ||
import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions; | ||
|
||
/** | ||
* Provides common functionality for handling sharing notifications. | ||
*/ | ||
public final class SharingNotificationUtil { | ||
/** | ||
* Shows a notification with a configuration common to all sharing notifications. | ||
* | ||
* @param type The type of notification. | ||
* @param group The notification group. | ||
* @param id The notification id. | ||
* @param contentIntent The notification content intent. | ||
* @param contentTitle The notification title text. | ||
* @param contentText The notification content text. | ||
* @param smallIcon The small notification icon. | ||
*/ | ||
public static void showNotification(@SystemNotificationType int type, String group, int id, | ||
PendingIntentProvider contentIntent, String contentTitle, String contentText, | ||
@DrawableRes int smallIcon) { | ||
Context context = ContextUtils.getApplicationContext(); | ||
Resources resources = context.getResources(); | ||
ChromeNotificationBuilder builder = | ||
NotificationBuilderFactory | ||
.createChromeNotificationBuilder(/*preferCompat=*/true, | ||
ChannelDefinitions.ChannelId.SHARING, | ||
/*remoteAppPackageName=*/null, | ||
new NotificationMetadata(type, group, id)) | ||
.setContentIntent(contentIntent) | ||
.setContentTitle(contentTitle) | ||
.setContentText(contentText) | ||
.setColor(ApiCompatibilityUtils.getColor( | ||
context.getResources(), R.color.default_icon_color_blue)) | ||
.setGroup(group) | ||
.setPriorityBeforeO(NotificationCompat.PRIORITY_HIGH) | ||
.setVibrate(new long[0]) | ||
.setSmallIcon(smallIcon) | ||
.setAutoCancel(true) | ||
.setDefaults(Notification.DEFAULT_ALL); | ||
ChromeNotification notification = builder.buildChromeNotification(); | ||
|
||
new NotificationManagerProxyImpl(context).notify(notification); | ||
NotificationUmaTracker.getInstance().onNotificationShown( | ||
type, notification.getNotification()); | ||
} | ||
|
||
private SharingNotificationUtil() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...c/org/chromium/chrome/browser/sharing/shared_clipboard/SharedClipboardMessageHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2019 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.sharing.shared_clipboard; | ||
|
||
import android.app.PendingIntent; | ||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
import org.chromium.base.ContextUtils; | ||
import org.chromium.base.annotations.CalledByNative; | ||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.notifications.NotificationConstants; | ||
import org.chromium.chrome.browser.notifications.NotificationUmaTracker; | ||
import org.chromium.chrome.browser.notifications.PendingIntentProvider; | ||
import org.chromium.chrome.browser.sharing.SharingNotificationUtil; | ||
|
||
/** | ||
* Handles Shared Clipboard messages and notifications for Android. | ||
*/ | ||
public class SharedClipboardMessageHandler { | ||
/** | ||
* Handles the tapping of a notification. | ||
*/ | ||
public static final class TapReceiver extends BroadcastReceiver { | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
// TODO(mvanouwerkerk): handle this. | ||
} | ||
} | ||
|
||
/** | ||
* Displays a notification to tell the user that new clipboard contents have been received and | ||
* written to the clipboard. | ||
*/ | ||
@CalledByNative | ||
private static void showNotification() { | ||
// TODO(mvanouwerkerk): Set the correct small icon for the notification. | ||
// TODO(mvanouwerkerk): Parameterize title text with machine name. | ||
Context context = ContextUtils.getApplicationContext(); | ||
PendingIntentProvider contentIntent = PendingIntentProvider.getBroadcast(context, | ||
/*requestCode=*/0, new Intent(context, TapReceiver.class), | ||
PendingIntent.FLAG_UPDATE_CURRENT); | ||
SharingNotificationUtil.showNotification( | ||
NotificationUmaTracker.SystemNotificationType.SHARED_CLIPBOARD, | ||
NotificationConstants.GROUP_SHARED_CLIPBOARD, | ||
NotificationConstants.NOTIFICATION_ID_SHARED_CLIPBOARD, contentIntent, | ||
context.getResources().getString(R.string.shared_clipboard_notification_title), | ||
context.getResources().getString(R.string.shared_clipboard_notification_text), | ||
R.drawable.ic_phone_googblue_36dp); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
chrome/browser/sharing/shared_clipboard/shared_clipboard_message_handler_android.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2019 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 "chrome/browser/sharing/shared_clipboard/shared_clipboard_message_handler_android.h" | ||
|
||
#include "base/logging.h" | ||
#include "base/strings/utf_string_conversions.h" | ||
#include "chrome/android/chrome_jni_headers/SharedClipboardMessageHandler_jni.h" | ||
#include "chrome/browser/sharing/proto/shared_clipboard_message.pb.h" | ||
#include "chrome/browser/sharing/proto/sharing_message.pb.h" | ||
#include "ui/base/clipboard/clipboard_types.h" | ||
#include "ui/base/clipboard/scoped_clipboard_writer.h" | ||
|
||
SharedClipboardMessageHandler::SharedClipboardMessageHandler() = default; | ||
|
||
SharedClipboardMessageHandler::~SharedClipboardMessageHandler() = default; | ||
|
||
void SharedClipboardMessageHandler::OnMessage( | ||
const chrome_browser_sharing::SharingMessage& message) { | ||
DCHECK(message.has_shared_clipboard_message()); | ||
|
||
ui::ScopedClipboardWriter(ui::ClipboardType::kCopyPaste) | ||
.WriteText(base::UTF8ToUTF16(message.shared_clipboard_message().text())); | ||
|
||
JNIEnv* env = base::android::AttachCurrentThread(); | ||
Java_SharedClipboardMessageHandler_showNotification(env); | ||
} |
25 changes: 25 additions & 0 deletions
25
chrome/browser/sharing/shared_clipboard/shared_clipboard_message_handler_android.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2019 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 CHROME_BROWSER_SHARING_SHARED_CLIPBOARD_SHARED_CLIPBOARD_MESSAGE_HANDLER_ANDROID_H_ | ||
#define CHROME_BROWSER_SHARING_SHARED_CLIPBOARD_SHARED_CLIPBOARD_MESSAGE_HANDLER_ANDROID_H_ | ||
|
||
#include "base/macros.h" | ||
#include "chrome/browser/sharing/sharing_message_handler.h" | ||
|
||
// Handles incoming messages for the shared clipboard feature. | ||
class SharedClipboardMessageHandler : public SharingMessageHandler { | ||
public: | ||
SharedClipboardMessageHandler(); | ||
~SharedClipboardMessageHandler() override; | ||
|
||
// SharingMessageHandler implementation: | ||
void OnMessage( | ||
const chrome_browser_sharing::SharingMessage& message) override; | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(SharedClipboardMessageHandler); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_SHARING_SHARED_CLIPBOARD_SHARED_CLIPBOARD_MESSAGE_HANDLER_ANDROID_H_ |
Oops, something went wrong.