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>
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"
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 {
28 ExtensionUninstallDialogCocoa(Profile* profile,
29 gfx::NativeWindow parent,
31 ~ExtensionUninstallDialogCocoa() override;
37 ExtensionUninstallDialogCocoa::ExtensionUninstallDialogCocoa(
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(
53 // Default to accept when triggered via chrome://extensions page.
54 if (triggering_extension_) {
55 [continueButton setKeyEquivalent:@""];
56 [cancelButton setKeyEquivalent:@"\r"];
59 [alert setMessageText:base::SysUTF8ToNSString(GetHeadingText())];
60 [alert setAlertStyle:NSWarningAlertStyle];
61 [alert setIcon:gfx::NSImageFromImageSkia(icon_)];
63 if ([alert runModal] == NSAlertFirstButtonReturn)
64 delegate_->ExtensionUninstallAccepted();
66 delegate_->ExtensionUninstallCanceled();
72 extensions::ExtensionUninstallDialog*
73 extensions::ExtensionUninstallDialog::Create(Profile* profile,
74 gfx::NativeWindow parent,
76 return new ExtensionUninstallDialogCocoa(profile, parent, delegate);