| Index: chrome/browser/renderer_host/pepper/flash_lso_settings_helper.cc
|
| diff --git a/chrome/browser/renderer_host/pepper/flash_lso_settings_helper.cc b/chrome/browser/renderer_host/pepper/flash_lso_settings_helper.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fafb58e31c331d08ce01cd13afb1a73e647e55f4
|
| --- /dev/null
|
| +++ b/chrome/browser/renderer_host/pepper/flash_lso_settings_helper.cc
|
| @@ -0,0 +1,139 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/renderer_host/pepper/flash_lso_settings_helper.h"
|
| +
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/common/chrome_notification_types.h"
|
| +#include "content/public/browser/browser_context.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/content_browser_client.h"
|
| +#include "content/public/browser/notification_source.h"
|
| +#include "content/public/browser/render_process_host.h"
|
| +#include "content/public/browser/resource_context.h"
|
| +#include "googleurl/src/gurl.h"
|
| +
|
| +using content::BrowserThread;
|
| +using content::RenderProcessHost;
|
| +using content::ResourceContext;
|
| +
|
| +namespace chrome {
|
| +
|
| +namespace {
|
| +
|
| +const PP_FlashLSORestrictions kDefaultLSORestrictions =
|
| + PP_FLASHLSORESTRICTIONS_NONE;
|
| +
|
| +} // namespace
|
| +
|
| +FlashLSOSettingsHelper::FlashLSOSettingsHelper(int render_process_id)
|
| + : render_process_id_(render_process_id),
|
| + initialized_(false),
|
| + resource_context_(NULL) {
|
| +}
|
| +
|
| +FlashLSOSettingsHelper::~FlashLSOSettingsHelper() {
|
| +}
|
| +
|
| +void FlashLSOSettingsHelper::GetLocalDataRestrictions(
|
| + const GURL& document_url,
|
| + const GURL& plugin_url,
|
| + base::Callback<void(PP_FlashLSORestrictions)> callback) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + // Getting the local data restrictions 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.
|
| + if (initialized_) {
|
| + GetLocalDataRestrictionsHelper(document_url, plugin_url, callback,
|
| + resource_context_);
|
| + } else {
|
| + BrowserThread::PostTaskAndReplyWithResult(BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&FlashLSOSettingsHelper::GetResourceContext, this,
|
| + render_process_id_),
|
| + base::Bind(&FlashLSOSettingsHelper::GetLocalDataRestrictionsHelper,
|
| + this, document_url, plugin_url, callback));
|
| + }
|
| +}
|
| +
|
| +void FlashLSOSettingsHelper::GetLocalDataRestrictionsHelper(
|
| + const GURL& document_url,
|
| + const GURL& plugin_url,
|
| + base::Callback<void(PP_FlashLSORestrictions)> callback,
|
| + ResourceContext* resource_context) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| +
|
| + if (!initialized_) {
|
| + initialized_ = true;
|
| + resource_context_ = resource_context;
|
| + }
|
| +
|
| + if (!resource_context_ ||
|
| + !document_url.is_valid() || !plugin_url.is_valid()) {
|
| + callback.Run(kDefaultLSORestrictions);
|
| + return;
|
| + }
|
| +
|
| + content::ContentBrowserClient* client =
|
| + content::GetContentClient()->browser();
|
| + if (!client->AllowPluginLocalDataAccess(document_url, plugin_url,
|
| + resource_context_)) {
|
| + callback.Run(PP_FLASHLSORESTRICTIONS_BLOCK);
|
| + } else if (client->AllowPluginLocalDataSessionOnly(plugin_url,
|
| + resource_context_)) {
|
| + callback.Run(PP_FLASHLSORESTRICTIONS_IN_MEMORY);
|
| + } else {
|
| + callback.Run(PP_FLASHLSORESTRICTIONS_NONE);
|
| + }
|
| +}
|
| +
|
| +ResourceContext* FlashLSOSettingsHelper::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 NULL;
|
| +
|
| + Profile* profile = Profile::FromBrowserContext(
|
| + render_process_host->GetBrowserContext());
|
| + ResourceContext* resource_context = profile->GetResourceContext();
|
| +
|
| + // Register for a notification when the profile is destroyed so that we
|
| + // don't access the resource context after that.
|
| + if (registrar_.get()) {
|
| + // If |registrar_| is already set, we've already registered for a
|
| + // notification.
|
| + return resource_context;
|
| + }
|
| + registrar_.reset(new content::NotificationRegistrar);
|
| + registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
|
| + content::Source<Profile>(profile));
|
| + // Hold a ref to ourselves until the profile is destroyed so that we always
|
| + // receive the destruction notification.
|
| + AddRef();
|
| + return resource_context;
|
| +}
|
| +
|
| +void FlashLSOSettingsHelper::Observe(int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + DCHECK(type == chrome::NOTIFICATION_PROFILE_DESTROYED);
|
| + // The profile associated with this class has been destroyed. We can now
|
| + // unregister for notifications (by deleting |registrar_|) and post a task
|
| + // to clear the resource context so that it is no longer used.
|
| + registrar_.reset();
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&FlashLSOSettingsHelper::ClearResourceContext, this));
|
| + Release(); // Balances the AddRef in GetResourceContext.
|
| +}
|
| +
|
| +void FlashLSOSettingsHelper::ClearResourceContext() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + resource_context_ = NULL;
|
| +}
|
| +
|
| +} // namespace chrome
|
|
|