1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64

content / browser / android / render_widget_host_connector.h [blame]

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_ANDROID_RENDER_WIDGET_HOST_CONNECTOR_H_
#define CONTENT_BROWSER_ANDROID_RENDER_WIDGET_HOST_CONNECTOR_H_

#include "base/gtest_prod_util.h"
#include "content/browser/renderer_host/render_widget_host_view_android.h"
#include "content/public/browser/web_contents_observer.h"

namespace content {

// A base class used to connect an object of the content layer lifecycle
// to |RenderWidgetHostViewAndroid|. The inherting class needs to
// override |UpdateRenderProcessConnection| to set itself to the RWHVA
// brought up foreground, and null out its reference in the RWHVA going
// away so it won't access the object any more.
// This class owns itself and gets deleted when the WebContents is deleted.
// Can also delete this object early (before the WebContents is destroyed)
// by calling Destroy directly.
class RenderWidgetHostConnector {
 public:
  explicit RenderWidgetHostConnector(WebContents* web_contents);

  RenderWidgetHostConnector(const RenderWidgetHostConnector&) = delete;
  RenderWidgetHostConnector& operator=(const RenderWidgetHostConnector&) =
      delete;

  virtual ~RenderWidgetHostConnector();

  // Establish initial connection to rwhva if it is present.
  void Initialize();

  // Method to set itself to the |new_rwhva|, and null out the reference
  // in |old_rwvha|. Example:
  //
  // if (old_rwhva)
  //   old_rwhva->set_object(nullptr);
  // if (new_rwhva)
  //   new_rwhva->set_object(this);
  virtual void UpdateRenderProcessConnection(
      RenderWidgetHostViewAndroid* old_rwhva,
      RenderWidgetHostViewAndroid* new_rhwva) = 0;

  RenderWidgetHostViewAndroid* GetRWHVAForTesting() const;

 protected:
  FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostConnectorTest, DestroyEarly);

  WebContents* web_contents() const;

  // Deletes this now. Note this is usually not required as this is
  // deleted when the corresponding WebContents is destroyed.
  void DestroyEarly();

 private:
  class Observer;
  std::unique_ptr<Observer> render_widget_observer_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_ANDROID_RENDER_WIDGET_HOST_CONNECTOR_H_