From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@slack-corp.com>
Date: Tue, 25 Feb 2020 13:28:30 -0800
Subject: feat: add support for overriding the base spellchecker download URL

This patch is required as the testing-only method we were using does not
take into account the dictionary name and therefore will not work for
production use cases.  This is unlikely to be upstreamed as the change
is entirely in //chrome.

diff --git a/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc b/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc
index 48b7a20c212578ba9055b781b5c05b312fa7e974..d7d92f326ba94be7a3960d527bc2b6d8d15890fa 100644
--- a/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc
+++ b/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc
@@ -13,6 +13,7 @@
 #include "base/functional/bind.h"
 #include "base/lazy_instance.h"
 #include "base/location.h"
+#include "base/no_destructor.h"
 #include "base/notreached.h"
 #include "base/observer_list.h"
 #include "base/path_service.h"
@@ -49,6 +50,8 @@ namespace {
 base::LazyInstance<GURL>::Leaky g_download_url_for_testing =
     LAZY_INSTANCE_INITIALIZER;
 
+base::NoDestructor<GURL> g_base_download_url_override;
+
 // Close the file.
 void CloseDictionary(base::File file) {
   base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
@@ -265,6 +268,10 @@ void SpellcheckHunspellDictionary::SetDownloadURLForTesting(const GURL url) {
   g_download_url_for_testing.Get() = url;
 }
 
+void SpellcheckHunspellDictionary::SetBaseDownloadURL(const GURL url) {
+  *g_base_download_url_override = url;
+}
+
 GURL SpellcheckHunspellDictionary::GetDictionaryURL() {
   if (g_download_url_for_testing.Get() != GURL())
     return g_download_url_for_testing.Get();
@@ -272,6 +279,9 @@ GURL SpellcheckHunspellDictionary::GetDictionaryURL() {
   std::string bdict_file = dictionary_file_.path.BaseName().MaybeAsASCII();
   DCHECK(!bdict_file.empty());
 
+  if (*g_base_download_url_override != GURL())
+    return GURL(g_base_download_url_override->spec() + base::ToLowerASCII(bdict_file));
+
   static const char kDownloadServerUrl[] =
       "https://redirector.gvt1.com/edgedl/chrome/dict/";
 
diff --git a/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h b/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h
index def025dbffec3f44074604fcfb441b769886c3ab..459e8be9dcbf6d3ede156b57abcf9c9ede5587c7 100644
--- a/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h
+++ b/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h
@@ -96,6 +96,8 @@ class SpellcheckHunspellDictionary : public SpellcheckDictionary {
   // Tests use this method to set a custom URL for downloading dictionaries.
   static void SetDownloadURLForTesting(const GURL url);
 
+  static void SetBaseDownloadURL(const GURL url);
+
  private:
   // Dictionary download status.
   enum DownloadStatus {
