Rename "swapped out" and "for oopif" in RenderWidget.

is swapped out => is frozen
for oopif => for child local root frame

"Swapped out" was used in RenderWidget as the term comes from
RenderViewHost, and RenderFrame. The main frame can be swapped out -
meaning hosted in another process. RenderWidget is a separate layer
of the code however and we would like to delete them but we can't,
so they must enter this state of "inactivity". Thus, frozen. Then
we can more clearly separate frozen RenderWidgets from swapped out
frames and freeze/thaw RenderWidgets more appropriately.

"For oopif" is confusing as it seems to mean the RenderWidget is not
in the same frame tree as the main frame. However it can be when
there is an oopif in between the frame in question and the main
frame. Rename it to be more clear about when it is true.

[email protected], [email protected]

Change-Id: I52e31acfbf098bfb993d1aea69b699b7bcbb8cbf
Bug: 905191, 419087
Reviewed-on: https://chromium-review.googlesource.com/c/1336218
Commit-Queue: danakj <[email protected]>
Reviewed-by: Antoine Labour <[email protected]>
Cr-Commit-Position: refs/heads/master@{#608808}
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index 910a2ea..56d06d661 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -381,7 +381,7 @@
                            WidgetType widget_type,
                            const ScreenInfo& screen_info,
                            blink::WebDisplayMode display_mode,
-                           bool swapped_out,
+                           bool is_frozen,
                            bool hidden,
                            bool never_visible,
                            mojom::WidgetRequest widget_request)
@@ -397,7 +397,7 @@
       ime_event_guard_(nullptr),
       closing_(false),
       host_will_close_this_(false),
-      is_swapped_out_(swapped_out),
+      is_frozen_(is_frozen),
       text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
       text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
       text_input_flags_(0),
@@ -413,7 +413,7 @@
       resizing_mode_selector_(new ResizingModeSelector()),
       has_host_context_menu_location_(false),
       has_focus_(false),
-      for_oopif_(false),
+      for_child_local_root_frame_(false),
 #if defined(OS_MACOSX)
       text_input_client_observer_(new TextInputClientObserver(this)),
 #endif
