Chromium Code Reviews| Index: chrome/browser/permissions/permission_infobar_manager.h |
| diff --git a/chrome/browser/permissions/permission_infobar_manager.h b/chrome/browser/permissions/permission_infobar_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..515bae383beb0a57dcca7c8502586b00fb47d3d5 |
| --- /dev/null |
| +++ b/chrome/browser/permissions/permission_infobar_manager.h |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_MANAGER_H_ |
| +#define CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_MANAGER_H_ |
| + |
| +#include "base/callback_forward.h" |
| +#include "base/containers/scoped_ptr_hash_map.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "chrome/browser/permissions/permission_request_id.h" |
| +#include "components/content_settings/core/common/content_settings.h" |
| +#include "components/content_settings/core/common/content_settings_types.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| +#include "content/public/browser/web_contents_user_data.h" |
| + |
| +class GURL; |
| +class PermissionInfoBarRequest; |
| + |
| +// Manages permsision requests using InfoBars. Requests are coalesced by |
| +// request_id. If multiple requests occur with overlapping permissions, both |
| +// will be shown and the last to have a response will be persisted. |
| +class PermissionInfoBarManager |
| + : public content::WebContentsObserver, |
| + public content::WebContentsUserData<PermissionInfoBarManager> { |
| + public: |
| + ~PermissionInfoBarManager() override; |
| + |
| + // Queues an infobar request to be shown at some point. Requests with |
| + // the same |request_id| are coalesced. |
| + void CreateRequest( |
| + const ContentSettingsType type, |
| + const PermissionRequestID& request, |
| + const GURL& requesting_origin, |
| + const GURL& embedding_origin, |
| + const base::Callback<void(bool, ContentSetting)>& response_callback); |
|
mlamouri (slow - plz ping)
2015/10/02 15:51:06
nit: rename to callback
Lalit Maganti
2015/10/02 16:06:43
Done.
|
| + |
| + // Cancels a specific infobar request. |
| + void CancelRequest(const PermissionRequestID& request); |
| + |
| + private: |
| + friend class GeolocationPermissionContextTests; |
| + friend class PermissionContextBaseTests; |
| + friend class content::WebContentsUserData<PermissionInfoBarManager>; |
| + using PermissionDecidedCallback = base::Callback<void(bool, ContentSetting)>; |
| + |
| + explicit PermissionInfoBarManager(content::WebContents* web_contents); |
| + |
| + // Posts a call to |ShowNextQueuedRequest| if there is no current request |
| + // and |queued_requests_| is not empty. |
| + void TriggerShowNextQueuedRequest(); |
| + |
| + // Shows the next request in |queued_requests_| if there is no current |
| + // request and if |queued_requests_| is not empty |
| + void ShowNextQueuedRequest(); |
| + |
| + // Callback function used when the infobar is dismissed, accepted or denied. |
| + void OnInfoBarClosed(); |
| + |
| + // Removes the current request and shows a next queued request if available. |
| + void ClearCurrentRequest(); |
| + |
| + // Returns whether the queue should be ignored when considering to show |
| + // a new request. |
| + bool ShouldIgnoreQueuedRequests(); |
| + |
| + // Pointer to the current request which is displayed to the user. |
| + scoped_ptr<PermissionInfoBarRequest> current_request_; |
| + |
| + // Indicates whether there is a currently pending call to |
| + // |ShowNextQueuedRequest| in the UI thread even loop. |
| + bool is_show_pending_; |
| + |
| + // The mapping of request_id to queued requests. Note that |current_request_| |
| + // will not be present in this map. |
| + base::ScopedPtrHashMap<int, |
| + scoped_ptr<PermissionInfoBarRequest>> queued_requests_; |
| + |
| + base::WeakPtrFactory<PermissionInfoBarManager> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarManager); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_MANAGER_H_ |