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

Unified Diff: content/public/browser/off_the_record_marker.cc

Issue 12041078: Clear the clipboard closing Incognito window (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed includes + style changes 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/public/browser/off_the_record_marker.cc
diff --git a/content/public/browser/off_the_record_marker.cc b/content/public/browser/off_the_record_marker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7fa50aa6359f6a8495cef2c240f7a3828cffbaeb
--- /dev/null
+++ b/content/public/browser/off_the_record_marker.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/browser/off_the_record_marker.h"
+
+#include "content/public/browser/browser_context.h"
+
+namespace content {
+namespace {
+
+const char* kClipboardDestroyerKey = "ClipboardDestroyerKey";
dcheng 2013/02/06 22:31:40 Nit: const char kClipboardDestroyerKey[]
vasilii 2013/02/07 17:30:05 Done.
+
+// 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;
+}
+
+} // anonymous namespace
+
+ui::Clipboard::SourceTag GetMarkerForOffTheRecordContext(
+ BrowserContext* context) {
+ if (context && context->IsOffTheRecord()) {
+ OffTheRecordClipboardDestroyer* clipboard_destroyer =
+ GetClipboardDestroyerForBrowserContext(context);
+
+ return ui::Clipboard::SourceTag(clipboard_destroyer);
+ }
+ return ui::Clipboard::SourceTag();
+}
dcheng 2013/02/06 22:31:40 Nit: newline here to mirror newline at beginning o
vasilii 2013/02/07 17:30:05 Done.
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698