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 // Many of these functions are based on those found in | 5 // Many of these functions are based on those found in |
6 // webkit/port/platform/PasteboardWin.cpp | 6 // webkit/port/platform/PasteboardWin.cpp |
7 | 7 |
8 #include "ui/base/clipboard/clipboard_win.h" | 8 #include "ui/base/clipboard/clipboard_win.h" |
9 | 9 |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
(...skipping 17 matching lines...) Expand all Loading... | |
28 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
29 #include "ui/base/clipboard/clipboard_util_win.h" | 29 #include "ui/base/clipboard/clipboard_util_win.h" |
30 #include "ui/base/clipboard/custom_data_helper.h" | 30 #include "ui/base/clipboard/custom_data_helper.h" |
31 #include "ui/gfx/canvas.h" | 31 #include "ui/gfx/canvas.h" |
32 #include "ui/gfx/size.h" | 32 #include "ui/gfx/size.h" |
33 | 33 |
34 namespace ui { | 34 namespace ui { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 // A scoper to impersonate the anonymous token and revert when leaving scope | |
39 class AnonymousImpersonator { | |
40 public: | |
41 AnonymousImpersonator() { | |
42 must_revert_ = ::ImpersonateAnonymousToken(::GetCurrentThread()); | |
Wez
2014/12/15 17:07:11
Under what circumstances can ImpersonateAnonymousT
forshaw
2014/12/16 09:07:30
It can fail if we're running under a restricted to
| |
43 } | |
44 | |
45 ~AnonymousImpersonator() { | |
46 if (must_revert_) | |
47 ::RevertToSelf(); | |
48 } | |
49 | |
50 private: | |
51 BOOL must_revert_; | |
52 DISALLOW_COPY_AND_ASSIGN(AnonymousImpersonator); | |
dcheng
2014/12/15 16:58:20
Note: I usually see a newline between DISALLOW_COP
forshaw
2014/12/16 09:07:30
Acknowledged.
| |
53 }; | |
54 | |
38 // A scoper to manage acquiring and automatically releasing the clipboard. | 55 // A scoper to manage acquiring and automatically releasing the clipboard. |
39 class ScopedClipboard { | 56 class ScopedClipboard { |
40 public: | 57 public: |
41 ScopedClipboard() : opened_(false) { } | 58 ScopedClipboard() : opened_(false) { } |
42 | 59 |
43 ~ScopedClipboard() { | 60 ~ScopedClipboard() { |
44 if (opened_) | 61 if (opened_) |
45 Release(); | 62 Release(); |
46 } | 63 } |
47 | 64 |
(...skipping 29 matching lines...) Expand all Loading... | |
77 return true; | 94 return true; |
78 } | 95 } |
79 } | 96 } |
80 | 97 |
81 // We failed to acquire the clipboard. | 98 // We failed to acquire the clipboard. |
82 return false; | 99 return false; |
83 } | 100 } |
84 | 101 |
85 void Release() { | 102 void Release() { |
86 if (opened_) { | 103 if (opened_) { |
104 // Impersonate the anonymous token during the call to CloseClipboard | |
105 // This prevents Windows 8+ capturing the broker's access token which | |
106 // could be accessed by lower-privileges chrome processes leading to | |
107 // a risk of EoP | |
Wez
2014/12/15 17:07:11
nit: punctuation
Impersonating the anonymous toke
forshaw
2014/12/16 09:07:30
The only thing I think this should impact is anyon
| |
108 AnonymousImpersonator impersonator; | |
87 ::CloseClipboard(); | 109 ::CloseClipboard(); |
88 opened_ = false; | 110 opened_ = false; |
89 } else { | 111 } else { |
90 NOTREACHED(); | 112 NOTREACHED(); |
91 } | 113 } |
92 } | 114 } |
93 | 115 |
94 private: | 116 private: |
95 bool opened_; | 117 bool opened_; |
96 }; | 118 }; |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
853 if (!clipboard_owner_) | 875 if (!clipboard_owner_) |
854 return NULL; | 876 return NULL; |
855 | 877 |
856 if (clipboard_owner_->hwnd() == NULL) | 878 if (clipboard_owner_->hwnd() == NULL) |
857 clipboard_owner_->Create(base::Bind(&ClipboardOwnerWndProc)); | 879 clipboard_owner_->Create(base::Bind(&ClipboardOwnerWndProc)); |
858 | 880 |
859 return clipboard_owner_->hwnd(); | 881 return clipboard_owner_->hwnd(); |
860 } | 882 } |
861 | 883 |
862 } // namespace ui | 884 } // namespace ui |
OLD | NEW |