1 // Copyright 2019 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 CHROME_BROWSER_UI_QRCODE_GENERATOR_QRCODE_GENERATOR_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_QRCODE_GENERATOR_QRCODE_GENERATOR_BUBBLE_CONTROLLER_H_
7 
8 #include "base/macros.h"
9 #include "base/strings/string16.h"
10 #include "content/public/browser/web_contents_user_data.h"
11 
12 class GURL;
13 
14 namespace content {
15 class WebContents;
16 }
17 
18 namespace qrcode_generator {
19 
20 class QRCodeGeneratorBubbleView;
21 
22 // Controller component of the QR Code Generator dialog bubble.
23 // Responsible for showing and hiding an owned bubble.
24 class QRCodeGeneratorBubbleController
25     : public content::WebContentsUserData<QRCodeGeneratorBubbleController> {
26  public:
27   ~QRCodeGeneratorBubbleController() override;
28 
29   // Returns whether the generator is available for a given page and
30   // state (incognito etc.).
31   static bool IsGeneratorAvailable(const GURL& url, bool in_incognito);
32 
33   static QRCodeGeneratorBubbleController* Get(
34       content::WebContents* web_contents);
35 
36   // Displays the QR Code Generator bubble.
37   void ShowBubble(const GURL& url);
38 
39   // Hides the QR Code Generator bubble.
40   void HideBubble();
41 
42   // Returns nullptr if no bubble is currently shown.
43   QRCodeGeneratorBubbleView* qrcode_generator_bubble_view() const;
44 
45   // Handler for when the bubble is dismissed.
46   void OnBubbleClosed();
47 
48  protected:
49   explicit QRCodeGeneratorBubbleController(content::WebContents* web_contents);
50 
51  private:
52   QRCodeGeneratorBubbleController();
53 
54   friend class content::WebContentsUserData<QRCodeGeneratorBubbleController>;
55 
56   // The web_contents associated with this controller.
57   content::WebContents* web_contents_;
58 
59   // Will be nullptr if no bubble is currently shown.
60   QRCodeGeneratorBubbleView* qrcode_generator_bubble_ = nullptr;
61 
62   WEB_CONTENTS_USER_DATA_KEY_DECL();
63 
64   DISALLOW_COPY_AND_ASSIGN(QRCodeGeneratorBubbleController);
65 };
66 
67 }  // namespace qrcode_generator
68 
69 #endif  // CHROME_BROWSER_UI_QRCODE_GENERATOR_QRCODE_GENERATOR_BUBBLE_CONTROLLER_H_
70