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

Unified Diff: chrome/browser/ui/webui/options2/web_intents_defaults_handler.cc

Issue 10808092: Add settings UI for managing defaults (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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
Index: chrome/browser/ui/webui/options2/web_intents_defaults_handler.cc
diff --git a/chrome/browser/ui/webui/options2/web_intents_defaults_handler.cc b/chrome/browser/ui/webui/options2/web_intents_defaults_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..543bf5524094792ca2f1015e6ffbbc60062b5366
--- /dev/null
+++ b/chrome/browser/ui/webui/options2/web_intents_defaults_handler.cc
@@ -0,0 +1,142 @@
+// Copyright (c) 2012 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/options2/web_intents_defaults_handler.h"
+
+#include <map>
+#include <string>
+#include <vector>
+#include "base/bind.h"
+#include "base/string16.h"
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/intents/web_intents_registry.h"
+#include "chrome/browser/intents/web_intents_registry_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/user_metrics.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+#include "content/public/browser/web_ui.h"
+#include "grit/generated_resources.h"
+
+namespace {
+
+typedef std::vector<string16> Vector16;
+typedef std::map<std::string, Vector16> ServiceMap;
+
+void ServicesToListValues(
+ const std::vector<DefaultWebIntentService>& services,
+ ListValue* values) {
+
+ // map of urls to list of "matchers" (action + type)
+ ServiceMap service_map;
+ WebIntentsRegistry::DefaultIntentServiceList::const_iterator service;
+ for (service = services.begin(); service != services.end(); ++service) {
+ string16 matcher = service->action;
+ matcher += ASCIIToUTF16(" ");
+ matcher += service->type;
+ service_map[service->service_url].push_back(matcher);
+ }
+
+ // showing contents:
+ ServiceMap::iterator it;
+ for (it = service_map.begin(); it != service_map.end(); ++it) {
+ ListValue* value = new ListValue;
+ std::string service_url = (*it).first;
+ std::vector<string16> matchers = (*it).second;
+ // TODO(smckay): add join method that works with strings
+ // so we can join on ", ".
+ string16 joined_matchers = JoinString(matchers, ',');
+ value->Append(Value::CreateStringValue(service_url));
+ value->Append(Value::CreateStringValue(joined_matchers));
+ values->Append(value);
+ }
+}
+} // namespace
+
+namespace options2 {
+
+WebIntentsDefaultsHandler::WebIntentsDefaultsHandler() {
+}
+
+WebIntentsDefaultsHandler::~WebIntentsDefaultsHandler() {
+}
+
+void WebIntentsDefaultsHandler::GetLocalizedValues(DictionaryValue* values) {
+ DCHECK(values);
+ static OptionsStringResource resources[] = {
+ { "web_intents_defaults_button_title",
+ IDS_WEB_INTENTS_DEFAULTS_BUTTON_TITLE },
+ {"web_intents_defaults_overlay_title",
+ IDS_WEB_INTENTS_DEFAULTS_OVERLAY_TITLE },
+ {"web_intents_defaults_matcher_column",
+ IDS_WEB_INTENTS_DEFAULTS_MATCHER_COLUMN },
+ {"web_intents_defaults_title_column",
+ IDS_WEB_INTENTS_DEFAULTS_TITLE_COLUMN },
csilv 2012/08/09 18:18:04 per previous comment, camelCase for i18n keys.
+ };
+
+ RegisterStrings(values, resources, arraysize(resources));
+ RegisterTitle(values, "web_intents_defaults_overlay_title",
+ IDS_WEB_INTENTS_DEFAULTS_OVERLAY_TITLE);
+}
+
+void WebIntentsDefaultsHandler::InitializeHandler() {
+ // TODO: plug into notifications to monitor registry changes.
csilv 2012/08/09 18:18:04 nit: TODO(smckay)
+}
+
+void WebIntentsDefaultsHandler::InitializePage() {
+ UpdateServiceList();
+}
+
+void WebIntentsDefaultsHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "removeServiceDefaults",
+ base::Bind(&WebIntentsDefaultsHandler::HandleRemoveServiceDefaults,
+ base::Unretained(this)));
+}
+
+void WebIntentsDefaultsHandler::UpdateServiceList() {
+ GetRegistry()->GetAllDefaultIntentServices(
+ base::Bind(&WebIntentsDefaultsHandler::OnServicesLoaded,
+ base::Unretained(this)));
+}
+
+void WebIntentsDefaultsHandler::OnServicesLoaded(
+ const std::vector<DefaultWebIntentService>& services) {
+
csilv 2012/08/09 18:18:04 nit: bikesheding, i'm not crazy about these newlin
+ ListValue values;
+ ServicesToListValues(services, &values);
+ web_ui()->CallJavascriptFunction("WebIntentsDefaults.setServices", values);
+}
+
+void WebIntentsDefaultsHandler::HandleRemoveServiceDefaults(
+ const base::ListValue* args) {
+
+ content::RecordAction(
+ content::UserMetricsAction("RemoveWebIntentServiceDefaults"));
+ std::string url;
+ bool ok = args->GetString(0, &url);
+ DCHECK(ok);
+
+ const GURL service_url(url);
+ // GetRegistry()->UnregisterServiceDefaults(service_url);
csilv 2012/08/09 18:18:04 why is this commented out..?
+
+ // TODO(smckay): dependon on registry change notifications to do this.
+ UpdateServiceList();
+}
+
+WebIntentsRegistry* WebIntentsDefaultsHandler::GetRegistry() {
+ Profile* profile = Profile::FromWebUI(web_ui());
+ return WebIntentsRegistryFactory::GetForProfile(profile);
+}
+
+void WebIntentsDefaultsHandler::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+}
+
+} // namespace options2

Powered by Google App Engine
This is Rietveld 408576698