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

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

Issue 1140763003: [Extensions] Show enterprise policy icon in the context menu when unremovable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/extensions/active_script_controller.h" 10 #include "chrome/browser/extensions/active_script_controller.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 if (!web_contents) 167 if (!web_contents)
168 return false; 168 return false;
169 169
170 return extension_action_ && 170 return extension_action_ &&
171 extension_action_->HasPopup(SessionTabHelper::IdForTab(web_contents)); 171 extension_action_->HasPopup(SessionTabHelper::IdForTab(web_contents));
172 } else if (command_id == UNINSTALL) { 172 } else if (command_id == UNINSTALL) {
173 // Some extension types can not be uninstalled. 173 // Some extension types can not be uninstalled.
174 extensions::ManagementPolicy* policy = 174 extensions::ManagementPolicy* policy =
175 extensions::ExtensionSystem::Get(profile_)->management_policy(); 175 extensions::ExtensionSystem::Get(profile_)->management_policy();
176 return policy->UserMayModifySettings(extension, nullptr) && 176 return policy->UserMayModifySettings(extension, nullptr) &&
177 !policy->MustRemainInstalled(extension, nullptr); 177 !policy->MustRemainInstalled(extension, nullptr);
Finnur 2015/05/20 12:02:35 nit: I think I'd like to see a private function ca
Devlin 2015/05/20 20:40:18 Done.
178 } 178 }
179 return true; 179 return true;
180 } 180 }
181 181
182 bool ExtensionContextMenuModel::GetAcceleratorForCommandId( 182 bool ExtensionContextMenuModel::GetAcceleratorForCommandId(
183 int command_id, ui::Accelerator* accelerator) { 183 int command_id, ui::Accelerator* accelerator) {
184 return false; 184 return false;
185 } 185 }
186 186
187 void ExtensionContextMenuModel::ExecuteCommand(int command_id, 187 void ExtensionContextMenuModel::ExecuteCommand(int command_id,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 WebContents* web_contents = GetActiveWebContents(); 299 WebContents* web_contents = GetActiveWebContents();
300 if (web_contents && 300 if (web_contents &&
301 extensions::ActiveScriptController::GetForWebContents(web_contents) 301 extensions::ActiveScriptController::GetForWebContents(web_contents)
302 ->WantsToRun(extension)) { 302 ->WantsToRun(extension)) {
303 AddItemWithStringId(ALWAYS_RUN, IDS_EXTENSIONS_ALWAYS_RUN); 303 AddItemWithStringId(ALWAYS_RUN, IDS_EXTENSIONS_ALWAYS_RUN);
304 } 304 }
305 305
306 if (!is_component_ || extensions::OptionsPageInfo::HasOptionsPage(extension)) 306 if (!is_component_ || extensions::OptionsPageInfo::HasOptionsPage(extension))
307 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); 307 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM);
308 308
309 if (!is_component_) 309 if (!is_component_) {
310 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); 310 extensions::ManagementPolicy* policy =
311 extensions::ExtensionSystem::Get(profile_)->management_policy();
312 bool is_required_by_policy =
313 !policy->UserMayModifySettings(extension, nullptr) ||
314 policy->MustRemainInstalled(extension, nullptr);
315 int message_id = is_required_by_policy ?
316 IDS_EXTENSIONS_INSTALLED_BY_ADMIN : IDS_EXTENSIONS_UNINSTALL;
317 AddItem(UNINSTALL, l10n_util::GetStringUTF16(message_id));
318 if (is_required_by_policy) {
319 int uninstall_index = GetIndexOfCommandId(UNINSTALL);
320 SetIcon(uninstall_index,
321 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
322 IDR_CONTROLLED_SETTING_MANDATORY));
323 }
324 }
311 325
312 // Add a toggle visibility (show/hide) if the extension icon is shown on the 326 // Add a toggle visibility (show/hide) if the extension icon is shown on the
313 // toolbar. 327 // toolbar.
314 int visibility_string_id = 328 int visibility_string_id =
315 GetVisibilityStringId(profile_, extension, button_visibility); 329 GetVisibilityStringId(profile_, extension, button_visibility);
316 if (visibility_string_id != -1) 330 if (visibility_string_id != -1)
317 AddItemWithStringId(TOGGLE_VISIBILITY, visibility_string_id); 331 AddItemWithStringId(TOGGLE_VISIBILITY, visibility_string_id);
318 332
319 if (!is_component_) { 333 if (!is_component_) {
320 AddSeparator(ui::NORMAL_SEPARATOR); 334 AddSeparator(ui::NORMAL_SEPARATOR);
(...skipping 20 matching lines...) Expand all
341 extension_items_count_ = 0; 355 extension_items_count_ = 0;
342 extension_items_->AppendExtensionItems(MenuItem::ExtensionKey(extension_id_), 356 extension_items_->AppendExtensionItems(MenuItem::ExtensionKey(extension_id_),
343 base::string16(), 357 base::string16(),
344 &extension_items_count_, 358 &extension_items_count_,
345 true); // is_action_menu 359 true); // is_action_menu
346 } 360 }
347 361
348 content::WebContents* ExtensionContextMenuModel::GetActiveWebContents() const { 362 content::WebContents* ExtensionContextMenuModel::GetActiveWebContents() const {
349 return browser_->tab_strip_model()->GetActiveWebContents(); 363 return browser_->tab_strip_model()->GetActiveWebContents();
350 } 364 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/extensions/extension_context_menu_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698