From ac2bfd69e3affed2b0991bafe9321b25bba4bb75 Mon Sep 17 00:00:00 2001 From: "finnur@chromium.org" Date: Tue, 8 Apr 2014 14:12:34 +0000 Subject: [PATCH] Add a box explaining that an extension is controlling the settings for a particular setting. This applies to the startup page, search engine and the home page section. BUG=356204 R=dbeam@chromium.org, mad@chromium.org Review URL: https://codereview.chromium.org/216773004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262394 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/resources/options/browser_options.css | 15 +++ .../browser/resources/options/browser_options.html | 3 +- .../browser/resources/options/browser_options.js | 112 +++++++++++++++++++++ chrome/browser/resources/options/options.html | 7 ++ .../browser/resources/options/startup_section.html | 2 +- .../ui/webui/options/browser_options_handler.cc | 66 ++++++++++++ .../ui/webui/options/browser_options_handler.h | 5 + 7 files changed, 208 insertions(+), 2 deletions(-) diff --git a/chrome/browser/resources/options/browser_options.css b/chrome/browser/resources/options/browser_options.css index accc34ce1e59..24ed45d766d7 100644 --- a/chrome/browser/resources/options/browser_options.css +++ b/chrome/browser/resources/options/browser_options.css @@ -159,6 +159,21 @@ input[type='range'] { padding-top: 0; } +.extension-controlled-warning-box { + background-color: #fbfbfb; + border: 1px solid #cecece; + border-radius: 3px; + padding: 19px; +} + +.extension-controlled-warning { + -webkit-padding-start: 35px; + background-repeat: no-repeat; + margin-bottom: 14px; + padding-bottom: 6px; + padding-top: 3px; +} + /* Override a platform specific rule in Widgets that may no longer be relevant. * Too late in the development cycle to update Widgets.css due to the number * of pages that depend on it. diff --git a/chrome/browser/resources/options/browser_options.html b/chrome/browser/resources/options/browser_options.html index 246cdb45d228..04d37a46dc30 100644 --- a/chrome/browser/resources/options/browser_options.html +++ b/chrome/browser/resources/options/browser_options.html @@ -71,6 +71,7 @@ +
@@ -131,7 +132,7 @@

