ConfirmInfoBarDelegate.java revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package org.chromium.chrome.browser.infobar;
6
7import org.chromium.base.CalledByNative;
8import org.chromium.chrome.browser.ResourceId;
9
10/**
11 * Provides JNI methods for ConfirmInfoBars
12 */
13public class ConfirmInfoBarDelegate {
14
15    private ConfirmInfoBarDelegate() {
16    }
17
18    @CalledByNative
19    public static ConfirmInfoBarDelegate create() {
20        return new ConfirmInfoBarDelegate();
21    }
22
23    /**
24     * Creates and begins the process for showing a ConfirmInfoBar.
25     * @param nativeInfoBar Pointer to the C++ InfoBar corresponding to the Java InfoBar.
26     * @param enumeratedIconId ID corresponding to the icon that will be shown for the InfoBar.
27     *                         The ID must have been mapped using the ResourceMapper class before
28     *                         passing it to this function.
29     * @param message Message to display to the user indicating what the InfoBar is for.
30     * @param buttonOk String to display on the OK button.
31     * @param buttonCancel String to display on the Cancel button.
32     */
33    @CalledByNative
34    InfoBar showConfirmInfoBar(int nativeInfoBar, int enumeratedIconId, String message,
35            String buttonOk, String buttonCancel) {
36        int drawableId = ResourceId.mapToDrawableId(enumeratedIconId);
37
38        // Apparently, yellow was the popular choice at the time these InfoBars were implemented
39        // because they stuck out more (hence the BACKGROUND_TYPE_WARNING) default.
40        ConfirmInfoBar infoBar = new ConfirmInfoBar(nativeInfoBar, null,
41                InfoBar.BACKGROUND_TYPE_WARNING, drawableId, message, buttonOk, buttonCancel);
42        return infoBar;
43    }
44}