| OLD | NEW |
| 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/ui/webui/options/handler_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/handler_options_handler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 ProtocolHandlerRegistry* HandlerOptionsHandler::GetProtocolHandlerRegistry() { | 84 ProtocolHandlerRegistry* HandlerOptionsHandler::GetProtocolHandlerRegistry() { |
| 85 return ProtocolHandlerRegistryFactory::GetForBrowserContext( | 85 return ProtocolHandlerRegistryFactory::GetForBrowserContext( |
| 86 Profile::FromWebUI(web_ui())); | 86 Profile::FromWebUI(web_ui())); |
| 87 } | 87 } |
| 88 | 88 |
| 89 static void GetHandlersAsListValue( | 89 static void GetHandlersAsListValue( |
| 90 const ProtocolHandlerRegistry::ProtocolHandlerList& handlers, | 90 const ProtocolHandlerRegistry::ProtocolHandlerList& handlers, |
| 91 base::ListValue* handler_list) { | 91 base::ListValue* handler_list) { |
| 92 ProtocolHandlerRegistry::ProtocolHandlerList::const_iterator handler; | 92 ProtocolHandlerRegistry::ProtocolHandlerList::const_iterator handler; |
| 93 for (handler = handlers.begin(); handler != handlers.end(); ++handler) { | 93 for (handler = handlers.begin(); handler != handlers.end(); ++handler) { |
| 94 std::unique_ptr<base::ListValue> handlerValue(new base::ListValue()); | 94 std::unique_ptr<base::ListValue> handler_value(new base::ListValue()); |
| 95 handlerValue->AppendString(handler->protocol()); | 95 handler_value->AppendString(handler->protocol()); |
| 96 handlerValue->AppendString(handler->url().spec()); | 96 handler_value->AppendString(handler->url().spec()); |
| 97 handlerValue->AppendString(handler->url().host()); | 97 handler_value->AppendString(handler->url().host()); |
| 98 handler_list->Append(std::move(handlerValue)); | 98 handler_list->Append(std::move(handler_value)); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 void HandlerOptionsHandler::GetHandlersForProtocol( | 102 void HandlerOptionsHandler::GetHandlersForProtocol( |
| 103 const std::string& protocol, | 103 const std::string& protocol, |
| 104 base::DictionaryValue* handlers_value) { | 104 base::DictionaryValue* handlers_value) { |
| 105 ProtocolHandlerRegistry* registry = GetProtocolHandlerRegistry(); | 105 ProtocolHandlerRegistry* registry = GetProtocolHandlerRegistry(); |
| 106 // The items which are to be written into |handlers_value| are also described | 106 // The items which are to be written into |handlers_value| are also described |
| 107 // in chrome/browser/resources/options/handler_options.js in @typedef | 107 // in chrome/browser/resources/options/handler_options.js in @typedef |
| 108 // for Handlers. Please update them whenever you add or remove any keys here. | 108 // for Handlers. Please update them whenever you add or remove any keys here. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 128 } | 128 } |
| 129 | 129 |
| 130 void HandlerOptionsHandler::UpdateHandlerList() { | 130 void HandlerOptionsHandler::UpdateHandlerList() { |
| 131 ProtocolHandlerRegistry* registry = GetProtocolHandlerRegistry(); | 131 ProtocolHandlerRegistry* registry = GetProtocolHandlerRegistry(); |
| 132 std::vector<std::string> protocols; | 132 std::vector<std::string> protocols; |
| 133 registry->GetRegisteredProtocols(&protocols); | 133 registry->GetRegisteredProtocols(&protocols); |
| 134 | 134 |
| 135 base::ListValue handlers; | 135 base::ListValue handlers; |
| 136 for (std::vector<std::string>::iterator protocol = protocols.begin(); | 136 for (std::vector<std::string>::iterator protocol = protocols.begin(); |
| 137 protocol != protocols.end(); protocol++) { | 137 protocol != protocols.end(); protocol++) { |
| 138 base::DictionaryValue* handler_value = new base::DictionaryValue(); | 138 std::unique_ptr<base::DictionaryValue> handler_value( |
| 139 GetHandlersForProtocol(*protocol, handler_value); | 139 new base::DictionaryValue()); |
| 140 handlers.Append(handler_value); | 140 GetHandlersForProtocol(*protocol, handler_value.get()); |
| 141 handlers.Append(std::move(handler_value)); |
| 141 } | 142 } |
| 142 | 143 |
| 143 std::unique_ptr<base::ListValue> ignored_handlers(new base::ListValue()); | 144 std::unique_ptr<base::ListValue> ignored_handlers(new base::ListValue()); |
| 144 GetIgnoredHandlers(ignored_handlers.get()); | 145 GetIgnoredHandlers(ignored_handlers.get()); |
| 145 web_ui()->CallJavascriptFunctionUnsafe("HandlerOptions.setHandlers", | 146 web_ui()->CallJavascriptFunctionUnsafe("HandlerOptions.setHandlers", |
| 146 handlers); | 147 handlers); |
| 147 web_ui()->CallJavascriptFunctionUnsafe("HandlerOptions.setIgnoredHandlers", | 148 web_ui()->CallJavascriptFunctionUnsafe("HandlerOptions.setIgnoredHandlers", |
| 148 *ignored_handlers); | 149 *ignored_handlers); |
| 149 } | 150 } |
| 150 | 151 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 213 |
| 213 void HandlerOptionsHandler::Observe( | 214 void HandlerOptionsHandler::Observe( |
| 214 int type, | 215 int type, |
| 215 const content::NotificationSource& source, | 216 const content::NotificationSource& source, |
| 216 const content::NotificationDetails& details) { | 217 const content::NotificationDetails& details) { |
| 217 DCHECK_EQ(chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, type); | 218 DCHECK_EQ(chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, type); |
| 218 UpdateHandlerList(); | 219 UpdateHandlerList(); |
| 219 } | 220 } |
| 220 | 221 |
| 221 } // namespace options | 222 } // namespace options |
| OLD | NEW |