Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/browser/ui/website_settings/permission_bubble_manager.h

Issue 150103013: Add basic coalescing behavior to the permission bubble manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: edited comment Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ 5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ 6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/timer/timer.h"
10 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" 11 #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_observer.h"
12 #include "content/public/browser/web_contents_user_data.h" 13 #include "content/public/browser/web_contents_user_data.h"
13 14
14 class PermissionBubbleRequest; 15 class PermissionBubbleRequest;
15 16
16 // Provides access to permissions bubbles. Allows clients to add a request 17 // Provides access to permissions bubbles. Allows clients to add a request
17 // callback interface to the existing permission bubble configuration. 18 // callback interface to the existing permission bubble configuration.
18 // Depending on the situation and policy, that may add new UI to an existing 19 // 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 // permission bubble, create and show a new permission bubble, or provide no
20 // visible UI action at all. (In that case, the request will be immediately 21 // visible UI action at all. (In that case, the request will be immediately
21 // informed that the permission request failed.) 22 // informed that the permission request failed.)
22 // 23 //
23 // A PermissionBubbleManager is associated with a particular WebContents. 24 // A PermissionBubbleManager is associated with a particular WebContents.
24 // Requests attached to a particular WebContents' PBM must outlive it. 25 // Requests attached to a particular WebContents' PBM must outlive it.
25 // 26 //
26 // The PermissionBubbleManager should be addressed on the UI thread. 27 // The PermissionBubbleManager should be addressed on the UI thread.
27 class PermissionBubbleManager 28 class PermissionBubbleManager
28 : public content::WebContentsObserver, 29 : public content::WebContentsObserver,
29 public content::WebContentsUserData<PermissionBubbleManager>, 30 public content::WebContentsUserData<PermissionBubbleManager>,
30 public PermissionBubbleView::Delegate { 31 public PermissionBubbleView::Delegate {
31 public: 32 public:
32 // Return the flag-driven enabled state of permissions bubbles. 33 // Return the flag-driven enabled state of permissions bubbles.
33 static bool Enabled(); 34 static bool Enabled();
34 35
35 virtual ~PermissionBubbleManager(); 36 virtual ~PermissionBubbleManager();
36 37
37 // Add a new request to the permission bubble. Ownership of the request 38 // Add a new request to the permission bubble. Ownership of the request
38 // remains with the caller. The caller must arrange for the request to 39 // remains with the caller. The caller must arrange for the request to
39 // outlive the PermissionBubbleManager. 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.
40 virtual void AddRequest(PermissionBubbleRequest* request); 43 virtual void AddRequest(PermissionBubbleRequest* request);
41 44
42 // Set the active view for the permission bubble. If this is NULL, it 45 // Set the active view for the permission bubble. If this is NULL, it
43 // means the permission bubble is no longer showing. 46 // means the permission bubble is no longer showing.
44 virtual void SetView(PermissionBubbleView* view); 47 virtual void SetView(PermissionBubbleView* view);
45 48
49 protected:
50 // Sets the coalesce time interval to |interval_ms|. For testing only.
51 void SetCoalesceIntervalForTesting(int interval_ms);
52
46 private: 53 private:
47 friend class PermissionBubbleManagerTest; 54 friend class PermissionBubbleManagerTest;
48 friend class content::WebContentsUserData<PermissionBubbleManager>; 55 friend class content::WebContentsUserData<PermissionBubbleManager>;
49 56
50 explicit PermissionBubbleManager(content::WebContents* web_contents); 57 explicit PermissionBubbleManager(content::WebContents* web_contents);
51 58
52 // contents::WebContentsObserver: 59 // contents::WebContentsObserver:
60 virtual void DidFinishLoad(
61 int64 frame_id,
62 const GURL& validated_url,
63 bool is_main_frame,
64 content::RenderViewHost* render_view_host) OVERRIDE;
53 virtual void WebContentsDestroyed( 65 virtual void WebContentsDestroyed(
54 content::WebContents* web_contents) OVERRIDE; 66 content::WebContents* web_contents) OVERRIDE;
55 67
56 // PermissionBubbleView::Delegate: 68 // PermissionBubbleView::Delegate:
57 virtual void ToggleAccept(int request_index, bool new_value) OVERRIDE; 69 virtual void ToggleAccept(int request_index, bool new_value) OVERRIDE;
58 virtual void SetCustomizationMode() OVERRIDE; 70 virtual void SetCustomizationMode() OVERRIDE;
59 virtual void Accept() OVERRIDE; 71 virtual void Accept() OVERRIDE;
60 virtual void Deny() OVERRIDE; 72 virtual void Deny() OVERRIDE;
61 virtual void Closing() OVERRIDE; 73 virtual void Closing() OVERRIDE;
62 74
75 // Called when the coalescing timer is done. Presents the bubble.
76 void ShowBubble();
77
63 // Finalize the pending permissions request. 78 // Finalize the pending permissions request.
64 void FinalizeBubble(); 79 void FinalizeBubble();
65 80
66 // Whether or not we are showing the bubble in this tab. 81 // Whether or not we are showing the bubble in this tab.
67 bool bubble_showing_; 82 bool bubble_showing_;
68 83
69 // Set to the UI surface to be used to display the permissions requests. 84 // Set to the UI surface to be used to display the permissions requests.
70 PermissionBubbleView* view_; 85 PermissionBubbleView* view_;
71 86
72 std::vector<PermissionBubbleRequest*> requests_; 87 std::vector<PermissionBubbleRequest*> requests_;
73 std::vector<bool> accept_state_; 88 std::vector<PermissionBubbleRequest*> queued_requests_;
89 std::vector<bool> accept_states_;
74 bool customization_mode_; 90 bool customization_mode_;
91
92 scoped_ptr<base::Timer> timer_;
75 }; 93 };
76 94
77 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_ 95 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698