Standardize usage of virtual/override/final in chrome/browser/ui/
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / extension_uninstall_dialog_cocoa.mm
blobb050d84705c007bf801621285e8d6bca8522d65c
1 // Copyright (c) 2011 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 "chrome/browser/extensions/extension_uninstall_dialog.h"
7 #import <Cocoa/Cocoa.h>
9 #include <string>
11 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "extensions/common/extension.h"
15 #include "skia/ext/skia_utils_mac.h"
16 #include "ui/base/l10n/l10n_util_mac.h"
17 #include "ui/gfx/image/image_skia_util_mac.h"
19 namespace {
21 // The Cocoa implementation of ExtensionUninstallDialog. This has a less
22 // complex life cycle than the Views and GTK implementations because the
23 // dialog blocks the page from navigating away and destroying the dialog,
24 // so there's no way for the dialog to outlive its delegate.
25 class ExtensionUninstallDialogCocoa
26     : public extensions::ExtensionUninstallDialog {
27  public:
28   ExtensionUninstallDialogCocoa(Profile* profile,
29                                 gfx::NativeWindow parent,
30                                 Delegate* delegate);
31   ~ExtensionUninstallDialogCocoa() override;
33  private:
34   void Show() override;
37 ExtensionUninstallDialogCocoa::ExtensionUninstallDialogCocoa(
38     Profile* profile,
39     gfx::NativeWindow parent,
40     extensions::ExtensionUninstallDialog::Delegate* delegate)
41     : extensions::ExtensionUninstallDialog(profile, parent, delegate) {
44 ExtensionUninstallDialogCocoa::~ExtensionUninstallDialogCocoa() {}
46 void ExtensionUninstallDialogCocoa::Show() {
47   NSAlert* alert = [[[NSAlert alloc] init] autorelease];
49   NSButton* continueButton = [alert addButtonWithTitle:l10n_util::GetNSString(
50       IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON)];
51   NSButton* cancelButton = [alert addButtonWithTitle:l10n_util::GetNSString(
52       IDS_CANCEL)];
53   // Default to accept when triggered via chrome://extensions page.
54   if (triggering_extension_) {
55     [continueButton setKeyEquivalent:@""];
56     [cancelButton setKeyEquivalent:@"\r"];
57   }
59   [alert setMessageText:base::SysUTF8ToNSString(GetHeadingText())];
60   [alert setAlertStyle:NSWarningAlertStyle];
61   [alert setIcon:gfx::NSImageFromImageSkia(icon_)];
63   if ([alert runModal] == NSAlertFirstButtonReturn)
64     delegate_->ExtensionUninstallAccepted();
65   else
66     delegate_->ExtensionUninstallCanceled();
69 }  // namespace
71 // static
72 extensions::ExtensionUninstallDialog*
73 extensions::ExtensionUninstallDialog::Create(Profile* profile,
74                                              gfx::NativeWindow parent,
75                                              Delegate* delegate) {
76   return new ExtensionUninstallDialogCocoa(profile, parent, delegate);