Remove initial size from WebContentsView::CreateView()

The size is not used intentionally because it can be wrong, but is
plumbed around by everyone anyways. The only consumer is for browser
plugin. Since the size is updated shortly after (that's why it is ok
to ignore says the comment in WebContentsViewAura) we don't need all
these setters and plumbings just for WebContentsViewGuest.

R=avi@chromium.org
TBR=halliwell

Bug: 998273
Change-Id: I5e783a3469a36f108766cdd256e629039dadc2f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790483
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: Luke Halliwell <halliwell@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696095}
diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc
index f7e171b..37d63ff 100644
--- a/chrome/browser/ui/browser_navigator.cc
+++ b/chrome/browser/ui/browser_navigator.cc
@@ -410,8 +410,6 @@
         params.opener->GetProcess()->GetID();
   }
   if (params.source_contents) {
-    create_params.initial_size =
-        params.source_contents->GetContainerBounds().size();
     create_params.created_with_opener = params.created_with_opener;
   }
   if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
diff --git a/chrome/browser/ui/browser_navigator_browsertest.cc b/chrome/browser/ui/browser_navigator_browsertest.cc
index 92572514..398409d 100644
--- a/chrome/browser/ui/browser_navigator_browsertest.cc
+++ b/chrome/browser/ui/browser_navigator_browsertest.cc
@@ -148,11 +148,6 @@
       initialize_renderer
           ? WebContents::CreateParams::kInitializeAndWarmupRendererProcess
           : WebContents::CreateParams::kOkayToHaveRendererProcess;
-  WebContents* base_web_contents =
-      browser()->tab_strip_model()->GetActiveWebContents();
-  if (base_web_contents) {
-    create_params.initial_size = base_web_contents->GetContainerBounds().size();
-  }
   return WebContents::Create(create_params);
 }
 
diff --git a/chrome/browser/ui/browser_tabrestore.cc b/chrome/browser/ui/browser_tabrestore.cc
index 2b5f55b..2179d42 100644
--- a/chrome/browser/ui/browser_tabrestore.cc
+++ b/chrome/browser/ui/browser_tabrestore.cc
@@ -68,11 +68,6 @@
   create_params.desired_renderer_state =
       WebContents::CreateParams::kNoRendererProcess;
   create_params.last_active_time = last_active_time;
-  WebContents* base_web_contents =
-      browser->tab_strip_model()->GetActiveWebContents();
-  if (base_web_contents) {
-    create_params.initial_size = base_web_contents->GetContainerBounds().size();
-  }
   std::unique_ptr<WebContents> web_contents =
       WebContents::CreateWithSessionStorage(create_params,
                                             session_storage_namespace_map);
diff --git a/chromecast/browser/cast_web_view_default.cc b/chromecast/browser/cast_web_view_default.cc
index 5a1a700..f15440a 100644
--- a/chromecast/browser/cast_web_view_default.cc
+++ b/chromecast/browser/cast_web_view_default.cc
@@ -42,12 +42,9 @@
     content::BrowserContext* browser_context,
     scoped_refptr<content::SiteInstance> site_instance) {
   CHECK(display::Screen::GetScreen());
-  gfx::Size display_size =
-      display::Screen::GetScreen()->GetPrimaryDisplay().size();
 
   content::WebContents::CreateParams create_params(browser_context, NULL);
   create_params.routing_id = MSG_ROUTING_NONE;
-  create_params.initial_size = display_size;
   create_params.site_instance = site_instance;
   return content::WebContents::Create(create_params);
 }
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 72043cf..ca4ee9d 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -1945,7 +1945,7 @@
   view_.reset(CreateWebContentsView(
       this, GetContentClient()->browser()->GetWebContentsViewDelegate(this),
       &render_view_host_delegate_view_));
-  view_->CreateView(GetPreferredSize(), nullptr);
+  view_->CreateView(nullptr);
   std::unique_ptr<WebContents> web_contents =
       node_.DisconnectFromOuterWebContents();
   DCHECK_EQ(web_contents.get(), this);
@@ -2040,7 +2040,6 @@
   // We pass our own opener so that the cloned page can access it if it was set
   // before.
   CreateParams create_params(GetBrowserContext(), GetSiteInstance());
-  create_params.initial_size = GetContainerBounds().size();
   FrameTreeNode* opener = frame_tree_.root()->opener();
   RenderFrameHostImpl* opener_rfh = nullptr;
   if (opener)
@@ -2155,8 +2154,7 @@
   CHECK(render_view_host_delegate_view_);
   CHECK(view_.get());
 
-  gfx::Size initial_size = params.initial_size;
-  view_->CreateView(initial_size, params.context);
+  view_->CreateView(params.context);
 
 #if BUILDFLAG(ENABLE_PLUGINS)
   plugin_content_origin_whitelist_.reset(
@@ -2874,7 +2872,6 @@
   std::unique_ptr<WebContents> new_contents;
   if (!is_guest) {
     create_params.context = view_->GetNativeView();
-    create_params.initial_size = GetContainerBounds().size();
     new_contents = WebContents::Create(create_params);
   }  else {
     new_contents = base::WrapUnique(
diff --git a/content/browser/web_contents/web_contents_impl_browsertest.cc b/content/browser/web_contents/web_contents_impl_browsertest.cc
index 3cb0de9..881fdc6 100644
--- a/content/browser/web_contents/web_contents_impl_browsertest.cc
+++ b/content/browser/web_contents/web_contents_impl_browsertest.cc
@@ -2567,8 +2567,6 @@
       base_web_contents->GetBrowserContext());
   create_params.desired_renderer_state =
       WebContents::CreateParams::kInitializeAndWarmupRendererProcess;
-  create_params.initial_size =
-      base_web_contents->GetContainerBounds().size();
   std::unique_ptr<WebContents> web_contents(WebContents::Create(create_params));
   ASSERT_TRUE(web_contents);
 
@@ -2619,7 +2617,6 @@
         base_web_contents->GetBrowserContext());
     create_params.desired_renderer_state =
         WebContents::CreateParams::kNoRendererProcess;
-    create_params.initial_size = base_web_contents->GetContainerBounds().size();
     std::unique_ptr<WebContents> web_contents(
         WebContents::Create(create_params));
     ASSERT_TRUE(web_contents);
@@ -2678,8 +2675,6 @@
       base_web_contents->GetBrowserContext());
   create_params.desired_renderer_state =
       WebContents::CreateParams::kInitializeAndWarmupRendererProcess;
-  create_params.initial_size =
-      base_web_contents->GetContainerBounds().size();
   std::unique_ptr<WebContents> web_contents(WebContents::Create(create_params));
   ASSERT_TRUE(web_contents);
 
@@ -3789,7 +3784,6 @@
   // the WebContents is fully controlled by the app.
   WebContents::CreateParams create_params(
       attached_web_contents->GetBrowserContext(), nullptr /* site_instance */);
-  create_params.initial_size = gfx::Size(100, 100);
   std::unique_ptr<WebContents> web_contents =
       WebContents::Create(create_params);
   EXPECT_EQ(Visibility::VISIBLE, web_contents->GetVisibility());
@@ -3864,7 +3858,6 @@
 
   WebContents::CreateParams create_params(
       attached_web_contents->GetBrowserContext(), /*site_instance=*/nullptr);
-  create_params.initial_size = gfx::Size(100, 100);
   std::unique_ptr<WebContents> public_web_contents =
       WebContents::Create(create_params);
   auto* web_contents = static_cast<WebContentsImpl*>(public_web_contents.get());
diff --git a/content/browser/web_contents/web_contents_view.h b/content/browser/web_contents/web_contents_view.h
index bfb918a..bff5b42 100644
--- a/content/browser/web_contents/web_contents_view.h
+++ b/content/browser/web_contents/web_contents_view.h
@@ -78,8 +78,7 @@
   // Get the bounds of the View, relative to the parent.
   virtual gfx::Rect GetViewBounds() const = 0;
 
