| 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_action_context_menu_model.h" | 
 |    6  | 
 |    7 #include "app/l10n_util.h" | 
 |    8 #include "chrome/browser/browser_list.h" | 
 |    9 #include "chrome/browser/browser_process.h" | 
 |   10 #include "chrome/browser/extensions/extensions_service.h" | 
 |   11 #include "chrome/browser/profile.h" | 
 |   12 #include "chrome/common/extensions/extension.h" | 
 |   13 #include "chrome/common/extensions/extension_constants.h" | 
 |   14 #include "chrome/common/url_constants.h" | 
 |   15 #include "grit/generated_resources.h" | 
 |   16  | 
 |   17 enum MenuEntries { | 
 |   18   NAME = 0, | 
 |   19   CONFIGURE, | 
 |   20   DISABLE, | 
 |   21   UNINSTALL, | 
 |   22   MANAGE, | 
 |   23 }; | 
 |   24  | 
 |   25 ExtensionActionContextMenuModel::ExtensionActionContextMenuModel( | 
 |   26     Extension* extension, ExtensionInstallUI::Delegate* delegate) | 
 |   27   : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)), | 
 |   28     extension_(extension), | 
 |   29     delegate_(delegate) { | 
 |   30   AddItem(NAME, ASCIIToUTF16(extension->name())); | 
 |   31   AddSeparator(); | 
 |   32   AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS); | 
 |   33   AddItemWithStringId(DISABLE, IDS_EXTENSIONS_DISABLE); | 
 |   34   AddItemWithStringId(UNINSTALL, IDS_EXTENSIONS_UNINSTALL); | 
 |   35   AddSeparator(); | 
 |   36  | 
 |   37   // TODO(finnur): It is too late in the process to do another round of | 
 |   38   // translations, so we'll switch fully to IDS_MANAGE_EXTENSIONS after merging | 
 |   39   // this to the beta branch. :/ | 
 |   40   std::string locale = g_browser_process->GetApplicationLocale(); | 
 |   41   if (locale.find_first_of("en-") == 0) | 
 |   42     AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS); | 
 |   43   else | 
 |   44     AddItemWithStringId(MANAGE, IDS_SHOW_EXTENSIONS); | 
 |   45 } | 
 |   46  | 
 |   47 ExtensionActionContextMenuModel::~ExtensionActionContextMenuModel() { | 
 |   48 } | 
 |   49  | 
 |   50 bool ExtensionActionContextMenuModel::IsCommandIdChecked(int command_id) const { | 
 |   51   return false; | 
 |   52 } | 
 |   53  | 
 |   54 bool ExtensionActionContextMenuModel::IsCommandIdEnabled(int command_id) const { | 
 |   55   if (command_id == CONFIGURE) | 
 |   56     return extension_->options_url().spec().length() > 0; | 
 |   57   return true; | 
 |   58 } | 
 |   59  | 
 |   60 bool ExtensionActionContextMenuModel::GetAcceleratorForCommandId( | 
 |   61     int command_id, views::Accelerator* accelerator) { | 
 |   62   return false; | 
 |   63 } | 
 |   64  | 
 |   65 void ExtensionActionContextMenuModel::ExecuteCommand(int command_id) { | 
 |   66   // TODO(finnur): GetLastActive returns NULL in unit tests. | 
 |   67   Browser* browser = BrowserList::GetLastActive(); | 
 |   68   Profile* profile = browser->profile(); | 
 |   69  | 
 |   70   switch (command_id) { | 
 |   71     case NAME: { | 
 |   72       GURL url(std::string(extension_urls::kGalleryBrowsePrefix) + | 
 |   73                std::string("/detail/") + extension_->id()); | 
 |   74       browser->OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | 
 |   75       break; | 
 |   76     } | 
 |   77     case CONFIGURE: | 
 |   78       DCHECK(!extension_->options_url().is_empty()); | 
 |   79       browser->OpenURL(extension_->options_url(), GURL(), | 
 |   80                        NEW_FOREGROUND_TAB, PageTransition::LINK); | 
 |   81       break; | 
 |   82     case DISABLE: { | 
 |   83       ExtensionsService* extension_service = profile->GetExtensionsService(); | 
 |   84       extension_service->DisableExtension(extension_->id()); | 
 |   85       break; | 
 |   86     } | 
 |   87     case UNINSTALL: { | 
 |   88       scoped_ptr<SkBitmap> uninstall_icon; | 
 |   89       Extension::DecodeIcon(extension_, Extension::EXTENSION_ICON_LARGE, | 
 |   90                             &uninstall_icon); | 
 |   91  | 
 |   92       ExtensionInstallUI client(profile); | 
 |   93       client.ConfirmUninstall(delegate_, extension_, uninstall_icon.get()); | 
 |   94       break; | 
 |   95     } | 
 |   96     case MANAGE: { | 
 |   97       browser->OpenURL(GURL(chrome::kChromeUIExtensionsURL), GURL(), | 
 |   98                        NEW_FOREGROUND_TAB, PageTransition::LINK); | 
 |   99       break; | 
 |  100     } | 
 |  101     default: | 
 |  102      NOTREACHED() << "Unknown option"; | 
 |  103      break; | 
 |  104   } | 
 |  105 } | 
| OLD | NEW |