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

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: Finnur's 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 string_id = IDS_EXTENSIONS_KEEP_BUTTON_IN_TOOLBAR; 100 string_id = IDS_EXTENSIONS_KEEP_BUTTON_IN_TOOLBAR;
101 break; 101 break;
102 case (ExtensionContextMenuModel::OVERFLOWED): 102 case (ExtensionContextMenuModel::OVERFLOWED):
103 string_id = IDS_EXTENSIONS_SHOW_BUTTON_IN_TOOLBAR; 103 string_id = IDS_EXTENSIONS_SHOW_BUTTON_IN_TOOLBAR;
104 break; 104 break;
105 } 105 }
106 } 106 }
107 return string_id; 107 return string_id;
108 } 108 }
109 109
110 // Returns true if the given |extension| is required to remain installed by
111 // policy.
112 bool IsExtensionRequiredByPolicy(const Extension* extension,
113 Profile* profile) {
114 extensions::ManagementPolicy* policy =
115 extensions::ExtensionSystem::Get(profile)->management_policy();
116 return !policy->UserMayModifySettings(extension, nullptr) ||
117 policy->MustRemainInstalled(extension, nullptr);
118 }
119
110 } // namespace 120 } // namespace
111 121
112 ExtensionContextMenuModel::ExtensionContextMenuModel( 122 ExtensionContextMenuModel::ExtensionContextMenuModel(
113 const Extension* extension, 123 const Extension* extension,
114 Browser* browser, 124 Browser* browser,
115 ButtonVisibility button_visibility, 125 ButtonVisibility button_visibility,
116 PopupDelegate* delegate) 126 PopupDelegate* delegate)
117 : SimpleMenuModel(this), 127 : SimpleMenuModel(this),
118 extension_id_(extension->id()), 128 extension_id_(extension->id()),
119 is_component_(extensions::Manifest::IsComponentLocation( 129 is_component_(extensions::Manifest::IsComponentLocation(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 return extensions::ManifestURL::GetHomepageURL(extension).is_valid() && 173 return extensions::ManifestURL::GetHomepageURL(extension).is_valid() &&
164 !is_component_; 174 !is_component_;
165 } else if (command_id == INSPECT_POPUP) { 175 } else if (command_id == INSPECT_POPUP) {
166 WebContents* web_contents = GetActiveWebContents(); 176 WebContents* web_contents = GetActiveWebContents();
167 if (!web_contents) 177 if (!web_contents)
168 return false; 178 return false;
169 179
170 return extension_action_ && 180 return extension_action_ &&
171 extension_action_->HasPopup(SessionTabHelper::IdForTab(web_contents)); 181 extension_action_->HasPopup(SessionTabHelper::IdForTab(web_contents));
172 } else if (command_id == UNINSTALL) { 182 } else if (command_id == UNINSTALL) {
173 // Some extension types can not be uninstalled. 183 return !IsExtensionRequiredByPolicy(extension, profile_);
174 extensions::ManagementPolicy* policy =
175 extensions::ExtensionSystem::Get(profile_)->management_policy();
176 return policy->UserMayModifySettings(extension, nullptr) &&
177 !policy->MustRemainInstalled(extension, nullptr);
178 } 184 }
179 return true; 185 return true;
180 } 186 }
181 187
182 bool ExtensionContextMenuModel::GetAcceleratorForCommandId( 188 bool ExtensionContextMenuModel::GetAcceleratorForCommandId(
183 int command_id, ui::Accelerator* accelerator) { 189 int command_id, ui::Accelerator* accelerator) {
184 return false; 190 return false;
185 } 191 }
186 192
187 void ExtensionContextMenuModel::ExecuteCommand(int command_id, 193 void ExtensionContextMenuModel::ExecuteCommand(int command_id,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 WebContents* web_contents = GetActiveWebContents(); 305 WebContents* web_contents = GetActiveWebContents();
300 if (web_contents && 306 if (web_contents &&
301 extensions::ActiveScriptController::GetForWebContents(web_contents) 307 extensions::ActiveScriptController::GetForWebContents(web_contents)
302 ->WantsToRun(extension)) { 308 ->WantsToRun(extension)) {
303 AddItemWithStringId(ALWAYS_RUN, IDS_EXTENSIONS_ALWAYS_RUN); 309 AddItemWithStringId(ALWAYS_RUN, IDS_EXTENSIONS_ALWAYS_RUN);
304 } 310 }
305 311
306 if (!is_component_ || extensions::OptionsPageInfo::HasOptionsPage(extension)) 312 if (!is_component_ || extensions::OptionsPageInfo::HasOptionsPage(extension))
307 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); 313 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM);
308 314
309 if (!is_component_) 315 if (!is_component_) {
310 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); 316 bool is_required_by_policy =
317 IsExtensionRequiredByPolicy(extension, profile_);
318 int message_id = is_required_by_policy ?
319 IDS_EXTENSIONS_INSTALLED_BY_ADMIN : IDS_EXTENSIONS_UNINSTALL;
320 AddItem(UNINSTALL, l10n_util::GetStringUTF16(message_id));
321 if (is_required_by_policy) {
322 int uninstall_index = GetIndexOfCommandId(UNINSTALL);
323 SetIcon(uninstall_index,
324 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
325 IDR_CONTROLLED_SETTING_MANDATORY));
326 }
327 }
311 328
312 // Add a toggle visibility (show/hide) if the extension icon is shown on the 329 // Add a toggle visibility (show/hide) if the extension icon is shown on the
313 // toolbar. 330 // toolbar.
314 int visibility_string_id = 331 int visibility_string_id =
315 GetVisibilityStringId(profile_, extension, button_visibility); 332 GetVisibilityStringId(profile_, extension, button_visibility);
316 if (visibility_string_id != -1) 333 if (visibility_string_id != -1)
317 AddItemWithStringId(TOGGLE_VISIBILITY, visibility_string_id); 334 AddItemWithStringId(TOGGLE_VISIBILITY, visibility_string_id);
318 335
319 if (!is_component_) { 336 if (!is_component_) {
320 AddSeparator(ui::NORMAL_SEPARATOR); 337 AddSeparator(ui::NORMAL_SEPARATOR);
(...skipping 20 matching lines...) Expand all
341 extension_items_count_ = 0; 358 extension_items_count_ = 0;
342 extension_items_->AppendExtensionItems(MenuItem::ExtensionKey(extension_id_), 359 extension_items_->AppendExtensionItems(MenuItem::ExtensionKey(extension_id_),
343 base::string16(), 360 base::string16(),
344 &extension_items_count_, 361 &extension_items_count_,
345 true); // is_action_menu 362 true); // is_action_menu
346 } 363 }
347 364
348 content::WebContents* ExtensionContextMenuModel::GetActiveWebContents() const { 365 content::WebContents* ExtensionContextMenuModel::GetActiveWebContents() const {
349 return browser_->tab_strip_model()->GetActiveWebContents(); 366 return browser_->tab_strip_model()->GetActiveWebContents();
350 } 367 }
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