Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Unified Diff: chrome/browser/ui/webui/settings/protocol_handlers_handler.cc

Issue 2131953002: Site Settings Desktop: Implement protocol handler section. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/settings/protocol_handlers_handler.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/settings/protocol_handlers_handler.cc
diff --git a/chrome/browser/ui/webui/options/handler_options_handler.cc b/chrome/browser/ui/webui/settings/protocol_handlers_handler.cc
similarity index 65%
copy from chrome/browser/ui/webui/options/handler_options_handler.cc
copy to chrome/browser/ui/webui/settings/protocol_handlers_handler.cc
index 0e5ea47773ccf5c383087ac1f52bba846da501d2..1d101970a90e471b141ec4e4a6b7fdf6affec6cd 100644
--- a/chrome/browser/ui/webui/options/handler_options_handler.cc
+++ b/chrome/browser/ui/webui/settings/protocol_handlers_handler.cc
@@ -1,8 +1,8 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/webui/options/handler_options_handler.h"
+#include "chrome/browser/ui/webui/settings/protocol_handlers_handler.h"
#include <memory>
#include <utility>
@@ -22,66 +22,46 @@
#include "components/prefs/pref_service.h"
#include "content/public/browser/web_ui.h"
-namespace options {
+namespace settings {
-HandlerOptionsHandler::HandlerOptionsHandler() {
+ProtocolHandlersHandler::ProtocolHandlersHandler() {
}
-HandlerOptionsHandler::~HandlerOptionsHandler() {
+ProtocolHandlersHandler::~ProtocolHandlersHandler() {
}
-void HandlerOptionsHandler::GetLocalizedValues(
- base::DictionaryValue* localized_strings) {
- DCHECK(localized_strings);
-
- static OptionsStringResource resources[] = {
- { "handlersTabLabel", IDS_HANDLERS_TAB_LABEL },
- { "handlersAllow", IDS_HANDLERS_ALLOW_RADIO },
- { "handlersBlock", IDS_HANDLERS_DONOTALLOW_RADIO },
- { "handlersTypeColumnHeader", IDS_HANDLERS_TYPE_COLUMN_HEADER },
- { "handlersSiteColumnHeader", IDS_HANDLERS_SITE_COLUMN_HEADER },
- { "handlersRemoveLink", IDS_HANDLERS_REMOVE_HANDLER_LINK },
- { "handlersNoneHandler", IDS_HANDLERS_NONE_HANDLER },
- { "handlersActiveHeading", IDS_HANDLERS_ACTIVE_HEADING },
- { "handlersIgnoredHeading", IDS_HANDLERS_IGNORED_HEADING },
- };
- RegisterTitle(localized_strings, "handlersPage",
- IDS_HANDLER_OPTIONS_WINDOW_TITLE);
- RegisterStrings(localized_strings, resources, arraysize(resources));
-
- localized_strings->SetString("handlersLearnMoreUrl",
- chrome::kLearnMoreRegisterProtocolHandlerURL);
-}
-
-void HandlerOptionsHandler::InitializeHandler() {
+void ProtocolHandlersHandler::OnJavascriptAllowed() {
notification_registrar_.Add(
this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED,
content::Source<Profile>(Profile::FromWebUI(web_ui())));
}
-void HandlerOptionsHandler::InitializePage() {
- UpdateHandlerList();
+void ProtocolHandlersHandler::OnJavascriptDisallowed() {
+ notification_registrar_.RemoveAll();
}
-void HandlerOptionsHandler::RegisterMessages() {
+void ProtocolHandlersHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback("initializeProtocolHandlerList",
+ base::Bind(&ProtocolHandlersHandler::InitializeProtocolHandlerList,
+ base::Unretained(this)));
web_ui()->RegisterMessageCallback("clearDefault",
- base::Bind(&HandlerOptionsHandler::ClearDefault,
+ base::Bind(&ProtocolHandlersHandler::ClearDefault,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("removeHandler",
- base::Bind(&HandlerOptionsHandler::RemoveHandler,
+ base::Bind(&ProtocolHandlersHandler::RemoveHandler,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("setHandlersEnabled",
- base::Bind(&HandlerOptionsHandler::SetHandlersEnabled,
+ base::Bind(&ProtocolHandlersHandler::SetHandlersEnabled,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("setDefault",
- base::Bind(&HandlerOptionsHandler::SetDefault,
+ base::Bind(&ProtocolHandlersHandler::SetDefault,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("removeIgnoredHandler",
- base::Bind(&HandlerOptionsHandler::RemoveIgnoredHandler,
+ base::Bind(&ProtocolHandlersHandler::RemoveIgnoredHandler,
base::Unretained(this)));
}
-ProtocolHandlerRegistry* HandlerOptionsHandler::GetProtocolHandlerRegistry() {
+ProtocolHandlerRegistry* ProtocolHandlersHandler::GetProtocolHandlerRegistry() {
return ProtocolHandlerRegistryFactory::GetForBrowserContext(
Profile::FromWebUI(web_ui()));
}
@@ -91,15 +71,16 @@ static void GetHandlersAsListValue(
base::ListValue* handler_list) {
ProtocolHandlerRegistry::ProtocolHandlerList::const_iterator handler;
for (handler = handlers.begin(); handler != handlers.end(); ++handler) {
- std::unique_ptr<base::ListValue> handler_value(new base::ListValue());
- handler_value->AppendString(handler->protocol());
- handler_value->AppendString(handler->url().spec());
- handler_value->AppendString(handler->url().host());
+ std::unique_ptr<base::DictionaryValue> handler_value(
+ new base::DictionaryValue());
+ handler_value->SetString("protocol", handler->protocol());
+ handler_value->SetString("spec", handler->url().spec());
+ handler_value->SetString("host", handler->url().host());
handler_list->Append(std::move(handler_value));
}
}
-void HandlerOptionsHandler::GetHandlersForProtocol(
+void ProtocolHandlersHandler::GetHandlersForProtocol(
const std::string& protocol,
base::DictionaryValue* handlers_value) {
ProtocolHandlerRegistry* registry = GetProtocolHandlerRegistry();
@@ -120,14 +101,14 @@ void HandlerOptionsHandler::GetHandlersForProtocol(
handlers_value->Set("handlers", handlers_list);
}
-void HandlerOptionsHandler::GetIgnoredHandlers(base::ListValue* handlers) {
+void ProtocolHandlersHandler::GetIgnoredHandlers(base::ListValue* handlers) {
ProtocolHandlerRegistry* registry = GetProtocolHandlerRegistry();
ProtocolHandlerRegistry::ProtocolHandlerList ignored_handlers =
registry->GetIgnoredHandlers();
return GetHandlersAsListValue(ignored_handlers, handlers);
}
-void HandlerOptionsHandler::UpdateHandlerList() {
+void ProtocolHandlersHandler::UpdateHandlerList() {
ProtocolHandlerRegistry* registry = GetProtocolHandlerRegistry();
std::vector<std::string> protocols;
registry->GetRegisteredProtocols(&protocols);
@@ -143,13 +124,29 @@ void HandlerOptionsHandler::UpdateHandlerList() {
std::unique_ptr<base::ListValue> ignored_handlers(new base::ListValue());
GetIgnoredHandlers(ignored_handlers.get());
- web_ui()->CallJavascriptFunctionUnsafe("HandlerOptions.setHandlers",
- handlers);
- web_ui()->CallJavascriptFunctionUnsafe("HandlerOptions.setIgnoredHandlers",
- *ignored_handlers);
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("setProtocolHandlers"),
+ handlers);
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("setIgnoredProtocolHandlers"),
+ *ignored_handlers);
+}
+
+void ProtocolHandlersHandler::InitializeProtocolHandlerList(
+ const base::ListValue* args) {
+ AllowJavascript();
+ SendHandlersEnabledValue();
+ UpdateHandlerList();
+}
+
+void ProtocolHandlersHandler::SendHandlersEnabledValue() {
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("setHandlersEnabled"),
+ base::FundamentalValue(
+ GetProtocolHandlerRegistry()->enabled()));
}
-void HandlerOptionsHandler::RemoveHandler(const base::ListValue* args) {
+void ProtocolHandlersHandler::RemoveHandler(const base::ListValue* args) {
const base::ListValue* list;
if (!args->GetList(0, &list)) {
NOTREACHED();
@@ -164,7 +161,8 @@ void HandlerOptionsHandler::RemoveHandler(const base::ListValue* args) {
// then.
}
-void HandlerOptionsHandler::RemoveIgnoredHandler(const base::ListValue* args) {
+void ProtocolHandlersHandler::RemoveIgnoredHandler(
+ const base::ListValue* args) {
const base::ListValue* list;
if (!args->GetList(0, &list)) {
NOTREACHED();
@@ -175,7 +173,7 @@ void HandlerOptionsHandler::RemoveIgnoredHandler(const base::ListValue* args) {
GetProtocolHandlerRegistry()->RemoveIgnoredHandler(handler);
}
-void HandlerOptionsHandler::SetHandlersEnabled(const base::ListValue* args) {
+void ProtocolHandlersHandler::SetHandlersEnabled(const base::ListValue* args) {
bool enabled = true;
CHECK(args->GetBoolean(0, &enabled));
if (enabled)
@@ -184,7 +182,7 @@ void HandlerOptionsHandler::SetHandlersEnabled(const base::ListValue* args) {
GetProtocolHandlerRegistry()->Disable();
}
-void HandlerOptionsHandler::ClearDefault(const base::ListValue* args) {
+void ProtocolHandlersHandler::ClearDefault(const base::ListValue* args) {
const base::Value* value;
CHECK(args->Get(0, &value));
std::string protocol_to_clear;
@@ -192,7 +190,7 @@ void HandlerOptionsHandler::ClearDefault(const base::ListValue* args) {
GetProtocolHandlerRegistry()->ClearDefault(protocol_to_clear);
}
-void HandlerOptionsHandler::SetDefault(const base::ListValue* args) {
+void ProtocolHandlersHandler::SetDefault(const base::ListValue* args) {
const base::ListValue* list;
CHECK(args->GetList(0, &list));
const ProtocolHandler& handler(ParseHandlerFromArgs(list));
@@ -200,7 +198,7 @@ void HandlerOptionsHandler::SetDefault(const base::ListValue* args) {
GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(handler);
}
-ProtocolHandler HandlerOptionsHandler::ParseHandlerFromArgs(
+ProtocolHandler ProtocolHandlersHandler::ParseHandlerFromArgs(
const base::ListValue* args) const {
base::string16 protocol;
base::string16 url;
@@ -211,12 +209,13 @@ ProtocolHandler HandlerOptionsHandler::ParseHandlerFromArgs(
GURL(base::UTF16ToUTF8(url)));
}
-void HandlerOptionsHandler::Observe(
+void ProtocolHandlersHandler::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, type);
+ SendHandlersEnabledValue();
UpdateHandlerList();
}
-} // namespace options
+} // namespace settings
« no previous file with comments | « chrome/browser/ui/webui/settings/protocol_handlers_handler.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698