Chromium Code Reviews| Index: chrome/browser/ui/webui/options/website_settings_handler.cc |
| diff --git a/chrome/browser/ui/webui/options/website_settings_handler.cc b/chrome/browser/ui/webui/options/website_settings_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ff706e986a31fd1fb171999e90266dbcd9a2ea26 |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/options/website_settings_handler.cc |
| @@ -0,0 +1,110 @@ |
| +// Copyright 2014 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/website_settings_handler.h" |
| + |
| +#include "chrome/browser/content_settings/content_settings_utils.h" |
| +#include "chrome/browser/content_settings/host_content_settings_map.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "content/public/browser/web_ui.h" |
| +#include "grit/generated_resources.h" |
| + |
| +const char* kPreferencesSource = "preference"; |
|
Dan Beam
2014/07/10 02:57:24
const char kPreferenceSource[] = "preference";
fo
Bernhard Bauer
2014/07/10 08:47:42
Does that actually create a static initializer? I
Daniel Nishi
2014/07/10 19:00:09
I don't think it makes a static initializer, but t
Dan Beam
2014/07/15 03:39:15
iirc, i've had to revert and change to this to mak
Bernhard Bauer
2014/07/15 08:32:49
Note that the anonymous namespace is not necessary
Daniel Nishi
2014/07/15 17:12:54
I added a "TODO(bauerb): Expose constants." to hos
|
| + |
| +namespace options { |
| + |
| +WebsiteSettingsHandler::WebsiteSettingsHandler() { |
| +} |
| + |
| +WebsiteSettingsHandler::~WebsiteSettingsHandler() { |
| +} |
| + |
| +void WebsiteSettingsHandler::GetLocalizedValues( |
| + base::DictionaryValue* localized_strings) { |
| + DCHECK(localized_strings); |
| + |
| + static OptionsStringResource resources[] = { |
| + {"websitesOptionsPageTabTitle", IDS_WEBSITES_SETTINGS_TITLE}, |
| + {"websitesManage", IDS_WEBSITE_SETTINGS_MANAGE}, |
| + {"websitesSearch", IDS_WEBSITE_SETTINGS_SEARCH_ORIGINS}, |
| + {"websitesLabelGeolocation", IDS_WEBSITE_SETTINGS_TYPE_LOCATION}, |
| + {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, |
| + {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, |
| + }; |
| + |
| + RegisterStrings(localized_strings, resources, arraysize(resources)); |
| + RegisterTitle( |
| + localized_strings, "websiteSettingsPage", IDS_WEBSITES_SETTINGS_TITLE); |
| +} |
| + |
| +void WebsiteSettingsHandler::RegisterMessages() { |
| + web_ui()->RegisterMessageCallback( |
| + "updateOrigins", |
| + base::Bind(&WebsiteSettingsHandler::UpdateOrigins, |
| + base::Unretained(this))); |
| + |
| + web_ui()->RegisterMessageCallback( |
| + "updateOriginsSearchResults", |
| + base::Bind(&WebsiteSettingsHandler::UpdateSearchResults, |
| + base::Unretained(this))); |
| +} |
| + |
| +void WebsiteSettingsHandler::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
|
Dan Beam
2014/07/10 02:57:24
what's the purpose of this?
Daniel Nishi
2014/07/10 19:00:09
Whoops. I guess I forgot to remove that.
Removed
|
| +} |
| + |
| +void WebsiteSettingsHandler::UpdateOrigins(const base::ListValue* args) { |
| + std::string content_setting_name; |
| + bool rv = args->GetString(0, &content_setting_name); |
| + DCHECK(rv); |
| + ContentSettingsType content_type = |
| + content_settings::GetTypeFromName(content_setting_name); |
| + |
| + last_setting_ = content_type; |
| + |
| + UpdateOrigins_(content_type, std::string()); |
| +} |
| + |
| +void WebsiteSettingsHandler::UpdateSearchResults(const base::ListValue* args) { |
| + std::string filter; |
| + bool rv = args->GetString(0, &filter); |
| + DCHECK(rv); |
| + |
| + UpdateOrigins_(last_setting_, filter); |
| +} |
| + |
| +void WebsiteSettingsHandler::UpdateOrigins_(ContentSettingsType content_type, |
|
Dan Beam
2014/07/10 02:57:24
remove |content_type|
Daniel Nishi
2014/07/10 19:00:09
Done.
|
| + const std::string& filter) { |
| + Profile* profile = Profile::FromWebUI(web_ui()); |
| + HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); |
|
Dan Beam
2014/07/10 02:57:24
nit: \n
Daniel Nishi
2014/07/10 19:00:09
Done.
|
| + ContentSettingsForOneType all_settings; |
| + settings->GetSettingsForOneType(last_setting_, std::string(), &all_settings); |
| + ContentSettingsForOneType::const_iterator it = all_settings.begin(); |
|
Bernhard Bauer
2014/07/10 08:47:42
If this is not inside of the for-loop header, can
Daniel Nishi
2014/07/10 19:00:09
Done.
|
| + |
| + base::DictionaryValue origins; |
| + for (; it != all_settings.end(); ++it) { |
| + // Don't add default settings. |
| + if (it->primary_pattern == ContentSettingsPattern::Wildcard() && |
| + it->secondary_pattern == ContentSettingsPattern::Wildcard() && |
| + it->source != kPreferencesSource) { |
| + continue; |
| + } |
| + |
| + const std::string origin = it->primary_pattern.ToString(); |
|
Bernhard Bauer
2014/07/10 08:47:42
We don't usually use const for non-reference, non-
Daniel Nishi
2014/07/10 19:00:09
Done.
|
| + |
| + if (origin.find(filter) == base::string16::npos) { |
| + continue; |
| + } |
|
Dan Beam
2014/07/10 02:57:24
nit: no { curlies }
Daniel Nishi
2014/07/10 19:00:09
Done.
|
| + |
| + // TODO(dhnishi): Make this map be a map of origin to last usage of API. |
| + origins.SetDoubleWithoutPathExpansion(origin, 0); |
| + } |
| + |
| + web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", |
| + origins); |
| +} |
| + |
| +} // namespace options |