cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ios / chrome / browser / translate / never_translate_infobar_controller.mm
blob9051548addb354973f175550bf15532997e61d97
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.
5 #include "ios/chrome/browser/translate/never_translate_infobar_controller.h"
7 #include "base/strings/sys_string_conversions.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/translate/core/browser/translate_infobar_delegate.h"
10 #include "grit/components_strings.h"
11 #include "ios/chrome/browser/translate/translate_infobar_tags.h"
12 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
13 #import "ios/public/provider/chrome/browser/string_provider.h"
14 #import "ios/public/provider/chrome/browser/ui/infobar_view_delegate.h"
15 #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/gfx/image/image.h"
19 @interface NeverTranslateInfoBarController ()
21 // Action for any of the user defined buttons.
22 - (void)infoBarButtonDidPress:(id)sender;
24 @end
26 @implementation NeverTranslateInfoBarController
28 #pragma mark -
29 #pragma mark InfoBarControllerProtocol
31 - (base::scoped_nsobject<UIView<InfoBarViewProtocol>>)
32     viewForDelegate:(infobars::InfoBarDelegate*)delegate
33               frame:(CGRect)frame {
34   base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView;
35   translate::TranslateInfoBarDelegate* translateInfoBarDelegate =
36       delegate->AsTranslateInfoBarDelegate();
37   ios::ChromeBrowserProvider* provider = ios::GetChromeBrowserProvider();
38   infoBarView.reset(
39       ios::GetChromeBrowserProvider()->CreateInfoBarView(frame, self.delegate));
40   // Icon
41   gfx::Image icon = translateInfoBarDelegate->GetIcon();
42   if (!icon.IsEmpty())
43     [infoBarView addLeftIcon:icon.ToUIImage()];
44   // Main text.
45   base::string16 originalLanguage = translateInfoBarDelegate->language_name_at(
46       translateInfoBarDelegate->original_language_index());
47   [infoBarView addLabel:l10n_util::GetNSStringF(
48                             IDS_TRANSLATE_INFOBAR_NEVER_MESSAGE_IOS,
49                             provider->GetStringProvider()->GetProductName(),
50                             originalLanguage)];
51   // Close button.
52   [infoBarView addCloseButtonWithTag:TranslateInfoBarIOSTag::CLOSE
53                               target:self
54                               action:@selector(infoBarButtonDidPress:)];
55   // Other buttons.
56   NSString* buttonLanguage = l10n_util::GetNSStringF(
57       IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, originalLanguage);
58   NSString* buttonSite = l10n_util::GetNSString(
59       IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE);
60   [infoBarView addButton1:buttonLanguage
61                      tag1:TranslateInfoBarIOSTag::DENY_LANGUAGE
62                   button2:buttonSite
63                      tag2:TranslateInfoBarIOSTag::DENY_WEBSITE
64                    target:self
65                    action:@selector(infoBarButtonDidPress:)];
66   return infoBarView;
69 #pragma mark - Handling of User Events
71 - (void)infoBarButtonDidPress:(id)sender {
72   // This press might have occurred after the user has already pressed a button,
73   // in which case the view has been detached from the delegate and this press
74   // should be ignored.
75   if (!self.delegate) {
76     return;
77   }
78   if ([sender isKindOfClass:[UIButton class]]) {
79     NSUInteger buttonId = static_cast<UIButton*>(sender).tag;
80     if (buttonId == TranslateInfoBarIOSTag::CLOSE) {
81       self.delegate->InfoBarDidCancel();
82     } else {
83       DCHECK(buttonId == TranslateInfoBarIOSTag::DENY_LANGUAGE ||
84              buttonId == TranslateInfoBarIOSTag::DENY_WEBSITE);
85       self.delegate->InfoBarButtonDidPress(buttonId);
86     }
87   }
90 @end