OLD | NEW |
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_tab.h" | 5 #include "chrome/browser/extensions/api/tab_capture/offscreen_tab.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | 12 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
| 13 #include "chrome/browser/media/router/receiver_presentation_service_delegate_imp
l.h" // nogncheck |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/web_contents_sizer.h" | 15 #include "chrome/browser/ui/web_contents_sizer.h" |
15 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
16 #include "content/public/browser/render_widget_host_view.h" | 17 #include "content/public/browser/render_widget_host_view.h" |
17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/web_preferences.h" | 19 #include "content/public/common/web_preferences.h" |
19 #include "extensions/browser/extension_host.h" | 20 #include "extensions/browser/extension_host.h" |
20 #include "extensions/browser/process_manager.h" | 21 #include "extensions/browser/process_manager.h" |
21 | 22 |
22 #if defined(ENABLE_MEDIA_ROUTER) | |
23 #include "chrome/browser/media/router/receiver_presentation_service_delegate_imp
l.h" // nogncheck | |
24 #endif | |
25 | |
26 using content::WebContents; | 23 using content::WebContents; |
27 | 24 |
28 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::OffscreenTabsOwner); | 25 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::OffscreenTabsOwner); |
29 | 26 |
30 namespace { | 27 namespace { |
31 | 28 |
32 // Upper limit on the number of simultaneous off-screen tabs per extension | 29 // Upper limit on the number of simultaneous off-screen tabs per extension |
33 // instance. | 30 // instance. |
34 const int kMaxOffscreenTabsPerExtension = 3; | 31 const int kMaxOffscreenTabsPerExtension = 3; |
35 | 32 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 111 |
115 // Set initial size, if specified. | 112 // Set initial size, if specified. |
116 if (!initial_size.IsEmpty()) | 113 if (!initial_size.IsEmpty()) |
117 ResizeWebContents(offscreen_tab_web_contents_.get(), | 114 ResizeWebContents(offscreen_tab_web_contents_.get(), |
118 gfx::Rect(initial_size)); | 115 gfx::Rect(initial_size)); |
119 | 116 |
120 // Mute audio output. When tab capture starts, the audio will be | 117 // Mute audio output. When tab capture starts, the audio will be |
121 // automatically unmuted, but will be captured into the MediaStream. | 118 // automatically unmuted, but will be captured into the MediaStream. |
122 offscreen_tab_web_contents_->SetAudioMuted(true); | 119 offscreen_tab_web_contents_->SetAudioMuted(true); |
123 | 120 |
124 #if defined(ENABLE_MEDIA_ROUTER) | |
125 if (!optional_presentation_id.empty()) { | 121 if (!optional_presentation_id.empty()) { |
126 DVLOG(1) << " Register with ReceiverPresentationServiceDelegateImpl, " | 122 DVLOG(1) << " Register with ReceiverPresentationServiceDelegateImpl, " |
127 << "[presentation_id]: " << optional_presentation_id; | 123 << "[presentation_id]: " << optional_presentation_id; |
128 // Create a ReceiverPSDImpl associated with the offscreen tab's WebContents. | 124 // Create a ReceiverPSDImpl associated with the offscreen tab's WebContents. |
129 // The new instance will set up the necessary infrastructure to allow | 125 // The new instance will set up the necessary infrastructure to allow |
130 // controlling peers the ability to connect to the offscreen tab. | 126 // controlling peers the ability to connect to the offscreen tab. |
131 media_router::ReceiverPresentationServiceDelegateImpl::CreateForWebContents( | 127 media_router::ReceiverPresentationServiceDelegateImpl::CreateForWebContents( |
132 offscreen_tab_web_contents_.get(), optional_presentation_id); | 128 offscreen_tab_web_contents_.get(), optional_presentation_id); |
133 | 129 |
134 if (auto* render_view_host = | 130 if (auto* render_view_host = |
135 offscreen_tab_web_contents_->GetRenderViewHost()) { | 131 offscreen_tab_web_contents_->GetRenderViewHost()) { |
136 auto web_prefs = render_view_host->GetWebkitPreferences(); | 132 auto web_prefs = render_view_host->GetWebkitPreferences(); |
137 web_prefs.presentation_receiver = true; | 133 web_prefs.presentation_receiver = true; |
138 render_view_host->UpdateWebkitPreferences(web_prefs); | 134 render_view_host->UpdateWebkitPreferences(web_prefs); |
139 } | 135 } |
140 } | 136 } |
141 #endif // defined(ENABLE_MEDIA_ROUTER) | |
142 | 137 |
143 // Navigate to the initial URL. | 138 // Navigate to the initial URL. |
144 content::NavigationController::LoadURLParams load_params(start_url_); | 139 content::NavigationController::LoadURLParams load_params(start_url_); |
145 load_params.should_replace_current_entry = true; | 140 load_params.should_replace_current_entry = true; |
146 load_params.should_clear_history_list = true; | 141 load_params.should_clear_history_list = true; |
147 offscreen_tab_web_contents_->GetController().LoadURLWithParams(load_params); | 142 offscreen_tab_web_contents_->GetController().LoadURLWithParams(load_params); |
148 | 143 |
149 start_time_ = base::TimeTicks::Now(); | 144 start_time_ = base::TimeTicks::Now(); |
150 DieIfContentCaptureEnded(); | 145 DieIfContentCaptureEnded(); |
151 } | 146 } |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 377 |
383 // Schedule the timer to check again in a second. | 378 // Schedule the timer to check again in a second. |
384 capture_poll_timer_.Start( | 379 capture_poll_timer_.Start( |
385 FROM_HERE, | 380 FROM_HERE, |
386 base::TimeDelta::FromSeconds(kPollIntervalInSeconds), | 381 base::TimeDelta::FromSeconds(kPollIntervalInSeconds), |
387 base::Bind(&OffscreenTab::DieIfContentCaptureEnded, | 382 base::Bind(&OffscreenTab::DieIfContentCaptureEnded, |
388 base::Unretained(this))); | 383 base::Unretained(this))); |
389 } | 384 } |
390 | 385 |
391 } // namespace extensions | 386 } // namespace extensions |
OLD | NEW |