| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ |
| 6 #define CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ | 6 #define CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/extensions/image_loading_tracker.h" | |
| 13 #include "content/public/common/media_stream_request.h" | 12 #include "content/public/common/media_stream_request.h" |
| 14 #include "ui/base/models/simple_menu_model.h" | 13 #include "ui/base/models/simple_menu_model.h" |
| 15 #include "ui/gfx/image/image_skia.h" | 14 #include "ui/gfx/image/image_skia.h" |
| 16 | 15 |
| 17 class StatusIcon; | 16 class StatusIcon; |
| 18 class StatusTray; | 17 class StatusTray; |
| 19 | 18 |
| 20 // This indicator is owned by MediaInternals and deleted when MediaInternals | 19 // This indicator is owned by MediaInternals and deleted when MediaInternals |
| 21 // is deleted. | 20 // is deleted. |
| 22 class MediaStreamCaptureIndicator : public ui::SimpleMenuModel::Delegate, | 21 class MediaStreamCaptureIndicator : public ui::SimpleMenuModel::Delegate { |
| 23 public ImageLoadingTracker::Observer { | |
| 24 public: | 22 public: |
| 25 MediaStreamCaptureIndicator(); | 23 MediaStreamCaptureIndicator(); |
| 26 virtual ~MediaStreamCaptureIndicator(); | 24 virtual ~MediaStreamCaptureIndicator(); |
| 27 | 25 |
| 28 // Overrides from SimpleMenuModel::Delegate implementation. | 26 // Overrides from SimpleMenuModel::Delegate implementation. |
| 29 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | 27 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
| 30 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | 28 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
| 31 virtual bool GetAcceleratorForCommandId( | 29 virtual bool GetAcceleratorForCommandId( |
| 32 int command_id, | 30 int command_id, |
| 33 ui::Accelerator* accelerator) OVERRIDE; | 31 ui::Accelerator* accelerator) OVERRIDE; |
| 34 virtual void ExecuteCommand(int command_id) OVERRIDE; | 32 virtual void ExecuteCommand(int command_id) OVERRIDE; |
| 35 | 33 |
| 36 // Called on IO thread when MediaStream opens new capture devices. | 34 // Called on IO thread when MediaStream opens new capture devices. |
| 37 void CaptureDevicesOpened(int render_process_id, | 35 void CaptureDevicesOpened(int render_process_id, |
| 38 int render_view_id, | 36 int render_view_id, |
| 39 const content::MediaStreamDevices& devices); | 37 const content::MediaStreamDevices& devices); |
| 40 | 38 |
| 41 // Called on IO thread when MediaStream closes the opened devices. | 39 // Called on IO thread when MediaStream closes the opened devices. |
| 42 void CaptureDevicesClosed(int render_process_id, | 40 void CaptureDevicesClosed(int render_process_id, |
| 43 int render_view_id, | 41 int render_view_id, |
| 44 const content::MediaStreamDevices& devices); | 42 const content::MediaStreamDevices& devices); |
| 45 | 43 |
| 46 // Returns true if the render process is capturing media. | 44 // Returns true if the render process is capturing media. |
| 47 bool IsProcessCapturing(int render_process_id, int render_view_id) const; | 45 bool IsProcessCapturing(int render_process_id, int render_view_id) const; |
| 48 | 46 |
| 49 // ImageLoadingTracker::Observer implementation. | 47 // ImageLoader callback. |
| 50 virtual void OnImageLoaded(const gfx::Image& image, | 48 void OnImageLoaded(const string16& message, const gfx::Image& image); |
| 51 const std::string& extension_id, | |
| 52 int index) OVERRIDE; | |
| 53 | 49 |
| 54 private: | 50 private: |
| 55 // Struct to store the usage information of the capture devices for each tab. | 51 // Struct to store the usage information of the capture devices for each tab. |
| 56 // TODO(estade): this should be called CaptureDeviceContents; not all the | 52 // TODO(estade): this should be called CaptureDeviceContents; not all the |
| 57 // render views it represents are tabs. | 53 // render views it represents are tabs. |
| 58 struct CaptureDeviceTab { | 54 struct CaptureDeviceTab { |
| 59 CaptureDeviceTab(int render_process_id, | 55 CaptureDeviceTab(int render_process_id, |
| 60 int render_view_id) | 56 int render_view_id) |
| 61 : render_process_id(render_process_id), | 57 : render_process_id(render_process_id), |
| 62 render_view_id(render_view_id), | 58 render_view_id(render_view_id), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 115 |
| 120 // Updates the status tray menu with the new device list. This call will be | 116 // Updates the status tray menu with the new device list. This call will be |
| 121 // triggered by both AddCaptureDeviceTab() and RemoveCaptureDeviceTab(). | 117 // triggered by both AddCaptureDeviceTab() and RemoveCaptureDeviceTab(). |
| 122 void UpdateStatusTrayIconContextMenu(); | 118 void UpdateStatusTrayIconContextMenu(); |
| 123 | 119 |
| 124 // Updates the status tray tooltip and image according to which kind of | 120 // Updates the status tray tooltip and image according to which kind of |
| 125 // devices are being used. This function is called by | 121 // devices are being used. This function is called by |
| 126 // UpdateStatusTrayIconContextMenu(). | 122 // UpdateStatusTrayIconContextMenu(). |
| 127 void UpdateStatusTrayIconDisplay(bool audio, bool video); | 123 void UpdateStatusTrayIconDisplay(bool audio, bool video); |
| 128 | 124 |
| 129 // Initializes image loading state. | |
| 130 void EnsureImageLoadingTracker(); | |
| 131 | |
| 132 // Reference to our status icon - owned by the StatusTray. If null, | 125 // Reference to our status icon - owned by the StatusTray. If null, |
| 133 // the platform doesn't support status icons. | 126 // the platform doesn't support status icons. |
| 134 StatusIcon* status_icon_; | 127 StatusIcon* status_icon_; |
| 135 | 128 |
| 136 // These images are owned by ResourceBundle and need not be destroyed. | 129 // These images are owned by ResourceBundle and need not be destroyed. |
| 137 gfx::ImageSkia* mic_image_; | 130 gfx::ImageSkia* mic_image_; |
| 138 gfx::ImageSkia* camera_image_; | 131 gfx::ImageSkia* camera_image_; |
| 139 gfx::ImageSkia* balloon_image_; | 132 gfx::ImageSkia* balloon_image_; |
| 140 | 133 |
| 141 // A list that contains the usage information of the opened capture devices. | 134 // A list that contains the usage information of the opened capture devices. |
| 142 typedef std::vector<CaptureDeviceTab> CaptureDeviceTabs; | 135 typedef std::vector<CaptureDeviceTab> CaptureDeviceTabs; |
| 143 CaptureDeviceTabs tabs_; | 136 CaptureDeviceTabs tabs_; |
| 144 | 137 |
| 145 // Tracks the load of extension icons. | |
| 146 scoped_ptr<ImageLoadingTracker> tracker_; | |
| 147 // The messages to display when extension images are loaded. The index | |
| 148 // corresponds to the index of the associated LoadImage request. | |
| 149 std::map<int, string16> pending_messages_; | |
| 150 // Tracks the number of requests to |tracker_|. | |
| 151 int request_index_; | |
| 152 | |
| 153 base::WeakPtrFactory<MediaStreamCaptureIndicator> weak_ptr_factory_; | 138 base::WeakPtrFactory<MediaStreamCaptureIndicator> weak_ptr_factory_; |
| 139 base::WeakPtrFactory<MediaStreamCaptureIndicator> icon_tracker_; |
| 154 | 140 |
| 155 DISALLOW_COPY_AND_ASSIGN(MediaStreamCaptureIndicator); | 141 DISALLOW_COPY_AND_ASSIGN(MediaStreamCaptureIndicator); |
| 156 }; | 142 }; |
| 157 | 143 |
| 158 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ | 144 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ |
| OLD | NEW |