Index: content/browser/browser_context.cc |
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc |
index 1b72aec2ba83165c923b9828515c071735b30201..6c5fd68255911e6f669dfbc9305a6b7b44314d04 100644 |
--- a/content/browser/browser_context.cc |
+++ b/content/browser/browser_context.cc |
@@ -23,6 +23,7 @@ |
#include "net/cookies/cookie_store.h" |
#include "net/url_request/url_request_context.h" |
#include "net/url_request/url_request_context_getter.h" |
+#include "ui/base/clipboard/clipboard.h" |
#include "webkit/database/database_tracker.h" |
#include "webkit/fileapi/external_mount_points.h" |
#endif // !OS_IOS |
@@ -36,6 +37,7 @@ namespace content { |
namespace { |
// Key names on BrowserContext. |
+const char kClipboardDestroyerKey[] = "clipboard_destroyer"; |
const char kDownloadManagerKeyName[] = "download_manager"; |
const char kMountPointsKey[] = "mount_points"; |
const char kStorageParitionMapKeyName[] = "content_storage_partition_map"; |
@@ -92,6 +94,32 @@ void PurgeMemoryOnIOThread(appcache::AppCacheService* appcache_service) { |
appcache_service->PurgeMemory(); |
} |
+// OffTheRecordClipboardDestroyer is supposed to clear the clipboard in |
+// destructor if current clipboard content came from corresponding OffTheRecord |
+// browser context. |
+class OffTheRecordClipboardDestroyer : public base::SupportsUserData::Data { |
+ public: |
+ virtual ~OffTheRecordClipboardDestroyer() { |
+ ui::Clipboard::SourceTag source_tag = |
+ ui::Clipboard::GetForCurrentThread()->ReadSourceTag(); |
+ if (source_tag == ui::Clipboard::SourceTag(this)) { |
+ ui::Clipboard::GetForCurrentThread()->Clear( |
+ ui::Clipboard::BUFFER_STANDARD); |
+ } |
+ } |
+}; |
+ |
+// Returns existing OffTheRecordClipboardDestroyer or creates one. |
+OffTheRecordClipboardDestroyer* GetClipboardDestroyerForBrowserContext( |
+ BrowserContext* context) { |
+ if (base::SupportsUserData::Data* data = context->GetUserData( |
+ kClipboardDestroyerKey)) |
+ return static_cast<OffTheRecordClipboardDestroyer*>(data); |
+ OffTheRecordClipboardDestroyer* data = new OffTheRecordClipboardDestroyer; |
+ context->SetUserData(kClipboardDestroyerKey, data); |
+ return data; |
+} |
+ |
} // namespace |
// static |
@@ -273,6 +301,17 @@ void BrowserContext::PurgeMemory(BrowserContext* browser_context) { |
ForEachStoragePartition(browser_context, |
base::Bind(&PurgeDOMStorageContextInPartition)); |
} |
+ |
+ui::Clipboard::SourceTag BrowserContext::GetMarkerForOffTheRecordContext( |
+ BrowserContext* context) { |
+ if (context && context->IsOffTheRecord()) { |
+ OffTheRecordClipboardDestroyer* clipboard_destroyer = |
+ GetClipboardDestroyerForBrowserContext(context); |
+ |
+ return ui::Clipboard::SourceTag(clipboard_destroyer); |
+ } |
+ return ui::Clipboard::SourceTag(); |
+} |
#endif // !OS_IOS |
BrowserContext::~BrowserContext() { |