OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/options/website_settings_handler.h" | |
6 | |
7 #include "chrome/browser/content_settings/content_settings_utils.h" | |
8 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "content/public/browser/web_ui.h" | |
11 #include "grit/generated_resources.h" | |
12 | |
13 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
| |
14 | |
15 namespace options { | |
16 | |
17 WebsiteSettingsHandler::WebsiteSettingsHandler() { | |
18 } | |
19 | |
20 WebsiteSettingsHandler::~WebsiteSettingsHandler() { | |
21 } | |
22 | |
23 void WebsiteSettingsHandler::GetLocalizedValues( | |
24 base::DictionaryValue* localized_strings) { | |
25 DCHECK(localized_strings); | |
26 | |
27 static OptionsStringResource resources[] = { | |
28 {"websitesOptionsPageTabTitle", IDS_WEBSITES_SETTINGS_TITLE}, | |
29 {"websitesManage", IDS_WEBSITE_SETTINGS_MANAGE}, | |
30 {"websitesSearch", IDS_WEBSITE_SETTINGS_SEARCH_ORIGINS}, | |
31 {"websitesLabelGeolocation", IDS_WEBSITE_SETTINGS_TYPE_LOCATION}, | |
32 {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, | |
33 {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, | |
34 }; | |
35 | |
36 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
37 RegisterTitle( | |
38 localized_strings, "websiteSettingsPage", IDS_WEBSITES_SETTINGS_TITLE); | |
39 } | |
40 | |
41 void WebsiteSettingsHandler::RegisterMessages() { | |
42 web_ui()->RegisterMessageCallback( | |
43 "updateOrigins", | |
44 base::Bind(&WebsiteSettingsHandler::UpdateOrigins, | |
45 base::Unretained(this))); | |
46 | |
47 web_ui()->RegisterMessageCallback( | |
48 "updateOriginsSearchResults", | |
49 base::Bind(&WebsiteSettingsHandler::UpdateSearchResults, | |
50 base::Unretained(this))); | |
51 } | |
52 | |
53 void WebsiteSettingsHandler::Observe( | |
54 int type, | |
55 const content::NotificationSource& source, | |
56 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
| |
57 } | |
58 | |
59 void WebsiteSettingsHandler::UpdateOrigins(const base::ListValue* args) { | |
60 std::string content_setting_name; | |
61 bool rv = args->GetString(0, &content_setting_name); | |
62 DCHECK(rv); | |
63 ContentSettingsType content_type = | |
64 content_settings::GetTypeFromName(content_setting_name); | |
65 | |
66 last_setting_ = content_type; | |
67 | |
68 UpdateOrigins_(content_type, std::string()); | |
69 } | |
70 | |
71 void WebsiteSettingsHandler::UpdateSearchResults(const base::ListValue* args) { | |
72 std::string filter; | |
73 bool rv = args->GetString(0, &filter); | |
74 DCHECK(rv); | |
75 | |
76 UpdateOrigins_(last_setting_, filter); | |
77 } | |
78 | |
79 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.
| |
80 const std::string& filter) { | |
81 Profile* profile = Profile::FromWebUI(web_ui()); | |
82 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | |
Dan Beam
2014/07/10 02:57:24
nit: \n
Daniel Nishi
2014/07/10 19:00:09
Done.
| |
83 ContentSettingsForOneType all_settings; | |
84 settings->GetSettingsForOneType(last_setting_, std::string(), &all_settings); | |
85 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.
| |
86 | |
87 base::DictionaryValue origins; | |
88 for (; it != all_settings.end(); ++it) { | |
89 // Don't add default settings. | |
90 if (it->primary_pattern == ContentSettingsPattern::Wildcard() && | |
91 it->secondary_pattern == ContentSettingsPattern::Wildcard() && | |
92 it->source != kPreferencesSource) { | |
93 continue; | |
94 } | |
95 | |
96 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.
| |
97 | |
98 if (origin.find(filter) == base::string16::npos) { | |
99 continue; | |
100 } | |
Dan Beam
2014/07/10 02:57:24
nit: no { curlies }
Daniel Nishi
2014/07/10 19:00:09
Done.
| |
101 | |
102 // TODO(dhnishi): Make this map be a map of origin to last usage of API. | |
103 origins.SetDoubleWithoutPathExpansion(origin, 0); | |
104 } | |
105 | |
106 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", | |
107 origins); | |
108 } | |
109 | |
110 } // namespace options | |
OLD | NEW |