/
MessageDispatcherBridge.java
49 lines (44 loc) · 2.09 KB
/
MessageDispatcherBridge.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 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.components.messages;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.WindowAndroid;
/**
* Java counterpart to MessageDispatcherBridge. Enables C++ feature code to enqueue/dismiss messages
* with MessageDispatcher.
*/
@JNINamespace("messages")
public class MessageDispatcherBridge {
/**
* Return false if it fails to enqueue message, which usually happens when
* activity is being recreated or destroyed; otherwise, return true.
*/
@CalledByNative
private static boolean enqueueMessage(MessageWrapper message, WebContents webContents,
@MessageScopeType int scopeType, boolean highPriority) {
MessageDispatcher messageDispatcher =
MessageDispatcherProvider.from(webContents.getTopLevelNativeWindow());
if (messageDispatcher == null) return false;
messageDispatcher.enqueueMessage(
message.getMessageProperties(), webContents, scopeType, highPriority);
return true;
}
@CalledByNative
private static boolean enqueueWindowScopedMessage(
MessageWrapper message, WindowAndroid windowAndroid, boolean highPriority) {
MessageDispatcher messageDispatcher = MessageDispatcherProvider.from(windowAndroid);
if (messageDispatcher == null) return false;
messageDispatcher.enqueueWindowScopedMessage(message.getMessageProperties(), highPriority);
return true;
}
@CalledByNative
private static void dismissMessage(
MessageWrapper message, WindowAndroid windowAndroid, @DismissReason int dismissReason) {
MessageDispatcher messageDispatcher = MessageDispatcherProvider.from(windowAndroid);
if (messageDispatcher == null) return;
messageDispatcher.dismissMessage(message.getMessageProperties(), dismissReason);
}
}