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" |
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_widget_host_view.h" | 16 #include "content/public/browser/render_widget_host_view.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "extensions/browser/extension_host.h" | 18 #include "extensions/browser/extension_host.h" |
18 #include "extensions/browser/process_manager.h" | 19 #include "extensions/browser/process_manager.h" |
19 | 20 |
20 using content::WebContents; | 21 using content::WebContents; |
21 | 22 |
22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::OffscreenTabsOwner); | 23 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::OffscreenTabsOwner); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 DVLOG(1) << "Destroying OffscreenTab for start_url=" << start_url_.spec(); | 93 DVLOG(1) << "Destroying OffscreenTab for start_url=" << start_url_.spec(); |
93 } | 94 } |
94 | 95 |
95 void OffscreenTab::Start(const GURL& start_url, | 96 void OffscreenTab::Start(const GURL& start_url, |
96 const gfx::Size& initial_size, | 97 const gfx::Size& initial_size, |
97 const std::string& optional_presentation_id) { | 98 const std::string& optional_presentation_id) { |
98 DCHECK(start_time_.is_null()); | 99 DCHECK(start_time_.is_null()); |
99 start_url_ = start_url; | 100 start_url_ = start_url; |
100 DVLOG(1) << "Starting OffscreenTab with initial size of " | 101 DVLOG(1) << "Starting OffscreenTab with initial size of " |
101 << initial_size.ToString() << " for start_url=" << start_url_.spec(); | 102 << initial_size.ToString() << " for start_url=" << start_url_.spec(); |
102 | |
103 // Create the WebContents to contain the off-screen tab's page. | 103 // Create the WebContents to contain the off-screen tab's page. |
104 offscreen_tab_web_contents_.reset( | 104 offscreen_tab_web_contents_.reset( |
105 WebContents::Create(WebContents::CreateParams(profile_.get()))); | 105 WebContents::Create(WebContents::CreateParams(profile_.get()))); |
106 offscreen_tab_web_contents_->SetDelegate(this); | 106 offscreen_tab_web_contents_->SetDelegate(this); |
107 WebContentsObserver::Observe(offscreen_tab_web_contents_.get()); | 107 WebContentsObserver::Observe(offscreen_tab_web_contents_.get()); |
108 | 108 |
109 // Set initial size, if specified. | 109 // Set initial size, if specified. |
110 if (!initial_size.IsEmpty()) | 110 if (!initial_size.IsEmpty()) |
111 ResizeWebContents(offscreen_tab_web_contents_.get(), | 111 ResizeWebContents(offscreen_tab_web_contents_.get(), |
112 gfx::Rect(initial_size)); | 112 gfx::Rect(initial_size)); |
113 | 113 |
114 // Mute audio output. When tab capture starts, the audio will be | 114 // Mute audio output. When tab capture starts, the audio will be |
115 // automatically unmuted, but will be captured into the MediaStream. | 115 // automatically unmuted, but will be captured into the MediaStream. |
116 offscreen_tab_web_contents_->SetAudioMuted(true); | 116 offscreen_tab_web_contents_->SetAudioMuted(true); |
117 | 117 |
118 // TODO(imcheng): If |optional_presentation_id| is not empty, register it with | |
119 // the PresentationRouter. http://crbug.com/513859 | |
120 if (!optional_presentation_id.empty()) { | 118 if (!optional_presentation_id.empty()) { |
121 NOTIMPLEMENTED() | 119 DVLOG(1) << " Register with ReceiverPresentationServiceDelegateImpl, id=" |
122 << "Register with PresentationRouter, id=" << optional_presentation_id; | 120 << optional_presentation_id; |
| 121 // Register the offscreen tab as the receiver of the offscreen presentation. |
| 122 media_router::ReceiverPresentationServiceDelegateImpl::CreateForWebContents( |
| 123 offscreen_tab_web_contents_.get(), optional_presentation_id); |
123 } | 124 } |
124 | 125 |
125 // Navigate to the initial URL. | 126 // Navigate to the initial URL. |
126 content::NavigationController::LoadURLParams load_params(start_url_); | 127 content::NavigationController::LoadURLParams load_params(start_url_); |
127 load_params.should_replace_current_entry = true; | 128 load_params.should_replace_current_entry = true; |
128 load_params.should_clear_history_list = true; | 129 load_params.should_clear_history_list = true; |
129 offscreen_tab_web_contents_->GetController().LoadURLWithParams(load_params); | 130 offscreen_tab_web_contents_->GetController().LoadURLWithParams(load_params); |
130 | 131 |
131 start_time_ = base::TimeTicks::Now(); | 132 start_time_ = base::TimeTicks::Now(); |
132 DieIfContentCaptureEnded(); | 133 DieIfContentCaptureEnded(); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 | 363 |
363 // Schedule the timer to check again in a second. | 364 // Schedule the timer to check again in a second. |
364 capture_poll_timer_.Start( | 365 capture_poll_timer_.Start( |
365 FROM_HERE, | 366 FROM_HERE, |
366 base::TimeDelta::FromSeconds(kPollIntervalInSeconds), | 367 base::TimeDelta::FromSeconds(kPollIntervalInSeconds), |
367 base::Bind(&OffscreenTab::DieIfContentCaptureEnded, | 368 base::Bind(&OffscreenTab::DieIfContentCaptureEnded, |
368 base::Unretained(this))); | 369 base::Unretained(this))); |
369 } | 370 } |
370 | 371 |
371 } // namespace extensions | 372 } // namespace extensions |
OLD | NEW |