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

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

Issue 11624036: Move the parsing of homepage_url" and "devtools_page" out of Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_context_menu_model.h" 5 #include "chrome/browser/extensions/extension_context_menu_model.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/extension_action.h" 8 #include "chrome/browser/extensions/extension_action.h"
9 #include "chrome/browser/extensions/extension_action_manager.h" 9 #include "chrome/browser/extensions/extension_action_manager.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/extensions/extension_tab_util.h" 12 #include "chrome/browser/extensions/extension_tab_util.h"
13 #include "chrome/browser/extensions/management_policy.h" 13 #include "chrome/browser/extensions/management_policy.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_tabstrip.h" 17 #include "chrome/browser/ui/browser_tabstrip.h"
18 #include "chrome/browser/ui/chrome_pages.h" 18 #include "chrome/browser/ui/chrome_pages.h"
19 #include "chrome/common/extensions/api/url_parser/url_info.h"
19 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "grit/chromium_strings.h" 25 #include "grit/chromium_strings.h"
25 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
27 28
28 using content::OpenURLParams; 29 using content::OpenURLParams;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 bool ExtensionContextMenuModel::IsCommandIdEnabled(int command_id) const { 67 bool ExtensionContextMenuModel::IsCommandIdEnabled(int command_id) const {
67 const Extension* extension = this->GetExtension(); 68 const Extension* extension = this->GetExtension();
68 if (!extension) 69 if (!extension)
69 return false; 70 return false;
70 71
71 if (command_id == CONFIGURE) { 72 if (command_id == CONFIGURE) {
72 return extension->options_url().spec().length() > 0; 73 return extension->options_url().spec().length() > 0;
73 } else if (command_id == NAME) { 74 } else if (command_id == NAME) {
74 // The NAME links to the Homepage URL. If the extension doesn't have a 75 // The NAME links to the Homepage URL. If the extension doesn't have a
75 // homepage, we just disable this menu item. 76 // homepage, we just disable this menu item.
76 return extension->GetHomepageURL().is_valid(); 77 return extensions::URLInfo::url(
78 extension, extensions::URLInfo::HOMEPAGE_URL).is_valid();
77 } else if (command_id == INSPECT_POPUP) { 79 } else if (command_id == INSPECT_POPUP) {
78 WebContents* web_contents = chrome::GetActiveWebContents(browser_); 80 WebContents* web_contents = chrome::GetActiveWebContents(browser_);
79 if (!web_contents) 81 if (!web_contents)
80 return false; 82 return false;
81 83
82 return extension_action_ && 84 return extension_action_ &&
83 extension_action_->HasPopup(SessionID::IdForTab(web_contents)); 85 extension_action_->HasPopup(SessionID::IdForTab(web_contents));
84 } else if (command_id == UNINSTALL) { 86 } else if (command_id == UNINSTALL) {
85 // Some extension types can not be uninstalled. 87 // Some extension types can not be uninstalled.
86 return extensions::ExtensionSystem::Get( 88 return extensions::ExtensionSystem::Get(
87 profile_)->management_policy()->UserMayModifySettings(extension, NULL); 89 profile_)->management_policy()->UserMayModifySettings(extension, NULL);
88 } 90 }
89 return true; 91 return true;
90 } 92 }
91 93
92 bool ExtensionContextMenuModel::GetAcceleratorForCommandId( 94 bool ExtensionContextMenuModel::GetAcceleratorForCommandId(
93 int command_id, ui::Accelerator* accelerator) { 95 int command_id, ui::Accelerator* accelerator) {
94 return false; 96 return false;
95 } 97 }
96 98
97 void ExtensionContextMenuModel::ExecuteCommand(int command_id) { 99 void ExtensionContextMenuModel::ExecuteCommand(int command_id) {
98 const Extension* extension = GetExtension(); 100 const Extension* extension = GetExtension();
99 if (!extension) 101 if (!extension)
100 return; 102 return;
101 103
102 switch (command_id) { 104 switch (command_id) {
103 case NAME: { 105 case NAME: {
104 OpenURLParams params(extension->GetHomepageURL(), Referrer(), 106 OpenURLParams params(
105 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, 107 extensions::URLInfo::url(
106 false); 108 extension, extensions::URLInfo::HOMEPAGE_URL), Referrer(),
109 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false);
107 browser_->OpenURL(params); 110 browser_->OpenURL(params);
108 break; 111 break;
109 } 112 }
110 case CONFIGURE: 113 case CONFIGURE:
111 DCHECK(!extension->options_url().is_empty()); 114 DCHECK(!extension->options_url().is_empty());
112 extensions::ExtensionSystem::Get(profile_)->process_manager()-> 115 extensions::ExtensionSystem::Get(profile_)->process_manager()->
113 OpenOptionsPage(extension, browser_); 116 OpenOptionsPage(extension, browser_);
114 break; 117 break;
115 case HIDE: { 118 case HIDE: {
116 ExtensionService* extension_service = 119 ExtensionService* extension_service =
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); 179 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON);
177 AddSeparator(ui::NORMAL_SEPARATOR); 180 AddSeparator(ui::NORMAL_SEPARATOR);
178 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS); 181 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS);
179 } 182 }
180 183
181 const Extension* ExtensionContextMenuModel::GetExtension() const { 184 const Extension* ExtensionContextMenuModel::GetExtension() const {
182 ExtensionService* extension_service = 185 ExtensionService* extension_service =
183 extensions::ExtensionSystem::Get(profile_)->extension_service(); 186 extensions::ExtensionSystem::Get(profile_)->extension_service();
184 return extension_service->GetExtensionById(extension_id_, false); 187 return extension_service->GetExtensionById(extension_id_, false);
185 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698