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

Unified Diff: chrome/browser/extensions/api/tab_capture/offscreen_presentation.cc

Issue 1314413005: [Presentation API] 1-UA presentation support + presenter APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/tab_capture/offscreen_presentation.cc
diff --git a/chrome/browser/extensions/api/tab_capture/offscreen_presentation.cc b/chrome/browser/extensions/api/tab_capture/offscreen_presentation.cc
index 2ccd614b8035321582aac9c7c12777da22d06bdf..9aaeba1986724c0a3717f6a6468472a8b8cf25e1 100644
--- a/chrome/browser/extensions/api/tab_capture/offscreen_presentation.cc
+++ b/chrome/browser/extensions/api/tab_capture/offscreen_presentation.cc
@@ -8,8 +8,12 @@
#include "base/bind.h"
#include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h"
+#include "chrome/browser/media/router/offscreen_presentation_manager.h"
+#include "chrome/browser/media/router/offscreen_presentation_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/web_contents_sizer.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_host.h"
@@ -183,9 +187,9 @@ OffscreenPresentation::OffscreenPresentation(OffscreenPresentationsOwner* owner,
: owner_(owner),
start_url_(start_url),
presentation_id_(id),
- profile_(Profile::FromBrowserContext(
- owner->extension_web_contents()->GetBrowserContext())
- ->CreateOffTheRecordProfile()),
+ profile_(Profile::FromBrowserContext(owner->extension_web_contents()
+ ->GetBrowserContext())
+ ->CreateOffTheRecordProfile()),
capture_poll_timer_(false, false),
content_capture_was_detected_(false) {
DCHECK(profile_);
@@ -219,6 +223,14 @@ void OffscreenPresentation::Start(const gfx::Size& initial_size) {
// automatically unmuted, but will be captured into the MediaStream.
presentation_web_contents_->SetAudioMuted(true);
+ // If the tab is for an offscreen presentation, register the tab as a
+ // presenter in OffscreenPresentationManager.
+ // Use the OffscreenPresentationManager keyed off the owner's BrowserContext.
+ // We assume that the presentation's potential controllers will be using the
+ // same OffscreenPresentationManager instance to connect with the presenter.
+ GetOffscreenPresentationManager()->RegisterPresenterTab(
+ presentation_id(), presentation_web_contents_.get());
+
// Navigate to the initial URL of the presentation.
content::NavigationController::LoadURLParams load_params(start_url_);
load_params.should_replace_current_entry = true;
@@ -234,7 +246,7 @@ void OffscreenPresentation::CloseContents(WebContents* source) {
// Javascript in the page called window.close().
DVLOG(1) << "OffscreenPresentation will die at renderer's request for "
"start_url=" << start_url_.spec();
- owner_->ClosePresentation(this);
+ Destroy();
}
bool OffscreenPresentation::ShouldSuppressDialogs(WebContents* source) {
@@ -444,7 +456,7 @@ void OffscreenPresentation::DieIfContentCaptureEnded() {
if (presentation_web_contents_->GetCapturerCount() == 0) {
DVLOG(2) << "Capture of OffscreenPresentation content has stopped for "
"start_url=" << start_url_.spec();
- owner_->ClosePresentation(this);
+ Destroy();
return;
} else {
DVLOG(3) << "Capture of OffscreenPresentation content continues for "
@@ -462,7 +474,7 @@ void OffscreenPresentation::DieIfContentCaptureEnded() {
// to free up resources.
LOG(WARNING) << "Capture of OffscreenPresentation content did not start "
"within timeout for start_url=" << start_url_.spec();
- owner_->ClosePresentation(this);
+ Destroy();
return;
}
@@ -474,4 +486,19 @@ void OffscreenPresentation::DieIfContentCaptureEnded() {
base::Unretained(this)));
}
+void OffscreenPresentation::Destroy() {
+ GetOffscreenPresentationManager()->UnregisterPresenterTab(
+ presentation_web_contents_.get());
+ owner_->ClosePresentation(this);
+}
+
+media_router::OffscreenPresentationManager*
+OffscreenPresentation::GetOffscreenPresentationManager() {
+ auto* manager = media_router::OffscreenPresentationManagerFactory::
+ GetOrCreateForBrowserContext(
+ owner_->extension_web_contents()->GetBrowserContext());
+ DCHECK(manager);
+ return manager;
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698