 Chromium Code Reviews
 Chromium Code Reviews Issue 1017193002:
  [App banners] Be less strict about navigations  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1017193002:
  [App banners] Be less strict about navigations  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 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/banners/app_banner_settings_helper.h" | 5 #include "chrome/browser/banners/app_banner_settings_helper.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" | 
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 const unsigned int kMinimumBannerBlockedToBannerShown = 90; | 38 const unsigned int kMinimumBannerBlockedToBannerShown = 90; | 
| 39 | 39 | 
| 40 // Dictionary keys to use for the events. | 40 // Dictionary keys to use for the events. | 
| 41 const char* kBannerEventKeys[] = { | 41 const char* kBannerEventKeys[] = { | 
| 42 "couldShowBannerEvents", | 42 "couldShowBannerEvents", | 
| 43 "didShowBannerEvent", | 43 "didShowBannerEvent", | 
| 44 "didBlockBannerEvent", | 44 "didBlockBannerEvent", | 
| 45 "didAddToHomescreenEvent", | 45 "didAddToHomescreenEvent", | 
| 46 }; | 46 }; | 
| 47 | 47 | 
| 48 // Dictionary key to use whether the banner has been blocked. | |
| 49 const char kHasBlockedKey[] = "hasBlocked"; | |
| 50 | |
| 51 scoped_ptr<base::DictionaryValue> GetOriginDict( | 48 scoped_ptr<base::DictionaryValue> GetOriginDict( | 
| 52 HostContentSettingsMap* settings, | 49 HostContentSettingsMap* settings, | 
| 53 const GURL& origin_url) { | 50 const GURL& origin_url) { | 
| 54 if (!settings) | 51 if (!settings) | 
| 55 return scoped_ptr<base::DictionaryValue>(); | 52 return scoped_ptr<base::DictionaryValue>(); | 
| 56 | 53 | 
| 57 scoped_ptr<base::Value> value = settings->GetWebsiteSetting( | 54 scoped_ptr<base::Value> value = settings->GetWebsiteSetting( | 
| 58 origin_url, origin_url, CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 55 origin_url, origin_url, CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 
| 59 NULL); | 56 NULL); | 
| 60 if (!value.get()) | 57 if (!value.get()) | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 75 app_dict = new base::DictionaryValue(); | 72 app_dict = new base::DictionaryValue(); | 
| 76 origin_dict->SetWithoutPathExpansion(key_name, make_scoped_ptr(app_dict)); | 73 origin_dict->SetWithoutPathExpansion(key_name, make_scoped_ptr(app_dict)); | 
| 77 } | 74 } | 
| 78 } | 75 } | 
| 79 | 76 | 
| 80 return app_dict; | 77 return app_dict; | 
| 81 } | 78 } | 
| 82 | 79 | 
| 83 } // namespace | 80 } // namespace | 
| 84 | 81 | 
| 82 bool AppBannerSettingsHelper::URLsAreForTheSamePage(const GURL& first, | |
| 83 const GURL& second) { | |
| 84 return first.GetWithEmptyPath() == second.GetWithEmptyPath() | |
| 85 && first.path() == second.path() && first.query() == second.query(); | |
| 
benwells
2015/03/19 07:18:55
Formatting nit: the && should be on the previous l
 
gone
2015/03/19 19:01:35
Ah, the fun differences between C++ and Java style
 
gone
2015/03/19 19:01:35
Done.
 
benwells
2015/03/20 00:44:33
git cl format is your friend.
 | |
| 86 } | |
| 87 | |
| 85 void AppBannerSettingsHelper::ClearHistoryForURLs( | 88 void AppBannerSettingsHelper::ClearHistoryForURLs( | 
| 86 Profile* profile, | 89 Profile* profile, | 
| 87 const std::set<GURL>& origin_urls) { | 90 const std::set<GURL>& origin_urls) { | 
| 88 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | 91 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | 
| 89 for (const GURL& origin_url : origin_urls) { | 92 for (const GURL& origin_url : origin_urls) { | 
| 90 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); | 93 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); | 
| 91 if (!pattern.IsValid()) | 94 if (!pattern.IsValid()) | 
| 92 continue; | 95 continue; | 
| 93 | 96 | 
| 94 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), | 97 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), | 
| 95 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 98 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 
| 96 nullptr); | 99 nullptr); | 
| 97 } | 100 } | 
| 98 } | 101 } | 
| 99 | 102 | 
| 100 void AppBannerSettingsHelper::RecordBannerEvent( | 103 void AppBannerSettingsHelper::RecordBannerEvent( | 
| 101 content::WebContents* web_contents, | 104 content::WebContents* web_contents, | 
| 102 const GURL& origin_url, | 105 const GURL& origin_url, | 
| 103 const std::string& package_name_or_start_url, | 106 const std::string& package_name_or_start_url, | 
| 104 AppBannerEvent event, | 107 AppBannerEvent event, | 
| 105 base::Time time) { | 108 base::Time time) { | 
| 106 Profile* profile = | 109 Profile* profile = | 
| 107 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 110 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 
| 108 if (profile->IsOffTheRecord() || web_contents->GetURL() != origin_url || | 111 if (profile->IsOffTheRecord() || package_name_or_start_url.empty()) | 
| 109 package_name_or_start_url.empty()) { | |
| 110 return; | 112 return; | 
| 111 } | |
| 112 | 113 | 
| 113 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); | 114 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); | 
| 114 if (!pattern.IsValid()) | 115 if (!pattern.IsValid()) | 
| 115 return; | 116 return; | 
| 116 | 117 | 
| 117 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | 118 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | 
| 118 scoped_ptr<base::DictionaryValue> origin_dict = | 119 scoped_ptr<base::DictionaryValue> origin_dict = | 
| 119 GetOriginDict(settings, origin_url); | 120 GetOriginDict(settings, origin_url); | 
| 120 if (!origin_dict) | 121 if (!origin_dict) | 
| 121 return; | 122 return; | 
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 if (!app_dict) | 291 if (!app_dict) | 
| 291 return base::Time(); | 292 return base::Time(); | 
| 292 | 293 | 
| 293 std::string event_key(kBannerEventKeys[event]); | 294 std::string event_key(kBannerEventKeys[event]); | 
| 294 double internal_time; | 295 double internal_time; | 
| 295 if (!app_dict->GetDouble(event_key, &internal_time)) | 296 if (!app_dict->GetDouble(event_key, &internal_time)) | 
| 296 return base::Time(); | 297 return base::Time(); | 
| 297 | 298 | 
| 298 return base::Time::FromInternalValue(internal_time); | 299 return base::Time::FromInternalValue(internal_time); | 
| 299 } | 300 } | 
| 300 | |
| 301 bool AppBannerSettingsHelper::IsAllowed( | |
| 
benwells
2015/03/19 07:18:55
Thanks for removing this dead stuff, I'd forgotten
 | |
| 302 content::WebContents* web_contents, | |
| 303 const GURL& origin_url, | |
| 304 const std::string& package_name_or_start_url) { | |
| 305 Profile* profile = | |
| 306 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 307 if (profile->IsOffTheRecord() || web_contents->GetURL() != origin_url || | |
| 308 package_name_or_start_url.empty()) { | |
| 309 return false; | |
| 310 } | |
| 311 | |
| 312 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | |
| 313 scoped_ptr<base::DictionaryValue> origin_dict = | |
| 314 GetOriginDict(settings, origin_url); | |
| 315 | |
| 316 if (!origin_dict) | |
| 317 return true; | |
| 318 | |
| 319 base::DictionaryValue* app_dict = | |
| 320 GetAppDict(origin_dict.get(), package_name_or_start_url); | |
| 321 if (!app_dict) | |
| 322 return true; | |
| 323 | |
| 324 bool has_blocked; | |
| 325 if (!app_dict->GetBoolean(kHasBlockedKey, &has_blocked)) | |
| 326 return true; | |
| 327 | |
| 328 return !has_blocked; | |
| 329 } | |
| 330 | |
| 331 void AppBannerSettingsHelper::Block( | |
| 332 content::WebContents* web_contents, | |
| 333 const GURL& origin_url, | |
| 334 const std::string& package_name_or_start_url) { | |
| 335 Profile* profile = | |
| 336 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 337 if (profile->IsOffTheRecord() || web_contents->GetURL() != origin_url || | |
| 338 package_name_or_start_url.empty()) { | |
| 339 return; | |
| 340 } | |
| 341 | |
| 342 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); | |
| 343 if (!pattern.IsValid()) | |
| 344 return; | |
| 345 | |
| 346 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | |
| 347 scoped_ptr<base::DictionaryValue> origin_dict = | |
| 348 GetOriginDict(settings, origin_url); | |
| 349 | |
| 350 if (!origin_dict) | |
| 351 return; | |
| 352 | |
| 353 base::DictionaryValue* app_dict = | |
| 354 GetAppDict(origin_dict.get(), package_name_or_start_url); | |
| 355 if (!app_dict) | |
| 356 return; | |
| 357 | |
| 358 // Update the setting and save it back. | |
| 359 app_dict->SetBoolean(kHasBlockedKey, true); | |
| 360 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), | |
| 361 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | |
| 362 origin_dict.release()); | |
| 363 } | |
| OLD | NEW |