Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / extension_uninstall_dialog_cocoa.mm
blob167aa9205469918af030df9812117e14e8e8831b
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     if (reportAbuseCheckbox.get() && [reportAbuseCheckbox state] == NSOnState)
73       HandleReportAbuse();
74     delegate_->ExtensionUninstallAccepted();
75   } else {
76     delegate_->ExtensionUninstallCanceled();
77   }
80 }  // namespace
82 // static
83 extensions::ExtensionUninstallDialog*
84 extensions::ExtensionUninstallDialog::Create(Profile* profile,
85                                              gfx::NativeWindow parent,
86                                              Delegate* delegate) {
87   return new ExtensionUninstallDialogCocoa(profile, delegate);