Extract code handling PrinterProviderAPI from PrintPreviewHandler
[chromium-blink-merge.git] / chrome / browser / android / preferences / website_preference_bridge.cc
blobd21bf9ddf2ee2c587b376588a6be7dde8ab82462
1 // Copyright 2015 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.
5 #include "chrome/browser/android/preferences/website_preference_bridge.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/files/file_path.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
15 #include "chrome/browser/browsing_data/cookies_tree_model.h"
16 #include "chrome/browser/browsing_data/local_data_container.h"
17 #include "chrome/browser/content_settings/cookie_settings.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_manager.h"
20 #include "components/content_settings/core/browser/host_content_settings_map.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/storage_partition.h"
23 #include "jni/WebsitePreferenceBridge_jni.h"
24 #include "storage/browser/quota/quota_client.h"
25 #include "storage/browser/quota/quota_manager.h"
27 using base::android::ConvertJavaStringToUTF8;
28 using base::android::ConvertUTF8ToJavaString;
29 using base::android::JavaRef;
30 using base::android::ScopedJavaGlobalRef;
31 using base::android::ScopedJavaLocalRef;
32 using content::BrowserThread;
34 static HostContentSettingsMap* GetHostContentSettingsMap() {
35 Profile* profile = ProfileManager::GetActiveUserProfile();
36 return profile->GetHostContentSettingsMap();
39 static void GetOrigins(JNIEnv* env,
40 ContentSettingsType content_type,
41 jobject list,
42 jboolean managedOnly) {
43 ContentSettingsForOneType all_settings;
44 HostContentSettingsMap* content_settings_map = GetHostContentSettingsMap();
45 content_settings_map->GetSettingsForOneType(
46 content_type, std::string(), &all_settings);
47 ContentSetting default_content_setting = content_settings_map->
48 GetDefaultContentSetting(content_type, NULL);
49 // Now add all origins that have a non-default setting to the list.
50 for (const auto& settings_it : all_settings) {
51 if (settings_it.setting == default_content_setting)
52 continue;
53 if (managedOnly &&
54 HostContentSettingsMap::GetProviderTypeFromSource(settings_it.source) !=
55 HostContentSettingsMap::ProviderType::POLICY_PROVIDER) {
56 continue;
58 const std::string origin = settings_it.primary_pattern.ToString();
59 const std::string embedder = settings_it.secondary_pattern.ToString();
60 ScopedJavaLocalRef<jstring> jorigin = ConvertUTF8ToJavaString(env, origin);
61 ScopedJavaLocalRef<jstring> jembedder;
62 if (embedder != origin)
63 jembedder = ConvertUTF8ToJavaString(env, embedder);
64 switch (content_type) {
65 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
66 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
67 Java_WebsitePreferenceBridge_insertVoiceAndVideoCaptureInfoIntoList(
68 env, list, jorigin.obj(), jembedder.obj());
69 break;
70 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
71 Java_WebsitePreferenceBridge_insertGeolocationInfoIntoList(
72 env, list, jorigin.obj(), jembedder.obj());
73 break;
74 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
75 Java_WebsitePreferenceBridge_insertMidiInfoIntoList(
76 env, list, jorigin.obj(), jembedder.obj());
77 break;
78 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
79 Java_WebsitePreferenceBridge_insertProtectedMediaIdentifierInfoIntoList(
80 env, list, jorigin.obj(), jembedder.obj());
81 break;
82 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
83 Java_WebsitePreferenceBridge_insertPushNotificationIntoList(
84 env, list, jorigin.obj(), jembedder.obj());
85 break;
86 default:
87 DCHECK(false);
88 break;
93 static jint GetSettingForOrigin(JNIEnv* env,
94 ContentSettingsType content_type,
95 jstring origin,
96 jstring embedder) {
97 GURL url(ConvertJavaStringToUTF8(env, origin));
98 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder));
99 ContentSetting setting = GetHostContentSettingsMap()->GetContentSetting(
100 url,
101 embedder_url,
102 content_type,
103 std::string());
104 return setting;
107 static void SetSettingForOrigin(JNIEnv* env,
108 ContentSettingsType content_type,
109 jstring origin,
110 ContentSettingsPattern secondary_pattern,
111 jint value) {
112 GURL url(ConvertJavaStringToUTF8(env, origin));
113 ContentSetting setting = CONTENT_SETTING_DEFAULT;
114 switch (value) {
115 case -1: break;
116 case 1: setting = CONTENT_SETTING_ALLOW; break;
117 case 2: setting = CONTENT_SETTING_BLOCK; break;
118 default:
119 NOTREACHED();
121 GetHostContentSettingsMap()->SetContentSetting(
122 ContentSettingsPattern::FromURLNoWildcard(url),
123 secondary_pattern,
124 content_type,
125 std::string(),
126 setting);
129 static void GetGeolocationOrigins(JNIEnv* env,
130 jclass clazz,
131 jobject list,
132 jboolean managedOnly) {
133 GetOrigins(env, CONTENT_SETTINGS_TYPE_GEOLOCATION, list, managedOnly);
136 static jint GetGeolocationSettingForOrigin(JNIEnv* env, jclass clazz,
137 jstring origin, jstring embedder) {
138 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_GEOLOCATION,
139 origin, embedder);
142 static void SetGeolocationSettingForOrigin(JNIEnv* env, jclass clazz,
143 jstring origin, jstring embedder, jint value) {
144 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder));
145 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_GEOLOCATION,
146 origin, ContentSettingsPattern::FromURLNoWildcard(embedder_url), value);
149 static void GetMidiOrigins(JNIEnv* env, jclass clazz, jobject list) {
150 GetOrigins(env, CONTENT_SETTINGS_TYPE_MIDI_SYSEX, list, false);
153 static jint GetMidiSettingForOrigin(JNIEnv* env, jclass clazz, jstring origin,
154 jstring embedder) {
155 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MIDI_SYSEX, origin,
156 embedder);
159 static void SetMidiSettingForOrigin(JNIEnv* env, jclass clazz, jstring origin,
160 jstring embedder, jint value) {
161 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder));
162 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MIDI_SYSEX, origin,
163 ContentSettingsPattern::FromURLNoWildcard(embedder_url), value);
166 static void GetProtectedMediaIdentifierOrigins(JNIEnv* env, jclass clazz,
167 jobject list) {
168 GetOrigins(env, CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, list,
169 false);
172 static jint GetProtectedMediaIdentifierSettingForOrigin(JNIEnv* env,
173 jclass clazz, jstring origin, jstring embedder) {
174 return GetSettingForOrigin(
175 env, CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, origin, embedder);
178 static void SetProtectedMediaIdentifierSettingForOrigin(JNIEnv* env,
179 jclass clazz, jstring origin, jstring embedder, jint value) {
180 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder));
181 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER,
182 origin, ContentSettingsPattern::FromURLNoWildcard(embedder_url), value);
185 static void GetPushNotificationOrigins(JNIEnv* env,
186 jclass clazz,
187 jobject list) {
188 GetOrigins(env, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, list, false);
191 static jint GetPushNotificationSettingForOrigin(JNIEnv* env, jclass clazz,
192 jstring origin, jstring embedder) {
193 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
194 origin, embedder);
197 static void SetPushNotificationSettingForOrigin(JNIEnv* env, jclass clazz,
198 jstring origin, jstring embedder, jint value) {
199 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder));
200 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
201 origin, ContentSettingsPattern::FromURLNoWildcard(embedder_url), value);
204 static void GetVoiceAndVideoCaptureOrigins(JNIEnv* env,
205 jclass clazz,
206 jobject list,
207 jboolean managedOnly) {
208 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, list, managedOnly);
209 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, list, managedOnly);
212 static jint GetVoiceCaptureSettingForOrigin(JNIEnv* env, jclass clazz,
213 jstring origin, jstring embedder) {
214 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
215 origin, embedder);
218 static jint GetVideoCaptureSettingForOrigin(JNIEnv* env, jclass clazz,
219 jstring origin, jstring embedder) {
220 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
221 origin, embedder);
224 static void SetVoiceCaptureSettingForOrigin(JNIEnv* env, jclass clazz,
225 jstring origin, jstring embedder, jint value) {
226 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
227 origin, ContentSettingsPattern::Wildcard(), value);
230 static void SetVideoCaptureSettingForOrigin(JNIEnv* env, jclass clazz,
231 jstring origin, jstring embedder, jint value) {
232 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
233 origin, ContentSettingsPattern::Wildcard(), value);
236 static scoped_refptr<CookieSettings> GetCookieSettings() {
237 Profile* profile = ProfileManager::GetActiveUserProfile();
238 return CookieSettings::Factory::GetForProfile(profile);
241 static void GetCookieOrigins(JNIEnv* env,
242 jclass clazz,
243 jobject list,
244 jboolean managedOnly) {
245 ContentSettingsForOneType all_settings;
246 GetCookieSettings()->GetCookieSettings(&all_settings);
247 const ContentSetting default_setting =
248 GetCookieSettings()->GetDefaultCookieSetting(nullptr);
249 for (const auto& settings_it : all_settings) {
250 if (settings_it.setting == default_setting)
251 continue;
252 if (managedOnly &&
253 HostContentSettingsMap::GetProviderTypeFromSource(settings_it.source) !=
254 HostContentSettingsMap::ProviderType::POLICY_PROVIDER) {
255 continue;
257 const std::string& origin = settings_it.primary_pattern.ToString();
258 const std::string& embedder = settings_it.secondary_pattern.ToString();
259 ScopedJavaLocalRef<jstring> jorigin = ConvertUTF8ToJavaString(env, origin);
260 ScopedJavaLocalRef<jstring> jembedder;
261 if (embedder != origin)
262 jembedder = ConvertUTF8ToJavaString(env, embedder);
263 Java_WebsitePreferenceBridge_insertCookieInfoIntoList(env, list,
264 jorigin.obj(), jembedder.obj());
268 static jint GetCookieSettingForOrigin(JNIEnv* env, jclass clazz,
269 jstring origin, jstring embedder) {
270 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_COOKIES, origin,
271 embedder);
274 static void SetCookieSettingForOrigin(JNIEnv* env, jclass clazz,
275 jstring origin, jstring embedder, jint value) {
276 GURL url(ConvertJavaStringToUTF8(env, origin));
277 ContentSettingsPattern primary_pattern(
278 ContentSettingsPattern::FromURLNoWildcard(url));
279 ContentSettingsPattern secondary_pattern(ContentSettingsPattern::Wildcard());
280 if (value == -1) {
281 GetCookieSettings()->ResetCookieSetting(primary_pattern, secondary_pattern);
282 } else {
283 GetCookieSettings()->SetCookieSetting(primary_pattern, secondary_pattern,
284 value ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
288 namespace {
290 class SiteDataDeleteHelper :
291 public base::RefCountedThreadSafe<SiteDataDeleteHelper>,
292 public CookiesTreeModel::Observer {
293 public:
294 SiteDataDeleteHelper(Profile* profile, const GURL& domain)
295 : profile_(profile), domain_(domain), ending_batch_processing_(false) {
298 void Run() {
299 AddRef(); // Balanced in TreeModelEndBatch.
301 content::StoragePartition* storage_partition =
302 content::BrowserContext::GetDefaultStoragePartition(profile_);
303 content::IndexedDBContext* indexed_db_context =
304 storage_partition->GetIndexedDBContext();
305 content::ServiceWorkerContext* service_worker_context =
306 storage_partition->GetServiceWorkerContext();
307 storage::FileSystemContext* file_system_context =
308 storage_partition->GetFileSystemContext();
309 LocalDataContainer* container = new LocalDataContainer(
310 new BrowsingDataCookieHelper(profile_->GetRequestContext()),
311 new BrowsingDataDatabaseHelper(profile_),
312 new BrowsingDataLocalStorageHelper(profile_),
313 NULL,
314 new BrowsingDataAppCacheHelper(profile_),
315 new BrowsingDataIndexedDBHelper(indexed_db_context),
316 BrowsingDataFileSystemHelper::Create(file_system_context),
317 BrowsingDataQuotaHelper::Create(profile_),
318 BrowsingDataChannelIDHelper::Create(profile_->GetRequestContext()),
319 new BrowsingDataServiceWorkerHelper(service_worker_context),
320 NULL);
322 cookies_tree_model_.reset(new CookiesTreeModel(
323 container, profile_->GetExtensionSpecialStoragePolicy(), false));
324 cookies_tree_model_->AddCookiesTreeObserver(this);
327 // TreeModelObserver:
328 void TreeNodesAdded(ui::TreeModel* model,
329 ui::TreeModelNode* parent,
330 int start,
331 int count) override {}
332 void TreeNodesRemoved(ui::TreeModel* model,
333 ui::TreeModelNode* parent,
334 int start,
335 int count) override {}
337 // CookiesTreeModel::Observer:
338 void TreeNodeChanged(ui::TreeModel* model, ui::TreeModelNode* node) override {
341 void TreeModelBeginBatch(CookiesTreeModel* model) override {
342 DCHECK(!ending_batch_processing_); // Extra batch-start sent.
345 void TreeModelEndBatch(CookiesTreeModel* model) override {
346 DCHECK(!ending_batch_processing_); // Already in end-stage.
347 ending_batch_processing_ = true;
349 RecursivelyFindSiteAndDelete(cookies_tree_model_->GetRoot());
351 // This will result in this class getting deleted.
352 Release();
355 void RecursivelyFindSiteAndDelete(CookieTreeNode* node) {
356 CookieTreeNode::DetailedInfo info = node->GetDetailedInfo();
357 for (int i = node->child_count(); i > 0; --i)
358 RecursivelyFindSiteAndDelete(node->GetChild(i - 1));
360 if (info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE &&
361 info.cookie &&
362 domain_.DomainIs(info.cookie->Domain().c_str()))
363 cookies_tree_model_->DeleteCookieNode(node);
366 private:
367 friend class base::RefCountedThreadSafe<SiteDataDeleteHelper>;
369 ~SiteDataDeleteHelper() override {}
371 Profile* profile_;
373 // The domain we want to delete data for.
374 GURL domain_;
376 // Keeps track of when we're ready to close batch processing.
377 bool ending_batch_processing_;
379 scoped_ptr<CookiesTreeModel> cookies_tree_model_;
381 DISALLOW_COPY_AND_ASSIGN(SiteDataDeleteHelper);
384 class StorageInfoFetcher :
385 public base::RefCountedThreadSafe<StorageInfoFetcher> {
386 public:
387 StorageInfoFetcher(storage::QuotaManager* quota_manager,
388 const JavaRef<jobject>& java_callback)
389 : env_(base::android::AttachCurrentThread()),
390 quota_manager_(quota_manager),
391 java_callback_(java_callback) {
394 void Run() {
395 // QuotaManager must be called on IO thread, but java_callback must then be
396 // called back on UI thread.
397 BrowserThread::PostTask(
398 BrowserThread::IO, FROM_HERE,
399 base::Bind(&StorageInfoFetcher::GetUsageInfo, this));
402 protected:
403 virtual ~StorageInfoFetcher() {}
405 private:
406 friend class base::RefCountedThreadSafe<StorageInfoFetcher>;
408 void GetUsageInfo() {
409 // We will have no explicit owner as soon as we leave this method.
410 AddRef();
411 quota_manager_->GetUsageInfo(
412 base::Bind(&StorageInfoFetcher::OnGetUsageInfo, this));
415 void OnGetUsageInfo(const storage::UsageInfoEntries& entries) {
416 entries_.insert(entries_.begin(), entries.begin(), entries.end());
417 BrowserThread::PostTask(
418 BrowserThread::UI, FROM_HERE,
419 base::Bind(&StorageInfoFetcher::InvokeCallback, this));
420 Release();
423 void InvokeCallback() {
424 ScopedJavaLocalRef<jobject> list =
425 Java_WebsitePreferenceBridge_createStorageInfoList(env_);
427 storage::UsageInfoEntries::const_iterator i;
428 for (i = entries_.begin(); i != entries_.end(); ++i) {
429 if (i->usage <= 0) continue;
430 ScopedJavaLocalRef<jstring> host =
431 ConvertUTF8ToJavaString(env_, i->host);
433 Java_WebsitePreferenceBridge_insertStorageInfoIntoList(
434 env_, list.obj(), host.obj(), i->type, i->usage);
436 Java_StorageInfoReadyCallback_onStorageInfoReady(
437 env_, java_callback_.obj(), list.obj());
440 JNIEnv* env_;
441 storage::QuotaManager* quota_manager_;
442 ScopedJavaGlobalRef<jobject> java_callback_;
443 storage::UsageInfoEntries entries_;
445 DISALLOW_COPY_AND_ASSIGN(StorageInfoFetcher);
448 class StorageDataDeleter :
449 public base::RefCountedThreadSafe<StorageDataDeleter> {
450 public:
451 StorageDataDeleter(storage::QuotaManager* quota_manager,
452 const std::string& host,
453 storage::StorageType type,
454 const JavaRef<jobject>& java_callback)
455 : env_(base::android::AttachCurrentThread()),
456 quota_manager_(quota_manager),
457 host_(host),
458 type_(type),
459 java_callback_(java_callback) {
462 void Run() {
463 // QuotaManager must be called on IO thread, but java_callback must then be
464 // called back on UI thread. Grant ourself an extra reference to avoid
465 // being deleted after DeleteHostData will return.
466 AddRef();
467 BrowserThread::PostTask(
468 BrowserThread::IO, FROM_HERE,
469 base::Bind(&storage::QuotaManager::DeleteHostData,
470 quota_manager_,
471 host_,
472 type_,
473 storage::QuotaClient::kAllClientsMask,
474 base::Bind(&StorageDataDeleter::OnHostDataDeleted,
475 this)));
478 protected:
479 virtual ~StorageDataDeleter() {}
481 private:
482 friend class base::RefCountedThreadSafe<StorageDataDeleter>;
484 void OnHostDataDeleted(storage::QuotaStatusCode) {
485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
486 quota_manager_->ResetUsageTracker(type_);
487 BrowserThread::PostTask(
488 BrowserThread::UI, FROM_HERE,
489 base::Bind(&StorageDataDeleter::InvokeCallback, this));
490 Release();
493 void InvokeCallback() {
494 Java_StorageInfoClearedCallback_onStorageInfoCleared(
495 env_, java_callback_.obj());
498 JNIEnv* env_;
499 storage::QuotaManager* quota_manager_;
500 std::string host_;
501 storage::StorageType type_;
502 ScopedJavaGlobalRef<jobject> java_callback_;
505 class LocalStorageInfoReadyCallback {
506 public:
507 LocalStorageInfoReadyCallback(
508 const ScopedJavaLocalRef<jobject>& java_callback)
509 : env_(base::android::AttachCurrentThread()),
510 java_callback_(java_callback) {
513 void OnLocalStorageModelInfoLoaded(
514 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>&
515 local_storage_info) {
516 ScopedJavaLocalRef<jobject> map =
517 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_);
519 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator
521 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) {
522 ScopedJavaLocalRef<jstring> full_origin =
523 ConvertUTF8ToJavaString(env_, i->origin_url.spec());
524 ScopedJavaLocalRef<jstring> origin =
525 ConvertUTF8ToJavaString(env_, i->origin_url.GetOrigin().spec());
526 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap(
527 env_, map.obj(), origin.obj(), full_origin.obj(), i->size);
530 Java_LocalStorageInfoReadyCallback_onLocalStorageInfoReady(
531 env_, java_callback_.obj(), map.obj());
532 delete this;
535 private:
536 JNIEnv* env_;
537 ScopedJavaGlobalRef<jobject> java_callback_;
540 } // anonymous namespace
542 // TODO(jknotten): These methods should not be static. Instead we should
543 // expose a class to Java so that the fetch requests can be cancelled,
544 // and manage the lifetimes of the callback (and indirectly the helper
545 // by having a reference to it).
547 // The helper methods (StartFetching, DeleteLocalStorageFile, DeleteDatabase)
548 // are asynchronous. A "use after free" error is not possible because the
549 // helpers keep a reference to themselves for the duration of their tasks,
550 // which includes callback invocation.
552 static void FetchLocalStorageInfo(JNIEnv* env, jclass clazz,
553 jobject java_callback) {
554 Profile* profile = ProfileManager::GetActiveUserProfile();
555 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper(
556 new BrowsingDataLocalStorageHelper(profile));
557 // local_storage_callback will delete itself when it is run.
558 LocalStorageInfoReadyCallback* local_storage_callback =
559 new LocalStorageInfoReadyCallback(
560 ScopedJavaLocalRef<jobject>(env, java_callback));
561 local_storage_helper->StartFetching(
562 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded,
563 base::Unretained(local_storage_callback)));
566 static void FetchStorageInfo(JNIEnv* env, jclass clazz, jobject java_callback) {
567 Profile* profile = ProfileManager::GetActiveUserProfile();
568 scoped_refptr<StorageInfoFetcher> storage_info_fetcher(new StorageInfoFetcher(
569 content::BrowserContext::GetDefaultStoragePartition(
570 profile)->GetQuotaManager(),
571 ScopedJavaLocalRef<jobject>(env, java_callback)));
572 storage_info_fetcher->Run();
575 static void ClearLocalStorageData(JNIEnv* env, jclass clazz, jstring jorigin) {
576 Profile* profile = ProfileManager::GetActiveUserProfile();
577 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper =
578 new BrowsingDataLocalStorageHelper(profile);
579 GURL origin_url = GURL(ConvertJavaStringToUTF8(env, jorigin));
580 local_storage_helper->DeleteOrigin(origin_url);
583 static void ClearStorageData(JNIEnv* env,
584 jclass clazz,
585 jstring jhost,
586 jint type,
587 jobject java_callback) {
588 Profile* profile = ProfileManager::GetActiveUserProfile();
589 std::string host = ConvertJavaStringToUTF8(env, jhost);
590 scoped_refptr<StorageDataDeleter> storage_data_deleter(new StorageDataDeleter(
591 content::BrowserContext::GetDefaultStoragePartition(
592 profile)->GetQuotaManager(),
593 host,
594 static_cast<storage::StorageType>(type),
595 ScopedJavaLocalRef<jobject>(env, java_callback)));
596 storage_data_deleter->Run();
599 static void ClearCookieData(JNIEnv* env, jclass clazz, jstring jorigin) {
600 Profile* profile = ProfileManager::GetActiveUserProfile();
601 GURL url(ConvertJavaStringToUTF8(env, jorigin));
602 scoped_refptr<SiteDataDeleteHelper> site_data_deleter(
603 new SiteDataDeleteHelper(profile, url));
604 site_data_deleter->Run();
607 // Register native methods
608 bool RegisterWebsitePreferenceBridge(JNIEnv* env) {
609 return RegisterNativesImpl(env);