Give names to all utility processes.
[chromium-blink-merge.git] / ios / chrome / browser / translate / never_translate_infobar_controller.mm
blob6ce746e324347f8a242bf2a1fd076eb9f65815c0
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 - (void)layoutForDelegate:(infobars::InfoBarDelegate*)delegate
32                     frame:(CGRect)frame {
33   translate::TranslateInfoBarDelegate* translateInfoBarDelegate =
34       delegate->AsTranslateInfoBarDelegate();
35   DCHECK(!infoBarView_);
36   ios::ChromeBrowserProvider* provider = ios::GetChromeBrowserProvider();
37   infoBarView_.reset([provider->CreateInfoBarView()
38       initWithFrame:frame
39            delegate: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:)];
68 #pragma mark - Handling of User Events
70 - (void)infoBarButtonDidPress:(id)sender {
71   // This press might have occurred after the user has already pressed a button,
72   // in which case the view has been detached from the delegate and this press
73   // should be ignored.
74   if (!delegate_) {
75     return;
76   }
77   if ([sender isKindOfClass:[UIButton class]]) {
78     NSUInteger buttonId = static_cast<UIButton*>(sender).tag;
79     if (buttonId == TranslateInfoBarIOSTag::CLOSE) {
80       delegate_->InfoBarDidCancel();
81     } else {
82       DCHECK(buttonId == TranslateInfoBarIOSTag::DENY_LANGUAGE ||
83              buttonId == TranslateInfoBarIOSTag::DENY_WEBSITE);
84       delegate_->InfoBarButtonDidPress(buttonId);
85     }
86   }
89 @end