OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 11 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 #include "grit/chromium_strings.h" | 14 #include "grit/chromium_strings.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "skia/ext/skia_utils_mac.h" | 16 #include "skia/ext/skia_utils_mac.h" |
17 #include "ui/base/l10n/l10n_util_mac.h" | 17 #include "ui/base/l10n/l10n_util_mac.h" |
18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
19 | 19 |
20 // static | 20 namespace { |
21 void ExtensionUninstallDialog::Show( | 21 |
22 Profile* profile, | 22 // The Cocoa implementation of ExtensionUninstallDialog. This has a less |
23 ExtensionUninstallDialog::Delegate* delegate, | 23 // complex life cycle than the Views and GTK implementations because the |
24 const Extension* extension, | 24 // dialog blocks the page from navigating away and destroying the dialog, |
25 SkBitmap* icon) { | 25 // so there's no way for the dialog to outlive its delegate. |
| 26 class ExtensionUninstallDialogCocoa : public ExtensionUninstallDialog { |
| 27 public: |
| 28 ExtensionUninstallDialogCocoa(Profile* profile, Delegate* delegate); |
| 29 virtual ~ExtensionUninstallDialogCocoa() OVERRIDE; |
| 30 |
| 31 private: |
| 32 virtual void Show() OVERRIDE; |
| 33 }; |
| 34 |
| 35 ExtensionUninstallDialogCocoa::ExtensionUninstallDialogCocoa( |
| 36 Profile* profile, ExtensionUninstallDialog::Delegate* delegate) |
| 37 : ExtensionUninstallDialog(profile, delegate) {} |
| 38 |
| 39 ExtensionUninstallDialogCocoa::~ExtensionUninstallDialogCocoa() {} |
| 40 |
| 41 void ExtensionUninstallDialogCocoa::Show() { |
26 NSAlert* alert = [[[NSAlert alloc] init] autorelease]; | 42 NSAlert* alert = [[[NSAlert alloc] init] autorelease]; |
27 | 43 |
28 NSButton* continueButton = [alert addButtonWithTitle:l10n_util::GetNSString( | 44 NSButton* continueButton = [alert addButtonWithTitle:l10n_util::GetNSString( |
29 IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON)]; | 45 IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON)]; |
30 // Clear the key equivalent (currently 'Return') because cancel is the default | 46 // Clear the key equivalent (currently 'Return') because cancel is the default |
31 // button. | 47 // button. |
32 [continueButton setKeyEquivalent:@""]; | 48 [continueButton setKeyEquivalent:@""]; |
33 | 49 |
34 NSButton* cancelButton = [alert addButtonWithTitle:l10n_util::GetNSString( | 50 NSButton* cancelButton = [alert addButtonWithTitle:l10n_util::GetNSString( |
35 IDS_CANCEL)]; | 51 IDS_CANCEL)]; |
36 [cancelButton setKeyEquivalent:@"\r"]; | 52 [cancelButton setKeyEquivalent:@"\r"]; |
37 | 53 |
38 [alert setMessageText:l10n_util::GetNSStringF( | 54 [alert setMessageText:l10n_util::GetNSStringF( |
39 IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, | 55 IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, |
40 UTF8ToUTF16(extension->name()))]; | 56 UTF8ToUTF16(extension_->name()))]; |
41 [alert setAlertStyle:NSWarningAlertStyle]; | 57 [alert setAlertStyle:NSWarningAlertStyle]; |
42 [alert setIcon:gfx::SkBitmapToNSImage(*icon)]; | 58 [alert setIcon:gfx::SkBitmapToNSImage(icon_)]; |
43 | 59 |
44 if ([alert runModal] == NSAlertFirstButtonReturn) | 60 if ([alert runModal] == NSAlertFirstButtonReturn) |
45 delegate->ExtensionDialogAccepted(); | 61 delegate_->ExtensionUninstallAccepted(); |
46 else | 62 else |
47 delegate->ExtensionDialogCanceled(); | 63 delegate_->ExtensionUninstallCanceled(); |
48 } | 64 } |
| 65 |
| 66 } // namespace |
| 67 |
| 68 // static |
| 69 ExtensionUninstallDialog* ExtensionUninstallDialog::Create( |
| 70 Profile* profile, Delegate* delegate) { |
| 71 return new ExtensionUninstallDialogCocoa(profile, delegate); |
| 72 } |
OLD | NEW |