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

Side by Side Diff: chrome/browser/extensions/api/tab_capture/offscreen_presentation.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: Mostly revert to Patch Set 6, plus minor tweaks. [and REBASE] 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/offscreen_presentation.h" 5 #include "chrome/browser/extensions/api/tab_capture/offscreen_presentation.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" 10 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 OffscreenPresentationsOwner::~OffscreenPresentationsOwner() {} 131 OffscreenPresentationsOwner::~OffscreenPresentationsOwner() {}
132 132
133 // static 133 // static
134 OffscreenPresentationsOwner* OffscreenPresentationsOwner::Get( 134 OffscreenPresentationsOwner* OffscreenPresentationsOwner::Get(
135 content::WebContents* extension_web_contents) { 135 content::WebContents* extension_web_contents) {
136 // CreateForWebContents() really means "create if not exists." 136 // CreateForWebContents() really means "create if not exists."
137 CreateForWebContents(extension_web_contents); 137 CreateForWebContents(extension_web_contents);
138 return FromWebContents(extension_web_contents); 138 return FromWebContents(extension_web_contents);
139 } 139 }
140 140
141 OffscreenPresentation* OffscreenPresentationsOwner::FindOrStartPresentation( 141 OffscreenPresentation* OffscreenPresentationsOwner::StartPresentation(
142 const GURL& start_url, 142 const GURL& start_url,
143 const std::string& presentation_id, 143 const std::string& presentation_id,
144 const gfx::Size& initial_size) { 144 const gfx::Size& initial_size) {
145 OffscreenPresentation* presentation =
146 FindPresentation(start_url, presentation_id);
147 if (presentation) {
148 DVLOG(1) << "Returning already-running OffscreenPresentation for start_url="
149 << presentation->start_url();
150 return presentation;
151 }
152
153 if (presentations_.size() >= kMaxPresentationsPerExtension) 145 if (presentations_.size() >= kMaxPresentationsPerExtension)
154 return nullptr; // Maximum number of presentations reached. 146 return nullptr; // Maximum number of presentations reached.
155 147
156 presentation = new OffscreenPresentation(this, start_url, presentation_id); 148 presentations_.push_back(
157 presentations_.push_back(presentation); 149 new OffscreenPresentation(this, start_url, presentation_id));
158 presentation->Start(initial_size); 150 presentations_.back()->Start(initial_size);
159 return presentation; 151 return presentations_.back();
160 } 152 }
161 153
162 void OffscreenPresentationsOwner::ClosePresentation( 154 void OffscreenPresentationsOwner::ClosePresentation(
163 OffscreenPresentation* presentation) { 155 OffscreenPresentation* presentation) {
164 const auto it = 156 const auto it =
165 std::find(presentations_.begin(), presentations_.end(), presentation); 157 std::find(presentations_.begin(), presentations_.end(), presentation);
166 if (it != presentations_.end()) 158 if (it != presentations_.end())
167 presentations_.erase(it); 159 presentations_.erase(it);
168 } 160 }
169 161
170 OffscreenPresentation* OffscreenPresentationsOwner::FindPresentation(
171 const GURL& start_url, const std::string& presentation_id) const {
172 for (OffscreenPresentation* presentation : presentations_) {
173 if (presentation->start_url() == start_url &&
174 presentation->presentation_id() == presentation_id)
175 return presentation;
176 }
177 return nullptr;
178 }
179
180 OffscreenPresentation::OffscreenPresentation(OffscreenPresentationsOwner* owner, 162 OffscreenPresentation::OffscreenPresentation(OffscreenPresentationsOwner* owner,
181 const GURL& start_url, 163 const GURL& start_url,
182 const std::string& id) 164 const std::string& id)
183 : owner_(owner), 165 : owner_(owner),
184 start_url_(start_url), 166 start_url_(start_url),
185 presentation_id_(id), 167 presentation_id_(id),
186 profile_(Profile::FromBrowserContext( 168 profile_(Profile::FromBrowserContext(
187 owner->extension_web_contents()->GetBrowserContext()) 169 owner->extension_web_contents()->GetBrowserContext())
188 ->CreateOffTheRecordProfile()), 170 ->CreateOffTheRecordProfile()),
189 capture_poll_timer_(false, false), 171 capture_poll_timer_(false, false),
(...skipping 22 matching lines...) Expand all
212 #endif 194 #endif
213 195
214 // Set initial size, if specified. 196 // Set initial size, if specified.
215 if (!initial_size.IsEmpty()) 197 if (!initial_size.IsEmpty())
216 ResizeWebContents(presentation_web_contents_.get(), initial_size); 198 ResizeWebContents(presentation_web_contents_.get(), initial_size);
217 199
218 // Mute audio output. When tab capture starts, the audio will be 200 // Mute audio output. When tab capture starts, the audio will be
219 // automatically unmuted, but will be captured into the MediaStream. 201 // automatically unmuted, but will be captured into the MediaStream.
220 presentation_web_contents_->SetAudioMuted(true); 202 presentation_web_contents_->SetAudioMuted(true);
221 203
204 // TODO(imcheng): If |presentation_id_| is not empty, register it with the
205 // PresentationRouter. http://crbug.com/513859
206 if (!presentation_id_.empty()) {
207 NOTIMPLEMENTED()
208 << "Register with PresentationRouter, id=" << presentation_id_;
209 }
210
222 // Navigate to the initial URL of the presentation. 211 // Navigate to the initial URL of the presentation.
223 content::NavigationController::LoadURLParams load_params(start_url_); 212 content::NavigationController::LoadURLParams load_params(start_url_);
224 load_params.should_replace_current_entry = true; 213 load_params.should_replace_current_entry = true;
225 load_params.should_clear_history_list = true; 214 load_params.should_clear_history_list = true;
226 presentation_web_contents_->GetController().LoadURLWithParams(load_params); 215 presentation_web_contents_->GetController().LoadURLWithParams(load_params);
227 216
228 start_time_ = base::TimeTicks::Now(); 217 start_time_ = base::TimeTicks::Now();
229 DieIfContentCaptureEnded(); 218 DieIfContentCaptureEnded();
230 } 219 }
231 220
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 DCHECK_EQ(presentation_web_contents_.get(), contents); 363 DCHECK_EQ(presentation_web_contents_.get(), contents);
375 364
376 // This method is being called to check whether an extension is permitted to 365 // This method is being called to check whether an extension is permitted to
377 // capture the page. Verify that the request is being made by the extension 366 // capture the page. Verify that the request is being made by the extension
378 // that spawned this OffscreenPresentation. 367 // that spawned this OffscreenPresentation.
379 368
380 // Find the extension ID associated with the extension background page's 369 // Find the extension ID associated with the extension background page's
381 // WebContents. 370 // WebContents.
382 content::BrowserContext* const extension_browser_context = 371 content::BrowserContext* const extension_browser_context =
383 owner_->extension_web_contents()->GetBrowserContext(); 372 owner_->extension_web_contents()->GetBrowserContext();
384 std::string extension_id; 373 const extensions::Extension* const extension =
385 for (const ExtensionHost* host : 374 ProcessManager::Get(extension_browser_context)->
386 ProcessManager::Get(extension_browser_context)->background_hosts()) { 375 GetExtensionForWebContents(owner_->extension_web_contents());
387 if (host->host_contents() == owner_->extension_web_contents()) { 376 const std::string extension_id = extension ? extension->id() : "";
388 extension_id = host->extension_id(); 377 LOG_IF(DFATAL, extension_id.empty())
389 break; 378 << "Extension that started this OffscreenPresentation was not found.";
390 }
391 }
392 379
393 // If verified, allow any tab capture audio/video devices that were requested. 380 // If verified, allow any tab capture audio/video devices that were requested.
394 extensions::TabCaptureRegistry* const tab_capture_registry = 381 extensions::TabCaptureRegistry* const tab_capture_registry =
395 extensions::TabCaptureRegistry::Get(extension_browser_context); 382 extensions::TabCaptureRegistry::Get(extension_browser_context);
396 content::MediaStreamDevices devices; 383 content::MediaStreamDevices devices;
397 if (tab_capture_registry && tab_capture_registry->VerifyRequest( 384 if (tab_capture_registry && tab_capture_registry->VerifyRequest(
398 request.render_process_id, 385 request.render_process_id,
399 request.render_frame_id, 386 request.render_frame_id,
400 extension_id)) { 387 extension_id)) {
401 if (request.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE) { 388 if (request.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 455
469 // Schedule the timer to check again in a second. 456 // Schedule the timer to check again in a second.
470 capture_poll_timer_.Start( 457 capture_poll_timer_.Start(
471 FROM_HERE, 458 FROM_HERE,
472 base::TimeDelta::FromSeconds(kPollIntervalInSeconds), 459 base::TimeDelta::FromSeconds(kPollIntervalInSeconds),
473 base::Bind(&OffscreenPresentation::DieIfContentCaptureEnded, 460 base::Bind(&OffscreenPresentation::DieIfContentCaptureEnded,
474 base::Unretained(this))); 461 base::Unretained(this)));
475 } 462 }
476 463
477 } // namespace extensions 464 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698