Chromium Code Reviews| 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/browser/renderer_host/pepper_message_filter.h" | 5 #include "content/browser/renderer_host/pepper_message_filter.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/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/file_path.h" | |
| 12 #include "base/file_util.h" | |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/process_util.h" | 16 #include "base/process_util.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "base/threading/worker_pool.h" | 18 #include "base/threading/worker_pool.h" |
| 17 #include "base/values.h" | 19 #include "base/values.h" |
| 18 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 19 #include "content/browser/renderer_host/pepper_lookup_request.h" | 21 #include "content/browser/renderer_host/pepper_lookup_request.h" |
| 20 #include "content/browser/renderer_host/pepper_tcp_server_socket.h" | 22 #include "content/browser/renderer_host/pepper_tcp_server_socket.h" |
| 21 #include "content/browser/renderer_host/pepper_tcp_socket.h" | 23 #include "content/browser/renderer_host/pepper_tcp_socket.h" |
| 22 #include "content/browser/renderer_host/pepper_udp_socket.h" | 24 #include "content/browser/renderer_host/pepper_udp_socket.h" |
| 23 #include "content/browser/renderer_host/render_process_host_impl.h" | 25 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 24 #include "content/browser/renderer_host/render_view_host_impl.h" | 26 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 25 #include "content/common/pepper_messages.h" | 27 #include "content/common/pepper_messages.h" |
| 28 #include "content/public/browser/browser_context.h" | |
| 26 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/content_browser_client.h" | 30 #include "content/public/browser/content_browser_client.h" |
| 28 #include "content/public/browser/font_list_async.h" | 31 #include "content/public/browser/font_list_async.h" |
| 29 #include "content/public/browser/resource_context.h" | 32 #include "content/public/browser/resource_context.h" |
| 30 #include "content/public/browser/site_instance.h" | 33 #include "content/public/browser/site_instance.h" |
| 31 #include "content/public/common/content_client.h" | 34 #include "content/public/common/content_client.h" |
| 32 #include "net/base/address_family.h" | 35 #include "net/base/address_family.h" |
| 33 #include "net/base/address_list.h" | 36 #include "net/base/address_list.h" |
| 34 #include "net/base/cert_verifier.h" | 37 #include "net/base/cert_verifier.h" |
| 35 #include "net/base/host_port_pair.h" | 38 #include "net/base/host_port_pair.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 48 | 51 |
| 49 using content::BrowserThread; | 52 using content::BrowserThread; |
| 50 using content::RenderViewHostImpl; | 53 using content::RenderViewHostImpl; |
| 51 using ppapi::NetAddressPrivateImpl; | 54 using ppapi::NetAddressPrivateImpl; |
| 52 | 55 |
| 53 namespace { | 56 namespace { |
| 54 | 57 |
| 55 const size_t kMaxSocketsAllowed = 1024; | 58 const size_t kMaxSocketsAllowed = 1024; |
| 56 const uint32 kInvalidSocketID = 0; | 59 const uint32 kInvalidSocketID = 0; |
| 57 | 60 |
| 61 // The ID is a 256-bit hash digest hex-encoded. | |
| 62 const int kDRMIdentifierSize = (256 / 8) * 2; | |
| 63 // The path to the file containing the DRM ID. | |
| 64 // It is mirrored from | |
| 65 // chrome/browser/chromeos/system/drm_settings.cc | |
|
jam
2012/06/01 22:21:06
this is a layering violation. this code, in conten
jam
2012/06/01 22:32:40
and just to be clear, there should be a getter, mo
| |
| 66 const char kDRMIdentifierFile[] = "Pepper DRM ID.0"; | |
| 67 | |
| 58 } // namespace | 68 } // namespace |
| 59 | 69 |
| 60 PepperMessageFilter::PepperMessageFilter( | 70 PepperMessageFilter::PepperMessageFilter( |
| 61 ProcessType type, | 71 ProcessType type, |
| 62 int process_id, | 72 int process_id, |
| 63 content::ResourceContext* resource_context) | 73 content::BrowserContext* browser_context) |
| 64 : process_type_(type), | 74 : process_type_(type), |
| 65 process_id_(process_id), | 75 process_id_(process_id), |
| 66 resource_context_(resource_context), | 76 resource_context_(browser_context ? |
| 77 browser_context->GetResourceContext() : NULL), | |
| 67 host_resolver_(NULL), | 78 host_resolver_(NULL), |
| 68 next_socket_id_(1) { | 79 next_socket_id_(1) { |
| 69 DCHECK(type == RENDERER); | 80 DCHECK(type == RENDERER); |
| 81 DCHECK(browser_context); | |
| 82 browser_path_ = browser_context->GetPath(); | |
| 70 DCHECK(resource_context_); | 83 DCHECK(resource_context_); |
| 71 } | 84 } |
| 72 | 85 |
| 73 PepperMessageFilter::PepperMessageFilter(ProcessType type, | 86 PepperMessageFilter::PepperMessageFilter(ProcessType type, |
| 74 net::HostResolver* host_resolver) | 87 net::HostResolver* host_resolver) |
| 75 : process_type_(type), | 88 : process_type_(type), |
| 76 process_id_(0), | 89 process_id_(0), |
| 77 resource_context_(NULL), | 90 resource_context_(NULL), |
| 78 host_resolver_(host_resolver), | 91 host_resolver_(host_resolver), |
| 79 next_socket_id_(1) { | 92 next_socket_id_(1) { |
| 80 DCHECK(type == PLUGIN); | 93 DCHECK(type == PLUGIN); |
| 81 DCHECK(host_resolver); | 94 DCHECK(host_resolver); |
| 82 } | 95 } |
| 83 | 96 |
| 84 void PepperMessageFilter::OverrideThreadForMessage( | 97 void PepperMessageFilter::OverrideThreadForMessage( |
| 85 const IPC::Message& message, | 98 const IPC::Message& message, |
| 86 BrowserThread::ID* thread) { | 99 BrowserThread::ID* thread) { |
| 87 if (message.type() == PpapiHostMsg_PPBTCPSocket_Connect::ID || | 100 if (message.type() == PpapiHostMsg_PPBTCPSocket_Connect::ID || |
| 88 message.type() == PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress::ID || | 101 message.type() == PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress::ID || |
| 89 message.type() == PpapiHostMsg_PPBUDPSocket_Bind::ID || | 102 message.type() == PpapiHostMsg_PPBUDPSocket_Bind::ID || |
| 90 message.type() == PpapiHostMsg_PPBTCPServerSocket_Listen::ID || | 103 message.type() == PpapiHostMsg_PPBTCPServerSocket_Listen::ID || |
| 91 message.type() == PpapiHostMsg_PPBHostResolver_Resolve::ID) { | 104 message.type() == PpapiHostMsg_PPBHostResolver_Resolve::ID) { |
| 92 *thread = BrowserThread::UI; | 105 *thread = BrowserThread::UI; |
| 93 } else if (message.type() == PpapiHostMsg_PPBFlash_GetDeviceID::ID) { | 106 } else if (message.type() == PepperMsg_GetDeviceID::ID) { |
| 94 *thread = BrowserThread::FILE; | 107 *thread = BrowserThread::FILE; |
| 95 } | 108 } |
| 96 } | 109 } |
| 97 | 110 |
| 98 bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg, | 111 bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg, |
| 99 bool* message_was_ok) { | 112 bool* message_was_ok) { |
| 100 bool handled = true; | 113 bool handled = true; |
| 101 IPC_BEGIN_MESSAGE_MAP_EX(PepperMessageFilter, msg, *message_was_ok) | 114 IPC_BEGIN_MESSAGE_MAP_EX(PepperMessageFilter, msg, *message_was_ok) |
| 102 IPC_MESSAGE_HANDLER(PepperMsg_GetLocalTimeZoneOffset, | 115 IPC_MESSAGE_HANDLER(PepperMsg_GetLocalTimeZoneOffset, |
| 103 OnGetLocalTimeZoneOffset) | 116 OnGetLocalTimeZoneOffset) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 OnNetworkMonitorStart) | 151 OnNetworkMonitorStart) |
| 139 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBNetworkMonitor_Stop, | 152 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBNetworkMonitor_Stop, |
| 140 OnNetworkMonitorStop) | 153 OnNetworkMonitorStop) |
| 141 | 154 |
| 142 // X509 certificate messages. | 155 // X509 certificate messages. |
| 143 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBX509Certificate_ParseDER, | 156 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBX509Certificate_ParseDER, |
| 144 OnX509CertificateParseDER); | 157 OnX509CertificateParseDER); |
| 145 | 158 |
| 146 // Flash messages. | 159 // Flash messages. |
| 147 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_UpdateActivity, OnUpdateActivity) | 160 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_UpdateActivity, OnUpdateActivity) |
| 148 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetDeviceID, OnGetDeviceID) | 161 IPC_MESSAGE_HANDLER(PepperMsg_GetDeviceID, OnGetDeviceID) |
| 149 | 162 |
| 150 IPC_MESSAGE_UNHANDLED(handled = false) | 163 IPC_MESSAGE_UNHANDLED(handled = false) |
| 151 IPC_END_MESSAGE_MAP_EX() | 164 IPC_END_MESSAGE_MAP_EX() |
| 152 return handled; | 165 return handled; |
| 153 } | 166 } |
| 154 | 167 |
| 155 void PepperMessageFilter::OnIPAddressChanged() { | 168 void PepperMessageFilter::OnIPAddressChanged() { |
| 156 GetAndSendNetworkList(); | 169 GetAndSendNetworkList(); |
| 157 } | 170 } |
| 158 | 171 |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 // than the screensaver timeout, it won't go on. | 639 // than the screensaver timeout, it won't go on. |
| 627 int value = 0; | 640 int value = 0; |
| 628 if (SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &value, 0)) | 641 if (SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &value, 0)) |
| 629 SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, value, NULL, 0); | 642 SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, value, NULL, 0); |
| 630 #else | 643 #else |
| 631 // TODO(brettw) implement this for other platforms. | 644 // TODO(brettw) implement this for other platforms. |
| 632 #endif | 645 #endif |
| 633 } | 646 } |
| 634 | 647 |
| 635 void PepperMessageFilter::OnGetDeviceID(std::string* id) { | 648 void PepperMessageFilter::OnGetDeviceID(std::string* id) { |
| 636 // TODO(brettw) implement this. | 649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 637 *id = "<undefined>"; | 650 id->clear(); |
| 651 | |
| 652 // Grab the contents of the DRM identifier file. | |
| 653 FilePath drm_id_file = browser_path_; | |
| 654 drm_id_file = drm_id_file.AppendASCII(kDRMIdentifierFile); | |
| 655 | |
| 656 // This method should not be called with high frequency and its | |
| 657 // useful to be able to validate use with a VLOG. | |
| 658 VLOG(1) << "DRM ID requested @ " << drm_id_file.value(); | |
| 659 | |
| 660 if (browser_path_.empty()) { | |
| 661 LOG(ERROR) << "GetDeviceID requested from outside the RENDERER context."; | |
| 662 return; | |
| 663 } | |
| 664 | |
| 665 // TODO(wad,brettw) Add OffTheRecord() enforcement here. | |
| 666 // Normally this is left for the plugin to do, but in the | |
| 667 // future we should check here as an added safeguard. | |
| 668 | |
| 669 char id_buf[kDRMIdentifierSize]; | |
| 670 if (file_util::ReadFile(drm_id_file, id_buf, kDRMIdentifierSize) != | |
| 671 kDRMIdentifierSize) { | |
| 672 VLOG(1) << "file not readable: " << drm_id_file.value(); | |
| 673 return; | |
| 674 } | |
| 675 id->assign(id_buf, kDRMIdentifierSize); | |
| 638 } | 676 } |
| 639 | 677 |
| 640 void PepperMessageFilter::GetFontFamiliesComplete( | 678 void PepperMessageFilter::GetFontFamiliesComplete( |
| 641 IPC::Message* reply_msg, | 679 IPC::Message* reply_msg, |
| 642 scoped_ptr<base::ListValue> result) { | 680 scoped_ptr<base::ListValue> result) { |
| 643 std::string output; | 681 std::string output; |
| 644 for (size_t i = 0; i < result->GetSize(); i++) { | 682 for (size_t i = 0; i < result->GetSize(); i++) { |
| 645 base::ListValue* cur_font; | 683 base::ListValue* cur_font; |
| 646 if (!result->GetList(i, &cur_font)) | 684 if (!result->GetList(i, &cur_font)) |
| 647 continue; | 685 continue; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 network_copy.state = PP_NETWORKLIST_UP; | 795 network_copy.state = PP_NETWORKLIST_UP; |
| 758 network_copy.display_name = network.name; | 796 network_copy.display_name = network.name; |
| 759 network_copy.mtu = 0; | 797 network_copy.mtu = 0; |
| 760 } | 798 } |
| 761 for (NetworkMonitorIdSet::iterator it = network_monitor_ids_.begin(); | 799 for (NetworkMonitorIdSet::iterator it = network_monitor_ids_.begin(); |
| 762 it != network_monitor_ids_.end(); ++it) { | 800 it != network_monitor_ids_.end(); ++it) { |
| 763 Send(new PpapiMsg_PPBNetworkMonitor_NetworkList( | 801 Send(new PpapiMsg_PPBNetworkMonitor_NetworkList( |
| 764 ppapi::API_ID_PPB_NETWORKMANAGER_PRIVATE, *it, *list_copy)); | 802 ppapi::API_ID_PPB_NETWORKMANAGER_PRIVATE, *it, *list_copy)); |
| 765 } | 803 } |
| 766 } | 804 } |
| OLD | NEW |