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

Side by Side Diff: chrome/browser/content_settings/tab_specific_content_settings.cc

Issue 7558024: Add UMA metrics for blocked plugins. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/content_settings/tab_specific_content_settings.h" 5 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/browsing_data_appcache_helper.h" 11 #include "chrome/browser/browsing_data_appcache_helper.h"
12 #include "chrome/browser/browsing_data_database_helper.h" 12 #include "chrome/browser/browsing_data_database_helper.h"
13 #include "chrome/browser/browsing_data_file_system_helper.h" 13 #include "chrome/browser/browsing_data_file_system_helper.h"
14 #include "chrome/browser/browsing_data_indexed_db_helper.h" 14 #include "chrome/browser/browsing_data_indexed_db_helper.h"
15 #include "chrome/browser/browsing_data_local_storage_helper.h" 15 #include "chrome/browser/browsing_data_local_storage_helper.h"
16 #include "chrome/browser/content_settings/content_settings_details.h" 16 #include "chrome/browser/content_settings/content_settings_details.h"
17 #include "chrome/browser/content_settings/host_content_settings_map.h" 17 #include "chrome/browser/content_settings/host_content_settings_map.h"
18 #include "chrome/browser/cookies_tree_model.h" 18 #include "chrome/browser/cookies_tree_model.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/chrome_notification_types.h" 20 #include "chrome/common/chrome_notification_types.h"
21 #include "chrome/common/render_messages.h" 21 #include "chrome/common/render_messages.h"
22 #include "content/browser/renderer_host/render_process_host.h" 22 #include "content/browser/renderer_host/render_process_host.h"
23 #include "content/browser/renderer_host/render_view_host.h" 23 #include "content/browser/renderer_host/render_view_host.h"
24 #include "content/browser/tab_contents/navigation_details.h" 24 #include "content/browser/tab_contents/navigation_details.h"
25 #include "content/browser/tab_contents/tab_contents.h" 25 #include "content/browser/tab_contents/tab_contents.h"
26 #include "content/browser/tab_contents/tab_contents_delegate.h" 26 #include "content/browser/tab_contents/tab_contents_delegate.h"
27 #include "content/browser/user_metrics.h"
27 #include "content/common/notification_service.h" 28 #include "content/common/notification_service.h"
28 #include "content/common/view_messages.h" 29 #include "content/common/view_messages.h"
29 #include "net/base/cookie_monster.h" 30 #include "net/base/cookie_monster.h"
30 #include "webkit/fileapi/file_system_types.h" 31 #include "webkit/fileapi/file_system_types.h"
31 32
32 namespace { 33 namespace {
33 typedef std::list<TabSpecificContentSettings*> TabSpecificList; 34 typedef std::list<TabSpecificContentSettings*> TabSpecificList;
34 static base::LazyInstance<TabSpecificList> g_tab_specific( 35 static base::LazyInstance<TabSpecificList> g_tab_specific(
35 base::LINKER_INITIALIZED); 36 base::LINKER_INITIALIZED);
36 } 37 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 void TabSpecificContentSettings::AddBlockedResource( 199 void TabSpecificContentSettings::AddBlockedResource(
199 ContentSettingsType content_type, 200 ContentSettingsType content_type,
200 const std::string& resource_identifier) { 201 const std::string& resource_identifier) {
201 if (!blocked_resources_[content_type].get()) 202 if (!blocked_resources_[content_type].get())
202 blocked_resources_[content_type].reset(new std::set<std::string>()); 203 blocked_resources_[content_type].reset(new std::set<std::string>());
203 blocked_resources_[content_type]->insert(resource_identifier); 204 blocked_resources_[content_type]->insert(resource_identifier);
204 } 205 }
205 206
206 void TabSpecificContentSettings::OnContentBlocked( 207 void TabSpecificContentSettings::OnContentBlocked(
207 ContentSettingsType type, 208 ContentSettingsType type,
208 const std::string& resource_identifier) { 209 const std::string& resource_identifier,
210 ContentSetting setting) {
209 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) 211 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION)
210 << "Geolocation settings handled by OnGeolocationPermissionSet"; 212 << "Geolocation settings handled by OnGeolocationPermissionSet";
213 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) {
214 if (setting == CONTENT_SETTING_BLOCK)
215 UserMetrics::RecordAction(UserMetricsAction("Plugin.Blocked"));
216 else if (setting == CONTENT_SETTING_ASK)
217 UserMetrics::RecordAction(UserMetricsAction("Plugin.ClickToPlay"));
218 else
219 NOTREACHED();
220 }
211 content_accessed_[type] = true; 221 content_accessed_[type] = true;
212 if (!resource_identifier.empty()) 222 if (!resource_identifier.empty())
213 AddBlockedResource(type, resource_identifier); 223 AddBlockedResource(type, resource_identifier);
214 if (!content_blocked_[type]) { 224 if (!content_blocked_[type]) {
215 content_blocked_[type] = true; 225 content_blocked_[type] = true;
216 // TODO: it would be nice to have a way of mocking this in tests. 226 // TODO: it would be nice to have a way of mocking this in tests.
217 NotificationService::current()->Notify( 227 NotificationService::current()->Notify(
218 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, 228 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED,
219 Source<TabContents>(tab_contents()), 229 Source<TabContents>(tab_contents()),
220 NotificationService::NoDetails()); 230 NotificationService::NoDetails());
(...skipping 26 matching lines...) Expand all
247 container.cookies()->SetCookieWithDetails(url, 257 container.cookies()->SetCookieWithDetails(url,
248 cookie->Name(), 258 cookie->Name(),
249 cookie->Value(), 259 cookie->Value(),
250 cookie->Domain(), 260 cookie->Domain(),
251 cookie->Path(), 261 cookie->Path(),
252 cookie->ExpiryDate(), 262 cookie->ExpiryDate(),
253 cookie->IsSecure(), 263 cookie->IsSecure(),
254 cookie->IsHttpOnly()); 264 cookie->IsHttpOnly());
255 } 265 }
256 if (blocked_by_policy) 266 if (blocked_by_policy)
257 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); 267 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
268 CONTENT_SETTING_BLOCK);
258 else 269 else
259 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); 270 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
260 } 271 }
261 272
262 void TabSpecificContentSettings::OnCookieChanged( 273 void TabSpecificContentSettings::OnCookieChanged(
263 const GURL& url, 274 const GURL& url,
264 const std::string& cookie_line, 275 const std::string& cookie_line,
265 const net::CookieOptions& options, 276 const net::CookieOptions& options,
266 bool blocked_by_policy) { 277 bool blocked_by_policy) {
267 if (blocked_by_policy) { 278 if (blocked_by_policy) {
268 blocked_local_shared_objects_.cookies()->SetCookieWithOptions( 279 blocked_local_shared_objects_.cookies()->SetCookieWithOptions(
269 url, cookie_line, options); 280 url, cookie_line, options);
270 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); 281 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
282 CONTENT_SETTING_BLOCK);
271 } else { 283 } else {
272 allowed_local_shared_objects_.cookies()->SetCookieWithOptions( 284 allowed_local_shared_objects_.cookies()->SetCookieWithOptions(
273 url, cookie_line, options); 285 url, cookie_line, options);
274 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); 286 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
275 } 287 }
276 } 288 }
277 289
278 void TabSpecificContentSettings::OnIndexedDBAccessed( 290 void TabSpecificContentSettings::OnIndexedDBAccessed(
279 const GURL& url, 291 const GURL& url,
280 const string16& description, 292 const string16& description,
281 bool blocked_by_policy) { 293 bool blocked_by_policy) {
282 if (blocked_by_policy) { 294 if (blocked_by_policy) {
283 blocked_local_shared_objects_.indexed_dbs()->AddIndexedDB( 295 blocked_local_shared_objects_.indexed_dbs()->AddIndexedDB(
284 url, description); 296 url, description);
285 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); 297 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
298 CONTENT_SETTING_BLOCK);
286 } else { 299 } else {
287 allowed_local_shared_objects_.indexed_dbs()->AddIndexedDB( 300 allowed_local_shared_objects_.indexed_dbs()->AddIndexedDB(
288 url, description); 301 url, description);
289 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); 302 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
290 } 303 }
291 } 304 }
292 305
293 void TabSpecificContentSettings::OnLocalStorageAccessed( 306 void TabSpecificContentSettings::OnLocalStorageAccessed(
294 const GURL& url, 307 const GURL& url,
295 DOMStorageType storage_type, 308 DOMStorageType storage_type,
296 bool blocked_by_policy) { 309 bool blocked_by_policy) {
297 LocalSharedObjectsContainer& container = blocked_by_policy ? 310 LocalSharedObjectsContainer& container = blocked_by_policy ?
298 blocked_local_shared_objects_ : allowed_local_shared_objects_; 311 blocked_local_shared_objects_ : allowed_local_shared_objects_;
299 CannedBrowsingDataLocalStorageHelper* helper = 312 CannedBrowsingDataLocalStorageHelper* helper =
300 storage_type == DOM_STORAGE_LOCAL ? 313 storage_type == DOM_STORAGE_LOCAL ?
301 container.local_storages() : container.session_storages(); 314 container.local_storages() : container.session_storages();
302 helper->AddLocalStorage(url); 315 helper->AddLocalStorage(url);
303 316
304 if (blocked_by_policy) 317 if (blocked_by_policy)
305 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); 318 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
319 CONTENT_SETTING_BLOCK);
306 else 320 else
307 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); 321 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
308 } 322 }
309 323
310 void TabSpecificContentSettings::OnWebDatabaseAccessed( 324 void TabSpecificContentSettings::OnWebDatabaseAccessed(
311 const GURL& url, 325 const GURL& url,
312 const string16& name, 326 const string16& name,
313 const string16& display_name, 327 const string16& display_name,
314 bool blocked_by_policy) { 328 bool blocked_by_policy) {
315 if (blocked_by_policy) { 329 if (blocked_by_policy) {
316 blocked_local_shared_objects_.databases()->AddDatabase( 330 blocked_local_shared_objects_.databases()->AddDatabase(
317 url, UTF16ToUTF8(name), UTF16ToUTF8(display_name)); 331 url, UTF16ToUTF8(name), UTF16ToUTF8(display_name));
318 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); 332 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
333 CONTENT_SETTING_BLOCK);
319 } else { 334 } else {
320 allowed_local_shared_objects_.databases()->AddDatabase( 335 allowed_local_shared_objects_.databases()->AddDatabase(
321 url, UTF16ToUTF8(name), UTF16ToUTF8(display_name)); 336 url, UTF16ToUTF8(name), UTF16ToUTF8(display_name));
322 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); 337 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
323 } 338 }
324 } 339 }
325 340
326 void TabSpecificContentSettings::OnAppCacheAccessed( 341 void TabSpecificContentSettings::OnAppCacheAccessed(
327 const GURL& manifest_url, bool blocked_by_policy) { 342 const GURL& manifest_url, bool blocked_by_policy) {
328 if (blocked_by_policy) { 343 if (blocked_by_policy) {
329 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url); 344 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url);
330 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); 345 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
346 CONTENT_SETTING_BLOCK);
331 } else { 347 } else {
332 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url); 348 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url);
333 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); 349 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
334 } 350 }
335 } 351 }
336 352
337 void TabSpecificContentSettings::OnFileSystemAccessed( 353 void TabSpecificContentSettings::OnFileSystemAccessed(
338 const GURL& url, 354 const GURL& url,
339 bool blocked_by_policy) { 355 bool blocked_by_policy) {
340 if (blocked_by_policy) { 356 if (blocked_by_policy) {
341 blocked_local_shared_objects_.file_systems()->AddFileSystem(url, 357 blocked_local_shared_objects_.file_systems()->AddFileSystem(url,
342 fileapi::kFileSystemTypeTemporary, 0); 358 fileapi::kFileSystemTypeTemporary, 0);
343 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); 359 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
360 CONTENT_SETTING_BLOCK);
344 } else { 361 } else {
345 allowed_local_shared_objects_.file_systems()->AddFileSystem(url, 362 allowed_local_shared_objects_.file_systems()->AddFileSystem(url,
346 fileapi::kFileSystemTypeTemporary, 0); 363 fileapi::kFileSystemTypeTemporary, 0);
347 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); 364 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
348 } 365 }
349 } 366 }
350 void TabSpecificContentSettings::OnGeolocationPermissionSet( 367 void TabSpecificContentSettings::OnGeolocationPermissionSet(
351 const GURL& requesting_origin, 368 const GURL& requesting_origin,
352 bool allowed) { 369 bool allowed) {
353 geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin, 370 geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin,
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 return new CookiesTreeModel(cookies_, 539 return new CookiesTreeModel(cookies_,
523 databases_->Clone(), 540 databases_->Clone(),
524 local_storages_->Clone(), 541 local_storages_->Clone(),
525 session_storages_->Clone(), 542 session_storages_->Clone(),
526 appcaches_->Clone(), 543 appcaches_->Clone(),
527 indexed_dbs_->Clone(), 544 indexed_dbs_->Clone(),
528 file_systems_->Clone(), 545 file_systems_->Clone(),
529 NULL, 546 NULL,
530 true); 547 true);
531 } 548 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698