Move Shell platform-specific code out to ShellPlatformDelegate

Reland of https://chromium-review.googlesource.com/c/chromium/src/+/2185445

This drops the shell_$PLATFORM files, and introduces a singleton
ShellPlatformDelegate, owned by the ShellBrowserMainParts, which
provides platform-specific code. Shell calls out to this delegate
instead of providing platform-specific implementations itself.

Why are we doing this?

1) While working on https://chromium-review.googlesource.com/c/chromium/src/+/2180920
   I discovered that Mac is lying about the window screen rect in the
   renderer but actually never hears about about the window screen
   rect in RenderWidgetHost{View} in the browser, leaving it at 0x0. It
   does not hear about this in web tests headless mode because the
   view is detached from any platform window.
2) In order to make that CL in 1) work, we need to inform the
   RenderWidgetHostViewMac (or RenderWidgetHostImpl) directly about
   the window screen rect. Adding content public APIs to do this would
   not be ideal.
3) Since we don't want to add public APIs, we need code in
   Shell::SizeTo() for mac that informs the RenderWidgetHostViewMac
   but this code also needs to be in a web_test/ directory in order
   to access //content/browser and see the RenderWidgetHostViewMac
   type.
4) We could have Shell call out to web_test/ code directly when
   running in web test mode. However that would prevent us from our
   future goals of making content_shell not a test-only target, and
   not depending on web_test/ code from Shell.

Thus, we introduce the ShellPlatformDelegate which we will be able
to subclass in web_test/ in order to do the inform of the
RenderWidgetHostViewMac of the window screen rect when the Shell
is resized.

[email protected]

Bug: 866140, 1069111
Change-Id: I111a742134498a9aa2040240105b2f42f1315b81
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2190043
Reviewed-by: Avi Drissman <[email protected]>
Commit-Queue: danakj <[email protected]>
Cr-Commit-Position: refs/heads/master@{#767839}
diff --git a/content/shell/browser/shell_platform_delegate_aura.cc b/content/shell/browser/shell_platform_delegate_aura.cc
new file mode 100644
index 0000000..802947e
--- /dev/null
+++ b/content/shell/browser/shell_platform_delegate_aura.cc
@@ -0,0 +1,85 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/shell/browser/shell_platform_delegate.h"
+
+#include "content/public/browser/web_contents.h"
+#include "content/shell/browser/shell.h"
+#include "content/shell/browser/shell_platform_data_aura.h"
+#include "ui/aura/env.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_event_dispatcher.h"
+
+namespace content {
+
+struct ShellPlatformDelegate::ShellData {
+  gfx::NativeWindow window;
+};
+
+struct ShellPlatformDelegate::PlatformData {
+  std::unique_ptr<ShellPlatformDataAura> aura;
+};
+
+ShellPlatformDelegate::ShellPlatformDelegate() = default;
+ShellPlatformDelegate::~ShellPlatformDelegate() = default;
+
+void ShellPlatformDelegate::Initialize(const gfx::Size& default_window_size) {
+  platform_ = std::make_unique<PlatformData>();
+  platform_->aura =
+      std::make_unique<ShellPlatformDataAura>(default_window_size);
+}
+
+void ShellPlatformDelegate::CreatePlatformWindow(
+    Shell* shell,
+    const gfx::Size& initial_size) {
+  ShellData* shell_data = new ShellData;
+  shell->set_platform_data(shell_data);
+
+  if (!shell->headless())
+    platform_->aura->ShowWindow();
+  platform_->aura->ResizeWindow(initial_size);
+
+  shell_data->window = platform_->aura->host()->window();
+}
+
+gfx::NativeWindow ShellPlatformDelegate::GetNativeWindow(Shell* shell) {
+  ShellData* shell_data = shell->platform_data();
+  return shell_data->window;
+}
+
+void ShellPlatformDelegate::CleanUp(Shell* shell) {
+  ShellData* shell_data = shell->platform_data();
+
+  // Any ShellData cleanup happens here.
+
+  delete shell_data;
+  // This shouldn't be used anymore, but just in case.
+  shell->set_platform_data(nullptr);
+}
+
+void ShellPlatformDelegate::SetContents(Shell* shell) {
+  aura::Window* content = shell->web_contents()->GetNativeView();
+  aura::Window* parent = platform_->aura->host()->window();
+  if (!parent->Contains(content))
+    parent->AddChild(content);
+
+  content->Show();
+}
+
+void ShellPlatformDelegate::EnableUIControl(Shell* shell,
+                                            UIControl control,
+                                            bool is_enabled) {}
+
+void ShellPlatformDelegate::SetAddressBarURL(Shell* shell, const GURL& url) {}
+
+void ShellPlatformDelegate::SetIsLoading(Shell* shell, bool loading) {}
+
+void ShellPlatformDelegate::SetTitle(Shell* shell,
+                                     const base::string16& title) {}
+
+bool ShellPlatformDelegate::DestroyShell(Shell* shell) {
+  return false;  // Shell destroys itself.
+}
+
+}  // namespace content