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/options2/handler_options_handler.h" | 5 #include "chrome/browser/ui/webui/options2/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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 124 } |
125 | 125 |
126 scoped_ptr<ListValue> ignored_handlers(new ListValue()); | 126 scoped_ptr<ListValue> ignored_handlers(new ListValue()); |
127 GetIgnoredHandlers(ignored_handlers.get()); | 127 GetIgnoredHandlers(ignored_handlers.get()); |
128 web_ui()->CallJavascriptFunction("HandlerOptions.setHandlers", handlers); | 128 web_ui()->CallJavascriptFunction("HandlerOptions.setHandlers", handlers); |
129 web_ui()->CallJavascriptFunction("HandlerOptions.setIgnoredHandlers", | 129 web_ui()->CallJavascriptFunction("HandlerOptions.setIgnoredHandlers", |
130 *ignored_handlers); | 130 *ignored_handlers); |
131 } | 131 } |
132 | 132 |
133 void HandlerOptionsHandler::RemoveHandler(const ListValue* args) { | 133 void HandlerOptionsHandler::RemoveHandler(const ListValue* args) { |
134 ListValue* list; | 134 const ListValue* list; |
135 if (!args->GetList(0, &list)) { | 135 if (!args->GetList(0, &list)) { |
136 NOTREACHED(); | 136 NOTREACHED(); |
137 return; | 137 return; |
138 } | 138 } |
139 | 139 |
140 ProtocolHandler handler(ParseHandlerFromArgs(list)); | 140 ProtocolHandler handler(ParseHandlerFromArgs(list)); |
141 GetProtocolHandlerRegistry()->RemoveHandler(handler); | 141 GetProtocolHandlerRegistry()->RemoveHandler(handler); |
142 | 142 |
143 // No need to call UpdateHandlerList() - we should receive a notification | 143 // No need to call UpdateHandlerList() - we should receive a notification |
144 // that the ProtocolHandlerRegistry has changed and we will update the view | 144 // that the ProtocolHandlerRegistry has changed and we will update the view |
145 // then. | 145 // then. |
146 } | 146 } |
147 | 147 |
148 void HandlerOptionsHandler::RemoveIgnoredHandler(const ListValue* args) { | 148 void HandlerOptionsHandler::RemoveIgnoredHandler(const ListValue* args) { |
149 ListValue* list; | 149 const ListValue* list; |
150 if (!args->GetList(0, &list)) { | 150 if (!args->GetList(0, &list)) { |
151 NOTREACHED(); | 151 NOTREACHED(); |
152 return; | 152 return; |
153 } | 153 } |
154 | 154 |
155 ProtocolHandler handler(ParseHandlerFromArgs(list)); | 155 ProtocolHandler handler(ParseHandlerFromArgs(list)); |
156 GetProtocolHandlerRegistry()->RemoveIgnoredHandler(handler); | 156 GetProtocolHandlerRegistry()->RemoveIgnoredHandler(handler); |
157 } | 157 } |
158 | 158 |
159 void HandlerOptionsHandler::SetHandlersEnabled(const ListValue* args) { | 159 void HandlerOptionsHandler::SetHandlersEnabled(const ListValue* args) { |
160 bool enabled = true; | 160 bool enabled = true; |
161 CHECK(args->GetBoolean(0, &enabled)); | 161 CHECK(args->GetBoolean(0, &enabled)); |
162 if (enabled) | 162 if (enabled) |
163 GetProtocolHandlerRegistry()->Enable(); | 163 GetProtocolHandlerRegistry()->Enable(); |
164 else | 164 else |
165 GetProtocolHandlerRegistry()->Disable(); | 165 GetProtocolHandlerRegistry()->Disable(); |
166 } | 166 } |
167 | 167 |
168 void HandlerOptionsHandler::ClearDefault(const ListValue* args) { | 168 void HandlerOptionsHandler::ClearDefault(const ListValue* args) { |
169 Value* value; | 169 const Value* value; |
170 CHECK(args->Get(0, &value)); | 170 CHECK(args->Get(0, &value)); |
171 std::string protocol_to_clear; | 171 std::string protocol_to_clear; |
172 CHECK(value->GetAsString(&protocol_to_clear)); | 172 CHECK(value->GetAsString(&protocol_to_clear)); |
173 GetProtocolHandlerRegistry()->ClearDefault(protocol_to_clear); | 173 GetProtocolHandlerRegistry()->ClearDefault(protocol_to_clear); |
174 } | 174 } |
175 | 175 |
176 void HandlerOptionsHandler::SetDefault(const ListValue* args) { | 176 void HandlerOptionsHandler::SetDefault(const ListValue* args) { |
177 Value* value; | 177 const ListValue* list; |
178 CHECK(args->Get(0, &value)); | |
179 ListValue* list; | |
180 CHECK(args->GetList(0, &list)); | 178 CHECK(args->GetList(0, &list)); |
181 const ProtocolHandler& handler(ParseHandlerFromArgs(list)); | 179 const ProtocolHandler& handler(ParseHandlerFromArgs(list)); |
182 CHECK(!handler.IsEmpty()); | 180 CHECK(!handler.IsEmpty()); |
183 GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(handler); | 181 GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(handler); |
184 } | 182 } |
185 | 183 |
186 ProtocolHandler HandlerOptionsHandler::ParseHandlerFromArgs( | 184 ProtocolHandler HandlerOptionsHandler::ParseHandlerFromArgs( |
187 const ListValue* args) const { | 185 const ListValue* args) const { |
188 string16 protocol; | 186 string16 protocol; |
189 string16 url; | 187 string16 url; |
(...skipping 11 matching lines...) Expand all Loading... |
201 int type, | 199 int type, |
202 const content::NotificationSource& source, | 200 const content::NotificationSource& source, |
203 const content::NotificationDetails& details) { | 201 const content::NotificationDetails& details) { |
204 if (type == chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED) | 202 if (type == chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED) |
205 UpdateHandlerList(); | 203 UpdateHandlerList(); |
206 else | 204 else |
207 NOTREACHED(); | 205 NOTREACHED(); |
208 } | 206 } |
209 | 207 |
210 } // namespace options2 | 208 } // namespace options2 |
OLD | NEW |