blob: 94169ceee5d218215c4bbffe544446df366ff9b9 [file] [log] [blame]
hcarmonaaa431c02015-08-28 18:45:571// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_
6#define COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_
7
dchenga0ee5fb82016-04-26 02:46:558#include <memory>
9
avibc5337b2015-12-25 23:16:3310#include "base/macros.h"
hcarmonaaa431c02015-08-28 18:45:5711#include "base/memory/weak_ptr.h"
hcarmona3e2a58c22015-09-08 23:46:1512#include "base/threading/thread_checker.h"
hcarmonaaa431c02015-08-28 18:45:5713#include "components/bubble/bubble_close_reason.h"
14
15class BubbleDelegate;
16class BubbleManager;
hcarmona3e2a58c22015-09-08 23:46:1517class BubbleUi;
spqchan41368d62017-09-28 00:40:2518class ExtensionInstalledBubbleBrowserTest;
jyasskin4a12e672016-02-09 22:39:0719namespace content {
20class RenderFrameHost;
21}
22
hcarmonaaa431c02015-08-28 18:45:5723// BubbleController is responsible for the lifetime of the delegate and its UI.
24class BubbleController : public base::SupportsWeakPtr<BubbleController> {
25 public:
26 explicit BubbleController(BubbleManager* manager,
dchenga0ee5fb82016-04-26 02:46:5527 std::unique_ptr<BubbleDelegate> delegate);
hcarmonaaa431c02015-08-28 18:45:5728 virtual ~BubbleController();
29
30 // Calls CloseBubble on the associated BubbleManager.
31 bool CloseBubble(BubbleCloseReason reason);
32
hcarmonaaa431c02015-08-28 18:45:5733 private:
34 friend class BubbleManager;
spqchan41368d62017-09-28 00:40:2535 friend class ExtensionInstalledBubbleBrowserTest;
hcarmonaaa431c02015-08-28 18:45:5736
37 // Creates and shows the UI for the delegate.
38 void Show();
39
40 // Notifies the bubble UI that it should update its anchor location.
41 // Important when there's a UI change (ex: fullscreen transition).
42 void UpdateAnchorPosition();
43
hcarmonade570002015-09-30 01:33:3644 // Returns true if the bubble should be closed.
45 bool ShouldClose(BubbleCloseReason reason) const;
46
jyasskin4a12e672016-02-09 22:39:0747 // Returns true if |frame| owns this bubble.
48 bool OwningFrameIs(const content::RenderFrameHost* frame) const;
49
hcarmonade570002015-09-30 01:33:3650 // Cleans up the delegate and its UI.
hcarmona5d511072016-02-23 23:23:5351 void DoClose(BubbleCloseReason reason);
hcarmonaaa431c02015-08-28 18:45:5752
53 BubbleManager* manager_;
dchenga0ee5fb82016-04-26 02:46:5554 std::unique_ptr<BubbleDelegate> delegate_;
55 std::unique_ptr<BubbleUi> bubble_ui_;
hcarmona3e2a58c22015-09-08 23:46:1556
57 // Verify that functions that affect the UI are done on the same thread.
58 base::ThreadChecker thread_checker_;
hcarmonaaa431c02015-08-28 18:45:5759
hcarmonaaa431c02015-08-28 18:45:5760 DISALLOW_COPY_AND_ASSIGN(BubbleController);
61};
62
63#endif // COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_