Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/gpu/browser_client_native_pixmap_manager_ozone.h" | |
| 6 | |
| 7 #include "base/memory/singleton.h" | |
| 8 #include "base/posix/eintr_wrapper.h" | |
| 9 #include "content/common/gpu/client_native_pixmap_manager_ozone_messages.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 #include "ui/ozone/public/ozone_platform.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 base::FileDescriptor DupVirtualDeviceFd(int virtual_device) { | |
| 18 int duped_fd = -1; | |
| 19 base::ThreadRestrictions::AssertIOAllowed(); | |
| 20 duped_fd = HANDLE_EINTR(dup(virtual_device)); | |
| 21 if (duped_fd < 0) { | |
| 22 PLOG(ERROR) << "dup() failed."; | |
| 23 return base::FileDescriptor(); | |
| 24 } | |
| 25 return base::FileDescriptor(duped_fd, true); | |
| 26 } | |
| 27 | |
| 28 void OnSendVirtualDevice(IPC::Sender* sender, | |
| 29 const base::FileDescriptor& virtual_device) { | |
| 30 sender->Send( | |
| 31 new ChildClientNativePixmapManagerMsg_SetVirtualDevice(virtual_device)); | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 struct BrowserClientNativePixmapManagerTrait | |
| 37 : public DefaultSingletonTraits<BrowserClientNativePixmapManager> { | |
| 38 static BrowserClientNativePixmapManager* New() { | |
| 39 BrowserClientNativePixmapManager* manager = | |
| 40 new BrowserClientNativePixmapManager(); | |
| 41 manager->Initialize(ui::OzonePlatform::GetInstance()->GetVirtualDeviceFd()); | |
| 42 return manager; | |
| 43 } | |
| 44 }; | |
| 45 | |
| 46 // static | |
| 47 BrowserClientNativePixmapManager* | |
| 48 BrowserClientNativePixmapManager::GetInstance() { | |
| 49 return Singleton<BrowserClientNativePixmapManager, | |
| 50 BrowserClientNativePixmapManagerTrait>::get(); | |
| 51 } | |
| 52 | |
| 53 BrowserClientNativePixmapManager::BrowserClientNativePixmapManager() {} | |
| 54 | |
| 55 BrowserClientNativePixmapManager::~BrowserClientNativePixmapManager() {} | |
| 56 | |
| 57 void BrowserClientNativePixmapManager::Initialize( | |
| 58 const base::FileDescriptor& virtual_device) { | |
| 59 pixmap_manager_ = ui::ClientNativePixmapManager::Create(virtual_device); | |
| 60 virtual_device_ = virtual_device; | |
| 61 } | |
| 62 | |
| 63 void BrowserClientNativePixmapManager::SendVirtualDevice(IPC::Sender* sender) { | |
| 64 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | |
| 65 base::PostTaskAndReplyWithResult( | |
| 66 pool, FROM_HERE, base::Bind(&DupVirtualDeviceFd, virtual_device_.fd), | |
|
spang
2015/08/04 17:47:31
I'm pretty sure that passing access to vgem by dup
dshwang
2015/08/05 09:44:26
I don't fully catch up which point is vulnerable f
| |
| 67 base::Bind(&OnSendVirtualDevice, sender)); | |
| 68 } | |
| 69 | |
| 70 std::vector<ui::ClientNativePixmapManager::Configuration> | |
| 71 BrowserClientNativePixmapManager::GetSupportedConfigurations() const { | |
| 72 return pixmap_manager_->GetSupportedConfigurations(); | |
| 73 } | |
| 74 | |
| 75 scoped_ptr<ui::ClientNativePixmap> | |
| 76 BrowserClientNativePixmapManager::ImportClientNativePixmap( | |
| 77 base::FileDescriptor handle, | |
| 78 gfx::Size size, | |
| 79 ui::NativePixmapFormat format, | |
| 80 ui::NativePixmapUsage usage) { | |
| 81 return pixmap_manager_->ImportClientNativePixmap(handle, size, format, usage); | |
| 82 } | |
| 83 | |
| 84 } // namespace content | |
| OLD | NEW |