Commit 0fbe5d02 authored by kaliamoorthi's avatar kaliamoorthi Committed by Commit bot

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}
parent 38311416
...@@ -533,6 +533,17 @@ bool ProtocolHandlerRegistry::IsRegistered( ...@@ -533,6 +533,17 @@ bool ProtocolHandlerRegistry::IsRegistered(
handlers->end(); 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 { bool ProtocolHandlerRegistry::IsIgnored(const ProtocolHandler& handler) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
ProtocolHandlerList::const_iterator i; ProtocolHandlerList::const_iterator i;
...@@ -605,10 +616,9 @@ void ProtocolHandlerRegistry::RemoveHandler( ...@@ -605,10 +616,9 @@ void ProtocolHandlerRegistry::RemoveHandler(
if (HandlerExists(handler, handlers) && if (HandlerExists(handler, handlers) &&
HandlerExists(handler, &user_protocol_handlers_)) { HandlerExists(handler, &user_protocol_handlers_)) {
EraseHandler(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_); EraseHandler(handler, &protocol_handlers_);
}
} }
ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol()); ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol());
if (erase_success && q != default_handlers_.end() && q->second == handler) { if (erase_success && q != default_handlers_.end() && q->second == handler) {
......
...@@ -201,6 +201,14 @@ class ProtocolHandlerRegistry : public KeyedService { ...@@ -201,6 +201,14 @@ class ProtocolHandlerRegistry : public KeyedService {
// Returns true if an identical protocol handler has already been registered. // Returns true if an identical protocol handler has already been registered.
bool IsRegistered(const ProtocolHandler& handler) const; 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. // Returns true if an identical protocol handler is being ignored.
bool IsIgnored(const ProtocolHandler& handler) const; bool IsIgnored(const ProtocolHandler& handler) const;
......
...@@ -151,16 +151,46 @@ cr.define('options', function() { ...@@ -151,16 +151,46 @@ cr.define('options', function() {
this.classList.add('none'); this.classList.add('none');
this.appendChild(handlerElement); this.appendChild(handlerElement);
// Remove link. if (data.has_policy_recommendations) {
var removeElement = document.createElement('div'); // Create an indicator to show that the handler has policy
removeElement.textContent = // recommendations.
loadTimeData.getString('handlers_remove_link'); var indicator = new options.ControlledSettingIndicator();
removeElement.addEventListener('click', function(e) { if (data.is_default_handler_set_by_user || data.default_handler == -1) {
var value = selectElement ? selectElement.value : 0; // The default handler is registered by the user or set to none, which
delegate.removeHandler(value, data.handlers[value]); // indicates that the user setting has overridden a policy
}); // recommendation. Show the appropriate bubble.
removeElement.className = 'handlers-remove-column handlers-remove-link'; indicator.controlledBy = 'hasRecommendation';
this.appendChild(removeElement); 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 */ /** @override */
......
...@@ -109,6 +109,11 @@ void HandlerOptionsHandler::GetHandlersForProtocol( ...@@ -109,6 +109,11 @@ void HandlerOptionsHandler::GetHandlersForProtocol(
handlers_value->SetString("protocol", protocol); handlers_value->SetString("protocol", protocol);
handlers_value->SetInteger("default_handler", handlers_value->SetInteger("default_handler",
registry->GetHandlerIndex(protocol)); 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(); base::ListValue* handlers_list = new base::ListValue();
GetHandlersAsListValue(registry->GetHandlersFor(protocol), handlers_list); GetHandlersAsListValue(registry->GetHandlersFor(protocol), handlers_list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment