Chromium Code Reviews| 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 "chrome/browser/extensions/event_names.h" | 9 #include "chrome/browser/extensions/event_names.h" |
| 10 #include "chrome/browser/extensions/event_router.h" | 10 #include "chrome/browser/extensions/event_router.h" |
| 11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | |
| 13 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 15 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | 16 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
| 18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 20 | 21 |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 using extensions::TabCaptureRegistry; | 23 using extensions::TabCaptureRegistry; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 | 101 |
| 101 TabCaptureRequest::~TabCaptureRequest() { | 102 TabCaptureRequest::~TabCaptureRequest() { |
| 102 } | 103 } |
| 103 | 104 |
| 104 TabCaptureRegistry::TabCaptureRegistry(Profile* profile) | 105 TabCaptureRegistry::TabCaptureRegistry(Profile* profile) |
| 105 : profile_(profile) { | 106 : profile_(profile) { |
| 106 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this); | 107 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this); |
| 107 registrar_.Add(this, | 108 registrar_.Add(this, |
| 108 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 109 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 109 content::Source<Profile>(profile_)); | 110 content::Source<Profile>(profile_)); |
| 110 // TODO(justinlin): Hook up HTML5 fullscreen. | 111 registrar_.Add(this, |
| 112 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 113 content::NotificationService::AllSources()); | |
| 111 } | 114 } |
| 112 | 115 |
| 113 TabCaptureRegistry::~TabCaptureRegistry() { | 116 TabCaptureRegistry::~TabCaptureRegistry() { |
| 114 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); | 117 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); |
| 115 } | 118 } |
| 116 | 119 |
| 117 const TabCaptureRegistry::RegistryCaptureInfo | 120 const TabCaptureRegistry::RegistryCaptureInfo |
| 118 TabCaptureRegistry::GetCapturedTabs(const std::string& extension_id) const { | 121 TabCaptureRegistry::GetCapturedTabs(const std::string& extension_id) const { |
| 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 120 RegistryCaptureInfo list; | 123 RegistryCaptureInfo list; |
| 121 for (ScopedVector<TabCaptureRequest>::const_iterator it = requests_.begin(); | 124 for (ScopedVector<TabCaptureRequest>::const_iterator it = requests_.begin(); |
| 122 it != requests_.end(); ++it) { | 125 it != requests_.end(); ++it) { |
| 123 if ((*it)->extension_id == extension_id) { | 126 if ((*it)->extension_id == extension_id) { |
| 124 list.push_back(std::make_pair((*it)->tab_id, (*it)->status)); | 127 list.push_back(std::make_pair((*it)->tab_id, (*it)->status)); |
| 125 } | 128 } |
| 126 } | 129 } |
| 127 return list; | 130 return list; |
| 128 } | 131 } |
| 129 | 132 |
| 130 void TabCaptureRegistry::Observe(int type, | 133 void TabCaptureRegistry::Observe(int type, |
| 131 const content::NotificationSource& source, | 134 const content::NotificationSource& source, |
| 132 const content::NotificationDetails& details) { | 135 const content::NotificationDetails& details) { |
| 136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 133 switch (type) { | 137 switch (type) { |
| 134 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 138 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 135 // Cleanup all the requested media streams for this extension. | 139 // Cleanup all the requested media streams for this extension. |
| 136 const std::string& extension_id = | 140 const std::string& extension_id = |
| 137 content::Details<extensions::UnloadedExtensionInfo>(details)-> | 141 content::Details<extensions::UnloadedExtensionInfo>(details)-> |
| 138 extension->id(); | 142 extension->id(); |
| 139 for (ScopedVector<TabCaptureRequest>::iterator it = requests_.begin(); | 143 for (ScopedVector<TabCaptureRequest>::iterator it = requests_.begin(); |
| 140 it != requests_.end();) { | 144 it != requests_.end();) { |
| 141 if ((*it)->extension_id == extension_id) { | 145 if ((*it)->extension_id == extension_id) { |
| 142 it = requests_.erase(it); | 146 it = requests_.erase(it); |
| 143 } else { | 147 } else { |
| 144 ++it; | 148 ++it; |
| 145 } | 149 } |
| 146 } | 150 } |
| 147 break; | 151 break; |
| 148 } | 152 } |
| 149 case chrome::NOTIFICATION_FULLSCREEN_CHANGED: { | 153 case chrome::NOTIFICATION_FULLSCREEN_CHANGED: { |
| 150 // TODO(justinlin): Hook up HTML5 fullscreen. | 154 FullscreenController* fullscreen_controller = |
| 155 content::Source<FullscreenController>(source).ptr(); | |
| 156 const bool is_fullscreen = *(content::Details<bool>(details).ptr()); | |
|
Matt Perry
2013/06/18 21:13:02
fyi, outer parens are unnecessary
justinlin
2013/06/18 21:36:21
Done.
| |
| 157 for (ScopedVector<TabCaptureRequest>::iterator it = requests_.begin(); | |
| 158 it != requests_.end(); ++it) { | |
| 159 // If we are exiting fullscreen mode, we only need to check if any of | |
| 160 // the requests had the fullscreen flag toggled previously. The | |
| 161 // fullscreen controller no longer has the reference to the fullscreen | |
| 162 // web_contents here. | |
| 163 if (!is_fullscreen) { | |
| 164 if ((*it)->fullscreen) { | |
| 165 (*it)->fullscreen = false; | |
| 166 DispatchStatusChangeEvent(*it); | |
| 167 break; | |
| 168 } | |
| 169 continue; | |
| 170 } | |
| 171 | |
| 172 // If we are entering fullscreen mode, find whether the web_contents we | |
| 173 // are capturing entered fullscreen mode. | |
| 174 content::RenderViewHost* const rvh = | |
| 175 content::RenderViewHost::FromID((*it)->render_process_id, | |
| 176 (*it)->render_view_id); | |
| 177 if (rvh && fullscreen_controller->IsFullscreenForTabOrPending( | |
| 178 content::WebContents::FromRenderViewHost(rvh))) { | |
| 179 (*it)->fullscreen = true; | |
| 180 DispatchStatusChangeEvent(*it); | |
| 181 break; | |
| 182 } | |
| 183 } | |
| 151 break; | 184 break; |
| 152 } | 185 } |
| 153 } | 186 } |
| 154 } | 187 } |
| 155 | 188 |
| 156 bool TabCaptureRegistry::AddRequest(int render_process_id, | 189 bool TabCaptureRegistry::AddRequest(int render_process_id, |
| 157 int render_view_id, | 190 int render_view_id, |
| 158 const std::string& extension_id, | 191 const std::string& extension_id, |
| 159 int tab_id, | 192 int tab_id, |
| 160 TabCaptureState status) { | 193 TabCaptureState status) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 it != requests_.end(); ++it) { | 336 it != requests_.end(); ++it) { |
| 304 if ((*it)->render_process_id == render_process_id && | 337 if ((*it)->render_process_id == render_process_id && |
| 305 (*it)->render_view_id == render_view_id) { | 338 (*it)->render_view_id == render_view_id) { |
| 306 requests_.erase(it); | 339 requests_.erase(it); |
| 307 return; | 340 return; |
| 308 } | 341 } |
| 309 } | 342 } |
| 310 } | 343 } |
| 311 | 344 |
| 312 } // namespace extensions | 345 } // namespace extensions |
| OLD | NEW |