🦁Add G icon for answers with no specific icon

This CL adds the G icon as a fallback icon for answers with no more
specific icon. It also renames the "currency" imageset to "stock" as
that icon is actually used for the stock price suggestion, not the
currency conversion suggestion (which uses the "conversion" icon).

Bug: 963860
Change-Id: I446a07cbab6b1a5ab0a38629947d09e17522499e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1614219
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661324}
diff --git a/ios/chrome/browser/ui/omnibox/BUILD.gn b/ios/chrome/browser/ui/omnibox/BUILD.gn
index c1ae2d2..08d80078 100644
--- a/ios/chrome/browser/ui/omnibox/BUILD.gn
+++ b/ios/chrome/browser/ui/omnibox/BUILD.gn
@@ -53,6 +53,8 @@
     "//components/omnibox/browser",
     "//ios/chrome/browser/ui:feature_flags",
     "//ios/chrome/browser/ui/colors",
+    "//ios/public/provider/chrome/browser",
+    "//ios/public/provider/chrome/browser/images",
     "//url",
   ]
 }
@@ -75,9 +77,9 @@
   deps = [
     "resources:answer_calculator",
     "resources:answer_conversion",
-    "resources:answer_currency",
     "resources:answer_dictionary",
     "resources:answer_local_time",
+    "resources:answer_stock",
     "resources:answer_sunrise",
     "resources:answer_translation",
     "resources:answer_when_is",
diff --git a/ios/chrome/browser/ui/omnibox/omnibox_icon_formatter.h b/ios/chrome/browser/ui/omnibox/omnibox_icon_formatter.h
index 3cea6eb..11ba9cf 100644
--- a/ios/chrome/browser/ui/omnibox/omnibox_icon_formatter.h
+++ b/ios/chrome/browser/ui/omnibox/omnibox_icon_formatter.h
@@ -17,6 +17,10 @@
     NS_DESIGNATED_INITIALIZER;
 - (instancetype)init NS_UNAVAILABLE;
 
+// Whether the default search engine is Google impacts which icon is used in
+// some cases
+@property(nonatomic, assign) BOOL defaultSearchEngineIsGoogle;
+
 @end
 
 #endif  // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_ICON_FORMATTER_H_
diff --git a/ios/chrome/browser/ui/omnibox/omnibox_icon_formatter.mm b/ios/chrome/browser/ui/omnibox/omnibox_icon_formatter.mm
index 1fc253f..9832978 100644
--- a/ios/chrome/browser/ui/omnibox/omnibox_icon_formatter.mm
+++ b/ios/chrome/browser/ui/omnibox/omnibox_icon_formatter.mm
@@ -8,6 +8,8 @@
 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
 #import "ios/chrome/browser/ui/omnibox/omnibox_util.h"
 #import "ios/chrome/browser/ui/ui_feature_flags.h"
+#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
+#include "ios/public/provider/chrome/browser/images/branded_image_provider.h"
 #import "url/gurl.h"
 
 #if !defined(__has_feature) || !__has_feature(objc_arc)
@@ -19,14 +21,12 @@
 OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType(
     AutocompleteMatchType::Type type,
     base::Optional<int> answerType) {
-  // Some suggestions have custom icons. Others fallback to the icon from the
-  // overall match type.
   if (answerType) {
     switch (answerType.value()) {
       case SuggestionAnswer::ANSWER_TYPE_DICTIONARY:
         return DICTIONARY;
       case SuggestionAnswer::ANSWER_TYPE_FINANCE:
-        return CURRENCY;
+        return STOCK;
       case SuggestionAnswer::ANSWER_TYPE_TRANSLATION:
         return TRANSLATION;
       case SuggestionAnswer::ANSWER_TYPE_WHEN_IS:
@@ -41,7 +41,7 @@
       case SuggestionAnswer::ANSWER_TYPE_LOCAL_TIME:
       case SuggestionAnswer::ANSWER_TYPE_PLAY_INSTALL:
       case SuggestionAnswer::ANSWER_TYPE_WEATHER:
-        break;
+        return FALLBACK_ANSWER;
       case SuggestionAnswer::ANSWER_TYPE_INVALID:
       case SuggestionAnswer::ANSWER_TYPE_TOTAL_COUNT:
         NOTREACHED();
@@ -127,10 +127,12 @@
 }
 
 - (UIImage*)iconImage {
-  NSString* imageName =
-      GetOmniboxNewSuggestionIconTypeAssetName(self.suggestionIconType);
-  return [[UIImage imageNamed:imageName]
-      imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
+  if (self.suggestionIconType == FALLBACK_ANSWER &&
+      self.defaultSearchEngineIsGoogle && [self fallbackAnswerBrandedIcon]) {
+    return [[self fallbackAnswerBrandedIcon]
+        imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
+  }
+  return GetOmniboxSuggestionIcon(self.suggestionIconType);
 }
 
 - (BOOL)hasCustomAnswerIcon {
@@ -143,18 +145,32 @@
     case CALCULATOR:
     case CONVERSION:
     case DICTIONARY:
-    case CURRENCY:
+    case STOCK:
     case SUNRISE:
     case LOCAL_TIME:
     case WHEN_IS:
     case TRANSLATION:
       return YES;
+    // For the fallback answer, this depends on whether the branded icon exists
+    // and whether the default search engine is Google (the icon only exists for
+    // Google branding).
+    // The default fallback answer icon uses the grey background styling, like
+    // the non-answer icons.
+    case FALLBACK_ANSWER:
+      return self.defaultSearchEngineIsGoogle &&
+             [self fallbackAnswerBrandedIcon];
     case OMNIBOX_SUGGESTION_ICON_TYPE_COUNT:
       NOTREACHED();
       return NO;
   }
 }
 
+- (UIImage*)fallbackAnswerBrandedIcon {
+  return ios::GetChromeBrowserProvider()
+      ->GetBrandedImageProvider()
+      ->GetOmniboxAnswerIcon();
+}
+
 - (UIColor*)iconImageTintColor {
   switch (self.iconType) {
     case OmniboxIconTypeImage:
diff --git a/ios/chrome/browser/ui/omnibox/omnibox_util.h b/ios/chrome/browser/ui/omnibox/omnibox_util.h
index a0a661b0..aa47ea0 100644
--- a/ios/chrome/browser/ui/omnibox/omnibox_util.h
+++ b/ios/chrome/browser/ui/omnibox/omnibox_util.h
@@ -21,11 +21,14 @@
   SEARCH,
   CONVERSION,
   DICTIONARY,
-  CURRENCY,
+  STOCK,
   SUNRISE,
   LOCAL_TIME,
   WHEN_IS,
   TRANSLATION,
+  // The FALLBACK_ANSWER icon is used for all answers that don't have special
+  // icons above.
+  FALLBACK_ANSWER,
   OMNIBOX_SUGGESTION_ICON_TYPE_COUNT,
 };
 
diff --git a/ios/chrome/browser/ui/omnibox/omnibox_util.mm b/ios/chrome/browser/ui/omnibox/omnibox_util.mm
index d7f1c66..5405b40 100644
--- a/ios/chrome/browser/ui/omnibox/omnibox_util.mm
+++ b/ios/chrome/browser/ui/omnibox/omnibox_util.mm
@@ -36,7 +36,7 @@
     case DICTIONARY:
       NOTREACHED();
       return @"omnibox_completion_default_favicon";
-    case CURRENCY:
+    case STOCK:
       NOTREACHED();
       return @"omnibox_completion_default_favicon";
     case SUNRISE:
@@ -51,6 +51,9 @@
     case TRANSLATION:
       NOTREACHED();
       return @"omnibox_completion_default_favicon";
+    case FALLBACK_ANSWER:
+      NOTREACHED();
+      return @"omnibox_completion_default_favicon";
     case OMNIBOX_SUGGESTION_ICON_TYPE_COUNT:
       NOTREACHED();
       return @"omnibox_completion_default_favicon";
@@ -78,8 +81,8 @@
       return @"answer_conversion";
     case DICTIONARY:
       return @"answer_dictionary";
-    case CURRENCY:
-      return @"answer_currency";
+    case STOCK:
+      return @"answer_stock";
     case SUNRISE:
       return @"answer_sunrise";
     case LOCAL_TIME:
@@ -88,6 +91,8 @@
       return @"answer_when_is";
     case TRANSLATION:
       return @"answer_translation";
+    case FALLBACK_ANSWER:
+      return @"search";
     case OMNIBOX_SUGGESTION_ICON_TYPE_COUNT:
       NOTREACHED();
       return @"favicon_fallback";
@@ -95,9 +100,12 @@
 }
 
 UIImage* GetOmniboxSuggestionIcon(OmniboxSuggestionIconType iconType) {
-  NSString* imageName = GetOmniboxSuggestionIconTypeAssetName(iconType);
-  if (base::FeatureList::IsEnabled(kNewOmniboxPopupLayout))
+  NSString* imageName = nil;
+  if (base::FeatureList::IsEnabled(kNewOmniboxPopupLayout)) {
     imageName = GetOmniboxNewSuggestionIconTypeAssetName(iconType);
+  } else {
+    imageName = GetOmniboxSuggestionIconTypeAssetName(iconType);
+  }
   return [[UIImage imageNamed:imageName]
       imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
 }
diff --git a/ios/chrome/browser/ui/omnibox/popup/BUILD.gn b/ios/chrome/browser/ui/omnibox/popup/BUILD.gn
index 004f0bc..789a887 100644
--- a/ios/chrome/browser/ui/omnibox/popup/BUILD.gn
+++ b/ios/chrome/browser/ui/omnibox/popup/BUILD.gn
@@ -22,10 +22,12 @@
     "//components/image_fetcher/ios",
     "//components/omnibox/browser",
     "//components/open_from_clipboard",
+    "//components/search_engines",
     "//ios/chrome/app/strings",
     "//ios/chrome/browser",
     "//ios/chrome/browser/browser_state",
     "//ios/chrome/browser/favicon",
+    "//ios/chrome/browser/search_engines",
     "//ios/chrome/browser/ui:feature_flags",
     "//ios/chrome/browser/ui/commands",
     "//ios/chrome/browser/ui/ntp:util",
diff --git a/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.h b/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.h
index ec10cb8..ff0a49c 100644
--- a/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.h
+++ b/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.h
@@ -8,12 +8,17 @@
 #import "ios/chrome/browser/ui/omnibox/popup/autocomplete_suggestion.h"
 
 struct AutocompleteMatch;
+
 @interface AutocompleteMatchFormatter : NSObject <AutocompleteSuggestion>
 
 // This is a temporary solution for coloring strings.
 @property(nonatomic, assign, getter=isIncognito) BOOL incognito;
 @property(nonatomic, assign, getter=isStarred) BOOL starred;
 
+// Whether the default search engine is Google impacts which icon is used in
+// some cases
+@property(nonatomic, assign) BOOL defaultSearchEngineIsGoogle;
+
 - (instancetype)initWithMatch:(const AutocompleteMatch&)match
     NS_DESIGNATED_INITIALIZER;
 - (instancetype)init NS_UNAVAILABLE;
diff --git a/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.mm b/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.mm
index edb3c61..5efb9a0 100644
--- a/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.mm
+++ b/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.mm
@@ -146,7 +146,10 @@
 }
 
 - (id<OmniboxIcon>)icon {
-  return [[OmniboxIconFormatter alloc] initWithMatch:_match];
+  OmniboxIconFormatter* icon =
+      [[OmniboxIconFormatter alloc] initWithMatch:_match];
+  icon.defaultSearchEngineIsGoogle = self.defaultSearchEngineIsGoogle;
+  return icon;
 }
 
 - (NSInteger)numberOfLines {
diff --git a/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_coordinator.mm b/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_coordinator.mm
index 0b01cf6..c0380e3 100644
--- a/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_coordinator.mm
+++ b/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_coordinator.mm
@@ -8,8 +8,10 @@
 #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h"
 #include "components/omnibox/browser/autocomplete_result.h"
 #include "components/omnibox/common/omnibox_features.h"
+#import "components/search_engines/template_url_service.h"
 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
 #include "ios/chrome/browser/favicon/ios_chrome_favicon_loader_factory.h"
+#include "ios/chrome/browser/search_engines/template_url_service_factory.h"
 #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
 #import "ios/chrome/browser/ui/ntp/ntp_util.h"
 #import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_legacy_view_controller.h"
@@ -68,6 +70,13 @@
              delegate:_popupView.get()];
   self.mediator.dispatcher = (id<BrowserCommands>)self.dispatcher;
   self.mediator.webStateList = self.webStateList;
+  TemplateURLService* templateURLService =
+      ios::TemplateURLServiceFactory::GetForBrowserState(self.browserState);
+  self.mediator.defaultSearchEngineIsGoogle =
+      templateURLService && templateURLService->GetDefaultSearchProvider() &&
+      templateURLService->GetDefaultSearchProvider()->GetEngineType(
+          templateURLService->search_terms_data()) == SEARCH_ENGINE_GOOGLE;
+
   if (base::FeatureList::IsEnabled(kNewOmniboxPopupLayout)) {
     self.popupViewController = [[OmniboxPopupViewController alloc] init];
   } else {
diff --git a/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.h b/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.h
index aa3ddb2..55b8f37 100644
--- a/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.h
+++ b/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.h
@@ -66,6 +66,9 @@
 @property(nonatomic, strong) OmniboxPopupPresenter* presenter;
 // The web state list this mediator is handling.
 @property(nonatomic, assign) WebStateList* webStateList;
+// Whether the default search engine is Google impacts which icon is used in
+// some cases
+@property(nonatomic, assign) BOOL defaultSearchEngineIsGoogle;
 
 // Designated initializer. Takes ownership of |imageFetcher|.
 - (instancetype)initWithFetcher:
diff --git a/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.mm b/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.mm
index aed8b27..f34485e 100644
--- a/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.mm
+++ b/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.mm
@@ -81,6 +81,7 @@
         [AutocompleteMatchFormatter formatterWithMatch:match];
     formatter.starred = _delegate->IsStarredMatch(match);
     formatter.incognito = _incognito;
+    formatter.defaultSearchEngineIsGoogle = self.defaultSearchEngineIsGoogle;
     [wrappedMatches addObject:formatter];
   }
 
diff --git a/ios/chrome/browser/ui/omnibox/resources/BUILD.gn b/ios/chrome/browser/ui/omnibox/resources/BUILD.gn
index 36f68a2..43c652a 100644
--- a/ios/chrome/browser/ui/omnibox/resources/BUILD.gn
+++ b/ios/chrome/browser/ui/omnibox/resources/BUILD.gn
@@ -100,11 +100,11 @@
   ]
 }
 
-imageset("answer_currency") {
+imageset("answer_stock") {
   sources = [
-    "answer_currency.imageset/Contents.json",
-    "answer_currency.imageset/answer_currency@2x.png",
-    "answer_currency.imageset/answer_currency@3x.png",
+    "answer_stock.imageset/Contents.json",
+    "answer_stock.imageset/answer_stock@2x.png",
+    "answer_stock.imageset/answer_stock@3x.png",
   ]
 }
 
diff --git a/ios/chrome/browser/ui/omnibox/resources/answer_currency.imageset/Contents.json b/ios/chrome/browser/ui/omnibox/resources/answer_stock.imageset/Contents.json
similarity index 72%
rename from ios/chrome/browser/ui/omnibox/resources/answer_currency.imageset/Contents.json
rename to ios/chrome/browser/ui/omnibox/resources/answer_stock.imageset/Contents.json
index b1ef0a8..714c3b3 100644
--- a/ios/chrome/browser/ui/omnibox/resources/answer_currency.imageset/Contents.json
+++ b/ios/chrome/browser/ui/omnibox/resources/answer_stock.imageset/Contents.json
@@ -3,12 +3,12 @@
         {
             "idiom": "universal",
             "scale": "2x",
-            "filename": "answer_currency@2x.png"
+            "filename": "answer_stock@2x.png"
         },
         {
             "idiom": "universal",
             "scale": "3x",
-            "filename": "answer_currency@3x.png"
+            "filename": "answer_stock@3x.png"
         }
     ],
     "info": {
diff --git a/ios/chrome/browser/ui/omnibox/resources/answer_currency.imageset/answer_currency@2x.png b/ios/chrome/browser/ui/omnibox/resources/answer_stock.imageset/answer_stock@2x.png
similarity index 100%
rename from ios/chrome/browser/ui/omnibox/resources/answer_currency.imageset/answer_currency@2x.png
rename to ios/chrome/browser/ui/omnibox/resources/answer_stock.imageset/answer_stock@2x.png
Binary files differ
diff --git a/ios/chrome/browser/ui/omnibox/resources/answer_currency.imageset/answer_currency@3x.png b/ios/chrome/browser/ui/omnibox/resources/answer_stock.imageset/answer_stock@3x.png
similarity index 100%
rename from ios/chrome/browser/ui/omnibox/resources/answer_currency.imageset/answer_currency@3x.png
rename to ios/chrome/browser/ui/omnibox/resources/answer_stock.imageset/answer_stock@3x.png
Binary files differ
diff --git a/ios/public/provider/chrome/browser/images/branded_image_provider.h b/ios/public/provider/chrome/browser/images/branded_image_provider.h
index a2c721d..03da08c 100644
--- a/ios/public/provider/chrome/browser/images/branded_image_provider.h
+++ b/ios/public/provider/chrome/browser/images/branded_image_provider.h
@@ -54,6 +54,10 @@
   virtual UIImage* GetToolbarSearchIcon(SearchEngineIcon type,
                                         bool dark_version);
 
+  // Returns the 30pt x 30pt image to use for the fallback icon for answers in
+  // the omnibox popup and in the omnibox as the default search engine icon.
+  virtual UIImage* GetOmniboxAnswerIcon();
+
  private:
   DISALLOW_COPY_AND_ASSIGN(BrandedImageProvider);
 };
diff --git a/ios/public/provider/chrome/browser/images/branded_image_provider.mm b/ios/public/provider/chrome/browser/images/branded_image_provider.mm
index 2867b0c..1a3164f 100644
--- a/ios/public/provider/chrome/browser/images/branded_image_provider.mm
+++ b/ios/public/provider/chrome/browser/images/branded_image_provider.mm
@@ -51,3 +51,7 @@
                                                     bool dark_version) {
   return [UIImage imageNamed:@"toolbar_search"];
 }
+
+UIImage* BrandedImageProvider::GetOmniboxAnswerIcon() {
+  return nil;
+}