OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ios/chrome/browser/infobars/infobar.h" | 5 #include "ios/chrome/browser/infobars/infobar.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "components/infobars/core/confirm_infobar_delegate.h" | 8 #include "components/infobars/core/confirm_infobar_delegate.h" |
9 #include "components/translate/core/browser/translate_infobar_delegate.h" | 9 #include "components/translate/core/browser/translate_infobar_delegate.h" |
10 #import "ios/chrome/browser/infobars/confirm_infobar_controller.h" | 10 #import "ios/chrome/browser/infobars/confirm_infobar_controller.h" |
11 #include "ios/chrome/browser/translate/translate_infobar_tags.h" | |
11 | 12 |
12 using infobars::InfoBar; | 13 using infobars::InfoBar; |
13 using infobars::InfoBarDelegate; | 14 using infobars::InfoBarDelegate; |
14 | 15 |
15 InfoBarIOS::InfoBarIOS(scoped_ptr<InfoBarDelegate> delegate) | 16 InfoBarIOS::InfoBarIOS(scoped_ptr<InfoBarDelegate> delegate) |
16 : InfoBar(delegate.Pass()) { | 17 : InfoBar(delegate.Pass()) { |
17 } | 18 } |
18 | 19 |
19 InfoBarIOS::~InfoBarIOS() { | 20 InfoBarIOS::~InfoBarIOS() { |
20 DCHECK(controller_); | 21 DCHECK(controller_); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 if (delegate()->AsConfirmInfoBarDelegate()) { | 68 if (delegate()->AsConfirmInfoBarDelegate()) { |
68 ConfirmInfoBarDelegate* confirmDelegate = | 69 ConfirmInfoBarDelegate* confirmDelegate = |
69 delegate()->AsConfirmInfoBarDelegate(); | 70 delegate()->AsConfirmInfoBarDelegate(); |
70 if ((button_id == ConfirmInfoBarDelegate::BUTTON_OK && | 71 if ((button_id == ConfirmInfoBarDelegate::BUTTON_OK && |
71 confirmDelegate->Accept()) || | 72 confirmDelegate->Accept()) || |
72 (button_id == ConfirmInfoBarDelegate::BUTTON_CANCEL && | 73 (button_id == ConfirmInfoBarDelegate::BUTTON_CANCEL && |
73 delegate()->AsConfirmInfoBarDelegate()->Cancel())) { | 74 delegate()->AsConfirmInfoBarDelegate()->Cancel())) { |
74 RemoveSelf(); | 75 RemoveSelf(); |
75 } | 76 } |
76 } else if (delegate()->AsTranslateInfoBarDelegate()) { | 77 } else if (delegate()->AsTranslateInfoBarDelegate()) { |
77 // TODO(droger): Upstream Translate infobars. | 78 translate::TranslateInfoBarDelegate* translateDelegate = |
78 NOTREACHED() << "Translate infobars not upstreamed yet."; | 79 delegate()->AsTranslateInfoBarDelegate(); |
80 switch (button_id) { | |
81 case TranslateInfoBarIos::AFTER_DONE: | |
sdefresne
2015/01/08 09:22:33
nit: TranslateInfoBarIOS
| |
82 InfoBarDidCancel(); | |
83 break; | |
84 case TranslateInfoBarIos::AFTER_REVERT: | |
85 translateDelegate->RevertTranslation(); | |
86 break; | |
87 case TranslateInfoBarIos::BEFORE_ACCEPT: | |
88 translateDelegate->Translate(); | |
89 break; | |
90 case TranslateInfoBarIos::BEFORE_DENY: | |
91 translateDelegate->TranslationDeclined(); | |
92 if (translateDelegate->ShouldShowNeverTranslateShortcut()) | |
93 translateDelegate->ShowNeverTranslateInfobar(); | |
94 else | |
95 RemoveSelf(); | |
96 break; | |
97 case TranslateInfoBarIos::DENY_LANGUAGE: | |
98 translateDelegate->NeverTranslatePageLanguage(); | |
99 RemoveSelf(); | |
100 break; | |
101 case TranslateInfoBarIos::DENY_WEBSITE: | |
102 if (!translateDelegate->IsSiteBlacklisted()) | |
103 translateDelegate->ToggleSiteBlacklist(); | |
104 RemoveSelf(); | |
105 break; | |
106 case TranslateInfoBarIos::MESSAGE: | |
107 translateDelegate->MessageInfoBarButtonPressed(); | |
108 break; | |
109 default: | |
110 NOTREACHED() << "Unexpected Translate button label"; | |
111 break; | |
112 } | |
79 } | 113 } |
80 } | 114 } |
81 | 115 |
82 void InfoBarIOS::InfoBarDidCancel() { | 116 void InfoBarIOS::InfoBarDidCancel() { |
83 // If not owned, the infobar has already been removed. | 117 // If not owned, the infobar has already been removed. |
84 if (!owner()) | 118 if (!owner()) |
85 return; | 119 return; |
86 delegate()->InfoBarDismissed(); | 120 delegate()->InfoBarDismissed(); |
87 RemoveSelf(); | 121 RemoveSelf(); |
88 } | 122 } |
OLD | NEW |