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