summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaliamoorthi <kaliamoorthi@chromium.org>2014-09-01 09:53:54 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-01 16:55:45 +0000
commit0fbe5d023244f05d6c5c1e03eac8576740dac38b (patch)
tree7bccbe1b60892cba32fca951a49797d01c22821e
parent3831141691e27d79130bc784e55e7ff34a75b099 (diff)
downloadchromium_src-0fbe5d023244f05d6c5c1e03eac8576740dac38b.zip
chromium_src-0fbe5d023244f05d6c5c1e03eac8576740dac38b.tar.gz
chromium_src-0fbe5d023244f05d6c5c1e03eac8576740dac38b.tar.bz2
Add policy indicator for protocol handlers
This CL adds policy indicators to show that a protocol handler is installed by policy. BUG=384361 Review URL: https://codereview.chromium.org/518673003 Cr-Commit-Position: refs/heads/master@{#292882}
-rw-r--r--chrome/browser/custom_handlers/protocol_handler_registry.cc16
-rw-r--r--chrome/browser/custom_handlers/protocol_handler_registry.h8
-rw-r--r--chrome/browser/resources/options/handler_options_list.js50
-rw-r--r--chrome/browser/ui/webui/options/handler_options_handler.cc5
4 files changed, 66 insertions, 13 deletions
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.cc b/chrome/browser/custom_handlers/protocol_handler_registry.cc
index 7302ce5..72f134d6 100644
--- a/chrome/browser/custom_handlers/protocol_handler_registry.cc
+++ b/chrome/browser/custom_handlers/protocol_handler_registry.cc
@@ -533,6 +533,17 @@ bool ProtocolHandlerRegistry::IsRegistered(
handlers->end();
}
+bool ProtocolHandlerRegistry::IsRegisteredByUser(
+ const ProtocolHandler& handler) {
+ return HandlerExists(handler, &user_protocol_handlers_);
+}
+
+bool ProtocolHandlerRegistry::HasPolicyRegisteredHandler(
+ const std::string& scheme) {
+ return (policy_protocol_handlers_.find(scheme) !=
+ policy_protocol_handlers_.end());
+}
+
bool ProtocolHandlerRegistry::IsIgnored(const ProtocolHandler& handler) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
ProtocolHandlerList::const_iterator i;
@@ -605,10 +616,9 @@ void ProtocolHandlerRegistry::RemoveHandler(
if (HandlerExists(handler, handlers) &&
HandlerExists(handler, &user_protocol_handlers_)) {
EraseHandler(handler, &user_protocol_handlers_);
- if (!HandlerExists(handler, &policy_protocol_handlers_)) {
- erase_success = true;
+ erase_success = true;
+ if (!HandlerExists(handler, &policy_protocol_handlers_))
EraseHandler(handler, &protocol_handlers_);
- }
}
ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol());
if (erase_success && q != default_handlers_.end() && q->second == handler) {
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.h b/chrome/browser/custom_handlers/protocol_handler_registry.h
index 724c591..4afc07f 100644
--- a/chrome/browser/custom_handlers/protocol_handler_registry.h
+++ b/chrome/browser/custom_handlers/protocol_handler_registry.h
@@ -201,6 +201,14 @@ class ProtocolHandlerRegistry : public KeyedService {
// Returns true if an identical protocol handler has already been registered.
bool IsRegistered(const ProtocolHandler& handler) const;
+ // Returns true if an identical protocol handler has already been registered
+ // by the user.
+ bool IsRegisteredByUser(const ProtocolHandler& handler);
+
+ // Returns true if the scheme has at least one handler that is registered by
+ // policy.
+ bool HasPolicyRegisteredHandler(const std::string& scheme);
+
// Returns true if an identical protocol handler is being ignored.
bool IsIgnored(const ProtocolHandler& handler) const;
diff --git a/chrome/browser/resources/options/handler_options_list.js b/chrome/browser/resources/options/handler_options_list.js
index 12129a8..0e15385 100644
--- a/chrome/browser/resources/options/handler_options_list.js
+++ b/chrome/browser/resources/options/handler_options_list.js
@@ -151,16 +151,46 @@ cr.define('options', function() {
this.classList.add('none');
this.appendChild(handlerElement);
- // Remove link.
- var removeElement = document.createElement('div');
- removeElement.textContent =
- loadTimeData.getString('handlers_remove_link');
- removeElement.addEventListener('click', function(e) {
- var value = selectElement ? selectElement.value : 0;
- delegate.removeHandler(value, data.handlers[value]);
- });
- removeElement.className = 'handlers-remove-column handlers-remove-link';
- this.appendChild(removeElement);
+ if (data.has_policy_recommendations) {
+ // Create an indicator to show that the handler has policy
+ // recommendations.
+ var indicator = new options.ControlledSettingIndicator();
+ if (data.is_default_handler_set_by_user || data.default_handler == -1) {
+ // The default handler is registered by the user or set to none, which
+ // indicates that the user setting has overridden a policy
+ // recommendation. Show the appropriate bubble.
+ indicator.controlledBy = 'hasRecommendation';
+ indicator.resetHandler = function() {
+ // If there is a policy recommendation, data.handlers.length >= 1.
+ // Setting the default handler to 0 ensures that it won't be 'none',
+ // and there *is* a user registered handler created by setDefault,
+ // which is required for a change notification.
+ // The user-registered handlers are removed in a loop. Note that if
+ // a handler is installed by policy, removeHandler does nothing.
+ delegate.setDefault(data.handlers[0]);
+ for (var i = 0; i < data.handlers.length; ++i) {
+ delegate.removeHandler(value, data.handlers[i]);
+ }
+ };
+ } else {
+ indicator.controlledBy = 'recommended';
+ }
+ this.appendChild(indicator);
+ }
+
+ if (data.registered_by_user) {
+ // Remove link.
+ var removeElement = document.createElement('div');
+ removeElement.textContent =
+ loadTimeData.getString('handlers_remove_link');
+ removeElement.addEventListener('click', function(e) {
+ var value = selectElement ? selectElement.value : 0;
+ delegate.removeHandler(value, data.handlers[value]);
+ });
+ removeElement.className =
+ 'handlers-remove-column handlers-remove-link';
+ this.appendChild(removeElement);
+ }
},
/** @override */
diff --git a/chrome/browser/ui/webui/options/handler_options_handler.cc b/chrome/browser/ui/webui/options/handler_options_handler.cc
index 2ba77cd..4af9abb 100644
--- a/chrome/browser/ui/webui/options/handler_options_handler.cc
+++ b/chrome/browser/ui/webui/options/handler_options_handler.cc
@@ -109,6 +109,11 @@ void HandlerOptionsHandler::GetHandlersForProtocol(
handlers_value->SetString("protocol", protocol);
handlers_value->SetInteger("default_handler",
registry->GetHandlerIndex(protocol));
+ handlers_value->SetBoolean(
+ "is_default_handler_set_by_user",
+ registry->IsRegisteredByUser(registry->GetHandlerFor(protocol)));
+ handlers_value->SetBoolean("has_policy_recommendations",
+ registry->HasPolicyRegisteredHandler(protocol));
base::ListValue* handlers_list = new base::ListValue();
GetHandlersAsListValue(registry->GetHandlersFor(protocol), handlers_list);