blob: 4e63450da4172be25b12d41a429187792e82f3e9 [file] [log] [blame]
// 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;
/**
* 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 void dismissMessage(
MessageWrapper message, WebContents webContents, @DismissReason int dismissReason) {
MessageDispatcher messageDispatcher =
MessageDispatcherProvider.from(webContents.getTopLevelNativeWindow());
messageDispatcher.dismissMessage(message.getMessageProperties(), dismissReason);
}
}