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

Unified Diff: content/browser/browser_context.cc

Issue 12041078: Clear the clipboard closing Incognito window (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merge and compilation fixes Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | content/browser/renderer_host/clipboard_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/browser_context.cc
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
index 3e3f57087981965aabc4009eedbd0b9f27ba6fb7..0117fa6853d50b59db87d42076c29b8b742e6f6f 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,42 @@ 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* clipboard = ui::Clipboard::GetForCurrentThread();
+ ExamineClipboard(clipboard, ui::Clipboard::BUFFER_STANDARD);
+ if (ui::Clipboard::IsValidBuffer(ui::Clipboard::BUFFER_SELECTION))
+ ExamineClipboard(clipboard, ui::Clipboard::BUFFER_SELECTION);
+ }
+
+ ui::Clipboard::SourceTag GetAsSourceTag() {
+ return ui::Clipboard::SourceTag(this);
+ }
+
+ private:
+ void ExamineClipboard(ui::Clipboard* clipboard,
+ ui::Clipboard::Buffer buffer) {
+ ui::Clipboard::SourceTag source_tag = clipboard->ReadSourceTag(buffer);
+ if (source_tag == ui::Clipboard::SourceTag(this))
+ clipboard->Clear(buffer);
+ }
+};
+
+// 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 +311,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 clipboard_destroyer->GetAsSourceTag();
+ }
+ return ui::Clipboard::SourceTag();
+}
#endif // !OS_IOS
BrowserContext::~BrowserContext() {
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | content/browser/renderer_host/clipboard_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698