@@ -477,7 +477,7 @@
 
 void RenderWidget::InitForChildLocalRoot(
     blink::WebFrameWidget* web_frame_widget) {
-  for_oopif_ = true;
+  for_child_local_root_frame_ = true;
   // Init() increments the reference count on |this|, making it
   // self-referencing.
   Init(base::NullCallback(), web_frame_widget);
@@ -626,10 +626,12 @@
 
 bool RenderWidget::Send(IPC::Message* message) {
   // Don't send any messages after the browser has told us to close, and filter
-  // most outgoing messages while swapped out.
-  if ((is_swapped_out_ &&
-       !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
-      closing_) {
+  // most outgoing messages when frozen.
+  if (closing_) {
+    delete message;
+    return false;
+  }
+  if (is_frozen_ && !SwappedOutMessages::CanSendWhileSwappedOut(message)) {
     delete message;
     return false;
   }
@@ -653,7 +655,7 @@
   // will be processed regardless of page focus. We should revisit this after
   // page focus for OOPIFs has been fully resolved (https://crbug.com/689777).
   return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() &&
-         (has_focus_ || for_oopif_);
+         (has_focus_ || for_child_local_root_frame_);
 }
 
 void RenderWidget::OnClose() {
@@ -678,7 +680,7 @@
     }
   }
 
-  if (for_oopif_) {
+  if (for_child_local_root_frame_) {
     // Widgets for frames may be created and closed at any time while the frame
     // is alive. However, WebWidget must be closed synchronously because frame
     // widgets and frames hold pointers to each other. The deferred call to
@@ -806,7 +808,7 @@
   TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
   // TODO(crbug.com/896836): CHECK to try track down why we make a frame sink
   // for a RenderWidget without a main frame.
-  CHECK(!is_swapped_out_);
+  CHECK(!is_frozen_);
 
   // During shutdown we can just ignore this message.
   if (!GetWebWidget())
@@ -859,7 +861,7 @@
     const blink::WebCoalescedInputEvent& input_event,
     const ui::LatencyInfo& latency_info,
     HandledEventCallback callback) {
-  if (owner_delegate_ && is_swapped_out_) {
+  if (owner_delegate_ && is_frozen_) {
     std::move(callback).Run(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, latency_info,
                             nullptr, base::nullopt);
     return;
@@ -972,8 +974,8 @@
   // For widgets that are never visible, we don't start the compositor, so we
   // never get a request for a cc::LayerTreeFrameSink.
   DCHECK(!compositor_never_visible_);
-  // Swapped out RenderWidgets should not be doing any compositing.
-  DCHECK(!is_swapped_out_);
+  // Inactive RenderWidgets should not be doing any compositing.
+  DCHECK(!is_frozen_);
 
   if (is_closing()) {
     // In this case, we drop the request which means the compositor waits
@@ -984,10 +986,10 @@
   // TODO(crbug.com/896836): CHECK to try track down why we make a frame sink
   // for a RenderWidget without a main frame. If there's no frame widget then
   // there is no main frame. This only applies for widgets for frames.
-  CHECK(!is_swapped_out_);
+  CHECK(!is_frozen_);
   if (owner_delegate_)
     CHECK(GetFrameWidget());
-  if (for_oopif_)
+  if (for_child_local_root_frame_)
     CHECK(GetFrameWidget());
 
   // TODO(jonross): have this generated by the LayerTreeFrameSink itself, which
@@ -1006,7 +1008,13 @@
   // The |url| is not always available, fallback to a fixed string.
   if (url.is_empty())
     url = GURL("chrome://gpu/RenderWidget::RequestNewLayerTreeFrameSink");
-  const char* client_name = for_oopif_ ? kOOPIF : kRenderer;
+  // TODO(danakj): This may not be accurate, depending on the intent. A child
+  // local root could be in the same process as the view, so if the client is
+  // meant to designate the process type, it seems kRenderer would be the
+  // correct choice. If client is meant to designate the widget type, then
+  // kOOPIF would denote that it is not for the main frame. However, kRenderer
+  // would also be used for other widgets such as popups.
+  const char* client_name = for_child_local_root_frame_ ? kOOPIF : kRenderer;
   RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
       routing_id_, frame_swap_message_queue_, std::move(url),
       std::move(callback), std::move(client_request), std::move(ptr),
@@ -1536,7 +1544,7 @@
       compositor_deps_->GetTaskGraphRunner(),
       compositor_deps_->GetWebMainThreadScheduler());
   layer_tree_view_->Initialize(
-      GenerateLayerTreeSettings(compositor_deps_, for_oopif_,
+      GenerateLayerTreeSettings(compositor_deps_, for_child_local_root_frame_,
                                 screen_info_.rect.size(),
                                 screen_info_.device_scale_factor),
       compositor_deps_->CreateUkmRecorderFactory());
@@ -1553,7 +1561,7 @@
   if (!should_generate_frame_sink) {
     // Prevents SetVisible() from blink from doing anything.
     layer_tree_view_->SetNeverVisible();
-  } else if (!is_swapped_out_) {
+  } else if (!is_frozen_) {
     // Begins the compositor's scheduler to start producing frames.
     // Don't do this if the RenderWidget is attached to a RenderViewImpl for a
     // remote main frame, as this RenderWidget is a zombie then, which won't be
@@ -1589,10 +1597,10 @@
   layer_tree_view_->ReleaseLayerTreeFrameSink();
 }
 
-void RenderWidget::SetSwappedOut(bool is_swapped_out) {
-  DCHECK_NE(is_swapped_out, is_swapped_out_);
-  is_swapped_out_ = is_swapped_out;
-  if (is_swapped_out)
+void RenderWidget::SetIsFrozen(bool is_frozen) {
+  DCHECK_NE(is_frozen, is_frozen_);
+  is_frozen_ = is_frozen;
+  if (is_frozen)
     StopCompositor();
   else
     StartCompositor();
@@ -1612,8 +1620,8 @@
 
 void RenderWidget::CloseWidgetSoon() {
   DCHECK(content::RenderThread::Get());
-  if (is_swapped_out_) {
-    // This widget is currently swapped out, and the active widget is in a
+  if (is_frozen_) {
+    // This widget is currently not active. The active main frame widget is in a
     // different process.  Have the browser route the close request to the
     // active widget instead, so that the correct unload handlers are run.
     Send(new WidgetHostMsg_RouteCloseEvent(routing_id_));
@@ -1633,9 +1641,9 @@
 }
 
 void RenderWidget::Close() {
-  // This was done immediately in the |for_oopif_| case in the OnClose() IPC
-  // handler.
-  if (!for_oopif_)
+  // This was done immediately in the |for_child_local_root_frame_| case in the
+  // OnClose() IPC handler.
+  if (!for_child_local_root_frame_)
     CloseWebWidget();
 
   layer_tree_view_.reset();
@@ -1775,9 +1783,9 @@
   // This path is for the renderer to change the on-screen position/size of
   // the widget by changing its window rect. This is not possible for
   // RenderWidgets whose position/size are controlled by layout from another
-  // frame tree (ie. child local root frames, informed by |for_oopif_|), as
-  // the window rect can only be set by the browser.
-  if (for_oopif_)
+  // frame tree (ie. child local root frames), as the window rect can only be
+  // set by the browser.
+  if (for_child_local_root_frame_)
     return;
 
   WebRect window_rect = rect_in_screen;
@@ -3258,8 +3266,9 @@
 #endif
 
 gfx::Rect RenderWidget::ViewportVisibleRect() {
-  return for_oopif_ ? compositor_visible_rect_
-                    : gfx::Rect(compositor_viewport_pixel_size_);
+  return for_child_local_root_frame_
+             ? compositor_visible_rect_
+             : gfx::Rect(compositor_viewport_pixel_size_);
 }
 
 // static