Allow-building-without-safebrowsing-for-Android.patch 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Tue, 18 Sep 2018 08:06:14 +0200
  3. Subject: Allow building without safebrowsing for Android
  4. Fix build from scratch (issue found by nikolowry)
  5. ---
  6. .../android/java/res/xml/privacy_preferences.xml | 8 -----
  7. .../preferences/privacy/PrivacyPreferences.java | 40 ----------------------
  8. .../chrome_browsing_data_remover_delegate.cc | 10 ------
  9. chrome/browser/chrome_content_browser_client.cc | 14 +-------
  10. .../file_type_policies_component_installer.cc | 2 ++
  11. .../download/chrome_download_manager_delegate.cc | 14 ++++++--
  12. .../download/chrome_download_manager_delegate.h | 6 ++++
  13. chrome/browser/download/download_item_model.cc | 10 ++++++
  14. chrome/browser/download/download_item_model.h | 4 +++
  15. chrome/browser/download/download_prefs.cc | 4 +++
  16. .../browser/download/download_target_determiner.cc | 18 ++++++++++
  17. .../browser/download/download_target_determiner.h | 6 ++++
  18. chrome/browser/download/download_target_info.cc | 4 +++
  19. chrome/browser/download/download_target_info.h | 4 +++
  20. chrome/browser/download/download_ui_model.cc | 4 +++
  21. chrome/browser/download/download_ui_model.h | 4 +++
  22. .../chrome_resource_dispatcher_host_delegate.cc | 4 +++
  23. chrome/browser/net/chrome_network_delegate.cc | 35 ++-----------------
  24. 18 files changed, 85 insertions(+), 106 deletions(-)
  25. diff --git a/chrome/android/java/res/xml/privacy_preferences.xml b/chrome/android/java/res/xml/privacy_preferences.xml
  26. --- a/chrome/android/java/res/xml/privacy_preferences.xml
  27. +++ b/chrome/android/java/res/xml/privacy_preferences.xml
  28. @@ -18,14 +18,6 @@
  29. android:summary="@string/search_suggestions_summary"
  30. android:defaultValue="true" />
  31. <org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference
  32. - android:key="safe_browsing_scout_reporting"
  33. - android:title="@string/safe_browsing_scout_reporting_title"
  34. - android:summary="@string/safe_browsing_scout_reporting_summary" />
  35. - <org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference
  36. - android:key="safe_browsing"
  37. - android:title="@string/safe_browsing_title"
  38. - android:summary="@string/safe_browsing_summary" />
  39. - <org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference
  40. android:key="network_predictions"
  41. android:title="@string/network_predictions_title"
  42. android:summary="@string/network_predictions_summary"
  43. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferences.java
  44. --- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferences.java
  45. +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferences.java
  46. @@ -38,9 +38,6 @@ public class PrivacyPreferences extends PreferenceFragment
  47. implements OnPreferenceChangeListener {
  48. private static final String PREF_NAVIGATION_ERROR = "navigation_error";
  49. private static final String PREF_SEARCH_SUGGESTIONS = "search_suggestions";
  50. - private static final String PREF_SAFE_BROWSING_SCOUT_REPORTING =
  51. - "safe_browsing_scout_reporting";
  52. - private static final String PREF_SAFE_BROWSING = "safe_browsing";
  53. private static final String PREF_CAN_MAKE_PAYMENT = "can_make_payment";
  54. private static final String PREF_CONTEXTUAL_SEARCH = "contextual_search";
  55. private static final String PREF_NETWORK_PREDICTIONS = "network_predictions";
  56. @@ -74,8 +71,6 @@ public class PrivacyPreferences extends PreferenceFragment
  57. // Remove preferences that were migrated to SyncAndServicesPreferences.
  58. preferenceScreen.removePreference(findPreference(PREF_NAVIGATION_ERROR));
  59. preferenceScreen.removePreference(findPreference(PREF_SEARCH_SUGGESTIONS));
  60. - preferenceScreen.removePreference(findPreference(PREF_SAFE_BROWSING_SCOUT_REPORTING));
  61. - preferenceScreen.removePreference(findPreference(PREF_SAFE_BROWSING));
  62. preferenceScreen.removePreference(findPreference(PREF_NETWORK_PREDICTIONS));
  63. preferenceScreen.removePreference(findPreference(PREF_CONTEXTUAL_SEARCH));
  64. preferenceScreen.removePreference(findPreference(PREF_USAGE_AND_CRASH_REPORTING));
  65. @@ -115,17 +110,6 @@ public class PrivacyPreferences extends PreferenceFragment
  66. preferenceScreen.removePreference(findPreference(PREF_CONTEXTUAL_SEARCH));
  67. }
  68. - // Listen to changes to the Extended Reporting pref.
  69. - ChromeBaseCheckBoxPreference scoutReportingPref =
  70. - (ChromeBaseCheckBoxPreference) findPreference(PREF_SAFE_BROWSING_SCOUT_REPORTING);
  71. - scoutReportingPref.setOnPreferenceChangeListener(this);
  72. - scoutReportingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
  73. -
  74. - ChromeBaseCheckBoxPreference safeBrowsingPref =
  75. - (ChromeBaseCheckBoxPreference) findPreference(PREF_SAFE_BROWSING);
  76. - safeBrowsingPref.setOnPreferenceChangeListener(this);
  77. - safeBrowsingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
  78. -
  79. updateSummaries();
  80. }
  81. @@ -134,11 +118,6 @@ public class PrivacyPreferences extends PreferenceFragment
  82. String key = preference.getKey();
  83. if (PREF_SEARCH_SUGGESTIONS.equals(key)) {
  84. PrefServiceBridge.getInstance().setSearchSuggestEnabled((boolean) newValue);
  85. - } else if (PREF_SAFE_BROWSING.equals(key)) {
  86. - PrefServiceBridge.getInstance().setSafeBrowsingEnabled((boolean) newValue);
  87. - } else if (PREF_SAFE_BROWSING_SCOUT_REPORTING.equals(key)) {
  88. - PrefServiceBridge.getInstance().setSafeBrowsingExtendedReportingEnabled(
  89. - (boolean) newValue);
  90. } else if (PREF_NETWORK_PREDICTIONS.equals(key)) {
  91. PrefServiceBridge.getInstance().setNetworkPredictionEnabled((boolean) newValue);
  92. recordNetworkPredictionEnablingUMA((boolean) newValue);
  93. @@ -187,19 +166,6 @@ public class PrivacyPreferences extends PreferenceFragment
  94. searchSuggestionsPref.setChecked(prefServiceBridge.isSearchSuggestEnabled());
  95. }
  96. - CheckBoxPreference extendedReportingPref =
  97. - (CheckBoxPreference) findPreference(PREF_SAFE_BROWSING_SCOUT_REPORTING);
  98. - if (extendedReportingPref != null) {
  99. - extendedReportingPref.setChecked(
  100. - prefServiceBridge.isSafeBrowsingExtendedReportingEnabled());
  101. - }
  102. -
  103. - CheckBoxPreference safeBrowsingPref =
  104. - (CheckBoxPreference) findPreference(PREF_SAFE_BROWSING);
  105. - if (safeBrowsingPref != null) {
  106. - safeBrowsingPref.setChecked(prefServiceBridge.isSafeBrowsingEnabled());
  107. - }
  108. -
  109. CheckBoxPreference canMakePaymentPref =
  110. (CheckBoxPreference) findPreference(PREF_CAN_MAKE_PAYMENT);
  111. if (canMakePaymentPref != null) {
  112. @@ -236,12 +202,6 @@ public class PrivacyPreferences extends PreferenceFragment
  113. if (PREF_SEARCH_SUGGESTIONS.equals(key)) {
  114. return prefs.isSearchSuggestManaged();
  115. }
  116. - if (PREF_SAFE_BROWSING_SCOUT_REPORTING.equals(key)) {
  117. - return prefs.isSafeBrowsingExtendedReportingManaged();
  118. - }
  119. - if (PREF_SAFE_BROWSING.equals(key)) {
  120. - return prefs.isSafeBrowsingManaged();
  121. - }
  122. if (PREF_NETWORK_PREDICTIONS.equals(key)) {
  123. return prefs.isNetworkPredictionManaged();
  124. }
  125. diff --git a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc
  126. --- a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc
  127. +++ b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc
  128. @@ -242,16 +242,6 @@ bool DoesOriginMatchEmbedderMask(int origin_type_mask,
  129. return false;
  130. }
  131. -// Callback for when cookies have been deleted. Invokes NotifyIfDone.
  132. -// Receiving |cookie_manager| as a parameter so that the receive pipe is
  133. -// not deleted before the response is received.
  134. -void OnClearedCookies(base::OnceClosure done,
  135. - network::mojom::CookieManagerPtr cookie_manager,
  136. - uint32_t num_deleted) {
  137. - DCHECK_CURRENTLY_ON(BrowserThread::UI);
  138. - std::move(done).Run();
  139. -}
  140. -
  141. } // namespace
  142. ChromeBrowsingDataRemoverDelegate::ChromeBrowsingDataRemoverDelegate(
  143. diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
  144. --- a/chrome/browser/chrome_content_browser_client.cc
  145. +++ b/chrome/browser/chrome_content_browser_client.cc
  146. @@ -5010,19 +5010,7 @@ ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
  147. content::ResourceContext* resource_context) {
  148. DCHECK_CURRENTLY_ON(BrowserThread::IO);
  149. - ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
  150. - if (!io_data->safe_browsing_enabled()->GetValue())
  151. - return nullptr;
  152. -
  153. - // |safe_browsing_service_| may be unavailable in tests.
  154. - if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
  155. - safe_browsing_url_checker_delegate_ =
  156. - base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
  157. - safe_browsing_service_->database_manager(),
  158. - safe_browsing_service_->ui_manager());
  159. - }
  160. -
  161. - return safe_browsing_url_checker_delegate_.get();
  162. + return nullptr;
  163. }
  164. base::Optional<std::string>
  165. diff --git a/chrome/browser/component_updater/file_type_policies_component_installer.cc b/chrome/browser/component_updater/file_type_policies_component_installer.cc
  166. --- a/chrome/browser/component_updater/file_type_policies_component_installer.cc
  167. +++ b/chrome/browser/component_updater/file_type_policies_component_installer.cc
  168. @@ -18,7 +18,9 @@
  169. #include "base/path_service.h"
  170. #include "base/task/post_task.h"
  171. #include "base/version.h"
  172. +#if defined(FULL_SAFE_BROWSING)
  173. #include "chrome/common/safe_browsing/file_type_policies.h"
  174. +#endif
  175. #include "components/component_updater/component_updater_paths.h"
  176. using component_updater::ComponentUpdateService;
  177. diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc
  178. --- a/chrome/browser/download/chrome_download_manager_delegate.cc
  179. +++ b/chrome/browser/download/chrome_download_manager_delegate.cc
  180. @@ -38,8 +38,10 @@
  181. #include "chrome/browser/download/save_package_file_picker.h"
  182. #include "chrome/browser/platform_util.h"
  183. #include "chrome/browser/profiles/profile.h"
  184. +#if defined(FULL_SAFE_BROWSING)
  185. #include "chrome/browser/safe_browsing/download_protection/download_protection_util.h"
  186. #include "chrome/browser/safe_browsing/safe_browsing_service.h"
  187. +#endif
  188. #include "chrome/browser/ui/browser.h"
  189. #include "chrome/browser/ui/browser_finder.h"
  190. #include "chrome/browser/ui/chrome_pages.h"
  191. @@ -49,7 +51,9 @@
  192. #include "chrome/common/chrome_features.h"
  193. #include "chrome/common/pdf_util.h"
  194. #include "chrome/common/pref_names.h"
  195. +#if defined(FULL_SAFE_BROWSING)
  196. #include "chrome/common/safe_browsing/file_type_policies.h"
  197. +#endif
  198. #include "chrome/grit/generated_resources.h"
  199. #include "components/download/public/common/download_interrupt_reasons.h"
  200. #include "components/download/public/common/download_item.h"
  201. @@ -94,8 +98,10 @@
  202. using content::BrowserThread;
  203. using download::DownloadItem;
  204. using content::DownloadManager;
  205. +#if defined(FULL_SAFE_BROWSING)
  206. using safe_browsing::DownloadFileType;
  207. using safe_browsing::DownloadProtectionService;
  208. +#endif
  209. namespace {
  210. @@ -744,19 +750,19 @@ ChromeDownloadManagerDelegate::ApplicationClientIdForFileScanning() const {
  211. return std::string(chrome::kApplicationClientIDStringForAVScanning);
  212. }
  213. +#if defined(FULL_SAFE_BROWSING)
  214. DownloadProtectionService*
  215. ChromeDownloadManagerDelegate::GetDownloadProtectionService() {
  216. DCHECK_CURRENTLY_ON(BrowserThread::UI);
  217. -#if defined(FULL_SAFE_BROWSING)
  218. safe_browsing::SafeBrowsingService* sb_service =
  219. g_browser_process->safe_browsing_service();
  220. if (sb_service && sb_service->download_protection_service() &&
  221. profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) {
  222. return sb_service->download_protection_service();
  223. }
  224. -#endif
  225. return NULL;
  226. }
  227. +#endif
  228. void ChromeDownloadManagerDelegate::NotifyExtensions(
  229. DownloadItem* download,
  230. @@ -1199,13 +1205,17 @@ void ChromeDownloadManagerDelegate::OnDownloadTargetDetermined(
  231. DownloadItemModel(item).SetShouldPreferOpeningInBrowser(true);
  232. #endif
  233. +#if defined(FULL_SAFE_BROWSING)
  234. DownloadItemModel(item).SetDangerLevel(target_info->danger_level);
  235. +#endif
  236. }
  237. +#if defined(FULL_SAFE_BROWSING)
  238. if (ShouldBlockFile(target_info->danger_type, item)) {
  239. target_info->result = download::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED;
  240. // A dangerous type would take precendence over the blocking of the file.
  241. target_info->danger_type = download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS;
  242. }
  243. +#endif
  244. callback.Run(target_info->target_path, target_info->target_disposition,
  245. target_info->danger_type, target_info->intermediate_path,
  246. diff --git a/chrome/browser/download/chrome_download_manager_delegate.h b/chrome/browser/download/chrome_download_manager_delegate.h
  247. --- a/chrome/browser/download/chrome_download_manager_delegate.h
  248. +++ b/chrome/browser/download/chrome_download_manager_delegate.h
  249. @@ -22,8 +22,10 @@
  250. #include "chrome/browser/download/download_path_reservation_tracker.h"
  251. #include "chrome/browser/download/download_target_determiner_delegate.h"
  252. #include "chrome/browser/download/download_target_info.h"
  253. +#if defined(FULL_SAFE_BROWSING)
  254. #include "chrome/browser/safe_browsing/download_protection/download_protection_service.h"
  255. #include "chrome/browser/safe_browsing/download_protection/download_protection_util.h"
  256. +#endif
  257. #include "components/download/public/common/download_danger_type.h"
  258. #include "components/download/public/common/download_item.h"
  259. #include "content/public/browser/download_manager_delegate.h"
  260. @@ -131,8 +133,10 @@ class ChromeDownloadManagerDelegate
  261. DownloadPrefs* download_prefs() { return download_prefs_.get(); }
  262. protected:
  263. +#if defined(FULL_SAFE_BROWSING)
  264. virtual safe_browsing::DownloadProtectionService*
  265. GetDownloadProtectionService();
  266. +#endif
  267. // Show file picker for |download|.
  268. virtual void ShowFilePickerForDownload(
  269. @@ -197,9 +201,11 @@ class ChromeDownloadManagerDelegate
  270. const content::NotificationSource& source,
  271. const content::NotificationDetails& details) override;
  272. +#if defined(FULL_SAFE_BROWSING)
  273. // Callback function after the DownloadProtectionService completes.
  274. void CheckClientDownloadDone(uint32_t download_id,
  275. safe_browsing::DownloadCheckResult result);
  276. +#endif
  277. // Internal gateways for ShouldCompleteDownload().
  278. bool IsDownloadReadyForCompletion(
  279. diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc
  280. --- a/chrome/browser/download/download_item_model.cc
  281. +++ b/chrome/browser/download/download_item_model.cc
  282. @@ -22,9 +22,11 @@
  283. #include "chrome/browser/download/download_stats.h"
  284. #include "chrome/browser/download/offline_item_utils.h"
  285. #include "chrome/browser/profiles/profile.h"
  286. +#if defined(FULL_SAFE_BROWSING)
  287. #include "chrome/browser/safe_browsing/download_protection/download_feedback_service.h"
  288. #include "chrome/common/safe_browsing/download_file_types.pb.h"
  289. #include "chrome/common/safe_browsing/file_type_policies.h"
  290. +#endif
  291. #include "chrome/grit/chromium_strings.h"
  292. #include "chrome/grit/generated_resources.h"
  293. #include "components/download/public/common/download_danger_type.h"
  294. @@ -37,7 +39,9 @@
  295. using base::TimeDelta;
  296. using download::DownloadItem;
  297. +#if defined(FULL_SAFE_BROWSING)
  298. using safe_browsing::DownloadFileType;
  299. +#endif
  300. namespace {
  301. @@ -67,9 +71,11 @@ class DownloadItemModelData : public base::SupportsUserData::Data {
  302. // for the file type.
  303. bool should_prefer_opening_in_browser_;
  304. +#if defined(FULL_SAFE_BROWSING)
  305. // Danger level of the file determined based on the file type and whether
  306. // there was a user action associated with the download.
  307. DownloadFileType::DangerLevel danger_level_;
  308. +#endif
  309. // Whether the download is currently being revived.
  310. bool is_being_revived_;
  311. @@ -106,7 +112,9 @@ DownloadItemModelData::DownloadItemModelData()
  312. : should_show_in_shelf_(true),
  313. was_ui_notified_(false),
  314. should_prefer_opening_in_browser_(false),
  315. +#if defined(FULL_SAFE_BROWSING)
  316. danger_level_(DownloadFileType::NOT_DANGEROUS),
  317. +#endif
  318. is_being_revived_(false) {}
  319. } // namespace
  320. @@ -368,6 +376,7 @@ void DownloadItemModel::SetShouldPreferOpeningInBrowser(bool preference) {
  321. data->should_prefer_opening_in_browser_ = preference;
  322. }
  323. +#if defined(FULL_SAFE_BROWSING)
  324. DownloadFileType::DangerLevel DownloadItemModel::GetDangerLevel() const {
  325. const DownloadItemModelData* data = DownloadItemModelData::Get(download_);
  326. return data ? data->danger_level_ : DownloadFileType::NOT_DANGEROUS;
  327. @@ -378,6 +387,7 @@ void DownloadItemModel::SetDangerLevel(
  328. DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_);
  329. data->danger_level_ = danger_level;
  330. }
  331. +#endif
  332. bool DownloadItemModel::IsBeingRevived() const {
  333. const DownloadItemModelData* data = DownloadItemModelData::Get(download_);
  334. diff --git a/chrome/browser/download/download_item_model.h b/chrome/browser/download/download_item_model.h
  335. --- a/chrome/browser/download/download_item_model.h
  336. +++ b/chrome/browser/download/download_item_model.h
  337. @@ -11,7 +11,9 @@
  338. #include "base/macros.h"
  339. #include "base/strings/string16.h"
  340. #include "chrome/browser/download/download_ui_model.h"
  341. +#if defined(FULL_SAFE_BROWSING)
  342. #include "chrome/common/safe_browsing/download_file_types.pb.h"
  343. +#endif
  344. #include "components/download/public/common/download_item.h"
  345. // Implementation of DownloadUIModel that wrappers around a |DownloadItem*|. As
  346. @@ -48,9 +50,11 @@ class DownloadItemModel : public DownloadUIModel,
  347. void SetWasUINotified(bool should_notify) override;
  348. bool ShouldPreferOpeningInBrowser() const override;
  349. void SetShouldPreferOpeningInBrowser(bool preference) override;
  350. +#if defined(FULL_SAFE_BROWSING)
  351. safe_browsing::DownloadFileType::DangerLevel GetDangerLevel() const override;
  352. void SetDangerLevel(
  353. safe_browsing::DownloadFileType::DangerLevel danger_level) override;
  354. +#endif
  355. void OpenUsingPlatformHandler() override;
  356. bool IsBeingRevived() const override;
  357. void SetIsBeingRevived(bool is_being_revived) override;
  358. diff --git a/chrome/browser/download/download_prefs.cc b/chrome/browser/download/download_prefs.cc
  359. --- a/chrome/browser/download/download_prefs.cc
  360. +++ b/chrome/browser/download/download_prefs.cc
  361. @@ -33,7 +33,9 @@
  362. #include "chrome/common/chrome_features.h"
  363. #include "chrome/common/chrome_paths.h"
  364. #include "chrome/common/pref_names.h"
  365. +#if defined(FULL_SAFE_BROWSING)
  366. #include "chrome/common/safe_browsing/file_type_policies.h"
  367. +#endif
  368. #include "components/download/public/common/download_item.h"
  369. #include "components/pref_registry/pref_registry_syncable.h"
  370. #include "components/prefs/pref_service.h"
  371. @@ -55,7 +57,9 @@
  372. using content::BrowserContext;
  373. using content::BrowserThread;
  374. using content::DownloadManager;
  375. +#if defined(FULL_SAFE_BROWSING)
  376. using safe_browsing::FileTypePolicies;
  377. +#endif
  378. namespace {
  379. diff --git a/chrome/browser/download/download_target_determiner.cc b/chrome/browser/download/download_target_determiner.cc
  380. --- a/chrome/browser/download/download_target_determiner.cc
  381. +++ b/chrome/browser/download/download_target_determiner.cc
  382. @@ -22,7 +22,9 @@
  383. #include "chrome/browser/history/history_service_factory.h"
  384. #include "chrome/browser/profiles/profile.h"
  385. #include "chrome/common/pref_names.h"
  386. +#if defined(FULL_SAFE_BROWSING)
  387. #include "chrome/common/safe_browsing/file_type_policies.h"
  388. +#endif
  389. #include "chrome/grit/generated_resources.h"
  390. #include "components/download/public/common/download_interrupt_reasons.h"
  391. #include "components/history/core/browser/history_service.h"
  392. @@ -56,13 +58,16 @@
  393. using content::BrowserThread;
  394. using download::DownloadItem;
  395. +#if defined(FULL_SAFE_BROWSING)
  396. using safe_browsing::DownloadFileType;
  397. +#endif
  398. namespace {
  399. const base::FilePath::CharType kCrdownloadSuffix[] =
  400. FILE_PATH_LITERAL(".crdownload");
  401. +#if defined(FULL_SAFE_BROWSING)
  402. // Condenses the results from HistoryService::GetVisibleVisitCountToHost() to a
  403. // single bool. A host is considered visited before if prior visible visits were
  404. // found in history and the first such visit was earlier than the most recent
  405. @@ -76,6 +81,7 @@ void VisitCountsToVisitedBefore(
  406. found_visits && count > 0 &&
  407. (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight()));
  408. }
  409. +#endif
  410. #if defined(OS_WIN)
  411. // Keeps track of whether Adobe Reader is up to date.
  412. @@ -100,7 +106,9 @@ DownloadTargetDeterminer::DownloadTargetDeterminer(
  413. create_target_directory_(false),
  414. conflict_action_(conflict_action),
  415. danger_type_(download->GetDangerType()),
  416. +#if defined(FULL_SAFE_BROWSING)
  417. danger_level_(DownloadFileType::NOT_DANGEROUS),
  418. +#endif
  419. virtual_path_(initial_virtual_path),
  420. is_filetype_handled_safely_(false),
  421. #if defined(OS_ANDROID)
  422. @@ -719,6 +727,7 @@ DownloadTargetDeterminer::Result
  423. return CONTINUE;
  424. }
  425. +#if defined(FULL_SAFE_BROWSING)
  426. // First determine the danger level assuming that the user doesn't have any
  427. // prior visits to the referrer recoreded in history. The resulting danger
  428. // level would be ALLOW_ON_USER_GESTURE if the level depends on the visit
  429. @@ -755,6 +764,7 @@ DownloadTargetDeterminer::Result
  430. // invalid, then assume the referrer has not been visited before.
  431. if (danger_type_ == download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)
  432. danger_type_ = download::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE;
  433. +#endif
  434. return CONTINUE;
  435. }
  436. @@ -762,11 +772,13 @@ void DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone(
  437. bool visited_referrer_before) {
  438. DCHECK_CURRENTLY_ON(BrowserThread::UI);
  439. DCHECK_EQ(STATE_DETERMINE_INTERMEDIATE_PATH, next_state_);
  440. +#if defined(FULL_SAFE_BROWSING)
  441. danger_level_ = GetDangerLevel(
  442. visited_referrer_before ? VISITED_REFERRER : NO_VISITS_TO_REFERRER);
  443. if (danger_level_ != DownloadFileType::NOT_DANGEROUS &&
  444. danger_type_ == download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)
  445. danger_type_ = download::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE;
  446. +#endif
  447. DoLoop();
  448. }
  449. @@ -861,7 +873,9 @@ void DownloadTargetDeterminer::ScheduleCallbackAndDeleteSelf(
  450. << " Intermediate:" << intermediate_path_.AsUTF8Unsafe()
  451. << " Confirmation reason:" << static_cast<int>(confirmation_reason_)
  452. << " Danger type:" << danger_type_
  453. +#if defined(FULL_SAFE_BROWSING)
  454. << " Danger level:" << danger_level_
  455. +#endif
  456. << " Result:" << static_cast<int>(result);
  457. std::unique_ptr<DownloadTargetInfo> target_info(new DownloadTargetInfo);
  458. @@ -873,7 +887,9 @@ void DownloadTargetDeterminer::ScheduleCallbackAndDeleteSelf(
  459. ? DownloadItem::TARGET_DISPOSITION_PROMPT
  460. : DownloadItem::TARGET_DISPOSITION_OVERWRITE);
  461. target_info->danger_type = danger_type_;
  462. +#if defined(FULL_SAFE_BROWSING)
  463. target_info->danger_level = danger_level_;
  464. +#endif
  465. target_info->intermediate_path = intermediate_path_;
  466. target_info->mime_type = mime_type_;
  467. target_info->is_filetype_handled_safely = is_filetype_handled_safely_;
  468. @@ -959,6 +975,7 @@ bool DownloadTargetDeterminer::HasPromptedForPath() const {
  469. DownloadItem::TARGET_DISPOSITION_PROMPT);
  470. }
  471. +#if defined(FULL_SAFE_BROWSING)
  472. DownloadFileType::DangerLevel DownloadTargetDeterminer::GetDangerLevel(
  473. PriorVisitsToReferrer visits) const {
  474. DCHECK_CURRENTLY_ON(BrowserThread::UI);
  475. @@ -990,6 +1007,7 @@ DownloadFileType::DangerLevel DownloadTargetDeterminer::GetDangerLevel(
  476. return DownloadFileType::NOT_DANGEROUS;
  477. }
  478. +#endif
  479. void DownloadTargetDeterminer::OnDownloadDestroyed(
  480. DownloadItem* download) {
  481. diff --git a/chrome/browser/download/download_target_determiner.h b/chrome/browser/download/download_target_determiner.h
  482. --- a/chrome/browser/download/download_target_determiner.h
  483. +++ b/chrome/browser/download/download_target_determiner.h
  484. @@ -17,7 +17,9 @@
  485. #include "chrome/browser/download/download_path_reservation_tracker.h"
  486. #include "chrome/browser/download/download_target_determiner_delegate.h"
  487. #include "chrome/browser/download/download_target_info.h"
  488. +#if defined(FULL_SAFE_BROWSING)
  489. #include "chrome/common/safe_browsing/download_file_types.pb.h"
  490. +#endif
  491. #include "components/download/public/common/download_danger_type.h"
  492. #include "components/download/public/common/download_item.h"
  493. #include "content/public/browser/download_manager_delegate.h"
  494. @@ -297,6 +299,7 @@ class DownloadTargetDeterminer : public download::DownloadItem::Observer {
  495. // operation.
  496. bool HasPromptedForPath() const;
  497. +#if defined(FULL_SAFE_BROWSING)
  498. // Returns true if this download should show the "dangerous file" warning.
  499. // Various factors are considered, such as the type of the file, whether a
  500. // user action initiated the download, and whether the user has explicitly
  501. @@ -306,6 +309,7 @@ class DownloadTargetDeterminer : public download::DownloadItem::Observer {
  502. // to true if the download requires explicit user consent.
  503. safe_browsing::DownloadFileType::DangerLevel GetDangerLevel(
  504. PriorVisitsToReferrer visits) const;
  505. +#endif
  506. // download::DownloadItem::Observer
  507. void OnDownloadDestroyed(download::DownloadItem* download) override;
  508. @@ -317,7 +321,9 @@ class DownloadTargetDeterminer : public download::DownloadItem::Observer {
  509. bool create_target_directory_;
  510. DownloadPathReservationTracker::FilenameConflictAction conflict_action_;
  511. download::DownloadDangerType danger_type_;
  512. +#if defined(FULL_SAFE_BROWSING)
  513. safe_browsing::DownloadFileType::DangerLevel danger_level_;
  514. +#endif
  515. base::FilePath virtual_path_;
  516. base::FilePath local_path_;
  517. base::FilePath intermediate_path_;
  518. diff --git a/chrome/browser/download/download_target_info.cc b/chrome/browser/download/download_target_info.cc
  519. --- a/chrome/browser/download/download_target_info.cc
  520. +++ b/chrome/browser/download/download_target_info.cc
  521. @@ -4,12 +4,16 @@
  522. #include "chrome/browser/download/download_target_info.h"
  523. +#if defined(FULL_SAFE_BROWSING)
  524. #include "chrome/common/safe_browsing/file_type_policies.h"
  525. +#endif
  526. DownloadTargetInfo::DownloadTargetInfo()
  527. : target_disposition(download::DownloadItem::TARGET_DISPOSITION_OVERWRITE),
  528. danger_type(download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
  529. +#if defined(FULL_SAFE_BROWSING)
  530. danger_level(safe_browsing::DownloadFileType::NOT_DANGEROUS),
  531. +#endif
  532. is_filetype_handled_safely(false),
  533. result(download::DOWNLOAD_INTERRUPT_REASON_NONE) {}
  534. diff --git a/chrome/browser/download/download_target_info.h b/chrome/browser/download/download_target_info.h
  535. --- a/chrome/browser/download/download_target_info.h
  536. +++ b/chrome/browser/download/download_target_info.h
  537. @@ -8,7 +8,9 @@
  538. #include <string>
  539. #include "base/files/file_path.h"
  540. +#if defined(FULL_SAFE_BROWSING)
  541. #include "chrome/common/safe_browsing/download_file_types.pb.h"
  542. +#endif
  543. #include "components/download/public/common/download_danger_type.h"
  544. #include "components/download/public/common/download_interrupt_reasons.h"
  545. #include "components/download/public/common/download_item.h"
  546. @@ -32,6 +34,7 @@ struct DownloadTargetInfo {
  547. // Danger type of the download.
  548. download::DownloadDangerType danger_type;
  549. +#if defined(FULL_SAFE_BROWSING)
  550. // The danger type of the download could be set to MAYBE_DANGEROUS_CONTENT if
  551. // the file type is handled by SafeBrowsing. However, if the SafeBrowsing
  552. // service is unable to verify whether the file is safe or not, we are on our
  553. @@ -57,6 +60,7 @@ struct DownloadTargetInfo {
  554. // SafeBrowsing may flag the file as being malicious, in which case the
  555. // malicious classification should take precedence.
  556. safe_browsing::DownloadFileType::DangerLevel danger_level;
  557. +#endif
  558. // Suggested intermediate path. The downloaded bytes should be written to this
  559. // path until all the bytes are available and the user has accepted a
  560. diff --git a/chrome/browser/download/download_ui_model.cc b/chrome/browser/download/download_ui_model.cc
  561. --- a/chrome/browser/download/download_ui_model.cc
  562. +++ b/chrome/browser/download/download_ui_model.cc
  563. @@ -23,7 +23,9 @@
  564. using base::TimeDelta;
  565. using download::DownloadItem;
  566. +#if defined(FULL_SAFE_BROWSING)
  567. using safe_browsing::DownloadFileType;
  568. +#endif
  569. using offline_items_collection::FailState;
  570. namespace {
  571. @@ -368,12 +370,14 @@ bool DownloadUIModel::ShouldPreferOpeningInBrowser() const {
  572. void DownloadUIModel::SetShouldPreferOpeningInBrowser(bool preference) {}
  573. +#if defined(FULL_SAFE_BROWSING)
  574. DownloadFileType::DangerLevel DownloadUIModel::GetDangerLevel() const {
  575. return DownloadFileType::NOT_DANGEROUS;
  576. }
  577. void DownloadUIModel::SetDangerLevel(
  578. DownloadFileType::DangerLevel danger_level) {}
  579. +#endif
  580. void DownloadUIModel::OpenUsingPlatformHandler() {}
  581. diff --git a/chrome/browser/download/download_ui_model.h b/chrome/browser/download/download_ui_model.h
  582. --- a/chrome/browser/download/download_ui_model.h
  583. +++ b/chrome/browser/download/download_ui_model.h
  584. @@ -14,7 +14,9 @@
  585. #include "base/strings/string16.h"
  586. #include "build/build_config.h"
  587. #include "chrome/browser/profiles/profile_manager.h"
  588. +#if defined(FULL_SAFE_BROWSING)
  589. #include "chrome/common/safe_browsing/download_file_types.pb.h"
  590. +#endif
  591. #include "components/download/public/common/download_item.h"
  592. #include "components/offline_items_collection/core/offline_item.h"
  593. @@ -172,6 +174,7 @@ class DownloadUIModel {
  594. // Change what's returned by ShouldPreferOpeningInBrowser to |preference|.
  595. virtual void SetShouldPreferOpeningInBrowser(bool preference);
  596. +#if defined(FULL_SAFE_BROWSING)
  597. // Return the danger level determined during download target determination.
  598. // The value returned here is independent of the danger level as determined by
  599. // the Safe Browsing.
  600. @@ -180,6 +183,7 @@ class DownloadUIModel {
  601. // Change what's returned by GetDangerLevel().
  602. virtual void SetDangerLevel(
  603. safe_browsing::DownloadFileType::DangerLevel danger_level);
  604. +#endif
  605. // Open the download using the platform handler for the download. The behavior
  606. // of this method will be different from DownloadItem::OpenDownload() if
  607. diff --git a/chrome/browser/loader/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/loader/chrome_resource_dispatcher_host_delegate.cc
  608. --- a/chrome/browser/loader/chrome_resource_dispatcher_host_delegate.cc
  609. +++ b/chrome/browser/loader/chrome_resource_dispatcher_host_delegate.cc
  610. @@ -421,14 +421,18 @@ void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles(
  611. content::ResourceContext* resource_context,
  612. ResourceType resource_type,
  613. std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) {
  614. +#if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
  615. ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
  616. +#endif // defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
  617. // Insert either safe browsing or data reduction proxy throttle at the front
  618. // of the list, so one of them gets to decide if the resource is safe.
  619. content::ResourceThrottle* first_throttle = NULL;
  620. #if defined(OS_ANDROID)
  621. +#if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
  622. first_throttle = DataReductionProxyResourceThrottle::MaybeCreate(
  623. request, resource_context, resource_type, nullptr);
  624. +#endif
  625. #endif // defined(OS_ANDROID)
  626. #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
  627. diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc
  628. --- a/chrome/browser/net/chrome_network_delegate.cc
  629. +++ b/chrome/browser/net/chrome_network_delegate.cc
  630. @@ -78,19 +78,6 @@ namespace {
  631. bool g_access_to_all_files_enabled = false;
  632. -// Gets called when the extensions finish work on the URL. If the extensions
  633. -// did not do a redirect (so |new_url| is empty) then we enforce the
  634. -// SafeSearch parameters. Otherwise we will get called again after the
  635. -// redirect and we enforce SafeSearch then.
  636. -void ForceGoogleSafeSearchCallbackWrapper(net::CompletionOnceCallback callback,
  637. - net::URLRequest* request,
  638. - GURL* new_url,
  639. - int rv) {
  640. - if (rv == net::OK && new_url->is_empty())
  641. - safe_search_util::ForceGoogleSafeSearch(request->url(), new_url);
  642. - std::move(callback).Run(rv);
  643. -}
  644. -
  645. bool IsAccessAllowedInternal(const base::FilePath& path,
  646. const base::FilePath& profile_path) {
  647. if (g_access_to_all_files_enabled)
  648. @@ -212,26 +199,8 @@ int ChromeNetworkDelegate::OnBeforeURLRequest(
  649. GURL* new_url) {
  650. extensions_delegate_->ForwardStartRequestStatus(request);
  651. - // The non-redirect case is handled in GoogleURLLoaderThrottle.
  652. - bool force_safe_search =
  653. - (force_google_safe_search_ && force_google_safe_search_->GetValue() &&
  654. - request->is_redirecting());
  655. -
  656. - net::CompletionOnceCallback wrapped_callback = std::move(callback);
  657. -
  658. - if (force_safe_search) {
  659. - wrapped_callback = base::BindOnce(
  660. - &ForceGoogleSafeSearchCallbackWrapper, std::move(wrapped_callback),
  661. - base::Unretained(request), base::Unretained(new_url));
  662. - }
  663. -
  664. - int rv = extensions_delegate_->NotifyBeforeURLRequest(
  665. - request, std::move(wrapped_callback), new_url);
  666. -
  667. - if (force_safe_search && rv == net::OK && new_url->is_empty())
  668. - safe_search_util::ForceGoogleSafeSearch(request->url(), new_url);
  669. -
  670. - return rv;
  671. + return extensions_delegate_->NotifyBeforeURLRequest(
  672. + request, std::move(callback), new_url);
  673. }
  674. int ChromeNetworkDelegate::OnBeforeStartTransaction(
  675. --
  676. 2.11.0