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

Side by Side Diff: chrome/browser/cocoa/extensions/extension_action_context_menu.mm

Issue 595017: [Mac] Use the ExtensionToolbarModel for ordering of the Browser Actions. Prep... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Remove redundant profile object. Created 10 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" 5 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h"
6 6
7 #include "app/l10n_util_mac.h" 7 #include "app/l10n_util_mac.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "base/task.h" 9 #include "base/task.h"
10 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // NOTE: You MUST keep this in sync with the |menuItems| NSArray below. 98 // NOTE: You MUST keep this in sync with the |menuItems| NSArray below.
99 enum { 99 enum {
100 kExtensionContextName = 0, 100 kExtensionContextName = 0,
101 kExtensionContextOptions = 2, 101 kExtensionContextOptions = 2,
102 kExtensionContextDisable = 3, 102 kExtensionContextDisable = 3,
103 kExtensionContextUninstall = 4, 103 kExtensionContextUninstall = 4,
104 kExtensionContextManage = 6 104 kExtensionContextManage = 6
105 }; 105 };
106 } // namespace 106 } // namespace
107 107
108 - (id)initWithExtension:(Extension*)extension { 108 - (id)initWithExtension:(Extension*)extension profile:(Profile*)profile {
109 if ((self = [super initWithTitle:@""])) { 109 if ((self = [super initWithTitle:@""])) {
110 extension_ = extension; 110 extension_ = extension;
111 profile_ = profile;
111 112
112 NSArray* menuItems = [NSArray arrayWithObjects: 113 NSArray* menuItems = [NSArray arrayWithObjects:
113 base::SysUTF8ToNSString(extension->name()), 114 base::SysUTF8ToNSString(extension->name()),
114 [NSMenuItem separatorItem], 115 [NSMenuItem separatorItem],
115 l10n_util::GetNSStringWithFixup(IDS_EXTENSIONS_OPTIONS), 116 l10n_util::GetNSStringWithFixup(IDS_EXTENSIONS_OPTIONS),
116 l10n_util::GetNSStringWithFixup(IDS_EXTENSIONS_DISABLE), 117 l10n_util::GetNSStringWithFixup(IDS_EXTENSIONS_DISABLE),
117 l10n_util::GetNSStringWithFixup(IDS_EXTENSIONS_UNINSTALL), 118 l10n_util::GetNSStringWithFixup(IDS_EXTENSIONS_UNINSTALL),
118 [NSMenuItem separatorItem], 119 [NSMenuItem separatorItem],
119 l10n_util::GetNSStringWithFixup(IDS_MANAGE_EXTENSIONS), 120 l10n_util::GetNSStringWithFixup(IDS_MANAGE_EXTENSIONS),
120 nil]; 121 nil];
(...skipping 20 matching lines...) Expand all
141 } 142 }
142 } 143 }
143 } 144 }
144 145
145 return self; 146 return self;
146 } 147 }
147 return nil; 148 return nil;
148 } 149 }
149 150
150 - (void)dispatch:(id)menuItem { 151 - (void)dispatch:(id)menuItem {
151 Browser* browser = BrowserList::GetLastActive(); 152 Browser* browser = BrowserList::FindBrowserWithProfile(profile_);
152 // GetLastActive() returns NULL during testing.
153 if (!browser) 153 if (!browser)
154 return; 154 return;
155 155
156 Profile* profile = browser->profile();
157
158 NSMenuItem* item = (NSMenuItem*)menuItem; 156 NSMenuItem* item = (NSMenuItem*)menuItem;
159 switch ([item tag]) { 157 switch ([item tag]) {
160 case kExtensionContextName: { 158 case kExtensionContextName: {
161 GURL url(std::string(extension_urls::kGalleryBrowsePrefix) + 159 GURL url(std::string(extension_urls::kGalleryBrowsePrefix) +
162 std::string("/detail/") + extension_->id()); 160 std::string("/detail/") + extension_->id());
163 browser->OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); 161 browser->OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
164 break; 162 break;
165 } 163 }
166 case kExtensionContextOptions: { 164 case kExtensionContextOptions: {
167 DCHECK(!extension_->options_url().is_empty()); 165 DCHECK(!extension_->options_url().is_empty());
168 browser->OpenURL(extension_->options_url(), GURL(), 166 browser->OpenURL(extension_->options_url(), GURL(),
169 NEW_FOREGROUND_TAB, PageTransition::LINK); 167 NEW_FOREGROUND_TAB, PageTransition::LINK);
170 break; 168 break;
171 } 169 }
172 case kExtensionContextDisable: { 170 case kExtensionContextDisable: {
173 ExtensionsService* extension_service = profile->GetExtensionsService(); 171 ExtensionsService* extensionService = profile_->GetExtensionsService();
174 extension_service->DisableExtension(extension_->id()); 172 if (!extensionService)
173 return; // Incognito mode.
174 extensionService->DisableExtension(extension_->id());
175 break; 175 break;
176 } 176 }
177 case kExtensionContextUninstall: { 177 case kExtensionContextUninstall: {
178 if (uninstaller_.get()) 178 if (uninstaller_.get())
179 uninstaller_->Cancel(); 179 uninstaller_->Cancel();
180 180
181 uninstaller_ = new AsyncUninstaller(extension_); 181 uninstaller_ = new AsyncUninstaller(extension_);
182 uninstaller_->LoadExtensionIconThenConfirmUninstall(); 182 uninstaller_->LoadExtensionIconThenConfirmUninstall();
183 break; 183 break;
184 } 184 }
185 case kExtensionContextManage: { 185 case kExtensionContextManage: {
186 browser->OpenURL(GURL(chrome::kChromeUIExtensionsURL), GURL(), 186 browser->OpenURL(GURL(chrome::kChromeUIExtensionsURL), GURL(),
187 NEW_FOREGROUND_TAB, PageTransition::LINK); 187 NEW_FOREGROUND_TAB, PageTransition::LINK);
188 break; 188 break;
189 } 189 }
190 default: 190 default:
191 NOTREACHED(); 191 NOTREACHED();
192 break; 192 break;
193 } 193 }
194 } 194 }
195 195
196 @end 196 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698