Convert ColorChooser from ipc to mojo.

Using a Factory to provide dedicated pipes for ColorChooser
and ColorChooserClient.  This removes the need for the identifier
currently in use for ipcs.  ColorChooserEnd messages
have been replaced with connection error handlers, and
each side can simply close the connection without explicitly
sending EndColorChooser msgs.

Replaced struct content::ColorSuggestion with
content::mojom::ColorSuggestion in content/public/common.


Bug: 788960
Change-Id: I436e277738bf0e37eda8bfa0fd7428aede015c43
Reviewed-on: https://chromium-review.googlesource.com/800350
Reviewed-by: John Abd-El-Malek <[email protected]>
Reviewed-by: Ken Rockot <[email protected]>
Reviewed-by: Ken Buchanan <[email protected]>
Reviewed-by: Nicholas Verne <[email protected]>
Reviewed-by: Sam McNally <[email protected]>
Commit-Queue: Joel Hockey <[email protected]>
Cr-Commit-Position: refs/heads/master@{#523071}
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
index b4ca68a..f66256f 100644
--- a/content/browser/web_contents/web_contents_impl.h
+++ b/content/browser/web_contents/web_contents_impl.h
@@ -35,6 +35,7 @@
 #include "content/browser/renderer_host/render_view_host_impl.h"
 #include "content/browser/renderer_host/render_widget_host_delegate.h"
 #include "content/browser/wake_lock/wake_lock_context_host.h"
+#include "content/common/color_chooser.mojom.h"
 #include "content/common/content_export.h"
 #include "content/public/browser/color_chooser.h"
 #include "content/public/browser/download_url_parameters.h"
@@ -96,7 +97,6 @@
 class WebContentsView;
 class WebContentsViewDelegate;
 struct AXEventNotificationDetails;
-struct ColorSuggestion;
 struct FaviconURL;
 struct LoadNotificationDetails;
 struct MHTMLGenerationParams;
@@ -127,6 +127,7 @@
                                        public RenderViewHostDelegate,
                                        public RenderWidgetHostDelegate,
                                        public RenderFrameHostManager::Delegate,
+                                       public mojom::ColorChooserFactory,
                                        public NotificationObserver,
                                        public NavigationControllerDelegate,
                                        public NavigatorDelegate {
@@ -771,6 +772,15 @@
   int GetOuterDelegateFrameTreeNodeId() override;
   RenderWidgetHostImpl* GetFullscreenRenderWidgetHost() const override;
 
+  // content::mojom::ColorChooserFactory ---------------------------------------
+
+  void OnColorChooserFactoryRequest(mojom::ColorChooserFactoryRequest request);
+  void OpenColorChooser(
+      mojom::ColorChooserRequest chooser,
+      mojom::ColorChooserClientPtr client,
+      SkColor color,
+      std::vector<mojom::ColorSuggestionPtr> suggestions) override;
+
   // NotificationObserver ------------------------------------------------------
 
   void Observe(int type,
@@ -1119,14 +1129,6 @@
   void OnAppCacheAccessed(RenderViewHostImpl* source,
                           const GURL& manifest_url,
                           bool blocked_by_policy);
-  void OnOpenColorChooser(RenderFrameHostImpl* source,
-                          int color_chooser_id,
-                          SkColor color,
-                          const std::vector<ColorSuggestion>& suggestions);
-  void OnEndColorChooser(RenderFrameHostImpl* source, int color_chooser_id);
-  void OnSetSelectedColorInColorChooser(RenderFrameHostImpl* source,
-                                        int color_chooser_id,
-                                        SkColor color);
   void OnUpdatePageImportanceSignals(RenderFrameHostImpl* source,
                                      const PageImportanceSignals& signals);
 #if BUILDFLAG(ENABLE_PLUGINS)
@@ -1522,32 +1524,8 @@
 #endif
 
   // Holds information about a current color chooser dialog, if one is visible.
-  struct ColorChooserInfo {
-    ColorChooserInfo(int render_process_id,
-                     int render_frame_id,
-                     ColorChooser* chooser,
-                     int identifier);
-    ~ColorChooserInfo();
-
-    bool Matches(RenderFrameHostImpl* render_frame_host, int color_chooser_id);
-
-    int render_process_id;
-    int render_frame_id;
-
-    // Color chooser that was opened by this tab.
-    std::unique_ptr<ColorChooser> chooser;
-
-    // A unique identifier for the current color chooser.  Identifiers are
-    // unique across a renderer process.  This avoids race conditions in
-    // synchronizing the browser and renderer processes.  For example, if a
-    // renderer closes one chooser and opens another, and simultaneously the
-    // user picks a color in the first chooser, the IDs can be used to drop the
-    // "chose a color" message rather than erroneously tell the renderer that
-    // the user picked a color in the second chooser.
-    int identifier;
-  };
-
-  std::unique_ptr<ColorChooserInfo> color_chooser_info_;
+  class ColorChooser;
+  std::unique_ptr<ColorChooser> color_chooser_;
 
   // Manages the embedder state for browser plugins, if this WebContents is an
   // embedder; NULL otherwise.
@@ -1603,6 +1581,10 @@
 
   device::mojom::WakeLockPtr renderer_wake_lock_;
 
+  service_manager::BinderRegistry registry_;
+
+  mojo::BindingSet<mojom::ColorChooserFactory> color_chooser_factory_bindings_;
+
 #if defined(OS_ANDROID)
   std::unique_ptr<NFCHost> nfc_host_;
 #endif