Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / media / media_stream_devices_controller.h
blobfb4da6724c3d87db8be7bb1c312ce8a41ad9f78e
1 // Copyright (c) 2012 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_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_
6 #define CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_
8 #include <map>
9 #include <string>
11 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
12 #include "components/content_settings/core/common/content_settings.h"
13 #include "content/public/browser/web_contents_delegate.h"
15 class Profile;
16 class TabSpecificContentSettings;
18 namespace content {
19 class WebContents;
22 namespace user_prefs {
23 class PrefRegistrySyncable;
26 class MediaStreamDevicesController : public PermissionBubbleRequest {
27 public:
28 MediaStreamDevicesController(content::WebContents* web_contents,
29 const content::MediaStreamRequest& request,
30 const content::MediaResponseCallback& callback);
32 ~MediaStreamDevicesController() override;
34 // Registers the prefs backing the audio and video policies.
35 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
37 // Public methods to be called by MediaStreamInfoBarDelegate;
38 bool IsAskingForAudio() const;
39 bool IsAskingForVideo() const;
40 const std::string& GetSecurityOriginSpec() const;
42 // PermissionBubbleRequest:
43 int GetIconID() const override;
44 base::string16 GetMessageText() const override;
45 base::string16 GetMessageTextFragment() const override;
46 bool HasUserGesture() const override;
47 GURL GetRequestingHostname() const override;
48 void PermissionGranted() override;
49 void PermissionDenied() override;
50 void Cancelled() override;
51 void RequestFinished() override;
53 private:
54 // Returns a list of devices available for the request for the given
55 // audio/video permission settings.
56 content::MediaStreamDevices GetDevices(ContentSetting audio_setting,
57 ContentSetting video_setting);
59 // Runs |callback_| with the given audio/video permission settings. If neither
60 // |audio_setting| or |video_setting| is set to allow, |denial_reason| should
61 // be set to the error to be reported when running |callback_|.
62 void RunCallback(ContentSetting audio_setting,
63 ContentSetting video_setting,
64 content::MediaStreamRequestResult denial_reason);
66 // Store the permission to use media devices for the origin of the request.
67 // This is triggered when the user makes a decision.
68 void StorePermission(ContentSetting new_audio_setting,
69 ContentSetting new_video_setting) const;
71 // Called when the permission has been set to update the
72 // TabSpecificContentSettings.
73 void UpdateTabSpecificContentSettings(ContentSetting audio_setting,
74 ContentSetting video_setting) const;
76 // Returns the content settings for the given content type and request.
77 ContentSetting GetContentSetting(
78 ContentSettingsType content_type,
79 const content::MediaStreamRequest& request,
80 content::MediaStreamRequestResult* denial_reason) const;
82 // Returns the content setting that should apply given an old content setting
83 // and a user decision that has been made. If a user isn't being asked for one
84 // of audio/video then we shouldn't change that setting, even if they accept
85 // the dialog.
86 ContentSetting GetNewSetting(ContentSettingsType content_type,
87 ContentSetting old_setting,
88 ContentSetting user_decision) const;
90 // Returns true if clicking allow on the dialog should give access to the
91 // requested devices.
92 bool IsUserAcceptAllowed(ContentSettingsType content_type) const;
94 // The audio/video content settings BEFORE the user clicks accept/deny.
95 ContentSetting old_audio_setting_;
96 ContentSetting old_video_setting_;
98 content::WebContents* web_contents_;
100 // The owner of this class needs to make sure it does not outlive the profile.
101 Profile* profile_;
103 // Weak pointer to the tab specific content settings of the tab for which the
104 // MediaStreamDevicesController was created. The tab specific content
105 // settings are associated with a the web contents of the tab. The
106 // MediaStreamDeviceController must not outlive the web contents for which it
107 // was created.
108 TabSpecificContentSettings* content_settings_;
110 // The original request for access to devices.
111 const content::MediaStreamRequest request_;
113 // The callback that needs to be Run to notify WebRTC of whether access to
114 // audio/video devices was granted or not.
115 content::MediaResponseCallback callback_;
118 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController);
121 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_