-  virtual void CreateView(
-      const gfx::Size& initial_size, gfx::NativeView context) = 0;
+  virtual void CreateView(gfx::NativeView context) = 0;
 
   // Sets up the View that holds the rendered web page, receives messages for
   // it and contains page plugins. The host view should be sized to the current
diff --git a/content/browser/web_contents/web_contents_view_android.cc b/content/browser/web_contents/web_contents_view_android.cc
index 10086ffc..9d82699 100644
--- a/content/browser/web_contents/web_contents_view_android.cc
+++ b/content/browser/web_contents/web_contents_view_android.cc
@@ -229,9 +229,7 @@
   return gfx::Rect(view_.GetSize());
 }
 
-void WebContentsViewAndroid::CreateView(
-    const gfx::Size& initial_size, gfx::NativeView context) {
-}
+void WebContentsViewAndroid::CreateView(gfx::NativeView context) {}
 
 RenderWidgetHostViewBase* WebContentsViewAndroid::CreateViewForWidget(
     RenderWidgetHost* render_widget_host, bool is_guest_view_hack) {
diff --git a/content/browser/web_contents/web_contents_view_android.h b/content/browser/web_contents/web_contents_view_android.h
index 37358129..59579dc 100644
--- a/content/browser/web_contents/web_contents_view_android.h
+++ b/content/browser/web_contents/web_contents_view_android.h
@@ -68,8 +68,7 @@
   void FocusThroughTabTraversal(bool reverse) override;
   DropData* GetDropData() const override;
   gfx::Rect GetViewBounds() const override;
-  void CreateView(const gfx::Size& initial_size,
-                  gfx::NativeView context) override;
+  void CreateView(gfx::NativeView context) override;
   RenderWidgetHostViewBase* CreateViewForWidget(
       RenderWidgetHost* render_widget_host,
       bool is_guest_view_hack) override;
diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc
index dda92e4..ac096c7 100644
--- a/content/browser/web_contents/web_contents_view_aura.cc
+++ b/content/browser/web_contents/web_contents_view_aura.cc
@@ -932,12 +932,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 // WebContentsViewAura, WebContentsView implementation:
 
-void WebContentsViewAura::CreateView(const gfx::Size& initial_size,
-                                     gfx::NativeView context) {
-  // NOTE: we ignore |initial_size| since in some cases it's wrong (such as
-  // if the bookmark bar is not shown and you create a new tab). The right
-  // value is set shortly after this, so its safe to ignore.
-
+void WebContentsViewAura::CreateView(gfx::NativeView context) {
   CreateAuraWindow(context);
 
   // delegate_->GetDragDestDelegate() creates a new delegate on every call.
diff --git a/content/browser/web_contents/web_contents_view_aura.h b/content/browser/web_contents/web_contents_view_aura.h
index ed3c8d8..149aeb2b 100644
--- a/content/browser/web_contents/web_contents_view_aura.h
+++ b/content/browser/web_contents/web_contents_view_aura.h
@@ -118,8 +118,7 @@
   void FocusThroughTabTraversal(bool reverse) override;
   DropData* GetDropData() const override;
   gfx::Rect GetViewBounds() const override;
-  void CreateView(const gfx::Size& initial_size,
-                  gfx::NativeView context) override;
+  void CreateView(gfx::NativeView context) override;
   RenderWidgetHostViewBase* CreateViewForWidget(
       RenderWidgetHost* render_widget_host,
       bool is_guest_view_hack) override;
diff --git a/content/browser/web_contents/web_contents_view_child_frame.cc b/content/browser/web_contents/web_contents_view_child_frame.cc
index 1a68298..a766385 100644
--- a/content/browser/web_contents/web_contents_view_child_frame.cc
+++ b/content/browser/web_contents/web_contents_view_child_frame.cc
@@ -77,8 +77,7 @@
   return gfx::Rect();
 }
 
-void WebContentsViewChildFrame::CreateView(const gfx::Size& initial_size,
-                                           gfx::NativeView context) {
+void WebContentsViewChildFrame::CreateView(gfx::NativeView context) {
   // The WebContentsViewChildFrame does not have a native view.
 }
 
diff --git a/content/browser/web_contents/web_contents_view_child_frame.h b/content/browser/web_contents/web_contents_view_child_frame.h
index 8aaa801..412bb35 100644
--- a/content/browser/web_contents/web_contents_view_child_frame.h
+++ b/content/browser/web_contents/web_contents_view_child_frame.h
@@ -36,8 +36,7 @@
   void FocusThroughTabTraversal(bool reverse) override;
   DropData* GetDropData() const override;
   gfx::Rect GetViewBounds() const override;
-  void CreateView(const gfx::Size& initial_size,
-                  gfx::NativeView context) override;
+  void CreateView(gfx::NativeView context) override;
   RenderWidgetHostViewBase* CreateViewForWidget(
       RenderWidgetHost* render_widget_host,
       bool is_guest_view_hack) override;
diff --git a/content/browser/web_contents/web_contents_view_guest.cc b/content/browser/web_contents/web_contents_view_guest.cc
index ecaf30b..c45581f 100644
--- a/content/browser/web_contents/web_contents_view_guest.cc
+++ b/content/browser/web_contents/web_contents_view_guest.cc
@@ -113,10 +113,8 @@
   return gfx::Rect(size_);
 }
 
-void WebContentsViewGuest::CreateView(const gfx::Size& initial_size,
-                                      gfx::NativeView context) {
-  platform_view_->CreateView(initial_size, context);
-  size_ = initial_size;
+void WebContentsViewGuest::CreateView(gfx::NativeView context) {
+  platform_view_->CreateView(context);
 }
 
 RenderWidgetHostViewBase* WebContentsViewGuest::CreateViewForWidget(
diff --git a/content/browser/web_contents/web_contents_view_guest.h b/content/browser/web_contents/web_contents_view_guest.h
index 913fbc4..12aa7cd 100644
--- a/content/browser/web_contents/web_contents_view_guest.h
+++ b/content/browser/web_contents/web_contents_view_guest.h
@@ -54,8 +54,7 @@
   void FocusThroughTabTraversal(bool reverse) override;
   DropData* GetDropData() const override;
   gfx::Rect GetViewBounds() const override;
-  void CreateView(const gfx::Size& initial_size,
-                  gfx::NativeView context) override;
+  void CreateView(gfx::NativeView context) override;
   RenderWidgetHostViewBase* CreateViewForWidget(
       RenderWidgetHost* render_widget_host,
       bool is_guest_view_hack) override;
diff --git a/content/browser/web_contents/web_contents_view_mac.h b/content/browser/web_contents/web_contents_view_mac.h
index 35da7e5..6fdec8c 100644
--- a/content/browser/web_contents/web_contents_view_mac.h
+++ b/content/browser/web_contents/web_contents_view_mac.h
@@ -73,8 +73,7 @@
   void FocusThroughTabTraversal(bool reverse) override;
   DropData* GetDropData() const override;
   gfx::Rect GetViewBounds() const override;
-  void CreateView(const gfx::Size& initial_size,
-                  gfx::NativeView context) override;
+  void CreateView(gfx::NativeView context) override;
   RenderWidgetHostViewBase* CreateViewForWidget(
       RenderWidgetHost* render_widget_host,
       bool is_guest_view_hack) override;
diff --git a/content/browser/web_contents/web_contents_view_mac.mm b/content/browser/web_contents/web_contents_view_mac.mm
index b35b9b4..4721a9b 100644
--- a/content/browser/web_contents/web_contents_view_mac.mm
+++ b/content/browser/web_contents/web_contents_view_mac.mm
@@ -315,8 +315,7 @@
   return gfx::ScreenRectFromNSRect(window_bounds);
 }
 
-void WebContentsViewMac::CreateView(
-    const gfx::Size& initial_size, gfx::NativeView context) {
+void WebContentsViewMac::CreateView(gfx::NativeView context) {
   in_process_ns_view_bridge_ =
       std::make_unique<remote_cocoa::WebContentsNSViewBridge>(ns_view_id_,
                                                               this);
diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h
index b5ff1cc5..17c509c 100644
--- a/content/public/browser/web_contents.h
+++ b/content/public/browser/web_contents.h
@@ -152,9 +152,6 @@
     // window.open('', 'bar')).
     std::string main_frame_name;
 
-    // Initial size of the new WebContent's view. Can be (0, 0) if not needed.
-    gfx::Size initial_size;
-
     // True if the contents should be initially hidden.
     bool initially_hidden;
 
diff --git a/content/shell/browser/shell.cc b/content/shell/browser/shell.cc
index 2ad5069..d2229f1 100644
--- a/content/shell/browser/shell.cc
+++ b/content/shell/browser/shell.cc
@@ -231,11 +231,10 @@
     create_params.starting_sandbox_flags =
         blink::kPresentationReceiverSandboxFlags;
   }
-  create_params.initial_size = AdjustWindowSize(initial_size);
   std::unique_ptr<WebContents> web_contents =
       WebContents::Create(create_params);
   Shell* shell =
-      CreateShell(std::move(web_contents), create_params.initial_size,
+      CreateShell(std::move(web_contents), AdjustWindowSize(initial_size),
                   true /* should_set_delegate */);
   if (!url.is_empty())
     shell->LoadURL(url);
@@ -254,14 +253,13 @@
     create_params.starting_sandbox_flags =
         blink::kPresentationReceiverSandboxFlags;
   }
-  create_params.initial_size = AdjustWindowSize(initial_size);
   std::map<std::string, scoped_refptr<SessionStorageNamespace>>
       session_storages;
   session_storages[""] = session_storage_namespace;
   std::unique_ptr<WebContents> web_contents =
       WebContents::CreateWithSessionStorage(create_params, session_storages);
   Shell* shell =
-      CreateShell(std::move(web_contents), create_params.initial_size,
+      CreateShell(std::move(web_contents), AdjustWindowSize(initial_size),
                   true /* should_set_delegate */);
   if (!url.is_empty())
     shell->LoadURL(url);
diff --git a/headless/lib/browser/headless_web_contents_impl.cc b/headless/lib/browser/headless_web_contents_impl.cc
index 5a69748..a59f28f 100644
--- a/headless/lib/browser/headless_web_contents_impl.cc
+++ b/headless/lib/browser/headless_web_contents_impl.cc
@@ -249,12 +249,8 @@
     HeadlessWebContents::Builder* builder) {
   content::WebContents::CreateParams create_params(builder->browser_context_,
                                                    nullptr);
-  create_params.initial_size = builder->window_size_;
-
-  std::unique_ptr<HeadlessWebContentsImpl> headless_web_contents =
-      base::WrapUnique(new HeadlessWebContentsImpl(
-          content::WebContents::Create(create_params),
-          builder->browser_context_));
+  auto headless_web_contents = base::WrapUnique(new HeadlessWebContentsImpl(
+      content::WebContents::Create(create_params), builder->browser_context_));
 
   headless_web_contents->begin_frame_control_enabled_ =
       builder->enable_begin_frame_control_ ||
diff --git a/weblayer/browser/browser_controller_impl.cc b/weblayer/browser/browser_controller_impl.cc
index 36c88b4..fdce547b 100644
--- a/weblayer/browser/browser_controller_impl.cc
+++ b/weblayer/browser/browser_controller_impl.cc
@@ -24,12 +24,10 @@
 
 namespace weblayer {
 
-BrowserControllerImpl::BrowserControllerImpl(ProfileImpl* profile,
-                                             const gfx::Size& initial_size)
+BrowserControllerImpl::BrowserControllerImpl(ProfileImpl* profile)
     : profile_(profile) {
   content::WebContents::CreateParams create_params(
       profile_->GetBrowserContext());
-  create_params.initial_size = initial_size;
   web_contents_ = content::WebContents::Create(create_params);
 
   web_contents_->SetDelegate(this);
@@ -66,9 +64,8 @@
 #if defined(OS_ANDROID)
 static jlong JNI_BrowserControllerImpl_CreateBrowserController(JNIEnv* env,
                                                                jlong profile) {
-  // TODO: figure out size.
-  return reinterpret_cast<intptr_t>(new BrowserControllerImpl(
-      reinterpret_cast<ProfileImpl*>(profile), gfx::Size()));
+  return reinterpret_cast<intptr_t>(
+      new BrowserControllerImpl(reinterpret_cast<ProfileImpl*>(profile)));
 }
 
 static void JNI_BrowserControllerImpl_DeleteBrowserController(
@@ -142,11 +139,9 @@
 #endif
 }
 
-std::unique_ptr<BrowserController> BrowserController::Create(
-    Profile* profile,
-    const gfx::Size& initial_size) {
+std::unique_ptr<BrowserController> BrowserController::Create(Profile* profile) {
   return std::make_unique<BrowserControllerImpl>(
-      static_cast<ProfileImpl*>(profile), initial_size);
+      static_cast<ProfileImpl*>(profile));
 }
 
 }  // namespace weblayer
diff --git a/weblayer/browser/browser_controller_impl.h b/weblayer/browser/browser_controller_impl.h
index 5067d12a..1b8821d 100644
--- a/weblayer/browser/browser_controller_impl.h
+++ b/weblayer/browser/browser_controller_impl.h
@@ -32,7 +32,7 @@
                               public content::WebContentsDelegate,
                               public content::WebContentsObserver {
  public:
-  BrowserControllerImpl(ProfileImpl* profile, const gfx::Size& initial_size);
+  explicit BrowserControllerImpl(ProfileImpl* profile);
   ~BrowserControllerImpl() override;
 
   content::WebContents* web_contents() const { return web_contents_.get(); }
diff --git a/weblayer/public/browser_controller.h b/weblayer/public/browser_controller.h
index 5670977..f66bc54 100644
--- a/weblayer/public/browser_controller.h
+++ b/weblayer/public/browser_controller.h
@@ -9,10 +9,6 @@
 
 #include "build/build_config.h"
 
-namespace gfx {
-class Size;
-}
-
 #if !defined(OS_ANDROID)
 namespace views {
 class WebView;
@@ -27,10 +23,7 @@
 // Represents a browser window that is navigable.
 class BrowserController {
  public:
-  // Pass an empty |path| for an in-memory profile.
-  static std::unique_ptr<BrowserController> Create(
-      Profile* profile,
-      const gfx::Size& initial_size);
+  static std::unique_ptr<BrowserController> Create(Profile* profile);
 
   virtual ~BrowserController() {}
 
diff --git a/weblayer/shell/browser/shell.cc b/weblayer/shell/browser/shell.cc
index 1c46cae..8a4b6c0 100644
--- a/weblayer/shell/browser/shell.cc
+++ b/weblayer/shell/browser/shell.cc
@@ -118,11 +118,10 @@
 Shell* Shell::CreateNewWindow(weblayer::Profile* web_profile,
                               const GURL& url,
                               const gfx::Size& initial_size) {
-  auto adjusted_size = AdjustWindowSize(initial_size);
-  auto browser_controller =
-      BrowserController::Create(web_profile, adjusted_size);
+  auto browser_controller = BrowserController::Create(web_profile);
 
-  Shell* shell = CreateShell(std::move(browser_controller), adjusted_size);
+  Shell* shell = CreateShell(std::move(browser_controller),
+                             AdjustWindowSize(initial_size));
   if (!url.is_empty())
     shell->LoadURL(url);
   return shell;