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 namespace { | |
14 | |
15 const char kPreferencesSource[] = "preference"; | |
16 | |
17 } // namespace | |
18 | |
19 namespace options { | |
20 | |
21 WebsiteSettingsHandler::WebsiteSettingsHandler() { | |
22 } | |
23 | |
24 WebsiteSettingsHandler::~WebsiteSettingsHandler() { | |
25 } | |
26 | |
27 void WebsiteSettingsHandler::GetLocalizedValues( | |
28 base::DictionaryValue* localized_strings) { | |
29 DCHECK(localized_strings); | |
30 | |
31 static OptionsStringResource resources[] = { | |
32 {"websitesOptionsPageTabTitle", IDS_WEBSITES_SETTINGS_TITLE}, | |
33 {"websitesManage", IDS_WEBSITE_SETTINGS_MANAGE}, | |
34 {"websitesSearch", IDS_WEBSITE_SETTINGS_SEARCH_ORIGINS}, | |
35 {"websitesLabelGeolocation", IDS_WEBSITE_SETTINGS_TYPE_LOCATION}, | |
36 {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, | |
37 {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, | |
38 }; | |
39 | |
40 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
41 RegisterTitle( | |
42 localized_strings, "websiteSettingsPage", IDS_WEBSITES_SETTINGS_TITLE); | |
43 } | |
44 | |
45 void WebsiteSettingsHandler::RegisterMessages() { | |
46 web_ui()->RegisterMessageCallback( | |
47 "updateOrigins", | |
48 base::Bind(&WebsiteSettingsHandler::HandleUpdateOrigins, | |
49 base::Unretained(this))); | |
50 | |
51 web_ui()->RegisterMessageCallback( | |
52 "updateOriginsSearchResults", | |
53 base::Bind(&WebsiteSettingsHandler::HandleUpdateSearchResults, | |
54 base::Unretained(this))); | |
55 } | |
56 | |
57 void WebsiteSettingsHandler::HandleUpdateOrigins(const base::ListValue* args) { | |
58 std::string content_setting_name; | |
59 bool rv = args->GetString(0, &content_setting_name); | |
60 DCHECK(rv); | |
61 ContentSettingsType content_type; | |
62 content_settings::GetTypeFromName(content_setting_name, &content_type); | |
63 | |
64 last_setting_ = content_type; | |
65 | |
66 UpdateOrigins(std::string()); | |
67 } | |
68 | |
69 void WebsiteSettingsHandler::HandleUpdateSearchResults( | |
70 const base::ListValue* args) { | |
71 std::string filter; | |
72 bool rv = args->GetString(0, &filter); | |
73 DCHECK(rv); | |
74 | |
75 UpdateOrigins(filter); | |
76 } | |
77 | |
78 void WebsiteSettingsHandler::UpdateOrigins(const std::string& filter) { | |
79 Profile* profile = Profile::FromWebUI(web_ui()); | |
80 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | |
81 | |
82 ContentSettingsForOneType all_settings; | |
83 settings->GetSettingsForOneType(last_setting_, std::string(), &all_settings); | |
84 | |
85 base::DictionaryValue origins; | |
86 for (ContentSettingsForOneType::const_iterator it = all_settings.begin(); | |
87 it != all_settings.end(); | |
88 ++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 std::string origin = it->primary_pattern.ToString(); | |
97 | |
98 if (origin.find(filter) == base::string16::npos) | |
99 continue; | |
100 | |
101 // TODO(dhnishi): Make this map be a map of origin to last usage of API. | |
Dan Beam
2014/07/15 03:39:15
i'm not sure what this comment means...
Daniel Nishi
2014/07/15 17:12:55
Clarified comment.
| |
102 origins.SetDoubleWithoutPathExpansion(origin, 0); | |
103 } | |
104 | |
105 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", | |
106 origins); | |
107 } | |
108 | |
109 } // namespace options | |
OLD | NEW |