Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / ios / chrome / browser / infobars / infobar.mm
blobeb558cf185a0fc873ebfb57df09a817297aaa4d4
1 // Copyright 2012 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.
5 #include "ios/chrome/browser/infobars/infobar.h"
7 #include "base/logging.h"
8 #include "components/infobars/core/confirm_infobar_delegate.h"
9 #include "components/translate/core/browser/translate_infobar_delegate.h"
10 #import "ios/chrome/browser/infobars/confirm_infobar_controller.h"
11 #include "ios/chrome/browser/translate/translate_infobar_tags.h"
13 using infobars::InfoBar;
14 using infobars::InfoBarDelegate;
16 InfoBarIOS::InfoBarIOS(scoped_ptr<InfoBarDelegate> delegate)
17     : InfoBar(delegate.Pass()) {
20 InfoBarIOS::~InfoBarIOS() {
21   DCHECK(controller_);
22   [controller_ detachView];
23   controller_.reset();
26 void InfoBarIOS::SetController(InfoBarController* controller) {
27   controller_.reset([controller retain]);
30 void InfoBarIOS::Layout(CGRect container_bounds) {
31   DCHECK(controller_);
32   if ([controller_ view]) {
33     [[controller_ view] setFrame:container_bounds];
34   } else {
35     [controller_ layoutForDelegate:delegate() frame:container_bounds];
36   }
37   SetBarTargetHeight([controller_ barHeight]);
40 UIView* InfoBarIOS::view() {
41   DCHECK(controller_);
42   return [controller_ view];
45 void InfoBarIOS::RemoveView() {
46   DCHECK(controller_);
47   [controller_ removeView];
50 void InfoBarIOS::PlatformSpecificOnHeightsRecalculated() {
51   DCHECK(controller_);
52   [controller_ onHeightsRecalculated:bar_height()];
55 #pragma mark - InfoBarViewDelegate
57 void InfoBarIOS::SetInfoBarTargetHeight(int height) {
58   SetBarTargetHeight(height);
61 // Some infobar button was pressed.
62 void InfoBarIOS::InfoBarButtonDidPress(NSUInteger button_id) {
63   // Do not add new logic for specific info bar delegates.
64   // TODO(droger): Move the logic elsewhere, http://crbug.com/307552.
65   // If not owned, the infobar has already been removed.
66   if (!owner())
67     return;
68   if (delegate()->AsConfirmInfoBarDelegate()) {
69     ConfirmInfoBarDelegate* confirmDelegate =
70         delegate()->AsConfirmInfoBarDelegate();
71     if ((button_id == ConfirmInfoBarDelegate::BUTTON_OK &&
72          confirmDelegate->Accept()) ||
73         (button_id == ConfirmInfoBarDelegate::BUTTON_CANCEL &&
74          delegate()->AsConfirmInfoBarDelegate()->Cancel())) {
75       RemoveSelf();
76     }
77   } else if (delegate()->AsTranslateInfoBarDelegate()) {
78     translate::TranslateInfoBarDelegate* translateDelegate =
79         delegate()->AsTranslateInfoBarDelegate();
80     switch (button_id) {
81       case TranslateInfoBarIOSTag::AFTER_DONE:
82         InfoBarDidCancel();
83         break;
84       case TranslateInfoBarIOSTag::AFTER_REVERT:
85         translateDelegate->RevertTranslation();
86         break;
87       case TranslateInfoBarIOSTag::BEFORE_ACCEPT:
88         translateDelegate->Translate();
89         break;
90       case TranslateInfoBarIOSTag::BEFORE_DENY:
91         translateDelegate->TranslationDeclined();
92         if (translateDelegate->ShouldShowNeverTranslateShortcut())
93           translateDelegate->ShowNeverTranslateInfobar();
94         else
95           RemoveSelf();
96         break;
97       case TranslateInfoBarIOSTag::DENY_LANGUAGE:
98         translateDelegate->NeverTranslatePageLanguage();
99         RemoveSelf();
100         break;
101       case TranslateInfoBarIOSTag::DENY_WEBSITE:
102         if (!translateDelegate->IsSiteBlacklisted())
103           translateDelegate->ToggleSiteBlacklist();
104         RemoveSelf();
105         break;
106       case TranslateInfoBarIOSTag::MESSAGE:
107         translateDelegate->MessageInfoBarButtonPressed();
108         break;
109       default:
110         NOTREACHED() << "Unexpected Translate button label";
111         break;
112     }
113   }
116 void InfoBarIOS::InfoBarDidCancel() {
117   // If not owned, the infobar has already been removed.
118   if (!owner())
119     return;
120   delegate()->InfoBarDismissed();
121   RemoveSelf();