Upstream version 9.37.195.0
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / infobar / ConfirmInfoBar.java
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
5 package org.chromium.chrome.browser.infobar;
6
7 /**
8  * An infobar that presents the user with several buttons.
9  *
10  * TODO(newt): merge this into InfoBar.java.
11  */
12 public class ConfirmInfoBar extends InfoBar {
13     /** Text shown on the primary button, e.g. "OK". */
14     private final String mPrimaryButtonText;
15
16     /** Text shown on the secondary button, e.g. "Cancel".*/
17     private final String mSecondaryButtonText;
18
19     /** Text shown on the extra button, e.g. "More info". */
20     private final String mTertiaryButtonText;
21
22     /** Notified when one of the buttons is clicked. */
23     private final InfoBarListeners.Confirm mConfirmListener;
24
25     public ConfirmInfoBar(long nativeInfoBar, InfoBarListeners.Confirm confirmListener,
26             int iconDrawableId, String message, String linkText, String primaryButtonText,
27             String secondaryButtonText) {
28         super(confirmListener, iconDrawableId, message);
29         mPrimaryButtonText = primaryButtonText;
30         mSecondaryButtonText = secondaryButtonText;
31         mTertiaryButtonText = linkText;
32         mConfirmListener = confirmListener;
33         setNativeInfoBar(nativeInfoBar);
34     }
35
36     @Override
37     public void createContent(InfoBarLayout layout) {
38         layout.setButtons(mPrimaryButtonText, mSecondaryButtonText, mTertiaryButtonText);
39     }
40
41     @Override
42     public void onButtonClicked(boolean isPrimaryButton) {
43         if (mConfirmListener != null) {
44             mConfirmListener.onConfirmInfoBarButtonClicked(this, isPrimaryButton);
45         }
46
47         if (mNativeInfoBarPtr != 0) {
48             int action = isPrimaryButton ? InfoBar.ACTION_TYPE_OK : InfoBar.ACTION_TYPE_CANCEL;
49             nativeOnButtonClicked(mNativeInfoBarPtr, action, "");
50         }
51     }
52
53     @Override
54     public void onCloseButtonClicked() {
55         if (mNativeInfoBarPtr != 0) {
56             nativeOnCloseButtonClicked(mNativeInfoBarPtr);
57         } else {
58             super.dismissJavaOnlyInfoBar();
59         }
60     }
61 }