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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 92 } |
93 | 93 |
94 static void GetHandlersAsListValue( | 94 static void GetHandlersAsListValue( |
95 const ProtocolHandlerRegistry::ProtocolHandlerList& handlers, | 95 const ProtocolHandlerRegistry::ProtocolHandlerList& handlers, |
96 base::ListValue* handler_list) { | 96 base::ListValue* handler_list) { |
97 ProtocolHandlerRegistry::ProtocolHandlerList::const_iterator handler; | 97 ProtocolHandlerRegistry::ProtocolHandlerList::const_iterator handler; |
98 for (handler = handlers.begin(); handler != handlers.end(); ++handler) { | 98 for (handler = handlers.begin(); handler != handlers.end(); ++handler) { |
99 base::ListValue* handlerValue = new base::ListValue(); | 99 base::ListValue* handlerValue = new base::ListValue(); |
100 handlerValue->Append(new base::StringValue(handler->protocol())); | 100 handlerValue->Append(new base::StringValue(handler->protocol())); |
101 handlerValue->Append(new base::StringValue(handler->url().spec())); | 101 handlerValue->Append(new base::StringValue(handler->url().spec())); |
102 handlerValue->Append(new base::StringValue(handler->title())); | 102 handlerValue->Append(new base::StringValue(handler->url().host())); |
103 handler_list->Append(handlerValue); | 103 handler_list->Append(handlerValue); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 void HandlerOptionsHandler::GetHandlersForProtocol( | 107 void HandlerOptionsHandler::GetHandlersForProtocol( |
108 const std::string& protocol, | 108 const std::string& protocol, |
109 base::DictionaryValue* handlers_value) { | 109 base::DictionaryValue* handlers_value) { |
110 ProtocolHandlerRegistry* registry = GetProtocolHandlerRegistry(); | 110 ProtocolHandlerRegistry* registry = GetProtocolHandlerRegistry(); |
111 handlers_value->SetString("protocol", protocol); | 111 handlers_value->SetString("protocol", protocol); |
112 handlers_value->SetInteger("default_handler", | 112 handlers_value->SetInteger("default_handler", |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 CHECK(args->GetList(0, &list)); | 192 CHECK(args->GetList(0, &list)); |
193 const ProtocolHandler& handler(ParseHandlerFromArgs(list)); | 193 const ProtocolHandler& handler(ParseHandlerFromArgs(list)); |
194 CHECK(!handler.IsEmpty()); | 194 CHECK(!handler.IsEmpty()); |
195 GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(handler); | 195 GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(handler); |
196 } | 196 } |
197 | 197 |
198 ProtocolHandler HandlerOptionsHandler::ParseHandlerFromArgs( | 198 ProtocolHandler HandlerOptionsHandler::ParseHandlerFromArgs( |
199 const base::ListValue* args) const { | 199 const base::ListValue* args) const { |
200 base::string16 protocol; | 200 base::string16 protocol; |
201 base::string16 url; | 201 base::string16 url; |
202 base::string16 title; | 202 bool ok = args->GetString(0, &protocol) && args->GetString(1, &url); |
203 bool ok = args->GetString(0, &protocol) && args->GetString(1, &url) && | |
204 args->GetString(2, &title); | |
205 if (!ok) | 203 if (!ok) |
206 return ProtocolHandler::EmptyProtocolHandler(); | 204 return ProtocolHandler::EmptyProtocolHandler(); |
207 return ProtocolHandler::CreateProtocolHandler(base::UTF16ToUTF8(protocol), | 205 return ProtocolHandler::CreateProtocolHandler(base::UTF16ToUTF8(protocol), |
208 GURL(base::UTF16ToUTF8(url)), | 206 GURL(base::UTF16ToUTF8(url))); |
209 title); | |
210 } | 207 } |
211 | 208 |
212 void HandlerOptionsHandler::Observe( | 209 void HandlerOptionsHandler::Observe( |
213 int type, | 210 int type, |
214 const content::NotificationSource& source, | 211 const content::NotificationSource& source, |
215 const content::NotificationDetails& details) { | 212 const content::NotificationDetails& details) { |
216 if (type == chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED) | 213 if (type == chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED) |
217 UpdateHandlerList(); | 214 UpdateHandlerList(); |
218 else | 215 else |
219 NOTREACHED(); | 216 NOTREACHED(); |
220 } | 217 } |
221 | 218 |
222 } // namespace options | 219 } // namespace options |
OLD | NEW |