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