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 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | 5 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 10 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 g_factory = LAZY_INSTANCE_INITIALIZER; | 129 g_factory = LAZY_INSTANCE_INITIALIZER; |
130 | 130 |
131 // static | 131 // static |
132 BrowserContextKeyedAPIFactory<TabCaptureRegistry>* | 132 BrowserContextKeyedAPIFactory<TabCaptureRegistry>* |
133 TabCaptureRegistry::GetFactoryInstance() { | 133 TabCaptureRegistry::GetFactoryInstance() { |
134 return g_factory.Pointer(); | 134 return g_factory.Pointer(); |
135 } | 135 } |
136 | 136 |
137 const TabCaptureRegistry::RegistryCaptureInfo | 137 const TabCaptureRegistry::RegistryCaptureInfo |
138 TabCaptureRegistry::GetCapturedTabs(const std::string& extension_id) const { | 138 TabCaptureRegistry::GetCapturedTabs(const std::string& extension_id) const { |
139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 139 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
140 RegistryCaptureInfo list; | 140 RegistryCaptureInfo list; |
141 for (ScopedVector<TabCaptureRequest>::const_iterator it = requests_.begin(); | 141 for (ScopedVector<TabCaptureRequest>::const_iterator it = requests_.begin(); |
142 it != requests_.end(); ++it) { | 142 it != requests_.end(); ++it) { |
143 if ((*it)->extension_id == extension_id) { | 143 if ((*it)->extension_id == extension_id) { |
144 list.push_back(std::make_pair((*it)->tab_id, (*it)->status)); | 144 list.push_back(std::make_pair((*it)->tab_id, (*it)->status)); |
145 } | 145 } |
146 } | 146 } |
147 return list; | 147 return list; |
148 } | 148 } |
149 | 149 |
150 void TabCaptureRegistry::Observe(int type, | 150 void TabCaptureRegistry::Observe(int type, |
151 const content::NotificationSource& source, | 151 const content::NotificationSource& source, |
152 const content::NotificationDetails& details) { | 152 const content::NotificationDetails& details) { |
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 153 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
154 switch (type) { | 154 switch (type) { |
155 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | 155 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
156 // Cleanup all the requested media streams for this extension. | 156 // Cleanup all the requested media streams for this extension. |
157 const std::string& extension_id = | 157 const std::string& extension_id = |
158 content::Details<extensions::UnloadedExtensionInfo>(details)-> | 158 content::Details<extensions::UnloadedExtensionInfo>(details)-> |
159 extension->id(); | 159 extension->id(); |
160 for (ScopedVector<TabCaptureRequest>::iterator it = requests_.begin(); | 160 for (ScopedVector<TabCaptureRequest>::iterator it = requests_.begin(); |
161 it != requests_.end();) { | 161 it != requests_.end();) { |
162 if ((*it)->extension_id == extension_id) { | 162 if ((*it)->extension_id == extension_id) { |
163 it = requests_.erase(it); | 163 it = requests_.erase(it); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 requests_.push_back(new TabCaptureRequest(render_process_id, | 223 requests_.push_back(new TabCaptureRequest(render_process_id, |
224 render_view_id, | 224 render_view_id, |
225 extension_id, | 225 extension_id, |
226 tab_id, | 226 tab_id, |
227 status)); | 227 status)); |
228 return true; | 228 return true; |
229 } | 229 } |
230 | 230 |
231 bool TabCaptureRegistry::VerifyRequest(int render_process_id, | 231 bool TabCaptureRegistry::VerifyRequest(int render_process_id, |
232 int render_view_id) { | 232 int render_view_id) { |
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 233 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
234 DVLOG(1) << "Verifying tabCapture request for " | 234 DVLOG(1) << "Verifying tabCapture request for " |
235 << render_process_id << ":" << render_view_id; | 235 << render_process_id << ":" << render_view_id; |
236 // TODO(justinlin): Verify extension too. | 236 // TODO(justinlin): Verify extension too. |
237 return (FindCaptureRequest(render_process_id, render_view_id) != NULL); | 237 return (FindCaptureRequest(render_process_id, render_view_id) != NULL); |
238 } | 238 } |
239 | 239 |
240 void TabCaptureRegistry::OnRequestUpdate( | 240 void TabCaptureRegistry::OnRequestUpdate( |
241 int render_process_id, | 241 int render_process_id, |
242 int render_view_id, | 242 int render_view_id, |
243 const content::MediaStreamDevice& device, | 243 const content::MediaStreamDevice& device, |
244 const content::MediaRequestState new_state) { | 244 const content::MediaRequestState new_state) { |
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 245 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
246 if (device.type != content::MEDIA_TAB_VIDEO_CAPTURE && | 246 if (device.type != content::MEDIA_TAB_VIDEO_CAPTURE && |
247 device.type != content::MEDIA_TAB_AUDIO_CAPTURE) { | 247 device.type != content::MEDIA_TAB_AUDIO_CAPTURE) { |
248 return; | 248 return; |
249 } | 249 } |
250 | 250 |
251 TabCaptureRequest* request = FindCaptureRequest(render_process_id, | 251 TabCaptureRequest* request = FindCaptureRequest(render_process_id, |
252 render_view_id); | 252 render_view_id); |
253 if (request == NULL) { | 253 if (request == NULL) { |
254 // TODO(justinlin): This can happen because the extension's renderer does | 254 // TODO(justinlin): This can happen because the extension's renderer does |
255 // not seem to always cleanup streams correctly. | 255 // not seem to always cleanup streams correctly. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 it != requests_.end(); ++it) { | 353 it != requests_.end(); ++it) { |
354 if ((*it)->render_process_id == render_process_id && | 354 if ((*it)->render_process_id == render_process_id && |
355 (*it)->render_view_id == render_view_id) { | 355 (*it)->render_view_id == render_view_id) { |
356 requests_.erase(it); | 356 requests_.erase(it); |
357 return; | 357 return; |
358 } | 358 } |
359 } | 359 } |
360 } | 360 } |
361 | 361 |
362 } // namespace extensions | 362 } // namespace extensions |
OLD | NEW |