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.
5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
10 #include "chrome/browser/ui/website_settings/permission_bubble_view.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "content/public/browser/web_contents_user_data.h"
14 class PermissionBubbleDelegate
;
16 // Provides access to permissions bubbles. Allows clients to add a delegate
17 // callback interface to the existing permission bubble configuration.
18 // Depending on the situation and policy, that may add new UI to an existing
19 // permission bubble, create and show a new permission bubble, or provide no
20 // visible UI action at all. (In that case, the delegate will be immediately
21 // informed that the permission request failed.)
23 // A PermissionBubbleManager is associated with a particular WebContents.
24 // Delegates attached to a particular WebContents' PBM must outlive it.
26 // The PermissionBubbleManager should be addressed on the UI thread.
27 class PermissionBubbleManager
28 : public content::WebContentsObserver
,
29 public content::WebContentsUserData
<PermissionBubbleManager
>,
30 public PermissionBubbleView::Delegate
{
32 virtual ~PermissionBubbleManager();
34 // Add a new consumer delegate to the permission bubble. Ownership of the
35 // delegate remains with the caller. The caller must arrange for the delegate
36 // to outlive the PermissionBubbleManager.
37 virtual void AddPermissionBubbleDelegate(PermissionBubbleDelegate
* delegate
);
39 // Remove a consumer delegate from the permission bubble.
40 virtual void RemovePermissionBubbleDelegate(
41 PermissionBubbleDelegate
* delegate
);
43 // Set the active view for the permission bubble. If this is NULL, it
44 // means the permission bubble is no longer showing.
45 virtual void SetView(PermissionBubbleView
* view
);
48 friend class PermissionBubbleManagerTest
;
49 friend class content::WebContentsUserData
<PermissionBubbleManager
>;
51 explicit PermissionBubbleManager(content::WebContents
* web_contents
);
53 // contents::WebContentsObserver:
54 virtual void WebContentsDestroyed(
55 content::WebContents
* web_contents
) OVERRIDE
;
57 // PermissionBubbleView::Delegate:
58 virtual void ToggleAccept(int delegate_index
, bool new_value
) OVERRIDE
;
59 virtual void Accept() OVERRIDE
;
60 virtual void Deny() OVERRIDE
;
61 virtual void Closing() OVERRIDE
;
63 // Finalize the pending permissions request.
64 void FinalizeBubble();
66 // Whether or not we are showing the bubble in this tab.
69 // Set to the UI surface to be used to display the permissions requests.
70 PermissionBubbleView
* view_
;
72 std::vector
<PermissionBubbleDelegate
*> delegates_
;
73 std::vector
<bool> accept_state_
;
76 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_