| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/settings/protocol_handlers_handler.h" | 5 #include "chrome/browser/ui/webui/settings/protocol_handlers_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 22 matching lines...) Expand all Loading... |
| 33 notification_registrar_.Add( | 33 notification_registrar_.Add( |
| 34 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, | 34 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, |
| 35 content::Source<Profile>(Profile::FromWebUI(web_ui()))); | 35 content::Source<Profile>(Profile::FromWebUI(web_ui()))); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void ProtocolHandlersHandler::OnJavascriptDisallowed() { | 38 void ProtocolHandlersHandler::OnJavascriptDisallowed() { |
| 39 notification_registrar_.RemoveAll(); | 39 notification_registrar_.RemoveAll(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void ProtocolHandlersHandler::RegisterMessages() { | 42 void ProtocolHandlersHandler::RegisterMessages() { |
| 43 web_ui()->RegisterMessageCallback("initializeProtocolHandlerList", | 43 web_ui()->RegisterMessageCallback("observeProtocolHandlers", |
| 44 base::Bind(&ProtocolHandlersHandler::HandleInitializeList, | 44 base::Bind(&ProtocolHandlersHandler::HandleObserveProtocolHandlers, |
| 45 base::Unretained(this))); | 45 base::Unretained(this))); |
| 46 web_ui()->RegisterMessageCallback("observeProtocolHandlersEnabledState", |
| 47 base::Bind( |
| 48 &ProtocolHandlersHandler::HandleObserveProtocolHandlersEnabledState, |
| 49 base::Unretained(this))); |
| 46 web_ui()->RegisterMessageCallback("clearDefault", | 50 web_ui()->RegisterMessageCallback("clearDefault", |
| 47 base::Bind(&ProtocolHandlersHandler::HandleClearDefault, | 51 base::Bind(&ProtocolHandlersHandler::HandleClearDefault, |
| 48 base::Unretained(this))); | 52 base::Unretained(this))); |
| 49 web_ui()->RegisterMessageCallback("removeHandler", | 53 web_ui()->RegisterMessageCallback("removeHandler", |
| 50 base::Bind(&ProtocolHandlersHandler::HandleRemoveHandler, | 54 base::Bind(&ProtocolHandlersHandler::HandleRemoveHandler, |
| 51 base::Unretained(this))); | 55 base::Unretained(this))); |
| 52 web_ui()->RegisterMessageCallback("setHandlersEnabled", | 56 web_ui()->RegisterMessageCallback("setHandlersEnabled", |
| 53 base::Bind(&ProtocolHandlersHandler::HandleSetHandlersEnabled, | 57 base::Bind(&ProtocolHandlersHandler::HandleSetHandlersEnabled, |
| 54 base::Unretained(this))); | 58 base::Unretained(this))); |
| 55 web_ui()->RegisterMessageCallback("setDefault", | 59 web_ui()->RegisterMessageCallback("setDefault", |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 std::unique_ptr<base::ListValue> ignored_handlers(new base::ListValue()); | 128 std::unique_ptr<base::ListValue> ignored_handlers(new base::ListValue()); |
| 125 GetIgnoredHandlers(ignored_handlers.get()); | 129 GetIgnoredHandlers(ignored_handlers.get()); |
| 126 CallJavascriptFunction("cr.webUIListenerCallback", | 130 CallJavascriptFunction("cr.webUIListenerCallback", |
| 127 base::StringValue("setProtocolHandlers"), | 131 base::StringValue("setProtocolHandlers"), |
| 128 handlers); | 132 handlers); |
| 129 CallJavascriptFunction("cr.webUIListenerCallback", | 133 CallJavascriptFunction("cr.webUIListenerCallback", |
| 130 base::StringValue("setIgnoredProtocolHandlers"), | 134 base::StringValue("setIgnoredProtocolHandlers"), |
| 131 *ignored_handlers); | 135 *ignored_handlers); |
| 132 } | 136 } |
| 133 | 137 |
| 134 void ProtocolHandlersHandler::HandleInitializeList( | 138 void ProtocolHandlersHandler::HandleObserveProtocolHandlers( |
| 135 const base::ListValue* args) { | 139 const base::ListValue* args) { |
| 136 AllowJavascript(); | 140 AllowJavascript(); |
| 137 SendHandlersEnabledValue(); | 141 SendHandlersEnabledValue(); |
| 138 UpdateHandlerList(); | 142 UpdateHandlerList(); |
| 139 } | 143 } |
| 140 | 144 |
| 145 void ProtocolHandlersHandler::HandleObserveProtocolHandlersEnabledState( |
| 146 const base::ListValue* args) { |
| 147 AllowJavascript(); |
| 148 SendHandlersEnabledValue(); |
| 149 } |
| 150 |
| 141 void ProtocolHandlersHandler::SendHandlersEnabledValue() { | 151 void ProtocolHandlersHandler::SendHandlersEnabledValue() { |
| 142 CallJavascriptFunction("cr.webUIListenerCallback", | 152 CallJavascriptFunction("cr.webUIListenerCallback", |
| 143 base::StringValue("setHandlersEnabled"), | 153 base::StringValue("setHandlersEnabled"), |
| 144 base::FundamentalValue( | 154 base::FundamentalValue( |
| 145 GetProtocolHandlerRegistry()->enabled())); | 155 GetProtocolHandlerRegistry()->enabled())); |
| 146 } | 156 } |
| 147 | 157 |
| 148 void ProtocolHandlersHandler::HandleRemoveHandler(const base::ListValue* args) { | 158 void ProtocolHandlersHandler::HandleRemoveHandler(const base::ListValue* args) { |
| 149 const base::ListValue* list; | 159 const base::ListValue* list; |
| 150 if (!args->GetList(0, &list)) { | 160 if (!args->GetList(0, &list)) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 void ProtocolHandlersHandler::Observe( | 222 void ProtocolHandlersHandler::Observe( |
| 213 int type, | 223 int type, |
| 214 const content::NotificationSource& source, | 224 const content::NotificationSource& source, |
| 215 const content::NotificationDetails& details) { | 225 const content::NotificationDetails& details) { |
| 216 DCHECK_EQ(chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, type); | 226 DCHECK_EQ(chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, type); |
| 217 SendHandlersEnabledValue(); | 227 SendHandlersEnabledValue(); |
| 218 UpdateHandlerList(); | 228 UpdateHandlerList(); |
| 219 } | 229 } |
| 220 | 230 |
| 221 } // namespace settings | 231 } // namespace settings |
| OLD | NEW |