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

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: Selection clipboard support 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
Index: content/browser/browser_context.cc
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
index 1b72aec2ba83165c923b9828515c071735b30201..9458bd53eeba4578aca8e3f8114a155acdac2586 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,37 @@ 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);
+ }
battre 2013/02/12 12:50:59 nit: new lien before private:
vasilii 2013/02/12 15:58:32 Done.
+ private:
+ void ExamineClipboard(ui::Clipboard* clipboard,
+ ui::Clipboard::Buffer buffer) {
battre 2013/02/12 12:50:59 nit: indentation
vasilii 2013/02/12 15:58:32 Done.
+ 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))
battre 2013/02/12 12:50:59 nit: +4 spaces indentation
vasilii 2013/02/12 15:58:32 Done.
+ return static_cast<OffTheRecordClipboardDestroyer*>(data);
+ OffTheRecordClipboardDestroyer* data = new OffTheRecordClipboardDestroyer;
+ context->SetUserData(kClipboardDestroyerKey, data);
+ return data;
+}
+
} // namespace
// static
@@ -273,6 +306,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);
battre 2013/02/12 12:50:59 How about adding a function ui::Clipboard::Source
vasilii 2013/02/12 15:58:32 Done.
+ }
+ return ui::Clipboard::SourceTag();
+}
#endif // !OS_IOS
BrowserContext::~BrowserContext() {

Powered by Google App Engine
This is Rietveld 408576698