| 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 "content/ppapi_plugin/broker_process_dispatcher.h" | 5 #include "content/ppapi_plugin/broker_process_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "content/common/child_process.h" | 10 #include "content/common/child_process.h" |
| 11 #include "ppapi/c/pp_bool.h" |
| 11 #include "ppapi/c/private/ppp_flash_browser_operations.h" | 12 #include "ppapi/c/private/ppp_flash_browser_operations.h" |
| 12 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // How long we wait before releasing the broker process. | 17 // How long we wait before releasing the broker process. |
| 17 const int kBrokerReleaseTimeSeconds = 30; | 18 const int kBrokerReleaseTimeSeconds = 30; |
| 18 | 19 |
| 20 std::string ConvertPluginDataPath(const FilePath& plugin_data_path) { |
| 21 // The string is always 8-bit, convert on Windows. |
| 22 #if defined(OS_WIN) |
| 23 return WideToUTF8(plugin_data_path.value()); |
| 24 #else |
| 25 return plugin_data_path.value(); |
| 26 #endif |
| 27 } |
| 28 |
| 19 } // namespace | 29 } // namespace |
| 20 | 30 |
| 21 BrokerProcessDispatcher::BrokerProcessDispatcher( | 31 BrokerProcessDispatcher::BrokerProcessDispatcher( |
| 22 PP_GetInterface_Func get_plugin_interface, | 32 PP_GetInterface_Func get_plugin_interface, |
| 23 PP_ConnectInstance_Func connect_instance) | 33 PP_ConnectInstance_Func connect_instance) |
| 24 : ppapi::proxy::BrokerSideDispatcher(connect_instance), | 34 : ppapi::proxy::BrokerSideDispatcher(connect_instance), |
| 25 get_plugin_interface_(get_plugin_interface) { | 35 get_plugin_interface_(get_plugin_interface) { |
| 26 ChildProcess::current()->AddRefProcess(); | 36 ChildProcess::current()->AddRefProcess(); |
| 27 } | 37 } |
| 28 | 38 |
| 29 BrokerProcessDispatcher::~BrokerProcessDispatcher() { | 39 BrokerProcessDispatcher::~BrokerProcessDispatcher() { |
| 30 DVLOG(1) << "BrokerProcessDispatcher::~BrokerProcessDispatcher()"; | 40 DVLOG(1) << "BrokerProcessDispatcher::~BrokerProcessDispatcher()"; |
| 31 // Don't free the process right away. This timer allows the child process | 41 // Don't free the process right away. This timer allows the child process |
| 32 // to be re-used if the user rapidly goes to a new page that requires this | 42 // to be re-used if the user rapidly goes to a new page that requires this |
| 33 // plugin. This is the case for common plugins where they may be used on a | 43 // plugin. This is the case for common plugins where they may be used on a |
| 34 // source and destination page of a navigation. We don't want to tear down | 44 // source and destination page of a navigation. We don't want to tear down |
| 35 // and re-start processes each time in these cases. | 45 // and re-start processes each time in these cases. |
| 36 MessageLoop::current()->PostDelayedTask( | 46 MessageLoop::current()->PostDelayedTask( |
| 37 FROM_HERE, | 47 FROM_HERE, |
| 38 base::Bind(&ChildProcess::ReleaseProcess, | 48 base::Bind(&ChildProcess::ReleaseProcess, |
| 39 base::Unretained(ChildProcess::current())), | 49 base::Unretained(ChildProcess::current())), |
| 40 base::TimeDelta::FromSeconds(kBrokerReleaseTimeSeconds)); | 50 base::TimeDelta::FromSeconds(kBrokerReleaseTimeSeconds)); |
| 41 } | 51 } |
| 42 | 52 |
| 43 bool BrokerProcessDispatcher::OnMessageReceived(const IPC::Message& msg) { | 53 bool BrokerProcessDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 44 IPC_BEGIN_MESSAGE_MAP(BrokerProcessDispatcher, msg) | 54 IPC_BEGIN_MESSAGE_MAP(BrokerProcessDispatcher, msg) |
| 45 IPC_MESSAGE_HANDLER(PpapiMsg_ClearSiteData, OnMsgClearSiteData) | 55 IPC_MESSAGE_HANDLER(PpapiMsg_ClearSiteData, OnMsgClearSiteData) |
| 56 IPC_MESSAGE_HANDLER(PpapiMsg_DeauthorizeContentLicenses, |
| 57 OnMsgDeauthorizeContentLicenses) |
| 46 IPC_MESSAGE_UNHANDLED(return BrokerSideDispatcher::OnMessageReceived(msg)) | 58 IPC_MESSAGE_UNHANDLED(return BrokerSideDispatcher::OnMessageReceived(msg)) |
| 47 IPC_END_MESSAGE_MAP() | 59 IPC_END_MESSAGE_MAP() |
| 48 return true; | 60 return true; |
| 49 } | 61 } |
| 50 | 62 |
| 51 void BrokerProcessDispatcher::OnMsgClearSiteData( | 63 void BrokerProcessDispatcher::OnMsgClearSiteData( |
| 52 const FilePath& plugin_data_path, | 64 const FilePath& plugin_data_path, |
| 53 const std::string& site, | 65 const std::string& site, |
| 54 uint64 flags, | 66 uint64 flags, |
| 55 uint64 max_age) { | 67 uint64 max_age) { |
| 56 Send(new PpapiHostMsg_ClearSiteDataResult( | 68 Send(new PpapiHostMsg_ClearSiteDataResult( |
| 57 ClearSiteData(plugin_data_path, site, flags, max_age))); | 69 ClearSiteData(plugin_data_path, site, flags, max_age))); |
| 58 } | 70 } |
| 59 | 71 |
| 72 void BrokerProcessDispatcher::OnMsgDeauthorizeContentLicenses( |
| 73 uint32 request_id, |
| 74 const FilePath& plugin_data_path) { |
| 75 Send(new PpapiHostMsg_DeauthorizeContentLicensesResult( |
| 76 request_id, DeauthorizeContentLicenses(plugin_data_path))); |
| 77 } |
| 78 |
| 60 bool BrokerProcessDispatcher::ClearSiteData(const FilePath& plugin_data_path, | 79 bool BrokerProcessDispatcher::ClearSiteData(const FilePath& plugin_data_path, |
| 61 const std::string& site, | 80 const std::string& site, |
| 62 uint64 flags, | 81 uint64 flags, |
| 63 uint64 max_age) { | 82 uint64 max_age) { |
| 64 if (!get_plugin_interface_) | 83 if (!get_plugin_interface_) |
| 65 return false; | 84 return false; |
| 66 const PPP_Flash_BrowserOperations_1_0* browser_interface = | 85 const PPP_Flash_BrowserOperations_1_0* browser_interface = |
| 67 static_cast<const PPP_Flash_BrowserOperations_1_0*>( | 86 static_cast<const PPP_Flash_BrowserOperations_1_0*>( |
| 68 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_0)); | 87 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_0)); |
| 69 if (!browser_interface) | 88 if (!browser_interface) |
| 70 return false; | 89 return false; |
| 71 | 90 |
| 72 // The string is always 8-bit, convert on Windows. | 91 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 73 #if defined(OS_WIN) | |
| 74 std::string data_str = WideToUTF8(plugin_data_path.value()); | |
| 75 #else | |
| 76 std::string data_str = plugin_data_path.value(); | |
| 77 #endif | |
| 78 | |
| 79 browser_interface->ClearSiteData(data_str.c_str(), | 92 browser_interface->ClearSiteData(data_str.c_str(), |
| 80 site.empty() ? NULL : site.c_str(), | 93 site.empty() ? NULL : site.c_str(), |
| 81 flags, max_age); | 94 flags, max_age); |
| 82 return true; | 95 return true; |
| 83 } | 96 } |
| 84 | 97 |
| 98 bool BrokerProcessDispatcher::DeauthorizeContentLicenses( |
| 99 const FilePath& plugin_data_path) { |
| 100 if (!get_plugin_interface_) |
| 101 return false; |
| 102 const PPP_Flash_BrowserOperations_1_1* browser_interface = |
| 103 static_cast<const PPP_Flash_BrowserOperations_1_1*>( |
| 104 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_1)); |
| 105 if (!browser_interface) |
| 106 return false; |
| 107 |
| 108 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 109 return PP_ToBool(browser_interface->DeauthorizeContentLicenses( |
| 110 data_str.c_str())); |
| 111 } |
| 112 |
| OLD | NEW |