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/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "chrome/browser/extensions/image_loading_tracker.h" |
12 #include "content/public/common/media_stream_request.h" | 13 #include "content/public/common/media_stream_request.h" |
13 #include "ui/base/models/simple_menu_model.h" | 14 #include "ui/base/models/simple_menu_model.h" |
14 #include "ui/gfx/image/image_skia.h" | 15 #include "ui/gfx/image/image_skia.h" |
15 | 16 |
16 class StatusIcon; | 17 class StatusIcon; |
17 class StatusTray; | 18 class StatusTray; |
18 | 19 |
19 // This indicator is owned by MediaInternals and deleted when MediaInternals | 20 // This indicator is owned by MediaInternals and deleted when MediaInternals |
20 // is deleted. | 21 // is deleted. |
21 class MediaStreamCaptureIndicator | 22 class MediaStreamCaptureIndicator |
22 : public base::RefCountedThreadSafe<MediaStreamCaptureIndicator>, | 23 : public base::RefCountedThreadSafe<MediaStreamCaptureIndicator>, |
23 public ui::SimpleMenuModel::Delegate { | 24 public ui::SimpleMenuModel::Delegate, |
| 25 public ImageLoadingTracker::Observer { |
24 public: | 26 public: |
25 MediaStreamCaptureIndicator(); | 27 MediaStreamCaptureIndicator(); |
26 | 28 |
27 // Overrides from SimpleMenuModel::Delegate implementation. | 29 // Overrides from SimpleMenuModel::Delegate implementation. |
28 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | 30 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
29 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | 31 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
30 virtual bool GetAcceleratorForCommandId( | 32 virtual bool GetAcceleratorForCommandId( |
31 int command_id, | 33 int command_id, |
32 ui::Accelerator* accelerator) OVERRIDE; | 34 ui::Accelerator* accelerator) OVERRIDE; |
33 virtual void ExecuteCommand(int command_id) OVERRIDE; | 35 virtual void ExecuteCommand(int command_id) OVERRIDE; |
34 | 36 |
35 // Called on IO thread when MediaStream opens new capture devices. | 37 // Called on IO thread when MediaStream opens new capture devices. |
36 void CaptureDevicesOpened(int render_process_id, | 38 void CaptureDevicesOpened(int render_process_id, |
37 int render_view_id, | 39 int render_view_id, |
38 const content::MediaStreamDevices& devices); | 40 const content::MediaStreamDevices& devices); |
39 | 41 |
40 // Called on IO thread when MediaStream closes the opened devices. | 42 // Called on IO thread when MediaStream closes the opened devices. |
41 void CaptureDevicesClosed(int render_process_id, | 43 void CaptureDevicesClosed(int render_process_id, |
42 int render_view_id, | 44 int render_view_id, |
43 const content::MediaStreamDevices& devices); | 45 const content::MediaStreamDevices& devices); |
44 | 46 |
| 47 // ImageLoadingTracker::Observer implementation. |
| 48 virtual void OnImageLoaded(const gfx::Image& image, |
| 49 const std::string& extension_id, |
| 50 int index) OVERRIDE; |
| 51 |
45 private: | 52 private: |
46 // Struct to store the usage information of the capture devices for each tab. | 53 // Struct to store the usage information of the capture devices for each tab. |
| 54 // TODO(estade): this should be called CaptureDeviceContents; not all the |
| 55 // render views it represents are tabs. |
47 struct CaptureDeviceTab { | 56 struct CaptureDeviceTab { |
48 CaptureDeviceTab(int render_process_id, | 57 CaptureDeviceTab(int render_process_id, |
49 int render_view_id) | 58 int render_view_id) |
50 : render_process_id(render_process_id), | 59 : render_process_id(render_process_id), |
51 render_view_id(render_view_id), | 60 render_view_id(render_view_id), |
52 audio_ref_count(0), | 61 audio_ref_count(0), |
53 video_ref_count(0) {} | 62 video_ref_count(0) {} |
54 | 63 |
55 int render_process_id; | 64 int render_process_id; |
56 int render_view_id; | 65 int render_view_id; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const content::MediaStreamDevices& devices); | 105 const content::MediaStreamDevices& devices); |
97 | 106 |
98 // Removes the tab from the device usage list. | 107 // Removes the tab from the device usage list. |
99 void RemoveCaptureDeviceTab(int render_process_id, | 108 void RemoveCaptureDeviceTab(int render_process_id, |
100 int render_view_id, | 109 int render_view_id, |
101 const content::MediaStreamDevices& devices); | 110 const content::MediaStreamDevices& devices); |
102 | 111 |
103 // Triggers a balloon in the corner telling capture devices are being used. | 112 // Triggers a balloon in the corner telling capture devices are being used. |
104 // This function is called by AddCaptureDeviceTab(). | 113 // This function is called by AddCaptureDeviceTab(). |
105 void ShowBalloon(int render_process_id, int render_view_id, | 114 void ShowBalloon(int render_process_id, int render_view_id, |
106 bool audio, bool video) const; | 115 bool audio, bool video); |
| 116 |
| 117 // First load the extension's image, then show a balloon for it. |
| 118 void ShowBalloonForExtension( |
| 119 const extensions::Extension* extension); |
107 | 120 |
108 // Hides the status tray from the desktop. This function is called by | 121 // Hides the status tray from the desktop. This function is called by |
109 // RemoveCaptureDeviceTab() when the device usage list becomes empty. | 122 // RemoveCaptureDeviceTab() when the device usage list becomes empty. |
110 void Hide(); | 123 void Hide(); |
111 | 124 |
112 // Gets the title of the tab. | |
113 string16 GetTitle(int render_process_id, int render_view_id) const; | |
114 | |
115 // Gets the security originator of the tab. It returns a string with no '/' | |
116 // at the end to display in the UI. | |
117 string16 GetSecurityOrigin(int render_process_id, int render_view_id) const; | |
118 | |
119 // Updates the status tray menu with the new device list. This call will be | 125 // Updates the status tray menu with the new device list. This call will be |
120 // triggered by both AddCaptureDeviceTab() and RemoveCaptureDeviceTab(). | 126 // triggered by both AddCaptureDeviceTab() and RemoveCaptureDeviceTab(). |
121 void UpdateStatusTrayIconContextMenu(); | 127 void UpdateStatusTrayIconContextMenu(); |
122 | 128 |
123 // Updates the status tray tooltip and image according to which kind of | 129 // Updates the status tray tooltip and image according to which kind of |
124 // devices are being used. This function is called by | 130 // devices are being used. This function is called by |
125 // UpdateStatusTrayIconContextMenu(). | 131 // UpdateStatusTrayIconContextMenu(). |
126 void UpdateStatusTrayIconDisplay(bool audio, bool video); | 132 void UpdateStatusTrayIconDisplay(bool audio, bool video); |
127 | 133 |
128 // Reference to our status icon - owned by the StatusTray. If null, | 134 // Reference to our status icon - owned by the StatusTray. If null, |
129 // the platform doesn't support status icons. | 135 // the platform doesn't support status icons. |
130 StatusIcon* status_icon_; | 136 StatusIcon* status_icon_; |
131 | 137 |
132 // These images are owned by ResourceBundle and need not be destroyed. | 138 // These images are owned by ResourceBundle and need not be destroyed. |
133 gfx::ImageSkia* mic_image_; | 139 gfx::ImageSkia* mic_image_; |
134 gfx::ImageSkia* camera_image_; | 140 gfx::ImageSkia* camera_image_; |
135 gfx::ImageSkia* balloon_image_; | 141 gfx::ImageSkia* balloon_image_; |
136 | 142 |
137 // A list that contains the usage information of the opened capture devices. | 143 // A list that contains the usage information of the opened capture devices. |
138 typedef std::vector<CaptureDeviceTab> CaptureDeviceTabs; | 144 typedef std::vector<CaptureDeviceTab> CaptureDeviceTabs; |
139 CaptureDeviceTabs tabs_; | 145 CaptureDeviceTabs tabs_; |
| 146 |
| 147 // Tracks the load of extension icons. |
| 148 ImageLoadingTracker tracker_; |
| 149 // The count of times that |tracker_| has been used (0-based). |
| 150 int image_load_index_; |
| 151 // The name of the extension that is currently getting its icon fetched. |
| 152 std::string pending_extension_name_; |
| 153 // The IDS_* value for the message the user will see for the pending balloon. |
| 154 int pending_message_id_; |
140 }; | 155 }; |
141 | 156 |
142 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ | 157 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ |
OLD | NEW |