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

Side by Side Diff: content/browser/appcache/chrome_appcache_service.cc

Issue 6951008: Have AppCache code go through the content embedder API for content settings checks. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/appcache/chrome_appcache_service.h" 5 #include "content/browser/appcache/chrome_appcache_service.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "content/browser/content_browser_client.h"
9 #include "content/common/notification_service.h" 10 #include "content/common/notification_service.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 #include "webkit/appcache/appcache_thread.h" 12 #include "webkit/appcache/appcache_thread.h"
12 13
13 static bool has_initialized_thread_ids; 14 static bool has_initialized_thread_ids;
14 15
15 namespace { 16 namespace {
16 17
17 // Used to defer deleting of local storage until the destructor has finished. 18 // Used to defer deleting of local storage until the destructor has finished.
18 void DeleteLocalStateOnIOThread(FilePath cache_path) { 19 void DeleteLocalStateOnIOThread(FilePath cache_path) {
19 // Post the actual deletion to the DB thread to ensure it happens after the 20 // Post the actual deletion to the DB thread to ensure it happens after the
20 // database file has been closed. 21 // database file has been closed.
21 BrowserThread::PostTask( 22 BrowserThread::PostTask(
22 BrowserThread::DB, FROM_HERE, 23 BrowserThread::DB, FROM_HERE,
23 NewRunnableFunction<bool(*)(const FilePath&, bool), FilePath, bool>( 24 NewRunnableFunction<bool(*)(const FilePath&, bool), FilePath, bool>(
24 &file_util::Delete, cache_path, true)); 25 &file_util::Delete, cache_path, true));
25 } 26 }
26 27
27 } // namespace 28 } // namespace
28 29
29 // ---------------------------------------------------------------------------- 30 // ----------------------------------------------------------------------------
30 31
31 ChromeAppCacheService::ChromeAppCacheService() 32 ChromeAppCacheService::ChromeAppCacheService()
32 : clear_local_state_on_exit_(false) { 33 : resource_context_(NULL), clear_local_state_on_exit_(false) {
33 } 34 }
34 35
35 void ChromeAppCacheService::InitializeOnIOThread( 36 void ChromeAppCacheService::InitializeOnIOThread(
36 const FilePath& cache_path, 37 const FilePath& cache_path,
37 scoped_refptr<HostContentSettingsMap> content_settings_map, 38 const content::ResourceContext* resource_context,
38 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, 39 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy,
39 bool clear_local_state_on_exit) { 40 bool clear_local_state_on_exit) {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
41 42
42 if (!has_initialized_thread_ids) { 43 if (!has_initialized_thread_ids) {
43 has_initialized_thread_ids = true; 44 has_initialized_thread_ids = true;
44 appcache::AppCacheThread::Init(BrowserThread::DB, BrowserThread::IO); 45 appcache::AppCacheThread::Init(BrowserThread::DB, BrowserThread::IO);
45 } 46 }
46 47
47 cache_path_ = cache_path; 48 cache_path_ = cache_path;
48 host_contents_settings_map_ = content_settings_map; 49 resource_context_ = resource_context;
49 registrar_.Add( 50 registrar_.Add(
50 this, NotificationType::PURGE_MEMORY, NotificationService::AllSources()); 51 this, NotificationType::PURGE_MEMORY, NotificationService::AllSources());
51 SetClearLocalStateOnExit(clear_local_state_on_exit); 52 SetClearLocalStateOnExit(clear_local_state_on_exit);
52 53
53 // Init our base class. 54 // Init our base class.
54 Initialize(cache_path_, 55 Initialize(cache_path_,
55 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); 56 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
56 set_appcache_policy(this); 57 set_appcache_policy(this);
57 set_special_storage_policy(special_storage_policy); 58 set_special_storage_policy(special_storage_policy);
58 } 59 }
(...skipping 16 matching lines...) Expand all
75 NewRunnableMethod(this, 76 NewRunnableMethod(this,
76 &ChromeAppCacheService::SetClearLocalStateOnExit, 77 &ChromeAppCacheService::SetClearLocalStateOnExit,
77 clear_local_state)); 78 clear_local_state));
78 return; 79 return;
79 } 80 }
80 clear_local_state_on_exit_ = clear_local_state; 81 clear_local_state_on_exit_ = clear_local_state;
81 } 82 }
82 83
83 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { 84 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) {
84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
85 ContentSetting setting = host_contents_settings_map_->GetContentSetting(
86 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, "");
87 DCHECK(setting != CONTENT_SETTING_DEFAULT);
88 // We don't prompt for read access. 86 // We don't prompt for read access.
89 return setting != CONTENT_SETTING_BLOCK; 87 return content::GetContentClient()->browser()->AllowAppCache(
88 manifest_url, resource_context_);
90 } 89 }
91 90
92 int ChromeAppCacheService::CanCreateAppCache( 91 int ChromeAppCacheService::CanCreateAppCache(
93 const GURL& manifest_url, net::CompletionCallback* callback) { 92 const GURL& manifest_url, net::CompletionCallback* callback) {
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
95 ContentSetting setting = host_contents_settings_map_->GetContentSetting( 94 return content::GetContentClient()->browser()->AllowAppCache(
96 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); 95 manifest_url, resource_context_) ? net::OK : net::ERR_ACCESS_DENIED;
97 DCHECK(setting != CONTENT_SETTING_DEFAULT);
98 return (setting != CONTENT_SETTING_BLOCK) ? net::OK :
99 net::ERR_ACCESS_DENIED;
100 } 96 }
101 97
102 void ChromeAppCacheService::Observe(NotificationType type, 98 void ChromeAppCacheService::Observe(NotificationType type,
103 const NotificationSource& source, 99 const NotificationSource& source,
104 const NotificationDetails& details) { 100 const NotificationDetails& details) {
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
106 DCHECK(type == NotificationType::PURGE_MEMORY); 102 DCHECK(type == NotificationType::PURGE_MEMORY);
107 PurgeMemory(); 103 PurgeMemory();
108 } 104 }
109 105
(...skipping 14 matching lines...) Expand all
124 const tracked_objects::Location& from_here, 120 const tracked_objects::Location& from_here,
125 Task* task) { 121 Task* task) {
126 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task); 122 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task);
127 } 123 }
128 124
129 bool AppCacheThread::CurrentlyOn(int id) { 125 bool AppCacheThread::CurrentlyOn(int id) {
130 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id)); 126 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id));
131 } 127 }
132 128
133 } // namespace appcache 129 } // namespace appcache
OLDNEW
« no previous file with comments | « content/browser/appcache/chrome_appcache_service.h ('k') | content/browser/appcache/chrome_appcache_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698