OLD | NEW |
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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browsing_data_appcache_helper.h" | 12 #include "chrome/browser/browsing_data_appcache_helper.h" |
13 #include "chrome/browser/browsing_data_cookie_helper.h" | 13 #include "chrome/browser/browsing_data_cookie_helper.h" |
14 #include "chrome/browser/browsing_data_database_helper.h" | 14 #include "chrome/browser/browsing_data_database_helper.h" |
15 #include "chrome/browser/browsing_data_file_system_helper.h" | 15 #include "chrome/browser/browsing_data_file_system_helper.h" |
16 #include "chrome/browser/browsing_data_indexed_db_helper.h" | 16 #include "chrome/browser/browsing_data_indexed_db_helper.h" |
17 #include "chrome/browser/browsing_data_local_storage_helper.h" | 17 #include "chrome/browser/browsing_data_local_storage_helper.h" |
18 #include "chrome/browser/content_settings/content_settings_details.h" | 18 #include "chrome/browser/content_settings/content_settings_details.h" |
19 #include "chrome/browser/content_settings/host_content_settings_map.h" | 19 #include "chrome/browser/content_settings/host_content_settings_map.h" |
20 #include "chrome/browser/cookies_tree_model.h" | 20 #include "chrome/browser/cookies_tree_model.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/render_messages.h" |
25 #include "content/browser/renderer_host/render_process_host.h" | 25 #include "content/browser/renderer_host/render_process_host.h" |
26 #include "content/browser/renderer_host/render_view_host.h" | 26 #include "content/browser/renderer_host/render_view_host.h" |
27 #include "content/browser/tab_contents/navigation_details.h" | 27 #include "content/browser/tab_contents/navigation_details.h" |
28 #include "content/browser/tab_contents/tab_contents.h" | 28 #include "content/browser/tab_contents/tab_contents.h" |
29 #include "content/browser/tab_contents/tab_contents_delegate.h" | 29 #include "content/browser/tab_contents/tab_contents_delegate.h" |
30 #include "content/common/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
31 #include "content/common/view_messages.h" | 31 #include "content/common/view_messages.h" |
32 #include "webkit/fileapi/file_system_types.h" | 32 #include "webkit/fileapi/file_system_types.h" |
33 | 33 |
34 namespace { | 34 namespace { |
35 typedef std::list<TabSpecificContentSettings*> TabSpecificList; | 35 typedef std::list<TabSpecificContentSettings*> TabSpecificList; |
36 static base::LazyInstance<TabSpecificList> g_tab_specific( | 36 static base::LazyInstance<TabSpecificList> g_tab_specific( |
37 base::LINKER_INITIALIZED); | 37 base::LINKER_INITIALIZED); |
38 } | 38 } |
39 | 39 |
40 bool TabSpecificContentSettings::LocalSharedObjectsContainer::empty() const { | 40 bool TabSpecificContentSettings::LocalSharedObjectsContainer::empty() const { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 std::string identifier; | 224 std::string identifier; |
225 if (CommandLine::ForCurrentProcess()->HasSwitch( | 225 if (CommandLine::ForCurrentProcess()->HasSwitch( |
226 switches::kEnableResourceContentSettings)) { | 226 switches::kEnableResourceContentSettings)) { |
227 identifier = resource_identifier; | 227 identifier = resource_identifier; |
228 } | 228 } |
229 if (!identifier.empty()) | 229 if (!identifier.empty()) |
230 AddBlockedResource(type, identifier); | 230 AddBlockedResource(type, identifier); |
231 if (!content_blocked_[type]) { | 231 if (!content_blocked_[type]) { |
232 content_blocked_[type] = true; | 232 content_blocked_[type] = true; |
233 // TODO: it would be nice to have a way of mocking this in tests. | 233 // TODO: it would be nice to have a way of mocking this in tests. |
234 NotificationService::current()->Notify( | 234 content::NotificationService::current()->Notify( |
235 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, | 235 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, |
236 content::Source<TabContents>(tab_contents()), | 236 content::Source<TabContents>(tab_contents()), |
237 NotificationService::NoDetails()); | 237 content::NotificationService::NoDetails()); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 void TabSpecificContentSettings::OnContentAccessed(ContentSettingsType type) { | 241 void TabSpecificContentSettings::OnContentAccessed(ContentSettingsType type) { |
242 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) | 242 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
243 << "Geolocation settings handled by OnGeolocationPermissionSet"; | 243 << "Geolocation settings handled by OnGeolocationPermissionSet"; |
244 if (!content_accessed_[type]) { | 244 if (!content_accessed_[type]) { |
245 content_accessed_[type] = true; | 245 content_accessed_[type] = true; |
246 NotificationService::current()->Notify( | 246 content::NotificationService::current()->Notify( |
247 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, | 247 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, |
248 content::Source<TabContents>(tab_contents()), | 248 content::Source<TabContents>(tab_contents()), |
249 NotificationService::NoDetails()); | 249 content::NotificationService::NoDetails()); |
250 } | 250 } |
251 } | 251 } |
252 | 252 |
253 void TabSpecificContentSettings::OnCookiesRead( | 253 void TabSpecificContentSettings::OnCookiesRead( |
254 const GURL& url, | 254 const GURL& url, |
255 const net::CookieList& cookie_list, | 255 const net::CookieList& cookie_list, |
256 bool blocked_by_policy) { | 256 bool blocked_by_policy) { |
257 if (cookie_list.empty()) | 257 if (cookie_list.empty()) |
258 return; | 258 return; |
259 if (blocked_by_policy) { | 259 if (blocked_by_policy) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 allowed_local_shared_objects_.file_systems()->AddFileSystem(url, | 342 allowed_local_shared_objects_.file_systems()->AddFileSystem(url, |
343 fileapi::kFileSystemTypeTemporary, 0); | 343 fileapi::kFileSystemTypeTemporary, 0); |
344 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); | 344 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); |
345 } | 345 } |
346 } | 346 } |
347 void TabSpecificContentSettings::OnGeolocationPermissionSet( | 347 void TabSpecificContentSettings::OnGeolocationPermissionSet( |
348 const GURL& requesting_origin, | 348 const GURL& requesting_origin, |
349 bool allowed) { | 349 bool allowed) { |
350 geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin, | 350 geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin, |
351 allowed); | 351 allowed); |
352 NotificationService::current()->Notify( | 352 content::NotificationService::current()->Notify( |
353 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, | 353 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, |
354 content::Source<TabContents>(tab_contents()), | 354 content::Source<TabContents>(tab_contents()), |
355 NotificationService::NoDetails()); | 355 content::NotificationService::NoDetails()); |
356 } | 356 } |
357 | 357 |
358 void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { | 358 void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { |
359 for (size_t i = 0; i < arraysize(content_blocked_); ++i) { | 359 for (size_t i = 0; i < arraysize(content_blocked_); ++i) { |
360 if (i == CONTENT_SETTINGS_TYPE_COOKIES) | 360 if (i == CONTENT_SETTINGS_TYPE_COOKIES) |
361 continue; | 361 continue; |
362 blocked_resources_[i].reset(); | 362 blocked_resources_[i].reset(); |
363 content_blocked_[i] = false; | 363 content_blocked_[i] = false; |
364 content_accessed_[i] = false; | 364 content_accessed_[i] = false; |
365 content_blockage_indicated_to_user_[i] = false; | 365 content_blockage_indicated_to_user_[i] = false; |
366 } | 366 } |
367 load_plugins_link_enabled_ = true; | 367 load_plugins_link_enabled_ = true; |
368 NotificationService::current()->Notify( | 368 content::NotificationService::current()->Notify( |
369 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, | 369 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, |
370 content::Source<TabContents>(tab_contents()), | 370 content::Source<TabContents>(tab_contents()), |
371 NotificationService::NoDetails()); | 371 content::NotificationService::NoDetails()); |
372 } | 372 } |
373 | 373 |
374 void TabSpecificContentSettings::ClearCookieSpecificContentSettings() { | 374 void TabSpecificContentSettings::ClearCookieSpecificContentSettings() { |
375 blocked_local_shared_objects_.Reset(); | 375 blocked_local_shared_objects_.Reset(); |
376 allowed_local_shared_objects_.Reset(); | 376 allowed_local_shared_objects_.Reset(); |
377 content_blocked_[CONTENT_SETTINGS_TYPE_COOKIES] = false; | 377 content_blocked_[CONTENT_SETTINGS_TYPE_COOKIES] = false; |
378 content_accessed_[CONTENT_SETTINGS_TYPE_COOKIES] = false; | 378 content_accessed_[CONTENT_SETTINGS_TYPE_COOKIES] = false; |
379 content_blockage_indicated_to_user_[CONTENT_SETTINGS_TYPE_COOKIES] = false; | 379 content_blockage_indicated_to_user_[CONTENT_SETTINGS_TYPE_COOKIES] = false; |
380 NotificationService::current()->Notify( | 380 content::NotificationService::current()->Notify( |
381 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, | 381 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, |
382 content::Source<TabContents>(tab_contents()), | 382 content::Source<TabContents>(tab_contents()), |
383 NotificationService::NoDetails()); | 383 content::NotificationService::NoDetails()); |
384 } | 384 } |
385 | 385 |
386 void TabSpecificContentSettings::SetPopupsBlocked(bool blocked) { | 386 void TabSpecificContentSettings::SetPopupsBlocked(bool blocked) { |
387 content_blocked_[CONTENT_SETTINGS_TYPE_POPUPS] = blocked; | 387 content_blocked_[CONTENT_SETTINGS_TYPE_POPUPS] = blocked; |
388 content_blockage_indicated_to_user_[CONTENT_SETTINGS_TYPE_POPUPS] = false; | 388 content_blockage_indicated_to_user_[CONTENT_SETTINGS_TYPE_POPUPS] = false; |
389 NotificationService::current()->Notify( | 389 content::NotificationService::current()->Notify( |
390 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, | 390 chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, |
391 content::Source<TabContents>(tab_contents()), | 391 content::Source<TabContents>(tab_contents()), |
392 NotificationService::NoDetails()); | 392 content::NotificationService::NoDetails()); |
393 } | 393 } |
394 | 394 |
395 void TabSpecificContentSettings::GeolocationDidNavigate( | 395 void TabSpecificContentSettings::GeolocationDidNavigate( |
396 const content::LoadCommittedDetails& details) { | 396 const content::LoadCommittedDetails& details) { |
397 geolocation_settings_state_.DidNavigate(details); | 397 geolocation_settings_state_.DidNavigate(details); |
398 } | 398 } |
399 | 399 |
400 void TabSpecificContentSettings::ClearGeolocationContentSettings() { | 400 void TabSpecificContentSettings::ClearGeolocationContentSettings() { |
401 geolocation_settings_state_.ClearStateMap(); | 401 geolocation_settings_state_.ClearStateMap(); |
402 } | 402 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 return new CookiesTreeModel(cookies_->Clone(), | 522 return new CookiesTreeModel(cookies_->Clone(), |
523 databases_->Clone(), | 523 databases_->Clone(), |
524 local_storages_->Clone(), | 524 local_storages_->Clone(), |
525 session_storages_->Clone(), | 525 session_storages_->Clone(), |
526 appcaches_->Clone(), | 526 appcaches_->Clone(), |
527 indexed_dbs_->Clone(), | 527 indexed_dbs_->Clone(), |
528 file_systems_->Clone(), | 528 file_systems_->Clone(), |
529 NULL, | 529 NULL, |
530 true); | 530 true); |
531 } | 531 } |
OLD | NEW |