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" | 8 #include "base/lock.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/waitable_event.h" | 11 #include "base/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/glue/plugins/plugin_instance.h" |
19 | 20 |
20 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
21 #include "base/eintr_wrapper.h" | 22 #include "base/eintr_wrapper.h" |
22 #include "ipc/ipc_channel_posix.h" | 23 #include "ipc/ipc_channel_posix.h" |
23 #endif | 24 #endif |
24 | 25 |
25 class PluginReleaseTask : public Task { | 26 class PluginReleaseTask : public Task { |
26 public: | 27 public: |
27 void Run() { | 28 void Run() { |
28 ChildProcess::current()->ReleaseProcess(); | 29 ChildProcess::current()->ReleaseProcess(); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } | 205 } |
205 PluginChannelBase::OnMessageReceived(msg); | 206 PluginChannelBase::OnMessageReceived(msg); |
206 } | 207 } |
207 | 208 |
208 void PluginChannel::OnControlMessageReceived(const IPC::Message& msg) { | 209 void PluginChannel::OnControlMessageReceived(const IPC::Message& msg) { |
209 IPC_BEGIN_MESSAGE_MAP(PluginChannel, msg) | 210 IPC_BEGIN_MESSAGE_MAP(PluginChannel, msg) |
210 IPC_MESSAGE_HANDLER(PluginMsg_CreateInstance, OnCreateInstance) | 211 IPC_MESSAGE_HANDLER(PluginMsg_CreateInstance, OnCreateInstance) |
211 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_DestroyInstance, | 212 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_DestroyInstance, |
212 OnDestroyInstance) | 213 OnDestroyInstance) |
213 IPC_MESSAGE_HANDLER(PluginMsg_GenerateRouteID, OnGenerateRouteID) | 214 IPC_MESSAGE_HANDLER(PluginMsg_GenerateRouteID, OnGenerateRouteID) |
| 215 IPC_MESSAGE_HANDLER(PluginMsg_ClearSiteData, OnClearSiteData) |
214 IPC_MESSAGE_UNHANDLED_ERROR() | 216 IPC_MESSAGE_UNHANDLED_ERROR() |
215 IPC_END_MESSAGE_MAP() | 217 IPC_END_MESSAGE_MAP() |
216 } | 218 } |
217 | 219 |
218 void PluginChannel::OnCreateInstance(const std::string& mime_type, | 220 void PluginChannel::OnCreateInstance(const std::string& mime_type, |
219 int* instance_id) { | 221 int* instance_id) { |
220 *instance_id = GenerateRouteID(); | 222 *instance_id = GenerateRouteID(); |
221 scoped_refptr<WebPluginDelegateStub> stub(new WebPluginDelegateStub( | 223 scoped_refptr<WebPluginDelegateStub> stub(new WebPluginDelegateStub( |
222 mime_type, *instance_id, this)); | 224 mime_type, *instance_id, this)); |
223 AddRoute(*instance_id, stub, NULL); | 225 AddRoute(*instance_id, stub, NULL); |
(...skipping 25 matching lines...) Expand all Loading... |
249 | 251 |
250 void PluginChannel::OnGenerateRouteID(int* route_id) { | 252 void PluginChannel::OnGenerateRouteID(int* route_id) { |
251 *route_id = GenerateRouteID(); | 253 *route_id = GenerateRouteID(); |
252 } | 254 } |
253 | 255 |
254 int PluginChannel::GenerateRouteID() { | 256 int PluginChannel::GenerateRouteID() { |
255 static int last_id = 0; | 257 static int last_id = 0; |
256 return ++last_id; | 258 return ++last_id; |
257 } | 259 } |
258 | 260 |
| 261 void PluginChannel::OnClearSiteData(uint64 flags, |
| 262 const std::string& domain, |
| 263 base::Time begin_time) { |
| 264 bool success = false; |
| 265 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 266 FilePath path = command_line->GetSwitchValuePath(switches::kPluginPath); |
| 267 scoped_refptr<NPAPI::PluginLib> plugin_lib( |
| 268 NPAPI::PluginLib::CreatePluginLib(path)); |
| 269 if (plugin_lib.get()) { |
| 270 NPError err = plugin_lib->NP_Initialize(); |
| 271 if (err == NPERR_NO_ERROR) { |
| 272 scoped_refptr<NPAPI::PluginInstance> instance( |
| 273 plugin_lib->CreateInstance(std::string())); |
| 274 |
| 275 const char* domain_str = domain.empty() ? NULL : domain.c_str(); |
| 276 uint64 max_age; |
| 277 if (begin_time > base::Time()) { |
| 278 base::TimeDelta delta = base::Time::Now() - begin_time; |
| 279 max_age = delta.InSeconds(); |
| 280 } else { |
| 281 max_age = kuint64max; |
| 282 } |
| 283 err = instance->NPP_ClearSiteData(flags, domain_str, max_age); |
| 284 success = (err == NPERR_NO_ERROR); |
| 285 } |
| 286 } |
| 287 Send(new PluginHostMsg_ClearSiteDataResult(success)); |
| 288 } |
| 289 |
259 base::WaitableEvent* PluginChannel::GetModalDialogEvent( | 290 base::WaitableEvent* PluginChannel::GetModalDialogEvent( |
260 gfx::NativeViewId containing_window) { | 291 gfx::NativeViewId containing_window) { |
261 return filter_->GetModalDialogEvent(containing_window); | 292 return filter_->GetModalDialogEvent(containing_window); |
262 } | 293 } |
263 | 294 |
264 void PluginChannel::OnChannelConnected(int32 peer_pid) { | 295 void PluginChannel::OnChannelConnected(int32 peer_pid) { |
265 #if defined(OS_POSIX) | 296 #if defined(OS_POSIX) |
266 // By this point, the renderer must have its own copy of the plugin channel | 297 // By this point, the renderer must have its own copy of the plugin channel |
267 // FD. | 298 // FD. |
268 CloseRendererFD(); | 299 CloseRendererFD(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 356 |
326 #if defined(OS_POSIX) | 357 #if defined(OS_POSIX) |
327 void PluginChannel::CloseRendererFD() { | 358 void PluginChannel::CloseRendererFD() { |
328 if (renderer_fd_ != -1) { | 359 if (renderer_fd_ != -1) { |
329 if (HANDLE_EINTR(close(renderer_fd_)) < 0) | 360 if (HANDLE_EINTR(close(renderer_fd_)) < 0) |
330 PLOG(ERROR) << "close"; | 361 PLOG(ERROR) << "close"; |
331 renderer_fd_ = -1; | 362 renderer_fd_ = -1; |
332 } | 363 } |
333 } | 364 } |
334 #endif | 365 #endif |
OLD | NEW |