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 #include "chrome/browser/renderer_host/pepper/pepper_flash_drm_host.h" | 5 #include "chrome/browser/renderer_host/pepper/pepper_flash_drm_host.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <Windows.h> | 8 #include <Windows.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "content/public/browser/browser_ppapi_host.h" | 15 #include "content/public/browser/browser_ppapi_host.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/child_process_security_policy.h" | 17 #include "content/public/browser/child_process_security_policy.h" |
18 #include "content/public/browser/render_widget_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
19 #include "content/public/browser/render_widget_host_view.h" | |
20 #include "content/public/common/pepper_plugin_info.h" | 19 #include "content/public/common/pepper_plugin_info.h" |
21 #include "ppapi/c/pp_errors.h" | 20 #include "ppapi/c/pp_errors.h" |
22 #include "ppapi/host/dispatch_host_message.h" | 21 #include "ppapi/host/dispatch_host_message.h" |
23 #include "ppapi/host/host_message_context.h" | 22 #include "ppapi/host/host_message_context.h" |
24 #include "ppapi/host/ppapi_host.h" | 23 #include "ppapi/host/ppapi_host.h" |
25 #include "ppapi/proxy/ppapi_messages.h" | 24 #include "ppapi/proxy/ppapi_messages.h" |
26 | 25 |
27 #if defined(USE_AURA) | 26 #if defined(USE_AURA) |
28 #include "ui/aura/root_window.h" | 27 #include "ui/aura/root_window.h" |
29 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
30 #endif | 29 #endif |
31 | 30 |
32 using content::BrowserPpapiHost; | 31 using content::BrowserPpapiHost; |
33 | 32 |
34 namespace chrome { | 33 namespace chrome { |
35 | 34 |
36 namespace { | 35 namespace { |
37 const base::FilePath::CharType kVoucherFilename[] = | 36 const base::FilePath::CharType kVoucherFilename[] = |
38 FILE_PATH_LITERAL("plugin.vch"); | 37 FILE_PATH_LITERAL("plugin.vch"); |
39 } | 38 } |
40 | 39 |
41 #if defined (OS_WIN) | 40 #if defined (OS_WIN) |
42 // Helper class to get the UI thread which monitor is showing the | 41 // Helper class to get the UI thread which monitor is showing the |
43 // window associated with the instance's render view. Since we get | 42 // window associated with the instance's render view. Since we get |
44 // called by the IO thread and we cannot block, the first answer is | 43 // called by the IO thread and we cannot block, the first answer is |
45 // of GetMonitor() may be NULL, but eventually it will contain the | 44 // of GetMonitor() may be NULL, but eventually it will contain the |
46 // right monitor. | 45 // right monitor. |
47 class MonitorFinder : public base::RefCountedThreadSafe<MonitorFinder> { | 46 class MonitorFinder : public base::RefCountedThreadSafe<MonitorFinder> { |
48 public: | 47 public: |
49 MonitorFinder(int process_id, int render_id) | 48 MonitorFinder(int process_id, int render_frame_id) |
50 : process_id_(process_id), | 49 : process_id_(process_id), |
51 render_id_(render_id), | 50 render_frame_id_(render_frame_id), |
52 monitor_(NULL), | 51 monitor_(NULL), |
53 request_sent_(0) { | 52 request_sent_(0) { |
54 } | 53 } |
55 | 54 |
56 int64_t GetMonitor() { | 55 int64_t GetMonitor() { |
57 // We use |request_sent_| as an atomic boolean so that we | 56 // We use |request_sent_| as an atomic boolean so that we |
58 // never have more than one task posted at a given time. We | 57 // never have more than one task posted at a given time. We |
59 // do this because we don't know how often our client is going | 58 // do this because we don't know how often our client is going |
60 // to call and we can't cache the |monitor_| value. | 59 // to call and we can't cache the |monitor_| value. |
61 if (InterlockedCompareExchange(&request_sent_, 1, 0) == 0) { | 60 if (InterlockedCompareExchange(&request_sent_, 1, 0) == 0) { |
62 content::BrowserThread::PostTask( | 61 content::BrowserThread::PostTask( |
63 content::BrowserThread::UI, FROM_HERE, | 62 content::BrowserThread::UI, FROM_HERE, |
64 base::Bind(&MonitorFinder::FetchMonitorFromWidget, this)); | 63 base::Bind(&MonitorFinder::FetchMonitorFromWidget, this)); |
65 } | 64 } |
66 return reinterpret_cast<int64_t>(monitor_); | 65 return reinterpret_cast<int64_t>(monitor_); |
67 } | 66 } |
68 | 67 |
69 private: | 68 private: |
70 friend class base::RefCountedThreadSafe<MonitorFinder>; | 69 friend class base::RefCountedThreadSafe<MonitorFinder>; |
71 ~MonitorFinder() { } | 70 ~MonitorFinder() { } |
72 | 71 |
73 void FetchMonitorFromWidget() { | 72 void FetchMonitorFromWidget() { |
74 InterlockedExchange(&request_sent_, 0); | 73 InterlockedExchange(&request_sent_, 0); |
75 content::RenderWidgetHost* rwh = | 74 content::RenderFrameHost* rfh = |
76 content::RenderWidgetHost::FromID(process_id_, render_id_); | 75 content::RenderFrameHost::FromID(process_id_, render_frame_id_); |
77 if (!rwh) | 76 if (!rfh) |
78 return; | 77 return; |
79 content::RenderWidgetHostView* view = rwh->GetView(); | 78 gfx::NativeView native_view = rfh->GetNativeView(); |
80 if (!view) | |
81 return; | |
82 gfx::NativeView native_view = view->GetNativeView(); | |
83 #if defined(USE_AURA) | 79 #if defined(USE_AURA) |
84 aura::WindowEventDispatcher* dispatcher = native_view->GetDispatcher(); | 80 aura::WindowEventDispatcher* dispatcher = native_view->GetDispatcher(); |
85 if (!dispatcher) | 81 if (!dispatcher) |
86 return; | 82 return; |
87 HWND window = dispatcher->host()->GetAcceleratedWidget(); | 83 HWND window = dispatcher->host()->GetAcceleratedWidget(); |
88 #else | 84 #else |
89 HWND window = native_view; | 85 HWND window = native_view; |
90 #endif | 86 #endif |
91 HMONITOR monitor = ::MonitorFromWindow(window, MONITOR_DEFAULTTONULL); | 87 HMONITOR monitor = ::MonitorFromWindow(window, MONITOR_DEFAULTTONULL); |
92 InterlockedExchangePointer(reinterpret_cast<void* volatile *>(&monitor_), | 88 InterlockedExchangePointer(reinterpret_cast<void* volatile *>(&monitor_), |
93 monitor); | 89 monitor); |
94 } | 90 } |
95 | 91 |
96 const int process_id_; | 92 const int process_id_; |
97 const int render_id_; | 93 const int render_frame_id_; |
98 volatile HMONITOR monitor_; | 94 volatile HMONITOR monitor_; |
99 volatile long request_sent_; | 95 volatile long request_sent_; |
100 }; | 96 }; |
101 #else | 97 #else |
102 // TODO(cpu): Support Mac and Linux someday. | 98 // TODO(cpu): Support Mac and Linux someday. |
103 class MonitorFinder : public base::RefCountedThreadSafe<MonitorFinder> { | 99 class MonitorFinder : public base::RefCountedThreadSafe<MonitorFinder> { |
104 public: | 100 public: |
105 MonitorFinder(int, int) { } | 101 MonitorFinder(int, int) { } |
106 int64_t GetMonitor() { return 0; } | 102 int64_t GetMonitor() { return 0; } |
107 | 103 |
108 private: | 104 private: |
109 friend class base::RefCountedThreadSafe<MonitorFinder>; | 105 friend class base::RefCountedThreadSafe<MonitorFinder>; |
110 ~MonitorFinder() { } | 106 ~MonitorFinder() { } |
111 }; | 107 }; |
112 #endif | 108 #endif |
113 | 109 |
114 PepperFlashDRMHost::PepperFlashDRMHost(BrowserPpapiHost* host, | 110 PepperFlashDRMHost::PepperFlashDRMHost(BrowserPpapiHost* host, |
115 PP_Instance instance, | 111 PP_Instance instance, |
116 PP_Resource resource) | 112 PP_Resource resource) |
117 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource), | 113 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource), |
118 weak_factory_(this){ | 114 weak_factory_(this){ |
119 // Grant permissions to read the flash voucher file. | 115 // Grant permissions to read the flash voucher file. |
120 int render_process_id; | 116 int render_process_id; |
121 int render_view_id; | 117 int render_frame_id; |
122 bool success = | 118 bool success = |
123 host->GetRenderViewIDsForInstance( | 119 host->GetRenderFrameIDsForInstance( |
124 instance, &render_process_id, &render_view_id); | 120 instance, &render_process_id, &render_frame_id); |
125 base::FilePath plugin_dir = host->GetPluginPath().DirName(); | 121 base::FilePath plugin_dir = host->GetPluginPath().DirName(); |
126 DCHECK(!plugin_dir.empty() && success); | 122 DCHECK(!plugin_dir.empty() && success); |
127 base::FilePath voucher_file = plugin_dir.Append( | 123 base::FilePath voucher_file = plugin_dir.Append( |
128 base::FilePath(kVoucherFilename)); | 124 base::FilePath(kVoucherFilename)); |
129 content::ChildProcessSecurityPolicy::GetInstance()->GrantReadFile( | 125 content::ChildProcessSecurityPolicy::GetInstance()->GrantReadFile( |
130 render_process_id, voucher_file); | 126 render_process_id, voucher_file); |
131 | 127 |
132 fetcher_ = new DeviceIDFetcher(render_process_id); | 128 fetcher_ = new DeviceIDFetcher(render_process_id); |
133 monitor_finder_ = new MonitorFinder(render_process_id, render_view_id); | 129 monitor_finder_ = new MonitorFinder(render_process_id, render_frame_id); |
134 monitor_finder_->GetMonitor(); | 130 monitor_finder_->GetMonitor(); |
135 } | 131 } |
136 | 132 |
137 PepperFlashDRMHost::~PepperFlashDRMHost() { | 133 PepperFlashDRMHost::~PepperFlashDRMHost() { |
138 } | 134 } |
139 | 135 |
140 int32_t PepperFlashDRMHost::OnResourceMessageReceived( | 136 int32_t PepperFlashDRMHost::OnResourceMessageReceived( |
141 const IPC::Message& msg, | 137 const IPC::Message& msg, |
142 ppapi::host::HostMessageContext* context) { | 138 ppapi::host::HostMessageContext* context) { |
143 IPC_BEGIN_MESSAGE_MAP(PepperFlashDRMHost, msg) | 139 IPC_BEGIN_MESSAGE_MAP(PepperFlashDRMHost, msg) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 if (id.empty() && result == PP_OK) { | 188 if (id.empty() && result == PP_OK) { |
193 NOTREACHED(); | 189 NOTREACHED(); |
194 result = PP_ERROR_FAILED; | 190 result = PP_ERROR_FAILED; |
195 } | 191 } |
196 reply_context.params.set_result(result); | 192 reply_context.params.set_result(result); |
197 host()->SendReply(reply_context, | 193 host()->SendReply(reply_context, |
198 PpapiPluginMsg_FlashDRM_GetDeviceIDReply(id)); | 194 PpapiPluginMsg_FlashDRM_GetDeviceIDReply(id)); |
199 } | 195 } |
200 | 196 |
201 } // namespace chrome | 197 } // namespace chrome |
OLD | NEW |