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