Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: chrome/browser/extensions/extension_install_ui.cc

Issue 160501: Try again to land: http://codereview.chromium.org/160483 (Closed)
Patch Set: Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2009 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_install_ui.h"
6
7 #include "app/l10n_util.h"
8 #include "grit/chromium_strings.h"
9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/extensions/theme_preview_infobar_delegate.h"
11 #include "chrome/browser/profile.h"
12 #include "chrome/browser/tab_contents/tab_contents.h"
13
14 #if defined(OS_WIN)
15 #include "app/win_util.h"
16 #elif defined(OS_MACOSX)
17 #include "base/scoped_cftyperef.h"
18 #include "base/sys_string_conversions.h"
19 #include <CoreFoundation/CFUserNotification.h>
20 #endif
21
22 ExtensionInstallUI::ExtensionInstallUI(Profile* profile)
23 : profile_(profile), ui_loop_(MessageLoop::current()) {
24 }
25
26 bool ExtensionInstallUI::ConfirmInstall(Extension* extension) {
27 DCHECK(ui_loop_ == MessageLoop::current());
28
29 // We special-case themes to not show any confirm UI. Instead they are
30 // immediately installed, and then we show an infobar (see OnInstallSuccess)
31 // to allow the user to revert if they don't like it.
32 if (extension->IsTheme())
33 return true;
34
35 #if defined(OS_WIN)
36 if (win_util::MessageBox(GetForegroundWindow(),
37 L"Are you sure you want to install this extension?\n\n"
38 L"You should only install extensions from sources you trust.",
39 l10n_util::GetString(IDS_PRODUCT_NAME).c_str(),
40 MB_OKCANCEL) != IDOK) {
41 return false;
42 }
43 #elif defined(OS_MACOSX)
44 // Using CoreFoundation to do this dialog is unimaginably lame but will do
45 // until the UI is redone.
46 scoped_cftyperef<CFStringRef> product_name(
47 base::SysWideToCFStringRef(l10n_util::GetString(IDS_PRODUCT_NAME)));
48 CFOptionFlags response;
49 if (kCFUserNotificationAlternateResponse == CFUserNotificationDisplayAlert(
50 0, kCFUserNotificationCautionAlertLevel, NULL, NULL, NULL,
51 product_name,
52 CFSTR("Are you sure you want to install this extension?\n\n"
53 "This is a temporary message and it will be removed when "
54 "extensions UI is finalized."),
55 NULL, CFSTR("Cancel"), NULL, &response)) {
56 return false;
57 }
58 #else
59 NOTREACHED();
60 #endif // OS_*
61
62 return true;
63 }
64
65 void ExtensionInstallUI::OnInstallSuccess(Extension* extension) {
66 ShowThemeInfoBar(extension);
67 }
68
69 void ExtensionInstallUI::OnInstallFailure(const std::string& error) {
70 DCHECK(ui_loop_ == MessageLoop::current());
71
72 #if defined(OS_WIN)
73 win_util::MessageBox(NULL, UTF8ToWide(error), L"Extension Install Error",
74 MB_OK | MB_SETFOREGROUND);
75 #elif defined(OS_MACOSX)
76 // There must be a better way to do this, for all platforms.
77 scoped_cftyperef<CFStringRef> message_cf(
78 base::SysUTF8ToCFStringRef(error));
79 CFOptionFlags response;
80 CFUserNotificationDisplayAlert(
81 0, kCFUserNotificationCautionAlertLevel, NULL, NULL, NULL,
82 CFSTR("Extension Install Error"), message_cf,
83 NULL, NULL, NULL, &response);
84 #else
85 LOG(ERROR) << "Extension install failed: " << error.c_str();
86 NOTREACHED();
87 #endif
88 }
89
90 void ExtensionInstallUI::OnOverinstallAttempted(Extension* extension) {
91 ShowThemeInfoBar(extension);
92 }
93
94 void ExtensionInstallUI::ShowThemeInfoBar(Extension* extension) {
95 if (!extension->IsTheme())
96 return;
97
98 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
99 if (!browser)
100 return;
101
102 TabContents* tab_contents = browser->GetSelectedTabContents();
103 if (!tab_contents)
104 return;
105
106 // First remove any previous theme preview infobar.
107 for (int i = 0; i < tab_contents->infobar_delegate_count(); ++i) {
108 InfoBarDelegate* delegate = tab_contents->GetInfoBarDelegateAt(i);
109 if (delegate->AsThemePreviewInfobarDelegate()) {
110 tab_contents->RemoveInfoBar(delegate);
111 break;
112 }
113 }
114
115 // Now add the new one.
116 tab_contents->AddInfoBar(new ThemePreviewInfobarDelegate(
117 tab_contents, extension->name()));
118 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_install_ui.h ('k') | chrome/browser/extensions/extensions_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698