Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 if (extension->IsTheme()) { | |
| 67 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | |
| 68 if (!browser) | |
| 69 return; | |
| 70 | |
| 71 TabContents* tab_contents = browser->GetSelectedTabContents(); | |
| 72 if (!tab_contents) | |
| 73 return; | |
| 74 | |
| 75 tab_contents->AddInfoBar(new ThemePreviewInfobarDelegate( | |
| 76 tab_contents, extension->name())); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 void ExtensionInstallUI::OnInstallFailure(const std::string& error) { | |
| 81 DCHECK(ui_loop_ == MessageLoop::current()); | |
| 82 | |
| 83 #if defined(OS_WIN) | |
| 84 win_util::MessageBox(NULL, UTF8ToWide(error), L"Extension Install Error", | |
| 85 MB_OK | MB_SETFOREGROUND); | |
| 86 #elif defined(OS_MACOSX) | |
| 87 // There must be a better way to do this, for all platforms. | |
| 88 scoped_cftyperef<CFStringRef> message_cf( | |
| 89 base::SysUTF8ToCFStringRef(error)); | |
| 90 CFOptionFlags response; | |
| 91 CFUserNotificationDisplayAlert( | |
| 92 0, kCFUserNotificationCautionAlertLevel, NULL, NULL, NULL, | |
| 93 CFSTR("Extension Install Error"), message_cf, | |
| 94 NULL, NULL, NULL, &response); | |
| 95 #else | |
| 96 LOG(ERROR) << error.c_str(); | |
|
Matt Perry
2009/07/31 22:33:39
nit: add a "Extension install failed:" prefix to t
| |
| 97 NOTREACHED(); | |
| 98 #endif | |
| 99 } | |
| OLD | NEW |