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_
13 #include "base/callback_forward.h"
14 #include "base/memory/ref_counted.h"
15 #include "chrome/browser/status_icons/status_icon_menu_model.h"
16 #include "content/public/common/media_stream_request.h"
20 } // namespace content
29 // This indicator is owned by MediaCaptureDevicesDispatcher
30 // (MediaCaptureDevicesDispatcher is a singleton).
31 class MediaStreamCaptureIndicator
32 : public base::RefCountedThreadSafe
<MediaStreamCaptureIndicator
>,
33 public StatusIconMenuModel::Delegate
{
35 MediaStreamCaptureIndicator();
37 // Registers a new media stream for |web_contents| and returns UI object
38 // that's used by the content layer to notify about state of the stream.
39 scoped_ptr
<content::MediaStreamUI
> RegisterMediaStream(
40 content::WebContents
* web_contents
,
41 const content::MediaStreamDevices
& devices
);
43 // Overrides from StatusIconMenuModel::Delegate implementation.
44 virtual void ExecuteCommand(int command_id
, int event_flags
) OVERRIDE
;
46 // Returns true if the |web_contents| is capturing user media (e.g., webcam or
48 bool IsCapturingUserMedia(content::WebContents
* web_contents
) const;
50 // Returns true if the |web_contents| is capturing video (e.g., webcam).
51 bool IsCapturingVideo(content::WebContents
* web_contents
) const;
53 // Returns true if the |web_contents| is capturing audio (e.g., microphone).
54 bool IsCapturingAudio(content::WebContents
* web_contents
) const;
56 // Returns true if the |web_contents| itself is being mirrored (e.g., a source
57 // of media for remote broadcast).
58 bool IsBeingMirrored(content::WebContents
* web_contents
) const;
62 class WebContentsDeviceUsage
;
63 friend class WebContentsDeviceUsage
;
65 friend class base::RefCountedThreadSafe
<MediaStreamCaptureIndicator
>;
66 virtual ~MediaStreamCaptureIndicator();
68 // Following functions/variables are executed/accessed only on UI thread.
70 // Called by WebContentsDeviceUsage when it's about to destroy itself, i.e.
71 // when WebContents is being destroyed.
72 void UnregisterWebContents(content::WebContents
* web_contents
);
74 // Updates the status tray menu. Called by WebContentsDeviceUsage.
75 void UpdateNotificationUserInterface();
77 // Helpers to create and destroy status tray icon. Called from
78 // UpdateNotificationUserInterface().
79 void EnsureStatusTrayIconResources();
80 void MaybeCreateStatusTrayIcon(bool audio
, bool video
);
81 void MaybeDestroyStatusTrayIcon();
83 // Gets the status icon image and the string to use as the tooltip.
84 void GetStatusTrayIconInfo(bool audio
,
86 gfx::ImageSkia
* image
,
87 base::string16
* tool_tip
);
89 // Reference to our status icon - owned by the StatusTray. If null,
90 // the platform doesn't support status icons.
91 StatusIcon
* status_icon_
;
93 // These images are owned by ResourceBundle and need not be destroyed.
94 gfx::ImageSkia
* mic_image_
;
95 gfx::ImageSkia
* camera_image_
;
97 // A map that contains the usage counts of the opened capture devices for each
98 // WebContents instance.
99 typedef std::map
<content::WebContents
*, WebContentsDeviceUsage
*> UsageMap
;
102 // A vector which maps command IDs to their associated WebContents
103 // instance. This is rebuilt each time the status tray icon context menu is
105 typedef std::vector
<content::WebContents
*> CommandTargets
;
106 CommandTargets command_targets_
;
109 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_