Commit 8b98537a authored by François Beaufort's avatar François Beaufort Committed by Commit Bot

Show local presentation pages in chrome://inspect

This CL makes sure local presentation pages (1UA cast and wired display
fullscreen tabs) are visible in chrome://inspect.
It also now uses one single prefix for the OTR profile for both types of
local presentation pages.

Change-Id: I65603c8258104d8c3219b1ba611780a82aa844cc
Bug: 840029
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2498588Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarPeter Marshall <petermarshall@chromium.org>
Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/master@{#822549}
parent 1e88b939
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "chrome/browser/devtools/device/devtools_android_bridge.h" #include "chrome/browser/devtools/device/devtools_android_bridge.h"
#include "chrome/browser/devtools/devtools_window.h" #include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/devtools/serialize_host_descriptions.h" #include "chrome/browser/devtools/serialize_host_descriptions.h"
#include "components/media_router/browser/presentation/local_presentation_manager.h"
#include "components/media_router/browser/presentation/local_presentation_manager_factory.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_agent_host_observer.h" #include "content/public/browser/devtools_agent_host_observer.h"
...@@ -94,13 +96,16 @@ class LocalTargetsUIHandler : public DevToolsTargetsUIHandler, ...@@ -94,13 +96,16 @@ class LocalTargetsUIHandler : public DevToolsTargetsUIHandler,
private: private:
// content::DevToolsAgentHostObserver overrides. // content::DevToolsAgentHostObserver overrides.
bool ShouldForceDevToolsAgentHostCreation() override; bool ShouldForceDevToolsAgentHostCreation() override;
void DevToolsAgentHostCreated(DevToolsAgentHost* agent_host) override; void DevToolsAgentHostCreated(DevToolsAgentHost* host) override;
void DevToolsAgentHostDestroyed(DevToolsAgentHost* agent_host) override; void DevToolsAgentHostDestroyed(DevToolsAgentHost* host) override;
void ScheduleUpdate(); void ScheduleUpdate();
void UpdateTargets(); void UpdateTargets();
bool AllowDevToolsFor(DevToolsAgentHost* host);
Profile* profile_; Profile* profile_;
media_router::LocalPresentationManager* local_presentation_manager_;
std::unique_ptr<CancelableTimer> timer_; std::unique_ptr<CancelableTimer> timer_;
base::WeakPtrFactory<LocalTargetsUIHandler> weak_factory_{this}; base::WeakPtrFactory<LocalTargetsUIHandler> weak_factory_{this};
}; };
...@@ -108,7 +113,10 @@ private: ...@@ -108,7 +113,10 @@ private:
LocalTargetsUIHandler::LocalTargetsUIHandler(const Callback& callback, LocalTargetsUIHandler::LocalTargetsUIHandler(const Callback& callback,
Profile* profile) Profile* profile)
: DevToolsTargetsUIHandler(kTargetSourceLocal, callback), : DevToolsTargetsUIHandler(kTargetSourceLocal, callback),
profile_(profile) { profile_(profile),
local_presentation_manager_(
media_router::LocalPresentationManagerFactory::
GetOrCreateForBrowserContext(profile_)) {
DevToolsAgentHost::AddObserver(this); DevToolsAgentHost::AddObserver(this);
UpdateTargets(); UpdateTargets();
} }
...@@ -150,10 +158,9 @@ void LocalTargetsUIHandler::UpdateTargets() { ...@@ -150,10 +158,9 @@ void LocalTargetsUIHandler::UpdateTargets() {
hosts.reserve(targets.size()); hosts.reserve(targets.size());
targets_.clear(); targets_.clear();
for (const scoped_refptr<DevToolsAgentHost>& host : targets) { for (const scoped_refptr<DevToolsAgentHost>& host : targets) {
if (Profile::FromBrowserContext(host->GetBrowserContext()) != profile_) if (!AllowDevToolsFor(host.get()))
continue;
if (!DevToolsWindow::AllowDevToolsFor(profile_, host->GetWebContents()))
continue; continue;
targets_[host->GetId()] = host; targets_[host->GetId()] = host;
hosts.push_back({host->GetId(), host->GetParentId(), hosts.push_back({host->GetId(), host->GetParentId(),
std::move(*Serialize(host.get()))}); std::move(*Serialize(host.get()))});
...@@ -163,6 +170,13 @@ void LocalTargetsUIHandler::UpdateTargets() { ...@@ -163,6 +170,13 @@ void LocalTargetsUIHandler::UpdateTargets() {
SerializeHostDescriptions(std::move(hosts), kGuestList)); SerializeHostDescriptions(std::move(hosts), kGuestList));
} }
bool LocalTargetsUIHandler::AllowDevToolsFor(DevToolsAgentHost* host) {
return local_presentation_manager_->IsLocalPresentation(
host->GetWebContents()) ||
(Profile::FromBrowserContext(host->GetBrowserContext()) == profile_ &&
DevToolsWindow::AllowDevToolsFor(profile_, host->GetWebContents()));
}
// AdbTargetsUIHandler -------------------------------------------------------- // AdbTargetsUIHandler --------------------------------------------------------
class AdbTargetsUIHandler class AdbTargetsUIHandler
......
...@@ -124,7 +124,7 @@ class OffscreenTab::WindowAdoptionAgent final : protected aura::WindowObserver { ...@@ -124,7 +124,7 @@ class OffscreenTab::WindowAdoptionAgent final : protected aura::WindowObserver {
OffscreenTab::OffscreenTab(Owner* owner, content::BrowserContext* context) OffscreenTab::OffscreenTab(Owner* owner, content::BrowserContext* context)
: owner_(owner), : owner_(owner),
otr_profile_(Profile::FromBrowserContext(context)->GetOffTheRecordProfile( otr_profile_(Profile::FromBrowserContext(context)->GetOffTheRecordProfile(
Profile::OTRProfileID::CreateUnique("Media::OffscreenTab"))), Profile::OTRProfileID::CreateUniqueForMediaRouter())),
content_capture_was_detected_(false), content_capture_was_detected_(false),
navigation_policy_( navigation_policy_(
std::make_unique<media_router::DefaultNavigationPolicy>()) { std::make_unique<media_router::DefaultNavigationPolicy>()) {
......
...@@ -119,6 +119,8 @@ class ChromeVariationsClient : public variations::VariationsClient { ...@@ -119,6 +119,8 @@ class ChromeVariationsClient : public variations::VariationsClient {
}; };
const char kDevToolsOTRProfileIDPrefix[] = "Devtools::BrowserContext"; const char kDevToolsOTRProfileIDPrefix[] = "Devtools::BrowserContext";
const char kMediaRouterOTRProfileIDPrefix[] = "MediaRouter::Presentation";
} // namespace } // namespace
Profile::OTRProfileID::OTRProfileID(const std::string& profile_id) Profile::OTRProfileID::OTRProfileID(const std::string& profile_id)
...@@ -126,9 +128,12 @@ Profile::OTRProfileID::OTRProfileID(const std::string& profile_id) ...@@ -126,9 +128,12 @@ Profile::OTRProfileID::OTRProfileID(const std::string& profile_id)
bool Profile::OTRProfileID::AllowsBrowserWindows() const { bool Profile::OTRProfileID::AllowsBrowserWindows() const {
// Non-Primary OTR profiles are not supposed to create Browser windows. // Non-Primary OTR profiles are not supposed to create Browser windows.
// DevTools::BrowserContext is an exception to this ban. // DevTools::BrowserContext and MediaRouter::Presentation are an
// exception to this ban.
return *this == PrimaryID() || return *this == PrimaryID() ||
base::StartsWith(profile_id_, kDevToolsOTRProfileIDPrefix, base::StartsWith(profile_id_, kDevToolsOTRProfileIDPrefix,
base::CompareCase::SENSITIVE) ||
base::StartsWith(profile_id_, kMediaRouterOTRProfileIDPrefix,
base::CompareCase::SENSITIVE); base::CompareCase::SENSITIVE);
} }
...@@ -152,6 +157,11 @@ Profile::OTRProfileID Profile::OTRProfileID::CreateUniqueForDevTools() { ...@@ -152,6 +157,11 @@ Profile::OTRProfileID Profile::OTRProfileID::CreateUniqueForDevTools() {
return CreateUnique(kDevToolsOTRProfileIDPrefix); return CreateUnique(kDevToolsOTRProfileIDPrefix);
} }
// static
Profile::OTRProfileID Profile::OTRProfileID::CreateUniqueForMediaRouter() {
return CreateUnique(kMediaRouterOTRProfileIDPrefix);
}
const std::string& Profile::OTRProfileID::ToString() const { const std::string& Profile::OTRProfileID::ToString() const {
return profile_id_; return profile_id_;
} }
......
...@@ -121,6 +121,9 @@ class Profile : public content::BrowserContext { ...@@ -121,6 +121,9 @@ class Profile : public content::BrowserContext {
// Creates a unique OTR profile id to be used for DevTools browser contexts. // Creates a unique OTR profile id to be used for DevTools browser contexts.
static OTRProfileID CreateUniqueForDevTools(); static OTRProfileID CreateUniqueForDevTools();
// Creates a unique OTR profile id to be used for media router.
static OTRProfileID CreateUniqueForMediaRouter();
bool operator==(const OTRProfileID& other) const { bool operator==(const OTRProfileID& other) const {
return profile_id_ == other.profile_id_; return profile_id_ == other.profile_id_;
} }
......
...@@ -113,9 +113,8 @@ PresentationReceiverWindowController::PresentationReceiverWindowController( ...@@ -113,9 +113,8 @@ PresentationReceiverWindowController::PresentationReceiverWindowController(
const gfx::Rect& bounds, const gfx::Rect& bounds,
base::OnceClosure termination_callback, base::OnceClosure termination_callback,
TitleChangeCallback title_change_callback) TitleChangeCallback title_change_callback)
: otr_profile_( : otr_profile_(profile->GetOffTheRecordProfile(
profile->GetOffTheRecordProfile(Profile::OTRProfileID::CreateUnique( Profile::OTRProfileID::CreateUniqueForMediaRouter())),
"MediaRouter::PresentationReciever"))),
web_contents_(WebContents::Create(CreateWebContentsParams(otr_profile_))), web_contents_(WebContents::Create(CreateWebContentsParams(otr_profile_))),
window_(PresentationReceiverWindow::Create(this, bounds)), window_(PresentationReceiverWindow::Create(this, bounds)),
termination_callback_(std::move(termination_callback)), termination_callback_(std::move(termination_callback)),
......
...@@ -66,10 +66,11 @@ void LocalPresentationManager::UnregisterLocalPresentationController( ...@@ -66,10 +66,11 @@ void LocalPresentationManager::UnregisterLocalPresentationController(
void LocalPresentationManager::OnLocalPresentationReceiverCreated( void LocalPresentationManager::OnLocalPresentationReceiverCreated(
const PresentationInfo& presentation_info, const PresentationInfo& presentation_info,
const content::ReceiverConnectionAvailableCallback& receiver_callback) { const content::ReceiverConnectionAvailableCallback& receiver_callback,
content::WebContents* receiver_web_contents) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
auto* presentation = GetOrCreateLocalPresentation(presentation_info); auto* presentation = GetOrCreateLocalPresentation(presentation_info);
presentation->RegisterReceiver(receiver_callback); presentation->RegisterReceiver(receiver_callback, receiver_web_contents);
} }
void LocalPresentationManager::OnLocalPresentationReceiverTerminated( void LocalPresentationManager::OnLocalPresentationReceiverTerminated(
...@@ -83,6 +84,15 @@ bool LocalPresentationManager::IsLocalPresentation( ...@@ -83,6 +84,15 @@ bool LocalPresentationManager::IsLocalPresentation(
return base::Contains(local_presentations_, presentation_id); return base::Contains(local_presentations_, presentation_id);
} }
bool LocalPresentationManager::IsLocalPresentation(
content::WebContents* web_contents) {
for (auto& local_presentation : local_presentations_) {
if (local_presentation.second->receiver_web_contents_ == web_contents)
return true;
}
return false;
}
const MediaRoute* LocalPresentationManager::GetRoute( const MediaRoute* LocalPresentationManager::GetRoute(
const std::string& presentation_id) { const std::string& presentation_id) {
auto it = local_presentations_.find(presentation_id); auto it = local_presentations_.find(presentation_id);
...@@ -124,8 +134,10 @@ void LocalPresentationManager::LocalPresentation::UnregisterController( ...@@ -124,8 +134,10 @@ void LocalPresentationManager::LocalPresentation::UnregisterController(
} }
void LocalPresentationManager::LocalPresentation::RegisterReceiver( void LocalPresentationManager::LocalPresentation::RegisterReceiver(
const content::ReceiverConnectionAvailableCallback& receiver_callback) { const content::ReceiverConnectionAvailableCallback& receiver_callback,
content::WebContents* receiver_web_contents) {
DCHECK(receiver_callback_.is_null()); DCHECK(receiver_callback_.is_null());
DCHECK(receiver_web_contents);
for (auto& controller : pending_controllers_) { for (auto& controller : pending_controllers_) {
receiver_callback.Run( receiver_callback.Run(
PresentationInfo::New(presentation_info_), PresentationInfo::New(presentation_info_),
...@@ -133,6 +145,7 @@ void LocalPresentationManager::LocalPresentation::RegisterReceiver( ...@@ -133,6 +145,7 @@ void LocalPresentationManager::LocalPresentation::RegisterReceiver(
std::move(controller.second->receiver_connection_receiver)); std::move(controller.second->receiver_connection_receiver));
} }
receiver_callback_ = receiver_callback; receiver_callback_ = receiver_callback;
receiver_web_contents_ = receiver_web_contents;
pending_controllers_.clear(); pending_controllers_.clear();
} }
......
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/mojom/presentation/presentation.mojom.h" #include "third_party/blink/public/mojom/presentation/presentation.mojom.h"
namespace content {
class WebContents;
}
namespace media_router { namespace media_router {
// Manages all local presentations started in the associated Profile and // Manages all local presentations started in the associated Profile and
// facilitates communication between the controllers and the receiver of a // facilitates communication between the controllers and the receiver of a
...@@ -132,10 +136,12 @@ class LocalPresentationManager : public KeyedService { ...@@ -132,10 +136,12 @@ class LocalPresentationManager : public KeyedService {
const std::string& presentation_id, const std::string& presentation_id,
const content::GlobalFrameRoutingId& render_frame_id); const content::GlobalFrameRoutingId& render_frame_id);
// Registers |receiver_callback| to presentation with |presentation_info|. // Registers |receiver_callback| and set |receiver_web_contents| to
// presentation with |presentation_info|.
virtual void OnLocalPresentationReceiverCreated( virtual void OnLocalPresentationReceiverCreated(
const blink::mojom::PresentationInfo& presentation_info, const blink::mojom::PresentationInfo& presentation_info,
const content::ReceiverConnectionAvailableCallback& receiver_callback); const content::ReceiverConnectionAvailableCallback& receiver_callback,
content::WebContents* receiver_web_contents);
// Unregisters ReceiverConnectionAvailableCallback associated with // Unregisters ReceiverConnectionAvailableCallback associated with
// |presentation_id|. // |presentation_id|.
...@@ -146,6 +152,9 @@ class LocalPresentationManager : public KeyedService { ...@@ -146,6 +152,9 @@ class LocalPresentationManager : public KeyedService {
// |presentation_id|. // |presentation_id|.
virtual bool IsLocalPresentation(const std::string& presentation_id); virtual bool IsLocalPresentation(const std::string& presentation_id);
// Returns true if this class has a local presentation with |web_contents|.
virtual bool IsLocalPresentation(content::WebContents* web_contents);
// Returns nullptr if |presentation_id| is not associated with a local // Returns nullptr if |presentation_id| is not associated with a local
// presentation. // presentation.
virtual const MediaRoute* GetRoute(const std::string& presentation_id); virtual const MediaRoute* GetRoute(const std::string& presentation_id);
...@@ -181,12 +190,13 @@ class LocalPresentationManager : public KeyedService { ...@@ -181,12 +190,13 @@ class LocalPresentationManager : public KeyedService {
void UnregisterController( void UnregisterController(
const content::GlobalFrameRoutingId& render_frame_id); const content::GlobalFrameRoutingId& render_frame_id);
// Register |receiver_callback| to current local_presentation object. // Register |receiver_callback| and set |receiver_web_contents| to current
// For each controller in |pending_controllers_| map, invoke // local_presentation object. For each controller in |pending_controllers_|
// |receiver_callback| with controller as parameter. Clear // map, invoke |receiver_callback| with controller as parameter. Clear
// |pending_controllers_| map afterwards. // |pending_controllers_| map afterwards.
void RegisterReceiver( void RegisterReceiver(
const content::ReceiverConnectionAvailableCallback& receiver_callback); const content::ReceiverConnectionAvailableCallback& receiver_callback,
content::WebContents* receiver_web_contents);
private: private:
friend class LocalPresentationManagerTest; friend class LocalPresentationManagerTest;
...@@ -198,6 +208,7 @@ class LocalPresentationManager : public KeyedService { ...@@ -198,6 +208,7 @@ class LocalPresentationManager : public KeyedService {
const blink::mojom::PresentationInfo presentation_info_; const blink::mojom::PresentationInfo presentation_info_;
base::Optional<MediaRoute> route_; base::Optional<MediaRoute> route_;
content::WebContents* receiver_web_contents_ = nullptr;
// Callback to invoke whenever a receiver connection is available. // Callback to invoke whenever a receiver connection is available.
content::ReceiverConnectionAvailableCallback receiver_callback_; content::ReceiverConnectionAvailableCallback receiver_callback_;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "components/media_router/browser/presentation/local_presentation_manager.h" #include "components/media_router/browser/presentation/local_presentation_manager.h"
#include "components/media_router/browser/test/test_helper.h" #include "components/media_router/browser/test/test_helper.h"
#include "content/public/test/test_renderer_host.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -36,7 +37,7 @@ class MockReceiverConnectionAvailableCallback { ...@@ -36,7 +37,7 @@ class MockReceiverConnectionAvailableCallback {
mojo::PendingReceiver<blink::mojom::PresentationConnection>)); mojo::PendingReceiver<blink::mojom::PresentationConnection>));
}; };
class LocalPresentationManagerTest : public ::testing::Test { class LocalPresentationManagerTest : public content::RenderViewHostTestHarness {
public: public:
LocalPresentationManagerTest() LocalPresentationManagerTest()
: render_frame_host_id_(1, 1), : render_frame_host_id_(1, 1),
...@@ -101,7 +102,8 @@ class LocalPresentationManagerTest : public ::testing::Test { ...@@ -101,7 +102,8 @@ class LocalPresentationManagerTest : public ::testing::Test {
PresentationInfo(GURL(kPresentationUrl), presentation_id), PresentationInfo(GURL(kPresentationUrl), presentation_id),
base::BindRepeating(&MockReceiverConnectionAvailableCallback:: base::BindRepeating(&MockReceiverConnectionAvailableCallback::
OnReceiverConnectionAvailable, OnReceiverConnectionAvailable,
base::Unretained(&receiver_callback))); base::Unretained(&receiver_callback)),
web_contents());
} }
void UnregisterController( void UnregisterController(
...@@ -319,13 +321,21 @@ TEST_F(LocalPresentationManagerTest, TwoPresentations) { ...@@ -319,13 +321,21 @@ TEST_F(LocalPresentationManagerTest, TwoPresentations) {
VerifyPresentationsSize(1); VerifyPresentationsSize(1);
} }
TEST_F(LocalPresentationManagerTest, TestIsLocalPresentation) { TEST_F(LocalPresentationManagerTest,
TestIsLocalPresentationWithPresentationId) {
EXPECT_FALSE(manager()->IsLocalPresentation(kPresentationId)); EXPECT_FALSE(manager()->IsLocalPresentation(kPresentationId));
mojo::PendingRemote<blink::mojom::PresentationConnection> controller1; mojo::PendingRemote<blink::mojom::PresentationConnection> controller1;
RegisterController(kPresentationId, std::move(controller1)); RegisterController(kPresentationId, std::move(controller1));
EXPECT_TRUE(manager()->IsLocalPresentation(kPresentationId)); EXPECT_TRUE(manager()->IsLocalPresentation(kPresentationId));
} }
TEST_F(LocalPresentationManagerTest, TestIsLocalPresentationWithWebContents) {
EXPECT_FALSE(manager()->IsLocalPresentation(web_contents()));
MockReceiverConnectionAvailableCallback receiver_callback;
RegisterReceiver(receiver_callback);
EXPECT_TRUE(manager()->IsLocalPresentation(web_contents()));
}
TEST_F(LocalPresentationManagerTest, TestRegisterAndGetRoute) { TEST_F(LocalPresentationManagerTest, TestRegisterAndGetRoute) {
MediaSource source("source_1"); MediaSource source("source_1");
MediaRoute route("route_1", source, "sink_1", "", false, false); MediaRoute route("route_1", source, "sink_1", "", false, false);
......
...@@ -73,7 +73,7 @@ void ReceiverPresentationServiceDelegateImpl:: ...@@ -73,7 +73,7 @@ void ReceiverPresentationServiceDelegateImpl::
local_presentation_manager_->OnLocalPresentationReceiverCreated( local_presentation_manager_->OnLocalPresentationReceiverCreated(
blink::mojom::PresentationInfo(web_contents_->GetLastCommittedURL(), blink::mojom::PresentationInfo(web_contents_->GetLastCommittedURL(),
presentation_id_), presentation_id_),
receiver_available_callback); receiver_available_callback, web_contents_);
} }
WEB_CONTENTS_USER_DATA_KEY_IMPL(ReceiverPresentationServiceDelegateImpl) WEB_CONTENTS_USER_DATA_KEY_IMPL(ReceiverPresentationServiceDelegateImpl)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment