Make sure bubbles in Views close before their RenderFrameHosts.

This is probably covered by navigation, but that isn't obvious from
reading the code, so this change adds code to close bubbles directly.

BUG=571466

Review URL: https://codereview.chromium.org/1572743002

Cr-Commit-Position: refs/heads/master@{#374503}
diff --git a/components/bubble/bubble_manager.h b/components/bubble/bubble_manager.h
index 3e2d838..5182381 100644
--- a/components/bubble/bubble_manager.h
+++ b/components/bubble/bubble_manager.h
@@ -15,6 +15,10 @@
 
 class BubbleDelegate;
 
+namespace content {
+class RenderFrameHost;
+}
+
 // Inherit from BubbleManager to show, update, and close bubbles.
 // Any class that inherits from BubbleManager should capture any events that
 // should dismiss a bubble or update its anchor point.
@@ -69,6 +73,10 @@
   // Will close any open bubbles and prevent new ones from being shown.
   void FinalizePendingRequests();
 
+  // Closes bubbles that declare |frame| as their owner, with
+  // a reason of BUBBLE_CLOSE_FRAME_DESTROYED.
+  void CloseBubblesOwnedBy(const content::RenderFrameHost* frame);
+
  private:
   enum ManagerState {
     SHOW_BUBBLES,
@@ -76,10 +84,12 @@
     ITERATING_BUBBLES,
   };
 
-  // All bubbles will get a close event for the specified |reason| if |match| is
-  // nullptr, otherwise only the bubble held by |match| will get a close event.
-  // Any bubble that is closed will also be deleted.
-  bool CloseAllMatchingBubbles(BubbleController* match,
+  // All matching bubbles will get a close event for the specified |reason|. Any
+  // bubble that is closed will also be deleted. Bubbles match if 1) |bubble| is
+  // null or it refers to the bubble, and 2) |owner| is null or owns the bubble.
+  // At most one can be non-null.
+  bool CloseAllMatchingBubbles(BubbleController* bubble,
+                               const content::RenderFrameHost* owner,
                                BubbleCloseReason reason);
 
   base::ObserverList<BubbleManagerObserver> observers_;