Chromium Code Reviews| 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()); | |
| 43 } | |
| 44 | |
| 45 ~AnonymousImpersonator() { | |
| 46 if (must_revert_) | |
| 47 ::RevertToSelf(); | |
| 48 } | |
| 49 | |
| 50 private: | |
| 51 BOOL must_revert_; | |
|
dcheng
2014/12/13 01:16:50
Actually, you probably want DISALLOW_COPY_AND_ASSI
| |
| 52 }; | |
| 53 | |
| 38 // A scoper to manage acquiring and automatically releasing the clipboard. | 54 // A scoper to manage acquiring and automatically releasing the clipboard. |
| 39 class ScopedClipboard { | 55 class ScopedClipboard { |
| 40 public: | 56 public: |
| 41 ScopedClipboard() : opened_(false) { } | 57 ScopedClipboard() : opened_(false) { } |
| 42 | 58 |
| 43 ~ScopedClipboard() { | 59 ~ScopedClipboard() { |
| 44 if (opened_) | 60 if (opened_) |
| 45 Release(); | 61 Release(); |
| 46 } | 62 } |
| 47 | 63 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 77 return true; | 93 return true; |
| 78 } | 94 } |
| 79 } | 95 } |
| 80 | 96 |
| 81 // We failed to acquire the clipboard. | 97 // We failed to acquire the clipboard. |
| 82 return false; | 98 return false; |
| 83 } | 99 } |
| 84 | 100 |
| 85 void Release() { | 101 void Release() { |
| 86 if (opened_) { | 102 if (opened_) { |
| 103 // Impersonate the anonymous token during the call to CloseClipboard | |
| 104 // This prevents Windows 8+ capturing the broker's access token which | |
| 105 // could be accessed by lower-privileges chrome processes leading to | |
| 106 // a risk of EoP | |
| 107 AnonymousImpersonator impersonator; | |
| 87 ::CloseClipboard(); | 108 ::CloseClipboard(); |
| 88 opened_ = false; | 109 opened_ = false; |
| 89 } else { | 110 } else { |
| 90 NOTREACHED(); | 111 NOTREACHED(); |
| 91 } | 112 } |
| 92 } | 113 } |
| 93 | 114 |
| 94 private: | 115 private: |
| 95 bool opened_; | 116 bool opened_; |
| 96 }; | 117 }; |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 853 if (!clipboard_owner_) | 874 if (!clipboard_owner_) |
| 854 return NULL; | 875 return NULL; |
| 855 | 876 |
| 856 if (clipboard_owner_->hwnd() == NULL) | 877 if (clipboard_owner_->hwnd() == NULL) |
| 857 clipboard_owner_->Create(base::Bind(&ClipboardOwnerWndProc)); | 878 clipboard_owner_->Create(base::Bind(&ClipboardOwnerWndProc)); |
| 858 | 879 |
| 859 return clipboard_owner_->hwnd(); | 880 return clipboard_owner_->hwnd(); |
| 860 } | 881 } |
| 861 | 882 |
| 862 } // namespace ui | 883 } // namespace ui |
| OLD | NEW |