Chromium Code Reviews| 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 ~BrokerMessageFilter(); | |
|
yzshen1
2012/12/06 19:59:46
add 'virtual' please.
(I understand it doesn't hav
raymes
2012/12/07 21:32:19
Done.
| |
| 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) { | |
|
yzshen1
2012/12/06 19:59:46
wrong indent.
raymes
2012/12/07 21:32:19
Done.
| |
| 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 if (!document_url_.is_valid()) | |
|
brettw
2012/12/05 23:00:26
Can you add a DCHECK on the thread you should be o
raymes
2012/12/07 21:32:19
Done.
| |
| 83 return PP_ERROR_FAILED; | |
| 84 RenderProcessHost* render_process_host = | |
| 85 RenderProcessHost::FromID(render_process_id_); | |
| 86 if (!render_process_host) | |
| 87 return PP_ERROR_FAILED; | |
| 88 Profile* profile = | |
| 89 Profile::FromBrowserContext(render_process_host->GetBrowserContext()); | |
| 90 HostContentSettingsMap* content_settings = | |
| 91 profile->GetHostContentSettingsMap(); | |
| 92 ContentSetting setting = | |
| 93 content_settings->GetContentSetting(document_url_, document_url_, | |
| 94 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | |
| 95 std::string()); | |
| 96 if (setting == CONTENT_SETTING_ALLOW) | |
| 97 return PP_OK; | |
| 98 return PP_ERROR_FAILED; | |
| 99 } | |
| 100 | |
| 101 } // namespace | |
| 102 | |
| 103 PepperBrokerHost::PepperBrokerHost(BrowserPpapiHost* host, | |
| 104 PP_Instance instance, | |
| 105 PP_Resource resource) | |
| 106 : ResourceHost(host->GetPpapiHost(), instance, resource) { | |
| 107 int render_process_id, unused; | |
| 108 host->GetRenderViewIDsForInstance(instance, &render_process_id, &unused); | |
| 109 const GURL& document_url = host->GetDocumentURLForInstance(instance); | |
| 110 AddFilter(make_scoped_refptr(new BrokerMessageFilter(render_process_id, | |
| 111 document_url))); | |
| 112 } | |
| 113 | |
| 114 PepperBrokerHost::~PepperBrokerHost() { | |
| 115 } | |
| 116 | |
| 117 } // namespace chrome | |
| OLD | NEW |