Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: chrome/browser/extensions/api/tab_capture/tab_capture_registry.cc

Issue 1221483002: New tabCapture.captureOffscreenTab API, initially for Presentation API 1UA mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert to only whitelisted extension use. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/sessions/session_tab_helper.h" 9 #include "chrome/browser/sessions/session_tab_helper.h"
10 #include "components/keyed_service/content/browser_context_dependency_manager.h" 10 #include "components/keyed_service/content/browser_context_dependency_manager.h"
(...skipping 12 matching lines...) Expand all
23 23
24 namespace tab_capture = api::tab_capture; 24 namespace tab_capture = api::tab_capture;
25 25
26 // Stores values associated with a tab capture request, maintains lifecycle 26 // Stores values associated with a tab capture request, maintains lifecycle
27 // state, and monitors WebContents for fullscreen transition events and 27 // state, and monitors WebContents for fullscreen transition events and
28 // destruction. 28 // destruction.
29 class TabCaptureRegistry::LiveRequest : public content::WebContentsObserver { 29 class TabCaptureRegistry::LiveRequest : public content::WebContentsObserver {
30 public: 30 public:
31 LiveRequest(content::WebContents* target_contents, 31 LiveRequest(content::WebContents* target_contents,
32 const std::string& extension_id, 32 const std::string& extension_id,
33 bool is_anonymous,
33 TabCaptureRegistry* registry) 34 TabCaptureRegistry* registry)
34 : content::WebContentsObserver(target_contents), 35 : content::WebContentsObserver(target_contents),
35 extension_id_(extension_id), 36 extension_id_(extension_id),
37 is_anonymous_(is_anonymous),
36 registry_(registry), 38 registry_(registry),
37 capture_state_(tab_capture::TAB_CAPTURE_STATE_NONE), 39 capture_state_(tab_capture::TAB_CAPTURE_STATE_NONE),
38 is_verified_(false), 40 is_verified_(false),
39 // TODO(miu): This initial value for |is_fullscreened_| is a faulty 41 // TODO(miu): This initial value for |is_fullscreened_| is a faulty
40 // assumption. http://crbug.com/350491 42 // assumption. http://crbug.com/350491
41 is_fullscreened_(false), 43 is_fullscreened_(false),
42 render_process_id_(-1), 44 render_process_id_(-1),
43 render_frame_id_(-1) { 45 render_frame_id_(-1) {
44 DCHECK(web_contents()); 46 DCHECK(web_contents());
45 DCHECK(registry_); 47 DCHECK(registry_);
46 } 48 }
47 49
48 ~LiveRequest() override {} 50 ~LiveRequest() override {}
49 51
50 // Accessors. 52 // Accessors.
51 const std::string& extension_id() const { 53 const std::string& extension_id() const {
52 return extension_id_; 54 return extension_id_;
53 } 55 }
56 bool is_anonymous() const {
57 return is_anonymous_;
58 }
54 TabCaptureState capture_state() const { 59 TabCaptureState capture_state() const {
55 return capture_state_; 60 return capture_state_;
56 } 61 }
57 bool is_verified() const { 62 bool is_verified() const {
58 return is_verified_; 63 return is_verified_;
59 } 64 }
60 65
61 void SetIsVerified() { 66 void SetIsVerified() {
62 DCHECK(!is_verified_); 67 DCHECK(!is_verified_);
63 is_verified_ = true; 68 is_verified_ = true;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 if (capture_state_ == tab_capture::TAB_CAPTURE_STATE_ACTIVE) 118 if (capture_state_ == tab_capture::TAB_CAPTURE_STATE_ACTIVE)
114 registry_->DispatchStatusChangeEvent(this); 119 registry_->DispatchStatusChangeEvent(this);
115 } 120 }
116 121
117 void WebContentsDestroyed() override { 122 void WebContentsDestroyed() override {
118 registry_->KillRequest(this); // Deletes |this|. 123 registry_->KillRequest(this); // Deletes |this|.
119 } 124 }
120 125
121 private: 126 private:
122 const std::string extension_id_; 127 const std::string extension_id_;
128 const bool is_anonymous_;
123 TabCaptureRegistry* const registry_; 129 TabCaptureRegistry* const registry_;
124 TabCaptureState capture_state_; 130 TabCaptureState capture_state_;
125 bool is_verified_; 131 bool is_verified_;
126 bool is_fullscreened_; 132 bool is_fullscreened_;
127 133
128 // These reference the originally targetted RenderFrameHost by its ID. The 134 // These reference the originally targetted RenderFrameHost by its ID. The
129 // RenderFrameHost may have gone away long before a LiveRequest closes, but 135 // RenderFrameHost may have gone away long before a LiveRequest closes, but
130 // calls to OnRequestUpdate() will always refer to this request by this ID. 136 // calls to OnRequestUpdate() will always refer to this request by this ID.
131 int render_process_id_; 137 int render_process_id_;
132 int render_frame_id_; 138 int render_frame_id_;
(...skipping 24 matching lines...) Expand all
157 TabCaptureRegistry::GetFactoryInstance() { 163 TabCaptureRegistry::GetFactoryInstance() {
158 return g_factory.Pointer(); 164 return g_factory.Pointer();
159 } 165 }
160 166
161 void TabCaptureRegistry::GetCapturedTabs( 167 void TabCaptureRegistry::GetCapturedTabs(
162 const std::string& extension_id, 168 const std::string& extension_id,
163 base::ListValue* list_of_capture_info) const { 169 base::ListValue* list_of_capture_info) const {
164 DCHECK_CURRENTLY_ON(BrowserThread::UI); 170 DCHECK_CURRENTLY_ON(BrowserThread::UI);
165 DCHECK(list_of_capture_info); 171 DCHECK(list_of_capture_info);
166 list_of_capture_info->Clear(); 172 list_of_capture_info->Clear();
167 for (ScopedVector<LiveRequest>::const_iterator it = requests_.begin(); 173 for (const LiveRequest* request : requests_) {
168 it != requests_.end(); ++it) { 174 if (request->is_anonymous() || !request->is_verified() ||
169 if ((*it)->is_verified() && (*it)->extension_id() == extension_id) { 175 request->extension_id() != extension_id)
170 tab_capture::CaptureInfo info; 176 return;
imcheng 2015/09/29 01:28:55 Did you mean continue; here?
miu 2015/09/30 19:46:38 Good catch. Done.
171 (*it)->GetCaptureInfo(&info); 177 tab_capture::CaptureInfo info;
172 list_of_capture_info->Append(info.ToValue().release()); 178 request->GetCaptureInfo(&info);
173 } 179 list_of_capture_info->Append(info.ToValue().release());
174 } 180 }
175 } 181 }
176 182
177 void TabCaptureRegistry::OnExtensionUnloaded( 183 void TabCaptureRegistry::OnExtensionUnloaded(
178 content::BrowserContext* browser_context, 184 content::BrowserContext* browser_context,
179 const Extension* extension, 185 const Extension* extension,
180 UnloadedExtensionInfo::Reason reason) { 186 UnloadedExtensionInfo::Reason reason) {
181 // Cleanup all the requested media streams for this extension. 187 // Cleanup all the requested media streams for this extension.
182 for (ScopedVector<LiveRequest>::iterator it = requests_.begin(); 188 for (ScopedVector<LiveRequest>::iterator it = requests_.begin();
183 it != requests_.end();) { 189 it != requests_.end();) {
184 if ((*it)->extension_id() == extension->id()) { 190 if ((*it)->extension_id() == extension->id()) {
185 it = requests_.erase(it); 191 it = requests_.erase(it);
186 } else { 192 } else {
187 ++it; 193 ++it;
188 } 194 }
189 } 195 }
190 } 196 }
191 197
192 bool TabCaptureRegistry::AddRequest(content::WebContents* target_contents, 198 bool TabCaptureRegistry::AddRequest(content::WebContents* target_contents,
193 const std::string& extension_id) { 199 const std::string& extension_id,
200 bool is_anonymous) {
194 LiveRequest* const request = FindRequest(target_contents); 201 LiveRequest* const request = FindRequest(target_contents);
195 202
196 // Currently, we do not allow multiple active captures for same tab. 203 // Currently, we do not allow multiple active captures for same tab.
197 if (request != NULL) { 204 if (request != NULL) {
198 if (request->capture_state() != tab_capture::TAB_CAPTURE_STATE_STOPPED && 205 if (request->capture_state() != tab_capture::TAB_CAPTURE_STATE_STOPPED &&
199 request->capture_state() != tab_capture::TAB_CAPTURE_STATE_ERROR) { 206 request->capture_state() != tab_capture::TAB_CAPTURE_STATE_ERROR) {
200 return false; 207 return false;
201 } else { 208 } else {
202 // Delete the request before creating its replacement (below). 209 // Delete the request before creating its replacement (below).
203 KillRequest(request); 210 KillRequest(request);
204 } 211 }
205 } 212 }
206 213
207 requests_.push_back(new LiveRequest(target_contents, extension_id, this)); 214 requests_.push_back(
215 new LiveRequest(target_contents, extension_id, is_anonymous, this));
208 return true; 216 return true;
209 } 217 }
210 218
211 bool TabCaptureRegistry::VerifyRequest( 219 bool TabCaptureRegistry::VerifyRequest(
212 int render_process_id, 220 int render_process_id,
213 int render_frame_id, 221 int render_frame_id,
214 const std::string& extension_id) { 222 const std::string& extension_id) {
215 DCHECK_CURRENTLY_ON(BrowserThread::UI); 223 DCHECK_CURRENTLY_ON(BrowserThread::UI);
216 224
217 LiveRequest* const request = FindRequest( 225 LiveRequest* const request = FindRequest(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // terminated, then something fishy is going on. 306 // terminated, then something fishy is going on.
299 NOTREACHED() << "Trying to capture tab with existing stream."; 307 NOTREACHED() << "Trying to capture tab with existing stream.";
300 return; 308 return;
301 } 309 }
302 310
303 request->UpdateCaptureState(next_state); 311 request->UpdateCaptureState(next_state);
304 } 312 }
305 313
306 void TabCaptureRegistry::DispatchStatusChangeEvent( 314 void TabCaptureRegistry::DispatchStatusChangeEvent(
307 const LiveRequest* request) const { 315 const LiveRequest* request) const {
316 if (request->is_anonymous())
317 return;
318
308 EventRouter* router = EventRouter::Get(browser_context_); 319 EventRouter* router = EventRouter::Get(browser_context_);
309 if (!router) 320 if (!router)
310 return; 321 return;
311 322
312 scoped_ptr<base::ListValue> args(new base::ListValue()); 323 scoped_ptr<base::ListValue> args(new base::ListValue());
313 tab_capture::CaptureInfo info; 324 tab_capture::CaptureInfo info;
314 request->GetCaptureInfo(&info); 325 request->GetCaptureInfo(&info);
315 args->Append(info.ToValue().release()); 326 args->Append(info.ToValue().release());
316 scoped_ptr<Event> event(new Event(events::TAB_CAPTURE_ON_STATUS_CHANGED, 327 scoped_ptr<Event> event(new Event(events::TAB_CAPTURE_ON_STATUS_CHANGED,
317 tab_capture::OnStatusChanged::kEventName, 328 tab_capture::OnStatusChanged::kEventName,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 it != requests_.end(); ++it) { 360 it != requests_.end(); ++it) {
350 if ((*it) == request) { 361 if ((*it) == request) {
351 requests_.erase(it); 362 requests_.erase(it);
352 return; 363 return;
353 } 364 }
354 } 365 }
355 NOTREACHED(); 366 NOTREACHED();
356 } 367 }
357 368
358 } // namespace extensions 369 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698