1a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#ifndef CHROME_BROWSER_CONTENT_SETTINGS_PERMISSION_QUEUE_CONTROLLER_H_ 6a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#define CHROME_BROWSER_CONTENT_SETTINGS_PERMISSION_QUEUE_CONTROLLER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h" 95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/content_settings/core/common/content_settings_types.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_registrar.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL; 14a3f7b4e666c476898878fa745f637129375cd889Ben Murdochclass PermissionRequestID; 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class InfoBarService; 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 18a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch// This class controls an infobar queue per profile, and it's used by 19a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch// GeolocationPermissionContext, and so on. 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An alternate approach would be to have this queue per tab, and use 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// notifications to broadcast when permission is set / listen to notification to 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// cancel pending requests. This may be specially useful if there are other 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// things listening for such notifications. 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// For the time being this class is self-contained and it doesn't seem pulling 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the notification infrastructure would simplify. 26558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochclass PermissionQueueController : public content::NotificationObserver { 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback<void(bool /* allowed */)> PermissionDecidedCallback; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 30a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch PermissionQueueController(Profile* profile, ContentSettingsType type); 31a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch virtual ~PermissionQueueController(); 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The InfoBar will be displayed immediately if the tab is not already 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // displaying one, otherwise it'll be queued. 35a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch void CreateInfoBarRequest(const PermissionRequestID& id, 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& requesting_frame, 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& embedder, 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PermissionDecidedCallback callback); 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancels a specific infobar request. 41a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch void CancelInfoBarRequest(const PermissionRequestID& id); 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called by the InfoBarDelegate to notify permission has been set. 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // It'll notify and dismiss any other pending InfoBar request for the same 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |requesting_frame| and embedder. 46a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch void OnPermissionSet(const PermissionRequestID& id, 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& requesting_frame, 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& embedder, 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool update_content_setting, 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool allowed); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Performs the update to content settings for a particular request frame 53116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // context. 54116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void UpdateContentSetting( 55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const GURL& requesting_frame, const GURL& embedder, bool allowed); 56116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) protected: 58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // content::NotificationObserver: 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Observe(int type, 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class PendingInfobarRequest; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class RequestEquals; 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) typedef std::vector<PendingInfobarRequest> PendingInfobarRequests; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if a geolocation infobar is already visible for the tab 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // corresponding to |id|. 71a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch bool AlreadyShowingInfoBarForTab(const PermissionRequestID& id) const; 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Shows the next pending infobar for the tab corresponding to |id|, if any. 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note that this may not be the pending request whose ID is |id| if other 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // requests are higher in the queue. If we can't show infobars because there 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // is no InfoBarService for this tab, removes all queued requests for this 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // tab. 78a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch void ShowQueuedInfoBarForTab(const PermissionRequestID& id); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void ClearPendingInfobarRequestsForTab(const PermissionRequestID& id); 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void RegisterForInfoBarNotifications(InfoBarService* infobar_service); 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void UnregisterForInfoBarNotifications(InfoBarService* infobar_service); 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::NotificationRegistrar registrar_; 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* const profile_; 88a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ContentSettingsType type_; 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PendingInfobarRequests pending_infobar_requests_; 90558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch bool in_shutdown_; 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 92a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch DISALLOW_COPY_AND_ASSIGN(PermissionQueueController); 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#endif // CHROME_BROWSER_CONTENT_SETTINGS_PERMISSION_QUEUE_CONTROLLER_H_ 96