| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // Defines the Chrome Extensions BrowsingData API functions, which entail | 5 // Defines the Chrome Extensions BrowsingData API functions, which entail |
| 6 // clearing browsing data, and clearing the browser's cache (which, let's be | 6 // clearing browsing data, and clearing the browser's cache (which, let's be |
| 7 // honest, are the same thing), as specified in the extension API JSON. | 7 // honest, are the same thing), as specified in the extension API JSON. |
| 8 | 8 |
| 9 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" | 9 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" |
| 10 | 10 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // download history. | 116 // download history. |
| 117 if ((removal_mask & BrowsingDataRemover::REMOVE_HISTORY) || | 117 if ((removal_mask & BrowsingDataRemover::REMOVE_HISTORY) || |
| 118 (removal_mask & BrowsingDataRemover::REMOVE_DOWNLOADS)) { | 118 (removal_mask & BrowsingDataRemover::REMOVE_DOWNLOADS)) { |
| 119 return prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory); | 119 return prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory); |
| 120 } | 120 } |
| 121 return true; | 121 return true; |
| 122 } | 122 } |
| 123 | 123 |
| 124 } // namespace | 124 } // namespace |
| 125 | 125 |
| 126 bool BrowsingDataSettingsFunction::RunSync() { | 126 ExtensionFunction::ResponseAction BrowsingDataSettingsFunction::Run() { |
| 127 PrefService* prefs = GetProfile()->GetPrefs(); | 127 prefs_ = Profile::FromBrowserContext(browser_context())->GetPrefs(); |
| 128 | 128 |
| 129 // Fill origin types. | 129 // Fill origin types. |
| 130 // The "cookies" and "hosted apps" UI checkboxes both map to | 130 // The "cookies" and "hosted apps" UI checkboxes both map to |
| 131 // REMOVE_SITE_DATA in browsing_data_remover.h, the former for the unprotected | 131 // REMOVE_SITE_DATA in browsing_data_remover.h, the former for the unprotected |
| 132 // web, the latter for protected web data. There is no UI control for | 132 // web, the latter for protected web data. There is no UI control for |
| 133 // extension data. | 133 // extension data. |
| 134 std::unique_ptr<base::DictionaryValue> origin_types( | 134 std::unique_ptr<base::DictionaryValue> origin_types( |
| 135 new base::DictionaryValue); | 135 new base::DictionaryValue); |
| 136 origin_types->SetBoolean( | 136 origin_types->SetBoolean( |
| 137 extension_browsing_data_api_constants::kUnprotectedWebKey, | 137 extension_browsing_data_api_constants::kUnprotectedWebKey, |
| 138 prefs->GetBoolean(browsing_data::prefs::kDeleteCookies)); | 138 prefs_->GetBoolean(browsing_data::prefs::kDeleteCookies)); |
| 139 origin_types->SetBoolean( | 139 origin_types->SetBoolean( |
| 140 extension_browsing_data_api_constants::kProtectedWebKey, | 140 extension_browsing_data_api_constants::kProtectedWebKey, |
| 141 prefs->GetBoolean(browsing_data::prefs::kDeleteHostedAppsData)); | 141 prefs_->GetBoolean(browsing_data::prefs::kDeleteHostedAppsData)); |
| 142 origin_types->SetBoolean( | 142 origin_types->SetBoolean( |
| 143 extension_browsing_data_api_constants::kExtensionsKey, false); | 143 extension_browsing_data_api_constants::kExtensionsKey, false); |
| 144 | 144 |
| 145 // Fill deletion time period. | 145 // Fill deletion time period. |
| 146 int period_pref = prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); | 146 int period_pref = prefs_->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
| 147 browsing_data::TimePeriod period = | 147 browsing_data::TimePeriod period = |
| 148 static_cast<browsing_data::TimePeriod>(period_pref); | 148 static_cast<browsing_data::TimePeriod>(period_pref); |
| 149 double since = 0; | 149 double since = 0; |
| 150 if (period != browsing_data::ALL_TIME) { | 150 if (period != browsing_data::ALL_TIME) { |
| 151 base::Time time = browsing_data::CalculateBeginDeleteTime(period); | 151 base::Time time = browsing_data::CalculateBeginDeleteTime(period); |
| 152 since = time.ToJsTime(); | 152 since = time.ToJsTime(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 std::unique_ptr<base::DictionaryValue> options(new base::DictionaryValue); | 155 std::unique_ptr<base::DictionaryValue> options(new base::DictionaryValue); |
| 156 options->Set(extension_browsing_data_api_constants::kOriginTypesKey, | 156 options->Set(extension_browsing_data_api_constants::kOriginTypesKey, |
| 157 origin_types.release()); | 157 origin_types.release()); |
| 158 options->SetDouble(extension_browsing_data_api_constants::kSinceKey, since); | 158 options->SetDouble(extension_browsing_data_api_constants::kSinceKey, since); |
| 159 | 159 |
| 160 // Fill dataToRemove and dataRemovalPermitted. | 160 // Fill dataToRemove and dataRemovalPermitted. |
| 161 std::unique_ptr<base::DictionaryValue> selected(new base::DictionaryValue); | 161 std::unique_ptr<base::DictionaryValue> selected(new base::DictionaryValue); |
| 162 std::unique_ptr<base::DictionaryValue> permitted(new base::DictionaryValue); | 162 std::unique_ptr<base::DictionaryValue> permitted(new base::DictionaryValue); |
| 163 | 163 |
| 164 bool delete_site_data = | 164 bool delete_site_data = |
| 165 prefs->GetBoolean(browsing_data::prefs::kDeleteCookies) || | 165 prefs_->GetBoolean(browsing_data::prefs::kDeleteCookies) || |
| 166 prefs->GetBoolean(browsing_data::prefs::kDeleteHostedAppsData); | 166 prefs_->GetBoolean(browsing_data::prefs::kDeleteHostedAppsData); |
| 167 | 167 |
| 168 SetDetails(selected.get(), permitted.get(), | 168 SetDetails(selected.get(), permitted.get(), |
| 169 extension_browsing_data_api_constants::kAppCacheKey, | 169 extension_browsing_data_api_constants::kAppCacheKey, |
| 170 delete_site_data); | 170 delete_site_data); |
| 171 SetDetails(selected.get(), permitted.get(), | 171 SetDetails(selected.get(), permitted.get(), |
| 172 extension_browsing_data_api_constants::kCookiesKey, | 172 extension_browsing_data_api_constants::kCookiesKey, |
| 173 delete_site_data); | 173 delete_site_data); |
| 174 SetDetails(selected.get(), permitted.get(), | 174 SetDetails(selected.get(), permitted.get(), |
| 175 extension_browsing_data_api_constants::kFileSystemsKey, | 175 extension_browsing_data_api_constants::kFileSystemsKey, |
| 176 delete_site_data); | 176 delete_site_data); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 187 extension_browsing_data_api_constants::kChannelIDsKey, | 187 extension_browsing_data_api_constants::kChannelIDsKey, |
| 188 delete_site_data); | 188 delete_site_data); |
| 189 SetDetails(selected.get(), permitted.get(), | 189 SetDetails(selected.get(), permitted.get(), |
| 190 extension_browsing_data_api_constants::kServiceWorkersKey, | 190 extension_browsing_data_api_constants::kServiceWorkersKey, |
| 191 delete_site_data); | 191 delete_site_data); |
| 192 SetDetails(selected.get(), permitted.get(), | 192 SetDetails(selected.get(), permitted.get(), |
| 193 extension_browsing_data_api_constants::kCacheStorageKey, | 193 extension_browsing_data_api_constants::kCacheStorageKey, |
| 194 delete_site_data); | 194 delete_site_data); |
| 195 | 195 |
| 196 SetDetails(selected.get(), permitted.get(), | 196 SetDetails(selected.get(), permitted.get(), |
| 197 extension_browsing_data_api_constants::kPluginDataKey, | 197 extension_browsing_data_api_constants::kPluginDataKey, |
| 198 delete_site_data && prefs->GetBoolean(prefs::kClearPluginLSODataEnabled)); | 198 delete_site_data && |
| 199 prefs_->GetBoolean(prefs::kClearPluginLSODataEnabled)); |
| 199 | 200 |
| 200 SetDetails(selected.get(), permitted.get(), | 201 SetDetails(selected.get(), permitted.get(), |
| 201 extension_browsing_data_api_constants::kHistoryKey, | 202 extension_browsing_data_api_constants::kHistoryKey, |
| 202 prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory)); | 203 prefs_->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory)); |
| 203 SetDetails(selected.get(), permitted.get(), | 204 SetDetails(selected.get(), permitted.get(), |
| 204 extension_browsing_data_api_constants::kDownloadsKey, | 205 extension_browsing_data_api_constants::kDownloadsKey, |
| 205 prefs->GetBoolean(browsing_data::prefs::kDeleteDownloadHistory)); | 206 prefs_->GetBoolean(browsing_data::prefs::kDeleteDownloadHistory)); |
| 206 SetDetails(selected.get(), permitted.get(), | 207 SetDetails(selected.get(), permitted.get(), |
| 207 extension_browsing_data_api_constants::kCacheKey, | 208 extension_browsing_data_api_constants::kCacheKey, |
| 208 prefs->GetBoolean(browsing_data::prefs::kDeleteCache)); | 209 prefs_->GetBoolean(browsing_data::prefs::kDeleteCache)); |
| 209 SetDetails(selected.get(), permitted.get(), | 210 SetDetails(selected.get(), permitted.get(), |
| 210 extension_browsing_data_api_constants::kFormDataKey, | 211 extension_browsing_data_api_constants::kFormDataKey, |
| 211 prefs->GetBoolean(browsing_data::prefs::kDeleteFormData)); | 212 prefs_->GetBoolean(browsing_data::prefs::kDeleteFormData)); |
| 212 SetDetails(selected.get(), permitted.get(), | 213 SetDetails(selected.get(), permitted.get(), |
| 213 extension_browsing_data_api_constants::kPasswordsKey, | 214 extension_browsing_data_api_constants::kPasswordsKey, |
| 214 prefs->GetBoolean(browsing_data::prefs::kDeletePasswords)); | 215 prefs_->GetBoolean(browsing_data::prefs::kDeletePasswords)); |
| 215 | 216 |
| 216 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); | 217 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
| 217 result->Set(extension_browsing_data_api_constants::kOptionsKey, | 218 result->Set(extension_browsing_data_api_constants::kOptionsKey, |
| 218 options.release()); | 219 options.release()); |
| 219 result->Set(extension_browsing_data_api_constants::kDataToRemoveKey, | 220 result->Set(extension_browsing_data_api_constants::kDataToRemoveKey, |
| 220 selected.release()); | 221 selected.release()); |
| 221 result->Set(extension_browsing_data_api_constants::kDataRemovalPermittedKey, | 222 result->Set(extension_browsing_data_api_constants::kDataRemovalPermittedKey, |
| 222 permitted.release()); | 223 permitted.release()); |
| 223 SetResult(std::move(result)); | 224 return RespondNow(OneArgument(std::move(result))); |
| 224 return true; | |
| 225 } | 225 } |
| 226 | 226 |
| 227 void BrowsingDataSettingsFunction::SetDetails( | 227 void BrowsingDataSettingsFunction::SetDetails( |
| 228 base::DictionaryValue* selected_dict, | 228 base::DictionaryValue* selected_dict, |
| 229 base::DictionaryValue* permitted_dict, | 229 base::DictionaryValue* permitted_dict, |
| 230 const char* data_type, | 230 const char* data_type, |
| 231 bool is_selected) { | 231 bool is_selected) { |
| 232 bool is_permitted = | 232 bool is_permitted = IsRemovalPermitted(MaskForKey(data_type), prefs_); |
| 233 IsRemovalPermitted(MaskForKey(data_type), GetProfile()->GetPrefs()); | |
| 234 selected_dict->SetBoolean(data_type, is_selected && is_permitted); | 233 selected_dict->SetBoolean(data_type, is_selected && is_permitted); |
| 235 permitted_dict->SetBoolean(data_type, is_permitted); | 234 permitted_dict->SetBoolean(data_type, is_permitted); |
| 236 } | 235 } |
| 237 | 236 |
| 238 BrowsingDataRemoverFunction::BrowsingDataRemoverFunction() : observer_(this) {} | 237 BrowsingDataRemoverFunction::BrowsingDataRemoverFunction() : observer_(this) {} |
| 239 | 238 |
| 240 void BrowsingDataRemoverFunction::OnBrowsingDataRemoverDone() { | 239 void BrowsingDataRemoverFunction::OnBrowsingDataRemoverDone() { |
| 241 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 240 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 242 | 241 |
| 243 observer_.RemoveAll(); | 242 observer_.RemoveAll(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 return BrowsingDataRemover::REMOVE_SERVICE_WORKERS; | 451 return BrowsingDataRemover::REMOVE_SERVICE_WORKERS; |
| 453 } | 452 } |
| 454 | 453 |
| 455 int BrowsingDataRemoveCacheStorageFunction::GetRemovalMask() { | 454 int BrowsingDataRemoveCacheStorageFunction::GetRemovalMask() { |
| 456 return BrowsingDataRemover::REMOVE_CACHE_STORAGE; | 455 return BrowsingDataRemover::REMOVE_CACHE_STORAGE; |
| 457 } | 456 } |
| 458 | 457 |
| 459 int BrowsingDataRemoveWebSQLFunction::GetRemovalMask() { | 458 int BrowsingDataRemoveWebSQLFunction::GetRemovalMask() { |
| 460 return BrowsingDataRemover::REMOVE_WEBSQL; | 459 return BrowsingDataRemover::REMOVE_WEBSQL; |
| 461 } | 460 } |
| OLD | NEW |