-
+
diff --git a/chrome/browser/resources/options/browser_options.js b/chrome/browser/resources/options/browser_options.js index c76154272f28..46ab1a6c1e66 100644 --- a/chrome/browser/resources/options/browser_options.js +++ b/chrome/browser/resources/options/browser_options.js @@ -542,6 +542,24 @@ cr.define('options', function() { }; $('reset-profile-settings-section').hidden = !loadTimeData.getBoolean('enableResetProfileSettings'); + + // Extension controlled UI. + this.addExtensionControlledBox_('search-section-content', + 'search-engine-controlled'); + this.addExtensionControlledBox_('extension-controlled-container', + 'homepage-controlled'); + this.addExtensionControlledBox_('startup-section-content', + 'startpage-controlled'); + + document.body.addEventListener('click', function(e) { + var button = findAncestor(e.target, function(el) { + return el.tagName == 'BUTTON' && + el.dataset.extensionId !== undefined && + el.dataset.extensionId.length; + }); + if (button) + chrome.send('disableExtension', [button.dataset.extensionId]); + }); }, /** @override */ @@ -1506,6 +1524,97 @@ cr.define('options', function() { }, /** + * Adds hidden warning boxes for settings potentially controlled by + * extensions. + * @param {string} parentDiv The div name to append the bubble to. + * @param {string} bubbleId The ID to use for the bubble. + * @private + */ + addExtensionControlledBox_: function(parentDiv, bubbleId) { + var bubble = $('extension-controlled-warning-template').cloneNode(true); + bubble.id = bubbleId; + var parent = $(parentDiv); + parent.insertBefore(bubble, parent.firstChild); + }, + + /** + * Adds a bubble showing that an extension is controlling a particular + * setting. + * @param {string} parentDiv The div name to append the bubble to. + * @param {string} bubbleId The ID to use for the bubble. + * @param {string} extensionId The ID of the controlling extension. + * @param {string} extensionName The name of the controlling extension. + * @private + */ + toggleExtensionControlledBox_: function( + parentDiv, bubbleId, extensionId, extensionName) { + var bubble = $(bubbleId); + assert(bubble); + bubble.hidden = extensionId.length == 0; + if (bubble.hidden) + return; + + // Set the extension image. + var div = bubble.firstElementChild; + div.style.backgroundImage = + 'url(chrome://extension-icon/' + extensionId + '/24/1)'; + + // Set the bubble label. + var label = loadTimeData.getStringF('extensionControlled', extensionName); + var docFrag = parseHtmlSubset('
' + label + '
', ['B', 'DIV']); + div.innerHTML = docFrag.firstChild.innerHTML; + + // Wire up the button to disable the right extension. + var button = div.nextElementSibling; + button.dataset.extensionId = extensionId; + }, + + /** + * Toggles the bubble that shows which extension is controlling the search + * engine. + * @param {string} extensionId The ID of the extension controlling the + * default search engine setting. + * @param {string} extensionName The name of the extension. + * @private + */ + toggleSearchEngineControlled_: function(extensionId, extensionName) { + this.toggleExtensionControlledBox_('search-section-content', + 'search-engine-controlled', + extensionId, + extensionName); + }, + + /** + * Toggles the bubble that shows which extension is controlling the home + * page. + * @param {string} extensionId The ID of the extension controlling the + * home page setting. + * @param {string} extensionName The name of the extension. + * @private + */ + toggleHomepageControlled_: function(extensionId, extensionName) { + this.toggleExtensionControlledBox_('extension-controlled-container', + 'homepage-controlled', + extensionId, + extensionName); + }, + + /** + * Toggles the bubble that shows which extension is controlling the startup + * pages. + * @param {string} extensionId The ID of the extension controlling the + * startup pages setting. + * @param {string} extensionName The name of the extension. + * @private + */ + toggleStartupPagesControlled_: function(extensionId, extensionName) { + this.toggleExtensionControlledBox_('startup-section-content', + 'startpage-controlled', + extensionId, + extensionName); + }, + + /** * Show/hide touchpad-related settings. * @private */ @@ -1659,6 +1768,9 @@ cr.define('options', function() { 'showManagedUserImportSuccess', 'showMouseControls', 'showTouchpadControls', + 'toggleHomepageControlled', + 'toggleSearchEngineControlled', + 'toggleStartupPagesControlled', 'updateAccountPicture', 'updateAutoLaunchState', 'updateDefaultBrowserState', diff --git a/chrome/browser/resources/options/options.html b/chrome/browser/resources/options/options.html index 1a49848924c0..111588428c33 100644 --- a/chrome/browser/resources/options/options.html +++ b/chrome/browser/resources/options/options.html @@ -93,6 +93,7 @@ + @@ -172,6 +173,12 @@
+ +
diff --git a/chrome/browser/resources/options/startup_section.html b/chrome/browser/resources/options/startup_section.html index 2eaea81c0bf3..ce1b7a9568d2 100644 --- a/chrome/browser/resources/options/startup_section.html +++ b/chrome/browser/resources/options/startup_section.html @@ -1,6 +1,6 @@

-
+
RegisterMessageCallback( + "refreshExtensionControlIndicators", + base::Bind( + &BrowserOptionsHandler::SetupExtensionControlledIndicators, + base::Unretained(this))); +#endif // defined(OS_WIN) } void BrowserOptionsHandler::Uninitialize() { @@ -791,6 +801,20 @@ void BrowserOptionsHandler::InitializeHandler() { base::Bind(&BrowserOptionsHandler::SetupEasyUnlock, base::Unretained(this))); +#if defined(OS_WIN) + const base::ListValue* empty = NULL; + profile_pref_registrar_.Add( + prefs::kURLsToRestoreOnStartup, + base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators, + base::Unretained(this), + empty)); + profile_pref_registrar_.Add( + prefs::kHomePage, + base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators, + base::Unretained(this), + empty)); +#endif // defined(OS_WIN) + #if defined(OS_CHROMEOS) if (!policy_registrar_) { policy_registrar_.reset(new policy::PolicyChangeRegistrar( @@ -832,6 +856,10 @@ void BrowserOptionsHandler::InitializePage() { SetupManagingSupervisedUsers(); SetupEasyUnlock(); +#if defined(OS_WIN) + SetupExtensionControlledIndicators(NULL); +#endif // defined(OS_WIN) + #if defined(OS_CHROMEOS) SetupAccessibilityFeatures(); policy::BrowserPolicyConnectorChromeOS* connector = @@ -1056,6 +1084,10 @@ void BrowserOptionsHandler::OnTemplateURLServiceChanged() { base::FundamentalValue( template_url_service_->is_default_search_managed() || template_url_service_->IsExtensionControlledDefaultSearch())); + +#if defined(OS_WIN) + SetupExtensionControlledIndicators(NULL); +#endif // defined(OS_WIN) } void BrowserOptionsHandler::SetDefaultSearchEngine( @@ -1673,4 +1705,38 @@ void BrowserOptionsHandler::SetupEasyUnlock() { has_pairing_value); } +#if defined(OS_WIN) +// Setup the UI for showing which settings are extension controlled. +void BrowserOptionsHandler::SetupExtensionControlledIndicators( + const base::ListValue* args) { + const extensions::Extension* extension = extensions::OverridesSearchEngine( + Profile::FromWebUI(web_ui()), NULL); + base::StringValue extension_id(extension ? extension->id() : std::string()); + base::StringValue extension_name( + extension ? extension->name() : std::string()); + web_ui()->CallJavascriptFunction( + "BrowserOptions.toggleSearchEngineControlled", + extension_id, + extension_name); + + extension = extensions::OverridesHomepage(Profile::FromWebUI(web_ui()), NULL); + extension_id = base::StringValue(extension ? extension->id() : std::string()); + extension_name = base::StringValue( + extension ? extension->name() : std::string()); + web_ui()->CallJavascriptFunction("BrowserOptions.toggleHomepageControlled", + extension_id, + extension_name); + + extension = extensions::OverridesStartupPages( + Profile::FromWebUI(web_ui()), NULL); + extension_id = base::StringValue(extension ? extension->id() : std::string()); + extension_name = base::StringValue( + extension ? extension->name() : std::string()); + web_ui()->CallJavascriptFunction( + "BrowserOptions.toggleStartupPagesControlled", + extension_id, + extension_name); +} +#endif // defined(OS_WIN) + } // namespace options diff --git a/chrome/browser/ui/webui/options/browser_options_handler.h b/chrome/browser/ui/webui/options/browser_options_handler.h index d5719b74911c..d935c27d2737 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.h +++ b/chrome/browser/ui/webui/options/browser_options_handler.h @@ -308,6 +308,11 @@ class BrowserOptionsHandler // Setup the UI for Easy Unlock. void SetupEasyUnlock(); +#if defined(OS_WIN) + // Setup the UI for showing which settings are extension controlled. + void SetupExtensionControlledIndicators(const base::ListValue* args); +#endif + #if defined(OS_CHROMEOS) // Setup the accessibility features for ChromeOS. void SetupAccessibilityFeatures(); -- 2.11.4.GIT