Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1324)

Unified Diff: content/browser/renderer_host/pepper/pepper_flash_browser_host.cc

Issue 11413200: Refactored PPB_Flash GetSettings to the new pepper resource model (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/pepper/pepper_flash_browser_host.cc
diff --git a/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc b/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc
index c27dfb03d6074e34e24319993ee560147d82332e..07f14a69a043458f96e7de91009830ba9b43f789 100644
--- a/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc
+++ b/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc
@@ -5,9 +5,16 @@
#include "content/browser/renderer_host/pepper/pepper_flash_browser_host.h"
#include "base/time.h"
+#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_ppapi_host.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/resource_context.h"
+#include "googleurl/src/gurl.h"
#include "ipc/ipc_message_macros.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/private/ppb_flash.h"
#include "ppapi/host/dispatch_host_message.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/resource_message_params.h"
@@ -21,11 +28,30 @@
namespace content {
+namespace {
+
+// Get the ResourceContext on the UI thread for the given render process ID.
+ResourceContext* GetResourceContext(int render_process_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ RenderProcessHost* render_process_host = RenderProcessHost::FromID(
+ render_process_id);
+ if (render_process_host && render_process_host->GetBrowserContext())
+ return render_process_host->GetBrowserContext()->GetResourceContext();
+ return NULL;
+}
+
+} // namespace
+
PepperFlashBrowserHost::PepperFlashBrowserHost(
BrowserPpapiHost* host,
PP_Instance instance,
PP_Resource resource)
- : ResourceHost(host->GetPpapiHost(), instance, resource) {
+ : ResourceHost(host->GetPpapiHost(), instance, resource),
+ host_(host),
+ resource_context_(NULL),
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ int unused;
+ host->GetRenderViewIDsForInstance(instance, &render_process_id_, &unused);
}
PepperFlashBrowserHost::~PepperFlashBrowserHost() {
@@ -39,6 +65,9 @@ int32_t PepperFlashBrowserHost::OnResourceMessageReceived(
OnMsgUpdateActivity);
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetLocalTimeZoneOffset,
OnMsgGetLocalTimeZoneOffset);
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
+ PpapiHostMsg_Flash_GetLocalDataRestrictions,
+ OnMsgGetLocalDataRestrictions);
IPC_END_MESSAGE_MAP()
return PP_ERROR_FAILED;
}
@@ -72,4 +101,53 @@ int32_t PepperFlashBrowserHost::OnMsgGetLocalTimeZoneOffset(
return PP_OK;
}
+int32_t PepperFlashBrowserHost::OnMsgGetLocalDataRestrictions(
+ ppapi::host::HostMessageContext* context) {
+ // Getting the LocalDataRestrictions needs to be done on the IO thread,
+ // however it relies on the ResourceContext which can only be accessed from
+ // the UI thread. We lazily initialize |resource_context_| by grabbing the
+ // pointer from the UI thread and then call |GetLocalDataRestrictions| with
+ // it.
+ GURL document_url = host_->GetDocumentURLForInstance(pp_instance());
+ GURL plugin_url = host_->GetPluginURLForInstance(pp_instance());
+ if (resource_context_) {
+ GetLocalDataRestrictions(context->MakeReplyMessageContext(), document_url,
+ plugin_url, resource_context_);
+ } else {
+ BrowserThread::PostTaskAndReplyWithResult(BrowserThread::UI, FROM_HERE,
+ base::Bind(&GetResourceContext, render_process_id_),
+ base::Bind(&PepperFlashBrowserHost::GetLocalDataRestrictions,
+ weak_factory_.GetWeakPtr(),
+ context->MakeReplyMessageContext(),
+ document_url, plugin_url));
+ }
+ return PP_OK_COMPLETIONPENDING;
+}
+
+void PepperFlashBrowserHost::GetLocalDataRestrictions(
+ ppapi::host::ReplyMessageContext reply_context,
+ const GURL& document_url,
+ const GURL& plugin_url,
+ ResourceContext* resource_context) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ // Note that the resource context lives on the IO thread and is owned by the
+ // browser profile so its lifetime should outlast ours.
+ if (!resource_context_)
+ resource_context_ = resource_context;
+
+ PP_FlashLSORestrictions restrictions = PP_FLASHLSORESTRICTIONS_NONE;
+ if (resource_context_ && document_url.is_valid() && plugin_url.is_valid()) {
+ ContentBrowserClient* client = GetContentClient()->browser();
+ if (!client->AllowPluginLocalDataAccess(document_url, plugin_url,
+ resource_context_)) {
+ restrictions = PP_FLASHLSORESTRICTIONS_BLOCK;
+ } else if (client->AllowPluginLocalDataSessionOnly(plugin_url,
+ resource_context_)) {
+ restrictions = PP_FLASHLSORESTRICTIONS_IN_MEMORY;
+ }
+ }
+ SendReply(reply_context, PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply(
+ static_cast<int32_t>(restrictions)));
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698