Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / website_settings / permission_bubble_manager.h
1 // Copyright 2014 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_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
7
8 #include <vector>
9
10 #include "base/timer/timer.h"
11 #include "chrome/browser/ui/website_settings/permission_bubble_view.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h"
14
15 class PermissionBubbleRequest;
16
17 // Provides access to permissions bubbles. Allows clients to add a request
18 // callback interface to the existing permission bubble configuration.
19 // Depending on the situation and policy, that may add new UI to an existing
20 // permission bubble, create and show a new permission bubble, or provide no
21 // visible UI action at all. (In that case, the request will be immediately
22 // informed that the permission request failed.)
23 //
24 // A PermissionBubbleManager is associated with a particular WebContents.
25 // Requests attached to a particular WebContents' PBM must outlive it.
26 //
27 // The PermissionBubbleManager should be addressed on the UI thread.
28 class PermissionBubbleManager
29     : public content::WebContentsObserver,
30       public content::WebContentsUserData<PermissionBubbleManager>,
31       public PermissionBubbleView::Delegate {
32  public:
33   // Return the flag-driven enabled state of permissions bubbles.
34   static bool Enabled();
35
36   virtual ~PermissionBubbleManager();
37
38   // Add a new request to the permission bubble. Ownership of the request
39   // remains with the caller. The caller must arrange for the request to
40   // outlive the PermissionBubbleManager. If a bubble is visible when this
41   // call is made, the request will be queued up and shown after the current
42   // bubble closes.
43   virtual void AddRequest(PermissionBubbleRequest* request);
44
45   // Set the active view for the permission bubble. If this is NULL, it
46   // means the permission bubble is no longer showing.
47   virtual void SetView(PermissionBubbleView* view) OVERRIDE;
48
49  protected:
50   // Sets the coalesce time interval to |interval_ms|. For testing only.
51   void SetCoalesceIntervalForTesting(int interval_ms);
52
53  private:
54   friend class PermissionBubbleManagerTest;
55   friend class content::WebContentsUserData<PermissionBubbleManager>;
56
57   explicit PermissionBubbleManager(content::WebContents* web_contents);
58
59   // contents::WebContentsObserver:
60   // TODO(leng):  Investigate the ordering and timing of page loading and
61   // permission requests with iFrames. DocumentOnLoadCompletedInMainFrame()
62   // and DocumentLoadedInFrame() might be needed as well.
63   virtual void DidFinishLoad(
64       int64 frame_id,
65       const GURL& validated_url,
66       bool is_main_frame,
67       content::RenderViewHost* render_view_host) OVERRIDE;
68   virtual void WebContentsDestroyed(
69       content::WebContents* web_contents) OVERRIDE;
70
71   // PermissionBubbleView::Delegate:
72   virtual void ToggleAccept(int request_index, bool new_value) OVERRIDE;
73   virtual void SetCustomizationMode() OVERRIDE;
74   virtual void Accept() OVERRIDE;
75   virtual void Deny() OVERRIDE;
76   virtual void Closing() OVERRIDE;
77
78   // Called when the coalescing timer is done. Presents the bubble.
79   void ShowBubble();
80
81   // Finalize the pending permissions request.
82   void FinalizeBubble();
83
84   // Whether or not we are showing the bubble in this tab.
85   bool bubble_showing_;
86
87   // Set to the UI surface to be used to display the permissions requests.
88   PermissionBubbleView* view_;
89
90   std::vector<PermissionBubbleRequest*> requests_;
91   std::vector<PermissionBubbleRequest*> queued_requests_;
92   std::vector<bool> accept_states_;
93   bool customization_mode_;
94
95   scoped_ptr<base::Timer> timer_;
96 };
97
98 #endif  // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_