OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/plugin/plugin_channel.h" | 5 #include "chrome/plugin/plugin_channel.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lock.h" | |
9 #include "base/process_util.h" | 8 #include "base/process_util.h" |
10 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/synchronization/lock.h" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/common/child_process.h" | 13 #include "chrome/common/child_process.h" |
14 #include "chrome/common/plugin_messages.h" | 14 #include "chrome/common/plugin_messages.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/plugin/plugin_thread.h" | 16 #include "chrome/plugin/plugin_thread.h" |
17 #include "chrome/plugin/webplugin_delegate_stub.h" | 17 #include "chrome/plugin/webplugin_delegate_stub.h" |
18 #include "chrome/plugin/webplugin_proxy.h" | 18 #include "chrome/plugin/webplugin_proxy.h" |
19 #include "webkit/plugins/npapi/plugin_instance.h" | 19 #include "webkit/plugins/npapi/plugin_instance.h" |
20 | 20 |
(...skipping 22 matching lines...) Expand all Loading... |
43 ~MessageFilter() { | 43 ~MessageFilter() { |
44 // Clean up in case of renderer crash. | 44 // Clean up in case of renderer crash. |
45 for (ModalDialogEventMap::iterator i = modal_dialog_event_map_.begin(); | 45 for (ModalDialogEventMap::iterator i = modal_dialog_event_map_.begin(); |
46 i != modal_dialog_event_map_.end(); ++i) { | 46 i != modal_dialog_event_map_.end(); ++i) { |
47 delete i->second.event; | 47 delete i->second.event; |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 base::WaitableEvent* GetModalDialogEvent( | 51 base::WaitableEvent* GetModalDialogEvent( |
52 gfx::NativeViewId containing_window) { | 52 gfx::NativeViewId containing_window) { |
53 AutoLock auto_lock(modal_dialog_event_map_lock_); | 53 base::AutoLock auto_lock(modal_dialog_event_map_lock_); |
54 if (!modal_dialog_event_map_.count(containing_window)) { | 54 if (!modal_dialog_event_map_.count(containing_window)) { |
55 NOTREACHED(); | 55 NOTREACHED(); |
56 return NULL; | 56 return NULL; |
57 } | 57 } |
58 | 58 |
59 return modal_dialog_event_map_[containing_window].event; | 59 return modal_dialog_event_map_[containing_window].event; |
60 } | 60 } |
61 | 61 |
62 // Decrement the ref count associated with the modal dialog event for the | 62 // Decrement the ref count associated with the modal dialog event for the |
63 // given tab. | 63 // given tab. |
64 void ReleaseModalDialogEvent(gfx::NativeViewId containing_window) { | 64 void ReleaseModalDialogEvent(gfx::NativeViewId containing_window) { |
65 AutoLock auto_lock(modal_dialog_event_map_lock_); | 65 base::AutoLock auto_lock(modal_dialog_event_map_lock_); |
66 if (!modal_dialog_event_map_.count(containing_window)) { | 66 if (!modal_dialog_event_map_.count(containing_window)) { |
67 NOTREACHED(); | 67 NOTREACHED(); |
68 return; | 68 return; |
69 } | 69 } |
70 | 70 |
71 if (--(modal_dialog_event_map_[containing_window].refcount)) | 71 if (--(modal_dialog_event_map_[containing_window].refcount)) |
72 return; | 72 return; |
73 | 73 |
74 // Delete the event when the stack unwinds as it could be in use now. | 74 // Delete the event when the stack unwinds as it could be in use now. |
75 MessageLoop::current()->DeleteSoon( | 75 MessageLoop::current()->DeleteSoon( |
(...skipping 15 matching lines...) Expand all Loading... |
91 IPC_MESSAGE_HANDLER(PluginMsg_SignalModalDialogEvent, | 91 IPC_MESSAGE_HANDLER(PluginMsg_SignalModalDialogEvent, |
92 OnSignalModalDialogEvent) | 92 OnSignalModalDialogEvent) |
93 IPC_MESSAGE_HANDLER(PluginMsg_ResetModalDialogEvent, | 93 IPC_MESSAGE_HANDLER(PluginMsg_ResetModalDialogEvent, |
94 OnResetModalDialogEvent) | 94 OnResetModalDialogEvent) |
95 IPC_END_MESSAGE_MAP() | 95 IPC_END_MESSAGE_MAP() |
96 return message.type() == PluginMsg_SignalModalDialogEvent::ID || | 96 return message.type() == PluginMsg_SignalModalDialogEvent::ID || |
97 message.type() == PluginMsg_ResetModalDialogEvent::ID; | 97 message.type() == PluginMsg_ResetModalDialogEvent::ID; |
98 } | 98 } |
99 | 99 |
100 void OnInit(const PluginMsg_Init_Params& params, IPC::Message* reply_msg) { | 100 void OnInit(const PluginMsg_Init_Params& params, IPC::Message* reply_msg) { |
101 AutoLock auto_lock(modal_dialog_event_map_lock_); | 101 base::AutoLock auto_lock(modal_dialog_event_map_lock_); |
102 if (modal_dialog_event_map_.count(params.containing_window)) { | 102 if (modal_dialog_event_map_.count(params.containing_window)) { |
103 modal_dialog_event_map_[params.containing_window].refcount++; | 103 modal_dialog_event_map_[params.containing_window].refcount++; |
104 return; | 104 return; |
105 } | 105 } |
106 | 106 |
107 WaitableEventWrapper wrapper; | 107 WaitableEventWrapper wrapper; |
108 wrapper.event = new base::WaitableEvent(true, false); | 108 wrapper.event = new base::WaitableEvent(true, false); |
109 wrapper.refcount = 1; | 109 wrapper.refcount = 1; |
110 modal_dialog_event_map_[params.containing_window] = wrapper; | 110 modal_dialog_event_map_[params.containing_window] = wrapper; |
111 } | 111 } |
112 | 112 |
113 void OnSignalModalDialogEvent(gfx::NativeViewId containing_window) { | 113 void OnSignalModalDialogEvent(gfx::NativeViewId containing_window) { |
114 AutoLock auto_lock(modal_dialog_event_map_lock_); | 114 base::AutoLock auto_lock(modal_dialog_event_map_lock_); |
115 if (modal_dialog_event_map_.count(containing_window)) | 115 if (modal_dialog_event_map_.count(containing_window)) |
116 modal_dialog_event_map_[containing_window].event->Signal(); | 116 modal_dialog_event_map_[containing_window].event->Signal(); |
117 } | 117 } |
118 | 118 |
119 void OnResetModalDialogEvent(gfx::NativeViewId containing_window) { | 119 void OnResetModalDialogEvent(gfx::NativeViewId containing_window) { |
120 AutoLock auto_lock(modal_dialog_event_map_lock_); | 120 base::AutoLock auto_lock(modal_dialog_event_map_lock_); |
121 if (modal_dialog_event_map_.count(containing_window)) | 121 if (modal_dialog_event_map_.count(containing_window)) |
122 modal_dialog_event_map_[containing_window].event->Reset(); | 122 modal_dialog_event_map_[containing_window].event->Reset(); |
123 } | 123 } |
124 | 124 |
125 struct WaitableEventWrapper { | 125 struct WaitableEventWrapper { |
126 base::WaitableEvent* event; | 126 base::WaitableEvent* event; |
127 int refcount; // There could be multiple plugin instances per tab. | 127 int refcount; // There could be multiple plugin instances per tab. |
128 }; | 128 }; |
129 typedef std::map<gfx::NativeViewId, WaitableEventWrapper> ModalDialogEventMap; | 129 typedef std::map<gfx::NativeViewId, WaitableEventWrapper> ModalDialogEventMap; |
130 ModalDialogEventMap modal_dialog_event_map_; | 130 ModalDialogEventMap modal_dialog_event_map_; |
131 Lock modal_dialog_event_map_lock_; | 131 base::Lock modal_dialog_event_map_lock_; |
132 | 132 |
133 IPC::Channel* channel_; | 133 IPC::Channel* channel_; |
134 }; | 134 }; |
135 | 135 |
136 | 136 |
137 PluginChannel* PluginChannel::GetPluginChannel(int renderer_id, | 137 PluginChannel* PluginChannel::GetPluginChannel(int renderer_id, |
138 MessageLoop* ipc_message_loop) { | 138 MessageLoop* ipc_message_loop) { |
139 // Map renderer ID to a (single) channel to that process. | 139 // Map renderer ID to a (single) channel to that process. |
140 std::string channel_key = StringPrintf( | 140 std::string channel_key = StringPrintf( |
141 "%d.r%d", base::GetCurrentProcId(), renderer_id); | 141 "%d.r%d", base::GetCurrentProcId(), renderer_id); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 317 } |
318 | 318 |
319 bool PluginChannel::Init(MessageLoop* ipc_message_loop, bool create_pipe_now) { | 319 bool PluginChannel::Init(MessageLoop* ipc_message_loop, bool create_pipe_now) { |
320 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now)) | 320 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now)) |
321 return false; | 321 return false; |
322 | 322 |
323 channel_->AddFilter(filter_.get()); | 323 channel_->AddFilter(filter_.get()); |
324 return true; | 324 return true; |
325 } | 325 } |
326 | 326 |
OLD | NEW |