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

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

Issue 164312: Make the theme install infobar have an 'undo' button instead of (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
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 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_install_ui.h" 5 #include "chrome/browser/extensions/extension_install_ui.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 19 matching lines...) Expand all
30 30
31 void ExtensionInstallUI::ConfirmInstall(CrxInstaller* installer, 31 void ExtensionInstallUI::ConfirmInstall(CrxInstaller* installer,
32 Extension* extension, 32 Extension* extension,
33 SkBitmap* install_icon) { 33 SkBitmap* install_icon) {
34 DCHECK(ui_loop_ == MessageLoop::current()); 34 DCHECK(ui_loop_ == MessageLoop::current());
35 35
36 // We special-case themes to not show any confirm UI. Instead they are 36 // We special-case themes to not show any confirm UI. Instead they are
37 // immediately installed, and then we show an infobar (see OnInstallSuccess) 37 // immediately installed, and then we show an infobar (see OnInstallSuccess)
38 // to allow the user to revert if they don't like it. 38 // to allow the user to revert if they don't like it.
39 if (extension->IsTheme()) { 39 if (extension->IsTheme()) {
40 // Remember the current theme in case the user pressed undo.
41 Extension* previous_theme = profile_->GetTheme();
42 if (previous_theme)
43 previous_theme_id_ = previous_theme->id();
44
40 installer->ContinueInstall(); 45 installer->ContinueInstall();
41 return; 46 return;
42 } 47 }
43 48
44 #if defined(OS_WIN) 49 #if defined(OS_WIN)
45 ShowExtensionInstallPrompt(profile_, installer, extension, install_icon); 50 ShowExtensionInstallPrompt(profile_, installer, extension, install_icon);
46 51
47 #elif defined(OS_MACOSX) 52 #elif defined(OS_MACOSX)
48 // TODO(port): Implement nicer UI. 53 // TODO(port): Implement nicer UI.
49 // Using CoreFoundation to do this dialog is unimaginably lame but will do 54 // Using CoreFoundation to do this dialog is unimaginably lame but will do
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", error.c_str()); 98 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", error.c_str());
94 gtk_dialog_run(GTK_DIALOG(dialog)); 99 gtk_dialog_run(GTK_DIALOG(dialog));
95 gtk_widget_destroy(dialog); 100 gtk_widget_destroy(dialog);
96 #endif 101 #endif
97 } 102 }
98 103
99 void ExtensionInstallUI::OnOverinstallAttempted(Extension* extension) { 104 void ExtensionInstallUI::OnOverinstallAttempted(Extension* extension) {
100 ShowThemeInfoBar(extension); 105 ShowThemeInfoBar(extension);
101 } 106 }
102 107
103 void ExtensionInstallUI::ShowThemeInfoBar(Extension* extension) { 108 void ExtensionInstallUI::ShowThemeInfoBar(Extension* new_theme) {
104 if (!extension->IsTheme()) 109 if (!new_theme->IsTheme())
105 return; 110 return;
106 111
107 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); 112 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
108 if (!browser) 113 if (!browser)
109 return; 114 return;
110 115
111 TabContents* tab_contents = browser->GetSelectedTabContents(); 116 TabContents* tab_contents = browser->GetSelectedTabContents();
112 if (!tab_contents) 117 if (!tab_contents)
113 return; 118 return;
114 119
115 // First find any previous theme preview infobars. 120 // First find any previous theme preview infobars.
116 InfoBarDelegate* old_delegate = NULL; 121 InfoBarDelegate* old_delegate = NULL;
117 for (int i = 0; i < tab_contents->infobar_delegate_count(); ++i) { 122 for (int i = 0; i < tab_contents->infobar_delegate_count(); ++i) {
118 InfoBarDelegate* delegate = tab_contents->GetInfoBarDelegateAt(i); 123 InfoBarDelegate* delegate = tab_contents->GetInfoBarDelegateAt(i);
119 if (delegate->AsThemePreviewInfobarDelegate()) { 124 if (delegate->AsThemePreviewInfobarDelegate()) {
120 old_delegate = delegate; 125 old_delegate = delegate;
121 break; 126 break;
122 } 127 }
123 } 128 }
124 129
125 // Then either replace that old one or add a new one. 130 // Then either replace that old one or add a new one.
126 InfoBarDelegate* new_delegate = new ThemePreviewInfobarDelegate(tab_contents, 131 InfoBarDelegate* new_delegate = new ThemePreviewInfobarDelegate(tab_contents,
127 extension->name()); 132 new_theme->name(), previous_theme_id_);
128 133
129 if (old_delegate) 134 if (old_delegate)
130 tab_contents->ReplaceInfoBar(old_delegate, new_delegate); 135 tab_contents->ReplaceInfoBar(old_delegate, new_delegate);
131 else 136 else
132 tab_contents->AddInfoBar(new_delegate); 137 tab_contents->AddInfoBar(new_delegate);
133 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698