| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 TabCaptureRegistry::GetFactoryInstance() { | 265 TabCaptureRegistry::GetFactoryInstance() { |
| 266 return g_factory.Pointer(); | 266 return g_factory.Pointer(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void TabCaptureRegistry::GetCapturedTabs( | 269 void TabCaptureRegistry::GetCapturedTabs( |
| 270 const std::string& extension_id, | 270 const std::string& extension_id, |
| 271 base::ListValue* list_of_capture_info) const { | 271 base::ListValue* list_of_capture_info) const { |
| 272 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 272 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 273 DCHECK(list_of_capture_info); | 273 DCHECK(list_of_capture_info); |
| 274 list_of_capture_info->Clear(); | 274 list_of_capture_info->Clear(); |
| 275 for (const LiveRequest* request : requests_) { | 275 for (const std::unique_ptr<LiveRequest>& request : requests_) { |
| 276 if (request->is_anonymous() || !request->is_verified() || | 276 if (request->is_anonymous() || !request->is_verified() || |
| 277 request->extension_id() != extension_id) | 277 request->extension_id() != extension_id) |
| 278 continue; | 278 continue; |
| 279 tab_capture::CaptureInfo info; | 279 tab_capture::CaptureInfo info; |
| 280 request->GetCaptureInfo(&info); | 280 request->GetCaptureInfo(&info); |
| 281 list_of_capture_info->Append(info.ToValue()); | 281 list_of_capture_info->Append(info.ToValue()); |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 void TabCaptureRegistry::OnExtensionUnloaded( | 285 void TabCaptureRegistry::OnExtensionUnloaded( |
| 286 content::BrowserContext* browser_context, | 286 content::BrowserContext* browser_context, |
| 287 const Extension* extension, | 287 const Extension* extension, |
| 288 UnloadedExtensionInfo::Reason reason) { | 288 UnloadedExtensionInfo::Reason reason) { |
| 289 // Cleanup all the requested media streams for this extension. | 289 // Cleanup all the requested media streams for this extension. |
| 290 for (ScopedVector<LiveRequest>::iterator it = requests_.begin(); | 290 for (std::vector<std::unique_ptr<LiveRequest>>::iterator it = |
| 291 requests_.begin(); |
| 291 it != requests_.end();) { | 292 it != requests_.end();) { |
| 292 if ((*it)->extension_id() == extension->id()) { | 293 if ((*it)->extension_id() == extension->id()) { |
| 293 it = requests_.erase(it); | 294 it = requests_.erase(it); |
| 294 } else { | 295 } else { |
| 295 ++it; | 296 ++it; |
| 296 } | 297 } |
| 297 } | 298 } |
| 298 } | 299 } |
| 299 | 300 |
| 300 bool TabCaptureRegistry::AddRequest(content::WebContents* target_contents, | 301 bool TabCaptureRegistry::AddRequest(content::WebContents* target_contents, |
| 301 const std::string& extension_id, | 302 const std::string& extension_id, |
| 302 bool is_anonymous) { | 303 bool is_anonymous) { |
| 303 LiveRequest* const request = FindRequest(target_contents); | 304 LiveRequest* const request = FindRequest(target_contents); |
| 304 | 305 |
| 305 // Currently, we do not allow multiple active captures for same tab. | 306 // Currently, we do not allow multiple active captures for same tab. |
| 306 if (request != NULL) { | 307 if (request != NULL) { |
| 307 if (request->capture_state() == tab_capture::TAB_CAPTURE_STATE_PENDING || | 308 if (request->capture_state() == tab_capture::TAB_CAPTURE_STATE_PENDING || |
| 308 request->capture_state() == tab_capture::TAB_CAPTURE_STATE_ACTIVE) { | 309 request->capture_state() == tab_capture::TAB_CAPTURE_STATE_ACTIVE) { |
| 309 return false; | 310 return false; |
| 310 } else { | 311 } else { |
| 311 // Delete the request before creating its replacement (below). | 312 // Delete the request before creating its replacement (below). |
| 312 KillRequest(request); | 313 KillRequest(request); |
| 313 } | 314 } |
| 314 } | 315 } |
| 315 | 316 |
| 316 requests_.push_back( | 317 requests_.push_back(base::MakeUnique<LiveRequest>( |
| 317 new LiveRequest(target_contents, extension_id, is_anonymous, this)); | 318 target_contents, extension_id, is_anonymous, this)); |
| 318 return true; | 319 return true; |
| 319 } | 320 } |
| 320 | 321 |
| 321 bool TabCaptureRegistry::VerifyRequest( | 322 bool TabCaptureRegistry::VerifyRequest( |
| 322 int render_process_id, | 323 int render_process_id, |
| 323 int render_frame_id, | 324 int render_frame_id, |
| 324 const std::string& extension_id) { | 325 const std::string& extension_id) { |
| 325 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 326 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 326 | 327 |
| 327 LiveRequest* const request = FindRequest( | 328 LiveRequest* const request = FindRequest( |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 std::unique_ptr<Event> event( | 430 std::unique_ptr<Event> event( |
| 430 new Event(events::TAB_CAPTURE_ON_STATUS_CHANGED, | 431 new Event(events::TAB_CAPTURE_ON_STATUS_CHANGED, |
| 431 tab_capture::OnStatusChanged::kEventName, std::move(args))); | 432 tab_capture::OnStatusChanged::kEventName, std::move(args))); |
| 432 event->restrict_to_browser_context = browser_context_; | 433 event->restrict_to_browser_context = browser_context_; |
| 433 | 434 |
| 434 router->DispatchEventToExtension(request->extension_id(), std::move(event)); | 435 router->DispatchEventToExtension(request->extension_id(), std::move(event)); |
| 435 } | 436 } |
| 436 | 437 |
| 437 TabCaptureRegistry::LiveRequest* TabCaptureRegistry::FindRequest( | 438 TabCaptureRegistry::LiveRequest* TabCaptureRegistry::FindRequest( |
| 438 const content::WebContents* target_contents) const { | 439 const content::WebContents* target_contents) const { |
| 439 for (ScopedVector<LiveRequest>::const_iterator it = requests_.begin(); | 440 for (const auto& request : requests_) { |
| 440 it != requests_.end(); ++it) { | 441 if (request->web_contents() == target_contents) |
| 441 if ((*it)->web_contents() == target_contents) | 442 return request.get(); |
| 442 return *it; | |
| 443 } | 443 } |
| 444 return NULL; | 444 return nullptr; |
| 445 } | 445 } |
| 446 | 446 |
| 447 TabCaptureRegistry::LiveRequest* TabCaptureRegistry::FindRequest( | 447 TabCaptureRegistry::LiveRequest* TabCaptureRegistry::FindRequest( |
| 448 int original_target_render_process_id, | 448 int original_target_render_process_id, |
| 449 int original_target_render_frame_id) const { | 449 int original_target_render_frame_id) const { |
| 450 for (ScopedVector<LiveRequest>::const_iterator it = requests_.begin(); | 450 for (const std::unique_ptr<LiveRequest>& request : requests_) { |
| 451 it != requests_.end(); ++it) { | 451 if (request->WasOriginallyTargettingRenderFrameID( |
| 452 if ((*it)->WasOriginallyTargettingRenderFrameID( | |
| 453 original_target_render_process_id, | 452 original_target_render_process_id, |
| 454 original_target_render_frame_id)) | 453 original_target_render_frame_id)) { |
| 455 return *it; | 454 return request.get(); |
| 455 } |
| 456 } | 456 } |
| 457 return NULL; | 457 return nullptr; |
| 458 } | 458 } |
| 459 | 459 |
| 460 void TabCaptureRegistry::KillRequest(LiveRequest* request) { | 460 void TabCaptureRegistry::KillRequest(LiveRequest* request) { |
| 461 for (ScopedVector<LiveRequest>::iterator it = requests_.begin(); | 461 for (std::vector<std::unique_ptr<LiveRequest>>::iterator it = |
| 462 requests_.begin(); |
| 462 it != requests_.end(); ++it) { | 463 it != requests_.end(); ++it) { |
| 463 if ((*it) == request) { | 464 if (it->get() == request) { |
| 464 requests_.erase(it); | 465 requests_.erase(it); |
| 465 return; | 466 return; |
| 466 } | 467 } |
| 467 } | 468 } |
| 468 NOTREACHED(); | 469 NOTREACHED(); |
| 469 } | 470 } |
| 470 | 471 |
| 471 } // namespace extensions | 472 } // namespace extensions |
| OLD | NEW |