Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / extension_uninstall_dialog_cocoa.mm
blobffc6c54e8914533516a5192de2efa9cce32a46a4
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 #import "base/mac/scoped_nsobject.h"
12 #import "base/strings/sys_string_conversions.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "extensions/common/extension.h"
16 #include "skia/ext/skia_utils_mac.h"
17 #include "ui/base/l10n/l10n_util_mac.h"
18 #include "ui/gfx/image/image_skia_util_mac.h"
20 namespace {
22 // The Cocoa implementation of ExtensionUninstallDialog. This has a less
23 // complex life cycle than the Views and GTK implementations because the
24 // dialog blocks the page from navigating away and destroying the dialog,
25 // so there's no way for the dialog to outlive its delegate.
26 class ExtensionUninstallDialogCocoa
27     : public extensions::ExtensionUninstallDialog {
28  public:
29   ExtensionUninstallDialogCocoa(Profile* profile, Delegate* delegate);
30   ~ExtensionUninstallDialogCocoa() override;
32  private:
33   void Show() override;
36 ExtensionUninstallDialogCocoa::ExtensionUninstallDialogCocoa(
37     Profile* profile,
38     extensions::ExtensionUninstallDialog::Delegate* delegate)
39     : extensions::ExtensionUninstallDialog(profile, delegate) {
42 ExtensionUninstallDialogCocoa::~ExtensionUninstallDialogCocoa() {}
44 void ExtensionUninstallDialogCocoa::Show() {
45   NSAlert* alert = [[[NSAlert alloc] init] autorelease];
47   NSButton* continueButton = [alert addButtonWithTitle:l10n_util::GetNSString(
48       IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON)];
49   NSButton* cancelButton = [alert addButtonWithTitle:l10n_util::GetNSString(
50       IDS_CANCEL)];
51   // Default to accept when triggered via chrome://extensions page.
52   if (triggering_extension()) {
53     [continueButton setKeyEquivalent:@""];
54     [cancelButton setKeyEquivalent:@"\r"];
55   }
57   [alert setMessageText:base::SysUTF8ToNSString(GetHeadingText())];
58   [alert setAlertStyle:NSWarningAlertStyle];
59   [alert setIcon:gfx::NSImageFromImageSkia(icon())];
61   base::scoped_nsobject<NSButton> reportAbuseCheckbox;
62   if (ShouldShowReportAbuseCheckbox()) {
63     reportAbuseCheckbox.reset([[NSButton alloc] initWithFrame:NSZeroRect]);
64     [reportAbuseCheckbox setButtonType:NSSwitchButton];
65     [reportAbuseCheckbox setTitle:l10n_util::GetNSString(
66         IDS_EXTENSION_PROMPT_UNINSTALL_REPORT_ABUSE)];
67     [reportAbuseCheckbox sizeToFit];
68     [alert setAccessoryView:reportAbuseCheckbox];
69   }
71   if ([alert runModal] == NSAlertFirstButtonReturn) {
72     bool report_abuse_checked =
73         reportAbuseCheckbox.get() && [reportAbuseCheckbox state] == NSOnState;
74     OnDialogClosed(report_abuse_checked ?
75         CLOSE_ACTION_UNINSTALL_AND_REPORT_ABUSE : CLOSE_ACTION_UNINSTALL);
76   } else {
77     OnDialogClosed(CLOSE_ACTION_CANCELED);
78   }
81 }  // namespace
83 // static
84 extensions::ExtensionUninstallDialog*
85 extensions::ExtensionUninstallDialog::Create(Profile* profile,
86                                              gfx::NativeWindow parent,
87                                              Delegate* delegate) {
88   return new ExtensionUninstallDialogCocoa(profile, delegate);