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 "ppapi/proxy/plugin_globals.h" | 5 #include "ppapi/proxy/plugin_globals.h" |
6 | 6 |
7 #include "ipc/ipc_message.h" | |
8 #include "ipc/ipc_sender.h" | |
7 #include "ppapi/proxy/plugin_dispatcher.h" | 9 #include "ppapi/proxy/plugin_dispatcher.h" |
8 #include "ppapi/proxy/plugin_proxy_delegate.h" | 10 #include "ppapi/proxy/plugin_proxy_delegate.h" |
9 #include "ppapi/proxy/ppb_message_loop_proxy.h" | 11 #include "ppapi/proxy/ppb_message_loop_proxy.h" |
12 #include "ppapi/shared_impl/proxy_lock.h" | |
10 #include "ppapi/thunk/enter.h" | 13 #include "ppapi/thunk/enter.h" |
11 | 14 |
12 namespace ppapi { | 15 namespace ppapi { |
13 namespace proxy { | 16 namespace proxy { |
14 | 17 |
18 // It performs necessary locking/unlocking of the proxy lock, and forwards all | |
19 // messages to the underlying sender. | |
20 class PluginGlobals::BrowserSender : public IPC::Sender { | |
21 public: | |
22 // |underlying_sender| must outlive this object. | |
23 explicit BrowserSender(IPC::Sender* underlying_sender) | |
24 : underlying_sender_(underlying_sender) { | |
25 } | |
26 | |
27 virtual ~BrowserSender() {} | |
28 | |
29 // IPC::Sender implementation. | |
30 virtual bool Send(IPC::Message* msg) OVERRIDE { | |
31 if (msg->is_sync()) { | |
32 // Synchronous messages might be re-entrant, so we need to drop the lock. | |
33 ProxyAutoUnlock unlock; | |
34 return underlying_sender_->Send(msg); | |
35 } | |
36 | |
37 return underlying_sender_->Send(msg); | |
38 } | |
39 | |
40 private: | |
41 // Non-owning pointer. | |
42 IPC::Sender* underlying_sender_; | |
43 | |
44 DISALLOW_COPY_AND_ASSIGN(BrowserSender); | |
45 }; | |
46 | |
15 PluginGlobals* PluginGlobals::plugin_globals_ = NULL; | 47 PluginGlobals* PluginGlobals::plugin_globals_ = NULL; |
16 | 48 |
17 PluginGlobals::PluginGlobals() | 49 PluginGlobals::PluginGlobals() |
18 : ppapi::PpapiGlobals(), | 50 : ppapi::PpapiGlobals(), |
19 plugin_proxy_delegate_(NULL), | 51 plugin_proxy_delegate_(NULL), |
20 callback_tracker_(new CallbackTracker), | 52 callback_tracker_(new CallbackTracker), |
21 loop_for_main_thread_( | 53 loop_for_main_thread_( |
22 new MessageLoopResource(MessageLoopResource::ForMainThread())) { | 54 new MessageLoopResource(MessageLoopResource::ForMainThread())) { |
23 DCHECK(!plugin_globals_); | 55 DCHECK(!plugin_globals_); |
24 plugin_globals_ = this; | 56 plugin_globals_ = this; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 PP_Module PluginGlobals::GetModuleForInstance(PP_Instance instance) { | 101 PP_Module PluginGlobals::GetModuleForInstance(PP_Instance instance) { |
70 // Currently proxied plugins don't use the PP_Module for anything useful. | 102 // Currently proxied plugins don't use the PP_Module for anything useful. |
71 return 0; | 103 return 0; |
72 } | 104 } |
73 | 105 |
74 std::string PluginGlobals::GetCmdLine() { | 106 std::string PluginGlobals::GetCmdLine() { |
75 return command_line_; | 107 return command_line_; |
76 } | 108 } |
77 | 109 |
78 void PluginGlobals::PreCacheFontForFlash(const void* logfontw) { | 110 void PluginGlobals::PreCacheFontForFlash(const void* logfontw) { |
111 ProxyAutoUnlock unlock; | |
yzshen1
2012/11/22 00:42:29
This is a little ugly, because unlocking here impl
| |
79 plugin_proxy_delegate_->PreCacheFont(logfontw); | 112 plugin_proxy_delegate_->PreCacheFont(logfontw); |
80 } | 113 } |
81 | 114 |
82 base::Lock* PluginGlobals::GetProxyLock() { | 115 base::Lock* PluginGlobals::GetProxyLock() { |
83 #ifdef ENABLE_PEPPER_THREADING | 116 #ifdef ENABLE_PEPPER_THREADING |
84 return &proxy_lock_; | 117 return &proxy_lock_; |
85 #else | 118 #else |
86 return NULL; | 119 return NULL; |
87 #endif | 120 #endif |
88 } | 121 } |
(...skipping 13 matching lines...) Expand all Loading... | |
102 // Since we have only one module in a plugin process, broadcast is always | 135 // Since we have only one module in a plugin process, broadcast is always |
103 // the same as "send to everybody" which is what the dispatcher implements | 136 // the same as "send to everybody" which is what the dispatcher implements |
104 // for the "instance = 0" case. | 137 // for the "instance = 0" case. |
105 LogWithSource(0, level, source, value); | 138 LogWithSource(0, level, source, value); |
106 } | 139 } |
107 | 140 |
108 MessageLoopShared* PluginGlobals::GetCurrentMessageLoop() { | 141 MessageLoopShared* PluginGlobals::GetCurrentMessageLoop() { |
109 return MessageLoopResource::GetCurrent(); | 142 return MessageLoopResource::GetCurrent(); |
110 } | 143 } |
111 | 144 |
145 IPC::Sender* PluginGlobals::GetBrowserSender() { | |
146 if (!browser_sender_.get()) { | |
147 browser_sender_.reset( | |
148 new BrowserSender(plugin_proxy_delegate_->GetBrowserSender())); | |
149 } | |
150 | |
151 return browser_sender_.get(); | |
152 } | |
153 | |
154 std::string PluginGlobals::GetUILanguage() { | |
155 return plugin_proxy_delegate_->GetUILanguage(); | |
156 } | |
157 | |
158 void PluginGlobals::SetActiveURL(const std::string& url) { | |
159 plugin_proxy_delegate_->SetActiveURL(url); | |
160 } | |
161 | |
112 MessageLoopResource* PluginGlobals::loop_for_main_thread() { | 162 MessageLoopResource* PluginGlobals::loop_for_main_thread() { |
113 return loop_for_main_thread_.get(); | 163 return loop_for_main_thread_.get(); |
114 } | 164 } |
115 | 165 |
116 bool PluginGlobals::IsPluginGlobals() const { | 166 bool PluginGlobals::IsPluginGlobals() const { |
117 return true; | 167 return true; |
118 } | 168 } |
119 | 169 |
120 } // namespace proxy | 170 } // namespace proxy |
121 } // namespace ppapi | 171 } // namespace ppapi |
OLD | NEW |