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

Side by Side Diff: chrome/browser/renderer_host/pepper/flash_lso_settings_helper.cc

Issue 11705003: Change PepperFlashBrowserHost to use CookieSettings to get the LSO settings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 12 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/flash_lso_settings_helper.h"
6
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/common/chrome_notification_types.h"
9 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/content_browser_client.h"
12 #include "content/public/browser/notification_source.h"
13 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/resource_context.h"
15 #include "googleurl/src/gurl.h"
16
17 using content::BrowserThread;
18 using content::RenderProcessHost;
19 using content::ResourceContext;
20
21 namespace chrome {
22
23 namespace {
24
25 const PP_FlashLSORestrictions kDefaultLSORestrictions =
26 PP_FLASHLSORESTRICTIONS_NONE;
27
28 } // namespace
29
30 FlashLSOSettingsHelper::FlashLSOSettingsHelper(int render_process_id)
31 : render_process_id_(render_process_id),
32 initialized_(false),
33 resource_context_(NULL),
34 is_shutdown_(false) {
35 }
36
37 FlashLSOSettingsHelper::~FlashLSOSettingsHelper() {
38 DCHECK(is_shutdown_);
39 }
40
41 void FlashLSOSettingsHelper::GetLocalDataRestrictions(
42 const GURL& document_url,
43 const GURL& plugin_url,
44 const base::Callback<void(PP_FlashLSORestrictions)>& callback) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
46 // Getting the local data restrictions needs to be done on the IO thread,
47 // however it relies on the ResourceContext which can only be accessed from
48 // the UI thread. We lazily initialize |resource_context_| by grabbing the
49 // pointer from the UI thread and then call |GetLocalDataRestrictionsHelper|
50 // with it.
51 if (initialized_) {
52 GetLocalDataRestrictionsHelper(document_url, plugin_url, callback,
53 resource_context_);
54 } else {
55 BrowserThread::PostTaskAndReplyWithResult(BrowserThread::UI, FROM_HERE,
56 base::Bind(&FlashLSOSettingsHelper::GetResourceContext, this,
57 render_process_id_),
58 base::Bind(&FlashLSOSettingsHelper::GetLocalDataRestrictionsHelper,
59 this, document_url, plugin_url, callback));
60 }
61 }
62
63 void FlashLSOSettingsHelper::ShutdownOnUIThread() {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
65 // We unregister for notifications (by deleting |registrar_|) and post a task
66 // to clear the resource context so that it is no longer used.
67 registrar_.reset();
68 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
69 base::Bind(&FlashLSOSettingsHelper::ClearResourceContext, this));
70 is_shutdown_ = true;
71 }
72
73 void FlashLSOSettingsHelper::GetLocalDataRestrictionsHelper(
74 const GURL& document_url,
75 const GURL& plugin_url,
76 const base::Callback<void(PP_FlashLSORestrictions)>& callback,
77 ResourceContext* resource_context) {
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
79
80 if (!initialized_) {
81 initialized_ = true;
82 resource_context_ = resource_context;
83 }
84
85 if (!resource_context_ ||
86 !document_url.is_valid() || !plugin_url.is_valid()) {
87 callback.Run(kDefaultLSORestrictions);
88 return;
89 }
90
91 content::ContentBrowserClient* client =
92 content::GetContentClient()->browser();
93 if (!client->AllowPluginLocalDataAccess(document_url, plugin_url,
94 resource_context_)) {
95 callback.Run(PP_FLASHLSORESTRICTIONS_BLOCK);
96 } else if (client->AllowPluginLocalDataSessionOnly(plugin_url,
97 resource_context_)) {
98 callback.Run(PP_FLASHLSORESTRICTIONS_IN_MEMORY);
99 } else {
100 callback.Run(PP_FLASHLSORESTRICTIONS_NONE);
101 }
102 }
103
104 ResourceContext* FlashLSOSettingsHelper::GetResourceContext(
105 int render_process_id) {
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
107 RenderProcessHost* render_process_host = RenderProcessHost::FromID(
108 render_process_id);
109 if (!render_process_host || !render_process_host->GetBrowserContext())
110 return NULL;
111
112 Profile* profile = Profile::FromBrowserContext(
113 render_process_host->GetBrowserContext());
114 ResourceContext* resource_context = profile->GetResourceContext();
115
116 // Register for a notification when the profile is destroyed so that we
117 // don't access the resource context after that.
118 if (registrar_.get()) {
119 // If |registrar_| is already set, we've already registered for a
120 // notification.
121 return resource_context;
122 }
123 registrar_.reset(new content::NotificationRegistrar);
124 registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
125 content::Source<Profile>(profile));
126 return resource_context;
127 }
128
129 void FlashLSOSettingsHelper::Observe(
130 int type,
131 const content::NotificationSource& source,
132 const content::NotificationDetails& details) {
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
134 DCHECK(type == chrome::NOTIFICATION_PROFILE_DESTROYED);
135 // The profile associated with this class has been destroyed.
136 ShutdownOnUIThread();
137 }
138
139 void FlashLSOSettingsHelper::ClearResourceContext() {
140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
141 resource_context_ = NULL;
142 }
143
144 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698