| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/renderer_host/pepper/pepper_broker_host.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/common/content_settings.h" | |
| 12 #include "content/public/browser/browser_ppapi_host.h" | |
| 13 #include "content/public/browser/browser_thread.h" | |
| 14 #include "content/public/browser/render_process_host.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 #include "ipc/ipc_message_macros.h" | |
| 17 #include "ppapi/c/pp_errors.h" | |
| 18 #include "ppapi/host/dispatch_host_message.h" | |
| 19 #include "ppapi/host/resource_message_filter.h" | |
| 20 #include "ppapi/proxy/ppapi_messages.h" | |
| 21 | |
| 22 using content::BrowserPpapiHost; | |
| 23 using content::BrowserThread; | |
| 24 using content::RenderProcessHost; | |
| 25 | |
| 26 namespace chrome { | |
| 27 | |
| 28 namespace { | |
| 29 | |
| 30 // This filter handles messages for the PepperBrokerHost on the UI thread. | |
| 31 class BrokerMessageFilter : public ppapi::host::ResourceMessageFilter { | |
| 32 public: | |
| 33 BrokerMessageFilter(int render_process_id, GURL document_url); | |
| 34 | |
| 35 protected: | |
| 36 // ppapi::host::ResourceMessageFilter override. | |
| 37 virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( | |
| 38 const IPC::Message& message) OVERRIDE; | |
| 39 | |
| 40 // ppapi::host::ResourceMessageHandler override. | |
| 41 virtual int32_t OnResourceMessageReceived( | |
| 42 const IPC::Message& msg, | |
| 43 ppapi::host::HostMessageContext* context) OVERRIDE; | |
| 44 | |
| 45 private: | |
| 46 virtual ~BrokerMessageFilter(); | |
| 47 | |
| 48 int32_t OnIsAllowed(ppapi::host::HostMessageContext* context); | |
| 49 | |
| 50 int render_process_id_; | |
| 51 GURL document_url_; | |
| 52 }; | |
| 53 | |
| 54 BrokerMessageFilter::BrokerMessageFilter( | |
| 55 int render_process_id, | |
| 56 GURL document_url) | |
| 57 : render_process_id_(render_process_id), | |
| 58 document_url_(document_url) { | |
| 59 } | |
| 60 | |
| 61 BrokerMessageFilter::~BrokerMessageFilter() { | |
| 62 } | |
| 63 | |
| 64 scoped_refptr<base::TaskRunner> | |
| 65 BrokerMessageFilter::OverrideTaskRunnerForMessage( | |
| 66 const IPC::Message& message) { | |
| 67 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | |
| 68 } | |
| 69 | |
| 70 int32_t BrokerMessageFilter::OnResourceMessageReceived( | |
| 71 const IPC::Message& msg, | |
| 72 ppapi::host::HostMessageContext* context) { | |
| 73 IPC_BEGIN_MESSAGE_MAP(BrokerMessageFilter, msg) | |
| 74 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Broker_IsAllowed, | |
| 75 OnIsAllowed) | |
| 76 IPC_END_MESSAGE_MAP() | |
| 77 return PP_ERROR_FAILED; | |
| 78 } | |
| 79 | |
| 80 int32_t BrokerMessageFilter::OnIsAllowed( | |
| 81 ppapi::host::HostMessageContext* context) { | |
| 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 83 if (!document_url_.is_valid()) | |
| 84 return PP_ERROR_FAILED; | |
| 85 RenderProcessHost* render_process_host = | |
| 86 RenderProcessHost::FromID(render_process_id_); | |
| 87 if (!render_process_host) | |
| 88 return PP_ERROR_FAILED; | |
| 89 Profile* profile = | |
| 90 Profile::FromBrowserContext(render_process_host->GetBrowserContext()); | |
| 91 HostContentSettingsMap* content_settings = | |
| 92 profile->GetHostContentSettingsMap(); | |
| 93 ContentSetting setting = | |
| 94 content_settings->GetContentSetting(document_url_, document_url_, | |
| 95 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | |
| 96 std::string()); | |
| 97 if (setting == CONTENT_SETTING_ALLOW) | |
| 98 return PP_OK; | |
| 99 return PP_ERROR_FAILED; | |
| 100 } | |
| 101 | |
| 102 } // namespace | |
| 103 | |
| 104 PepperBrokerHost::PepperBrokerHost(BrowserPpapiHost* host, | |
| 105 PP_Instance instance, | |
| 106 PP_Resource resource) | |
| 107 : ResourceHost(host->GetPpapiHost(), instance, resource) { | |
| 108 int render_process_id, unused; | |
| 109 host->GetRenderViewIDsForInstance(instance, &render_process_id, &unused); | |
| 110 const GURL& document_url = host->GetDocumentURLForInstance(instance); | |
| 111 AddFilter(make_scoped_refptr(new BrokerMessageFilter(render_process_id, | |
| 112 document_url))); | |
| 113 } | |
| 114 | |
| 115 PepperBrokerHost::~PepperBrokerHost() { | |
| 116 } | |
| 117 | |
| 118 } // namespace chrome | |
| OLD | NEW |