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

Side by Side Diff: chrome/browser/android/banners/app_banner_settings_helper.cc

Issue 542253003: Add a global on/off switch for content settings and expose a toggle on the Website Settings options… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@global-settings
Patch Set: Rebase. Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/chrome_content_browser_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/banners/app_banner_settings_helper.h" 5 #include "chrome/browser/android/banners/app_banner_settings_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "chrome/browser/content_settings/host_content_settings_map.h" 10 #include "chrome/browser/content_settings/host_content_settings_map.h"
(...skipping 22 matching lines...) Expand all
33 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 33 Profile::FromBrowserContext(web_contents->GetBrowserContext());
34 if (profile->IsOffTheRecord() || web_contents->GetURL() != origin_url || 34 if (profile->IsOffTheRecord() || web_contents->GetURL() != origin_url ||
35 sanitized_package_name.empty()) { 35 sanitized_package_name.empty()) {
36 return false; 36 return false;
37 } 37 }
38 38
39 // Check if this combination has been previously disabled. 39 // Check if this combination has been previously disabled.
40 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); 40 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap();
41 if (!settings) 41 if (!settings)
42 return false; 42 return false;
43 scoped_ptr<base::Value> value( 43 scoped_ptr<base::Value> value =
44 settings->GetWebsiteSetting(origin_url, 44 settings->GetWebsiteSetting(origin_url,
45 origin_url, 45 origin_url,
46 CONTENT_SETTINGS_TYPE_APP_BANNER, 46 CONTENT_SETTINGS_TYPE_APP_BANNER,
47 std::string(), 47 std::string(),
48 NULL)); 48 NULL);
49 if (!value.get()) { 49 if (!value.get()) {
50 // We've never blocked a banner on this site. 50 // We've never blocked a banner on this site.
51 return true; 51 return true;
52 } else if (value->IsType(base::Value::TYPE_DICTIONARY)) { 52 } else if (value->IsType(base::Value::TYPE_DICTIONARY)) {
53 // We expect to get a Dictionary back, where the keys are the package names. 53 // We expect to get a Dictionary back, where the keys are the package names.
54 base::DictionaryValue* banner_dict = 54 base::DictionaryValue* banner_dict =
55 static_cast<base::DictionaryValue*>(value.get()); 55 static_cast<base::DictionaryValue*>(value.get());
56 bool is_allowed = false; 56 bool is_allowed = false;
57 if (banner_dict->GetBoolean(sanitized_package_name, &is_allowed)) { 57 if (banner_dict->GetBoolean(sanitized_package_name, &is_allowed)) {
58 return is_allowed; 58 return is_allowed;
(...skipping 23 matching lines...) Expand all
82 std::string sanitized_package_name = SanitizePackageName(package_name); 82 std::string sanitized_package_name = SanitizePackageName(package_name);
83 DCHECK(!sanitized_package_name.empty()); 83 DCHECK(!sanitized_package_name.empty());
84 84
85 Profile* profile = 85 Profile* profile =
86 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 86 Profile::FromBrowserContext(web_contents->GetBrowserContext());
87 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); 87 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap();
88 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); 88 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url));
89 if (!settings || !pattern.IsValid()) 89 if (!settings || !pattern.IsValid())
90 return; 90 return;
91 91
92 scoped_ptr<base::Value> value( 92 scoped_ptr<base::Value> value =
93 settings->GetWebsiteSetting(origin_url, 93 settings->GetWebsiteSetting(origin_url,
94 origin_url, 94 origin_url,
95 CONTENT_SETTINGS_TYPE_APP_BANNER, 95 CONTENT_SETTINGS_TYPE_APP_BANNER,
96 std::string(), 96 std::string(),
97 NULL)); 97 NULL);
98 base::DictionaryValue* banner_dict = NULL; 98 base::DictionaryValue* banner_dict = NULL;
99 if (value.get() && value->IsType(base::Value::TYPE_DICTIONARY)) { 99 if (value.get() && value->IsType(base::Value::TYPE_DICTIONARY)) {
100 banner_dict = static_cast<base::DictionaryValue*>(value.release()); 100 banner_dict = static_cast<base::DictionaryValue*>(value.release());
101 } else { 101 } else {
102 banner_dict = new base::DictionaryValue(); 102 banner_dict = new base::DictionaryValue();
103 } 103 }
104 104
105 // Update the setting and save it back. 105 // Update the setting and save it back.
106 banner_dict->SetBoolean(sanitized_package_name, false); 106 banner_dict->SetBoolean(sanitized_package_name, false);
107 settings->SetWebsiteSetting(pattern, 107 settings->SetWebsiteSetting(pattern,
108 ContentSettingsPattern::Wildcard(), 108 ContentSettingsPattern::Wildcard(),
109 CONTENT_SETTINGS_TYPE_APP_BANNER, 109 CONTENT_SETTINGS_TYPE_APP_BANNER,
110 std::string(), 110 std::string(),
111 banner_dict); 111 banner_dict);
112 } 112 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/chrome_content_browser_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698