Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / media / media_stream_capture_indicator.h
blobf6391be1066fbd1c0fbfe89bce4639017e598ea8
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_CAPTURE_INDICATOR_H_
6 #define CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_
8 #include <vector>
10 #include "base/callback_forward.h"
11 #include "base/containers/scoped_ptr_hash_map.h"
12 #include "base/memory/ref_counted.h"
13 #include "chrome/browser/status_icons/status_icon_menu_model.h"
14 #include "content/public/common/media_stream_request.h"
16 namespace content {
17 class WebContents;
18 } // namespace content
20 namespace gfx {
21 class ImageSkia;
22 } // namespace gfx
24 class StatusIcon;
26 // This indicator is owned by MediaCaptureDevicesDispatcher
27 // (MediaCaptureDevicesDispatcher is a singleton).
28 class MediaStreamCaptureIndicator
29 : public base::RefCountedThreadSafe<MediaStreamCaptureIndicator>,
30 public StatusIconMenuModel::Delegate {
31 public:
32 MediaStreamCaptureIndicator();
34 // Registers a new media stream for |web_contents| and returns UI object
35 // that's used by the content layer to notify about state of the stream.
36 scoped_ptr<content::MediaStreamUI> RegisterMediaStream(
37 content::WebContents* web_contents,
38 const content::MediaStreamDevices& devices);
40 // Overrides from StatusIconMenuModel::Delegate implementation.
41 void ExecuteCommand(int command_id, int event_flags) override;
43 // Returns true if the |web_contents| is capturing user media (e.g., webcam or
44 // microphone input).
45 bool IsCapturingUserMedia(content::WebContents* web_contents) const;
47 // Returns true if the |web_contents| is capturing video (e.g., webcam).
48 bool IsCapturingVideo(content::WebContents* web_contents) const;
50 // Returns true if the |web_contents| is capturing audio (e.g., microphone).
51 bool IsCapturingAudio(content::WebContents* web_contents) const;
53 // Returns true if the |web_contents| itself is being mirrored (e.g., a source
54 // of media for remote broadcast).
55 bool IsBeingMirrored(content::WebContents* web_contents) const;
57 private:
58 class UIDelegate;
59 class WebContentsDeviceUsage;
60 friend class WebContentsDeviceUsage;
62 friend class base::RefCountedThreadSafe<MediaStreamCaptureIndicator>;
63 ~MediaStreamCaptureIndicator() override;
65 // Following functions/variables are executed/accessed only on UI thread.
67 // Called by WebContentsDeviceUsage when it's about to destroy itself, i.e.
68 // when WebContents is being destroyed.
69 void UnregisterWebContents(content::WebContents* web_contents);
71 // Updates the status tray menu. Called by WebContentsDeviceUsage.
72 void UpdateNotificationUserInterface();
74 // Helpers to create and destroy status tray icon. Called from
75 // UpdateNotificationUserInterface().
76 void EnsureStatusTrayIconResources();
77 void MaybeCreateStatusTrayIcon(bool audio, bool video);
78 void MaybeDestroyStatusTrayIcon();
80 // Gets the status icon image and the string to use as the tooltip.
81 void GetStatusTrayIconInfo(bool audio,
82 bool video,
83 gfx::ImageSkia* image,
84 base::string16* tool_tip);
86 // Reference to our status icon - owned by the StatusTray. If null,
87 // the platform doesn't support status icons.
88 StatusIcon* status_icon_;
90 // These images are owned by ResourceBundle and need not be destroyed.
91 gfx::ImageSkia* mic_image_;
92 gfx::ImageSkia* camera_image_;
94 // A map that contains the usage counts of the opened capture devices for each
95 // WebContents instance.
96 base::ScopedPtrHashMap<content::WebContents*,
97 scoped_ptr<WebContentsDeviceUsage>> usage_map_;
99 // A vector which maps command IDs to their associated WebContents
100 // instance. This is rebuilt each time the status tray icon context menu is
101 // updated.
102 typedef std::vector<content::WebContents*> CommandTargets;
103 CommandTargets command_targets_;
105 DISALLOW_COPY_AND_ASSIGN(MediaStreamCaptureIndicator);
108 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_