OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/public/browser/browser_context.h" | 5 #include "content/public/browser/browser_context.h" |
6 | 6 |
7 #if !defined(OS_IOS) | 7 #if !defined(OS_IOS) |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "content/browser/appcache/chrome_appcache_service.h" | 9 #include "content/browser/appcache/chrome_appcache_service.h" |
10 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 10 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
11 #include "content/browser/download/download_manager_impl.h" | 11 #include "content/browser/download/download_manager_impl.h" |
12 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" | 12 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" |
13 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 13 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
14 #include "content/public/browser/site_instance.h" | 14 #include "content/public/browser/site_instance.h" |
15 #include "content/browser/storage_partition_impl.h" | 15 #include "content/browser/storage_partition_impl.h" |
16 #include "content/browser/storage_partition_impl_map.h" | 16 #include "content/browser/storage_partition_impl_map.h" |
17 #include "content/common/child_process_host_impl.h" | 17 #include "content/common/child_process_host_impl.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
20 #include "net/base/server_bound_cert_service.h" | 20 #include "net/base/server_bound_cert_service.h" |
21 #include "net/base/server_bound_cert_store.h" | 21 #include "net/base/server_bound_cert_store.h" |
22 #include "net/cookies/cookie_monster.h" | 22 #include "net/cookies/cookie_monster.h" |
23 #include "net/cookies/cookie_store.h" | 23 #include "net/cookies/cookie_store.h" |
24 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
25 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
| 26 #include "ui/base/clipboard/clipboard.h" |
26 #include "webkit/database/database_tracker.h" | 27 #include "webkit/database/database_tracker.h" |
27 #include "webkit/fileapi/external_mount_points.h" | 28 #include "webkit/fileapi/external_mount_points.h" |
28 #endif // !OS_IOS | 29 #endif // !OS_IOS |
29 | 30 |
30 using base::UserDataAdapter; | 31 using base::UserDataAdapter; |
31 | 32 |
32 namespace content { | 33 namespace content { |
33 | 34 |
34 // Only ~BrowserContext() is needed on iOS. | 35 // Only ~BrowserContext() is needed on iOS. |
35 #if !defined(OS_IOS) | 36 #if !defined(OS_IOS) |
36 namespace { | 37 namespace { |
37 | 38 |
38 // Key names on BrowserContext. | 39 // Key names on BrowserContext. |
| 40 const char kClipboardDestroyerKey[] = "clipboard_destroyer"; |
39 const char kDownloadManagerKeyName[] = "download_manager"; | 41 const char kDownloadManagerKeyName[] = "download_manager"; |
40 const char kMountPointsKey[] = "mount_points"; | 42 const char kMountPointsKey[] = "mount_points"; |
41 const char kStorageParitionMapKeyName[] = "content_storage_partition_map"; | 43 const char kStorageParitionMapKeyName[] = "content_storage_partition_map"; |
42 | 44 |
43 StoragePartitionImplMap* GetStoragePartitionMap( | 45 StoragePartitionImplMap* GetStoragePartitionMap( |
44 BrowserContext* browser_context) { | 46 BrowserContext* browser_context) { |
45 StoragePartitionImplMap* partition_map = | 47 StoragePartitionImplMap* partition_map = |
46 static_cast<StoragePartitionImplMap*>( | 48 static_cast<StoragePartitionImplMap*>( |
47 browser_context->GetUserData(kStorageParitionMapKeyName)); | 49 browser_context->GetUserData(kStorageParitionMapKeyName)); |
48 if (!partition_map) { | 50 if (!partition_map) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 87 |
86 void SaveSessionStateOnWebkitThread( | 88 void SaveSessionStateOnWebkitThread( |
87 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { | 89 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { |
88 indexed_db_context->SetForceKeepSessionState(); | 90 indexed_db_context->SetForceKeepSessionState(); |
89 } | 91 } |
90 | 92 |
91 void PurgeMemoryOnIOThread(appcache::AppCacheService* appcache_service) { | 93 void PurgeMemoryOnIOThread(appcache::AppCacheService* appcache_service) { |
92 appcache_service->PurgeMemory(); | 94 appcache_service->PurgeMemory(); |
93 } | 95 } |
94 | 96 |
| 97 // OffTheRecordClipboardDestroyer is supposed to clear the clipboard in |
| 98 // destructor if current clipboard content came from corresponding OffTheRecord |
| 99 // browser context. |
| 100 class OffTheRecordClipboardDestroyer : public base::SupportsUserData::Data { |
| 101 public: |
| 102 virtual ~OffTheRecordClipboardDestroyer() { |
| 103 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
| 104 ExamineClipboard(clipboard, ui::Clipboard::BUFFER_STANDARD); |
| 105 if (ui::Clipboard::IsValidBuffer(ui::Clipboard::BUFFER_SELECTION)) |
| 106 ExamineClipboard(clipboard, ui::Clipboard::BUFFER_SELECTION); |
| 107 } |
| 108 |
| 109 ui::Clipboard::SourceTag GetAsSourceTag() { |
| 110 return ui::Clipboard::SourceTag(this); |
| 111 } |
| 112 |
| 113 private: |
| 114 void ExamineClipboard(ui::Clipboard* clipboard, |
| 115 ui::Clipboard::Buffer buffer) { |
| 116 ui::Clipboard::SourceTag source_tag = clipboard->ReadSourceTag(buffer); |
| 117 if (source_tag == ui::Clipboard::SourceTag(this)) |
| 118 clipboard->Clear(buffer); |
| 119 } |
| 120 }; |
| 121 |
| 122 // Returns existing OffTheRecordClipboardDestroyer or creates one. |
| 123 OffTheRecordClipboardDestroyer* GetClipboardDestroyerForBrowserContext( |
| 124 BrowserContext* context) { |
| 125 if (base::SupportsUserData::Data* data = context->GetUserData( |
| 126 kClipboardDestroyerKey)) |
| 127 return static_cast<OffTheRecordClipboardDestroyer*>(data); |
| 128 OffTheRecordClipboardDestroyer* data = new OffTheRecordClipboardDestroyer; |
| 129 context->SetUserData(kClipboardDestroyerKey, data); |
| 130 return data; |
| 131 } |
| 132 |
95 } // namespace | 133 } // namespace |
96 | 134 |
97 // static | 135 // static |
98 void BrowserContext::AsyncObliterateStoragePartition( | 136 void BrowserContext::AsyncObliterateStoragePartition( |
99 BrowserContext* browser_context, | 137 BrowserContext* browser_context, |
100 const GURL& site, | 138 const GURL& site, |
101 const base::Closure& on_gc_required) { | 139 const base::Closure& on_gc_required) { |
102 GetStoragePartitionMap(browser_context)->AsyncObliterate(site, | 140 GetStoragePartitionMap(browser_context)->AsyncObliterate(site, |
103 on_gc_required); | 141 on_gc_required); |
104 } | 142 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 BrowserThread::IO, FROM_HERE, | 304 BrowserThread::IO, FROM_HERE, |
267 base::Bind( | 305 base::Bind( |
268 &PurgeMemoryOnIOThread, | 306 &PurgeMemoryOnIOThread, |
269 BrowserContext::GetDefaultStoragePartition(browser_context)-> | 307 BrowserContext::GetDefaultStoragePartition(browser_context)-> |
270 GetAppCacheService())); | 308 GetAppCacheService())); |
271 } | 309 } |
272 | 310 |
273 ForEachStoragePartition(browser_context, | 311 ForEachStoragePartition(browser_context, |
274 base::Bind(&PurgeDOMStorageContextInPartition)); | 312 base::Bind(&PurgeDOMStorageContextInPartition)); |
275 } | 313 } |
| 314 |
| 315 ui::Clipboard::SourceTag BrowserContext::GetMarkerForOffTheRecordContext( |
| 316 BrowserContext* context) { |
| 317 if (context && context->IsOffTheRecord()) { |
| 318 OffTheRecordClipboardDestroyer* clipboard_destroyer = |
| 319 GetClipboardDestroyerForBrowserContext(context); |
| 320 |
| 321 return clipboard_destroyer->GetAsSourceTag(); |
| 322 } |
| 323 return ui::Clipboard::SourceTag(); |
| 324 } |
276 #endif // !OS_IOS | 325 #endif // !OS_IOS |
277 | 326 |
278 BrowserContext::~BrowserContext() { | 327 BrowserContext::~BrowserContext() { |
279 #if !defined(OS_IOS) | 328 #if !defined(OS_IOS) |
280 if (GetUserData(kDownloadManagerKeyName)) | 329 if (GetUserData(kDownloadManagerKeyName)) |
281 GetDownloadManager(this)->Shutdown(); | 330 GetDownloadManager(this)->Shutdown(); |
282 #endif | 331 #endif |
283 } | 332 } |
284 | 333 |
285 } // namespace content | 334 } // namespace content |
OLD | NEW |