| 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 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 5 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "extensions/common/extension.h" | 13 #include "extensions/common/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 #include "ui/gfx/image/image_skia_util_mac.h" | 19 #include "ui/gfx/image/image_skia_util_mac.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // The Cocoa implementation of ExtensionUninstallDialog. This has a less | 23 // The Cocoa implementation of ExtensionUninstallDialog. This has a less |
| 24 // complex life cycle than the Views and GTK implementations because the | 24 // complex life cycle than the Views and GTK implementations because the |
| 25 // dialog blocks the page from navigating away and destroying the dialog, | 25 // dialog blocks the page from navigating away and destroying the dialog, |
| 26 // so there's no way for the dialog to outlive its delegate. | 26 // so there's no way for the dialog to outlive its delegate. |
| 27 class ExtensionUninstallDialogCocoa | 27 class ExtensionUninstallDialogCocoa |
| 28 : public extensions::ExtensionUninstallDialog { | 28 : public extensions::ExtensionUninstallDialog { |
| 29 public: | 29 public: |
| 30 ExtensionUninstallDialogCocoa( | 30 ExtensionUninstallDialogCocoa(Profile* profile, |
| 31 Profile* profile, | 31 gfx::NativeWindow parent, |
| 32 Browser* browser, | 32 Delegate* delegate); |
| 33 Delegate* delegate); | |
| 34 virtual ~ExtensionUninstallDialogCocoa() OVERRIDE; | 33 virtual ~ExtensionUninstallDialogCocoa() OVERRIDE; |
| 35 | 34 |
| 36 private: | 35 private: |
| 37 virtual void Show() OVERRIDE; | 36 virtual void Show() OVERRIDE; |
| 37 virtual void RefreshIcon() OVERRIDE; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 ExtensionUninstallDialogCocoa::ExtensionUninstallDialogCocoa( | 40 ExtensionUninstallDialogCocoa::ExtensionUninstallDialogCocoa( |
| 41 Profile* profile, | 41 Profile* profile, |
| 42 Browser* browser, | 42 gfx::NativeWindow parent, |
| 43 extensions::ExtensionUninstallDialog::Delegate* delegate) | 43 extensions::ExtensionUninstallDialog::Delegate* delegate) |
| 44 : extensions::ExtensionUninstallDialog(profile, browser, delegate) { | 44 : extensions::ExtensionUninstallDialog(profile, parent, delegate) { |
| 45 } | 45 } |
| 46 | 46 |
| 47 ExtensionUninstallDialogCocoa::~ExtensionUninstallDialogCocoa() {} | 47 ExtensionUninstallDialogCocoa::~ExtensionUninstallDialogCocoa() {} |
| 48 | 48 |
| 49 void ExtensionUninstallDialogCocoa::Show() { | 49 void ExtensionUninstallDialogCocoa::Show() { |
| 50 NSAlert* alert = [[[NSAlert alloc] init] autorelease]; | 50 NSAlert* alert = [[[NSAlert alloc] init] autorelease]; |
| 51 | 51 |
| 52 NSButton* continueButton = [alert addButtonWithTitle:l10n_util::GetNSString( | 52 NSButton* continueButton = [alert addButtonWithTitle:l10n_util::GetNSString( |
| 53 IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON)]; | 53 IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON)]; |
| 54 NSButton* cancelButton = [alert addButtonWithTitle:l10n_util::GetNSString( | 54 NSButton* cancelButton = [alert addButtonWithTitle:l10n_util::GetNSString( |
| 55 IDS_CANCEL)]; | 55 IDS_CANCEL)]; |
| 56 // Default to accept when triggered via chrome://extensions page. | 56 // Default to accept when triggered via chrome://extensions page. |
| 57 if (triggering_extension_) { | 57 if (triggering_extension_) { |
| 58 [continueButton setKeyEquivalent:@""]; | 58 [continueButton setKeyEquivalent:@""]; |
| 59 [cancelButton setKeyEquivalent:@"\r"]; | 59 [cancelButton setKeyEquivalent:@"\r"]; |
| 60 } | 60 } |
| 61 | 61 |
| 62 [alert setMessageText:base::SysUTF8ToNSString(GetHeadingText())]; | 62 [alert setMessageText:base::SysUTF8ToNSString(GetHeadingText())]; |
| 63 [alert setAlertStyle:NSWarningAlertStyle]; | 63 [alert setAlertStyle:NSWarningAlertStyle]; |
| 64 [alert setIcon:gfx::NSImageFromImageSkia(icon_)]; | 64 [alert setIcon:gfx::NSImageFromImageSkia(icon_)]; |
| 65 | 65 |
| 66 if ([alert runModal] == NSAlertFirstButtonReturn) | 66 if ([alert runModal] == NSAlertFirstButtonReturn) |
| 67 delegate_->ExtensionUninstallAccepted(); | 67 delegate_->ExtensionUninstallAccepted(); |
| 68 else | 68 else |
| 69 delegate_->ExtensionUninstallCanceled(); | 69 delegate_->ExtensionUninstallCanceled(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void ExtensionUninstallDialogCocoa::RefreshIcon() { |
| 73 // TODO: Refresh the icon in Cocoa somehow |
| 74 } |
| 75 |
| 72 } // namespace | 76 } // namespace |
| 73 | 77 |
| 74 // static | 78 // static |
| 75 extensions::ExtensionUninstallDialog* | 79 extensions::ExtensionUninstallDialog* |
| 76 extensions::ExtensionUninstallDialog::Create(Profile* profile, | 80 extensions::ExtensionUninstallDialog::Create(Profile* profile, |
| 77 Browser* browser, | 81 gfx::NativeWindow parent, |
| 78 Delegate* delegate) { | 82 Delegate* delegate) { |
| 79 return new ExtensionUninstallDialogCocoa(profile, browser, delegate); | 83 return new ExtensionUninstallDialogCocoa(profile, parent, delegate); |
| 80 } | 84 } |
| OLD | NEW |