- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / extensions / extension_uninstall_dialog_cocoa.mm
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.
4
5 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include <string>
10
11 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/common/extensions/extension.h"
14 #include "grit/chromium_strings.h"
15 #include "grit/generated_resources.h"
16 #include "skia/ext/skia_utils_mac.h"
17 #include "ui/base/l10n/l10n_util_mac.h"
18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/image/image_skia_util_mac.h"
20
21 namespace {
22
23 // The Cocoa implementation of ExtensionUninstallDialog. This has a less
24 // complex life cycle than the Views and GTK implementations because the
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.
27 class ExtensionUninstallDialogCocoa : public ExtensionUninstallDialog {
28  public:
29   ExtensionUninstallDialogCocoa(
30       Profile* profile,
31       Browser* browser,
32       Delegate* delegate);
33   virtual ~ExtensionUninstallDialogCocoa() OVERRIDE;
34
35  private:
36   virtual void Show() OVERRIDE;
37 };
38
39 ExtensionUninstallDialogCocoa::ExtensionUninstallDialogCocoa(
40     Profile* profile,
41     Browser* browser,
42     ExtensionUninstallDialog::Delegate* delegate)
43     : ExtensionUninstallDialog(profile, browser, delegate) {}
44
45 ExtensionUninstallDialogCocoa::~ExtensionUninstallDialogCocoa() {}
46
47 void ExtensionUninstallDialogCocoa::Show() {
48   NSAlert* alert = [[[NSAlert alloc] init] autorelease];
49
50   NSButton* continueButton = [alert addButtonWithTitle:l10n_util::GetNSString(
51       IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON)];
52   // Clear the key equivalent (currently 'Return') because cancel is the default
53   // button.
54   [continueButton setKeyEquivalent:@""];
55
56   NSButton* cancelButton = [alert addButtonWithTitle:l10n_util::GetNSString(
57       IDS_CANCEL)];
58   [cancelButton setKeyEquivalent:@"\r"];
59
60   [alert setMessageText:l10n_util::GetNSStringF(
61        IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
62        UTF8ToUTF16(extension_->name()))];
63   [alert setAlertStyle:NSWarningAlertStyle];
64   [alert setIcon:gfx::NSImageFromImageSkia(icon_)];
65
66   if ([alert runModal] == NSAlertFirstButtonReturn)
67     delegate_->ExtensionUninstallAccepted();
68   else
69     delegate_->ExtensionUninstallCanceled();
70 }
71
72 }  // namespace
73
74 // static
75 ExtensionUninstallDialog* ExtensionUninstallDialog::Create(
76     Profile* profile,
77     Browser* browser,
78     Delegate* delegate) {
79   return new ExtensionUninstallDialogCocoa(profile, browser, delegate);
80 }