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

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