diff options
Diffstat (limited to 'chromium/fuchsia/engine/browser')
21 files changed, 561 insertions, 159 deletions
diff --git a/chromium/fuchsia/engine/browser/DEPS b/chromium/fuchsia/engine/browser/DEPS index 79f6dcab122..6ffa902e765 100644 --- a/chromium/fuchsia/engine/browser/DEPS +++ b/chromium/fuchsia/engine/browser/DEPS @@ -6,6 +6,8 @@ include_rules = [ "+media/capabilities", "+media/fuchsia/cdm/service", "+media/fuchsia/mojom", + "+media/mojo/common", + "+media/mojo/mojom", "+media/mojo/services", "+mojo/public/cpp/bindings", "+mojo/public/cpp/system", diff --git a/chromium/fuchsia/engine/browser/accessibility_bridge_browsertest.cc b/chromium/fuchsia/engine/browser/accessibility_bridge_browsertest.cc index 0d97daf24e1..6476e8a0f28 100644 --- a/chromium/fuchsia/engine/browser/accessibility_bridge_browsertest.cc +++ b/chromium/fuchsia/engine/browser/accessibility_bridge_browsertest.cc @@ -4,13 +4,11 @@ #include <fuchsia/accessibility/semantics/cpp/fidl.h> #include <fuchsia/accessibility/semantics/cpp/fidl_test_base.h> -#include <lib/sys/cpp/component_context.h> #include <lib/ui/scenic/cpp/view_ref_pair.h> #include <zircon/types.h> #include "base/auto_reset.h" #include "base/check.h" -#include "base/fuchsia/default_context.h" #include "base/fuchsia/scoped_service_binding.h" #include "base/notreached.h" #include "base/test/bind_test_util.h" diff --git a/chromium/fuchsia/engine/browser/cast_streaming_browsertest.cc b/chromium/fuchsia/engine/browser/cast_streaming_browsertest.cc new file mode 100644 index 00000000000..cc94207a341 --- /dev/null +++ b/chromium/fuchsia/engine/browser/cast_streaming_browsertest.cc @@ -0,0 +1,129 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/public/test/browser_test.h" +#include "fuchsia/base/fit_adapter.h" +#include "fuchsia/base/frame_test_util.h" +#include "fuchsia/base/mem_buffer_util.h" +#include "fuchsia/base/result_receiver.h" +#include "fuchsia/base/test_navigation_listener.h" +#include "fuchsia/engine/browser/frame_impl.h" +#include "fuchsia/engine/switches.h" +#include "fuchsia/engine/test/test_data.h" +#include "fuchsia/engine/test/web_engine_browser_test.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +const char kCastStreamingReceiverPath[] = "/cast_streaming_receiver.html"; + +} // namespace + +// Base test fixture for Cast Streaming tests. +class CastStreamingBaseTest : public cr_fuchsia::WebEngineBrowserTest { + public: + CastStreamingBaseTest() { + set_test_server_root(base::FilePath(cr_fuchsia::kTestServerRoot)); + } + ~CastStreamingBaseTest() override = default; + + CastStreamingBaseTest(const CastStreamingBaseTest&) = delete; + CastStreamingBaseTest& operator=(const CastStreamingBaseTest&) = delete; + + protected: + // Creates a Frame with |navigation_listener_| attached. + fuchsia::web::FramePtr CreateFrame() { + return WebEngineBrowserTest::CreateFrame(&navigation_listener_); + } + + cr_fuchsia::TestNavigationListener navigation_listener_; +}; + +// Test fixture for Cast Streaming tests with the Cast Streaming Receiver flag +// disabled. +class CastStreamingDisabledTest : public CastStreamingBaseTest { + public: + CastStreamingDisabledTest() = default; + ~CastStreamingDisabledTest() override = default; + CastStreamingDisabledTest(const CastStreamingDisabledTest&) = delete; + CastStreamingDisabledTest& operator=(const CastStreamingDisabledTest&) = + delete; + + protected: + void SetUpCommandLine(base::CommandLine* command_line) override { + content::BrowserTestBase::SetUpCommandLine(command_line); + command_line->RemoveSwitch(switches::kEnableCastStreamingReceiver); + } +}; + +// Test fixture for Cast Streaming tests with the Cast Streaming Receiver flag +// enabled. +class CastStreamingTest : public CastStreamingBaseTest { + public: + CastStreamingTest() = default; + ~CastStreamingTest() override = default; + CastStreamingTest(const CastStreamingTest&) = delete; + CastStreamingTest& operator=(const CastStreamingTest&) = delete; + + protected: + void SetUpCommandLine(base::CommandLine* command_line) override { + content::BrowserTestBase::SetUpCommandLine(command_line); + command_line->AppendSwitch(switches::kEnableCastStreamingReceiver); + } +}; + +// Check that attempting to load the cast streaming media source URL when the +// command line switch is not set fails as expected. +IN_PROC_BROWSER_TEST_F(CastStreamingDisabledTest, LoadFailure) { + ASSERT_TRUE(embedded_test_server()->Start()); + GURL page_url(embedded_test_server()->GetURL(kCastStreamingReceiverPath)); + + fuchsia::web::FramePtr frame = CreateFrame(); + fuchsia::web::NavigationControllerPtr controller; + frame->GetNavigationController(controller.NewRequest()); + EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse( + controller.get(), fuchsia::web::LoadUrlParams(), page_url.spec())); + navigation_listener_.RunUntilTitleEquals("error"); +} + +// Check that the Cast Streaming MessagePort gets properly set on the Frame. +IN_PROC_BROWSER_TEST_F(CastStreamingTest, FrameMessagePort) { + fuchsia::web::FramePtr frame = CreateFrame(); + + FrameImpl* frame_impl = context_impl()->GetFrameImplForTest(&frame); + ASSERT_TRUE(frame_impl); + EXPECT_FALSE(frame_impl->cast_streaming_session_client_for_test()); + + fuchsia::web::MessagePortPtr cast_streaming_message_port; + + base::RunLoop run_loop; + cr_fuchsia::ResultReceiver<fuchsia::web::Frame_PostMessage_Result> + post_result(run_loop.QuitClosure()); + frame->PostMessage( + "cast-streaming:receiver", + cr_fuchsia::CreateWebMessageWithMessagePortRequest( + cast_streaming_message_port.NewRequest(), + cr_fuchsia::MemBufferFromString("hi", "test")), + cr_fuchsia::CallbackToFitFunction(post_result.GetReceiveCallback())); + run_loop.Run(); + ASSERT_TRUE(post_result->is_response()); + + EXPECT_TRUE(frame_impl->cast_streaming_session_client_for_test()); +} + +// Check that attempting to load the cast streaming media source URL when the +// command line switch is set properly succeeds. +// TODO(crbug.com/1087537): Re-enable when we have a test implementation for a +// Cast Streaming Sender. +IN_PROC_BROWSER_TEST_F(CastStreamingTest, DISABLED_LoadSuccess) { + ASSERT_TRUE(embedded_test_server()->Start()); + GURL page_url(embedded_test_server()->GetURL(kCastStreamingReceiverPath)); + + fuchsia::web::FramePtr frame = CreateFrame(); + fuchsia::web::NavigationControllerPtr controller; + frame->GetNavigationController(controller.NewRequest()); + EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse( + controller.get(), fuchsia::web::LoadUrlParams(), page_url.spec())); + navigation_listener_.RunUntilTitleEquals("canplay"); +} diff --git a/chromium/fuchsia/engine/browser/cast_streaming_session_client.cc b/chromium/fuchsia/engine/browser/cast_streaming_session_client.cc new file mode 100644 index 00000000000..5b022f927eb --- /dev/null +++ b/chromium/fuchsia/engine/browser/cast_streaming_session_client.cc @@ -0,0 +1,111 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "fuchsia/engine/browser/cast_streaming_session_client.h" + +#include "base/threading/sequenced_task_runner_handle.h" +#include "media/base/audio_decoder_config.h" +#include "media/base/video_decoder_config.h" +#include "media/mojo/mojom/media_types.mojom.h" + +CastStreamingSessionClient::CastStreamingSessionClient( + fidl::InterfaceRequest<fuchsia::web::MessagePort> message_port_request) + : message_port_request_(std::move(message_port_request)) {} + +CastStreamingSessionClient::~CastStreamingSessionClient() = default; + +void CastStreamingSessionClient::StartMojoConnection( + mojo::AssociatedRemote<mojom::CastStreamingReceiver> + cast_streaming_receiver) { + DVLOG(1) << __func__; + cast_streaming_receiver_ = std::move(cast_streaming_receiver); + + // It is fine to use an unretained pointer to |this| here as the + // AssociatedRemote, is owned by |this| and will be torn-down at the same time + // as |this|. + cast_streaming_receiver_->EnableReceiver(base::BindOnce( + &CastStreamingSessionClient::OnReceiverEnabled, base::Unretained(this))); + cast_streaming_receiver_.set_disconnect_handler(base::BindOnce( + &CastStreamingSessionClient::OnMojoDisconnect, base::Unretained(this))); +} + +void CastStreamingSessionClient::OnReceiverEnabled() { + DVLOG(1) << __func__; + DCHECK(message_port_request_); + cast_streaming_session_.Start(this, std::move(message_port_request_), + base::SequencedTaskRunnerHandle::Get()); +} + +void CastStreamingSessionClient::OnInitializationSuccess( + base::Optional<cast_streaming::CastStreamingSession::AudioStreamInfo> + audio_stream_info, + base::Optional<cast_streaming::CastStreamingSession::VideoStreamInfo> + video_stream_info) { + DVLOG(1) << __func__; + DCHECK(audio_stream_info || video_stream_info); + + mojom::AudioStreamInfoPtr mojo_audio_stream_info; + if (audio_stream_info) { + mojo_audio_stream_info = + mojom::AudioStreamInfo::New(audio_stream_info->decoder_config, + audio_remote_.BindNewPipeAndPassReceiver(), + std::move(audio_stream_info->data_pipe)); + } + + mojom::VideoStreamInfoPtr mojo_video_stream_info; + if (video_stream_info) { + mojo_video_stream_info = + mojom::VideoStreamInfo::New(video_stream_info->decoder_config, + video_remote_.BindNewPipeAndPassReceiver(), + std::move(video_stream_info->data_pipe)); + } + + cast_streaming_receiver_->OnStreamsInitialized( + std::move(mojo_audio_stream_info), std::move(mojo_video_stream_info)); +} + +void CastStreamingSessionClient::OnInitializationFailure() { + DVLOG(1) << __func__; + cast_streaming_receiver_.reset(); +} + +void CastStreamingSessionClient::OnAudioBufferReceived( + media::mojom::DecoderBufferPtr buffer) { + DVLOG(3) << __func__; + DCHECK(audio_remote_); + audio_remote_->ProvideBuffer(std::move(buffer)); +} + +void CastStreamingSessionClient::OnVideoBufferReceived( + media::mojom::DecoderBufferPtr buffer) { + DVLOG(3) << __func__; + DCHECK(video_remote_); + video_remote_->ProvideBuffer(std::move(buffer)); +} + +void CastStreamingSessionClient::OnReceiverSessionEnded() { + DVLOG(1) << __func__; + + // Tear down the Mojo connection. + cast_streaming_receiver_.reset(); +} + +void CastStreamingSessionClient::OnMojoDisconnect() { + DVLOG(1) << __func__; + + if (message_port_request_) { + // Close the MessagePort if the Cast Streaming Session was never started. + message_port_request_.Close(ZX_ERR_PEER_CLOSED); + cast_streaming_receiver_.reset(); + return; + } + + // Close the Cast Streaming Session. This will eventually call + // OnReceiverSessionEnded(), which will tear down the Mojo connection. + cast_streaming_session_.Stop(); + + // Tear down all remaining Mojo objects. + audio_remote_.reset(); + video_remote_.reset(); +} diff --git a/chromium/fuchsia/engine/browser/cast_streaming_session_client.h b/chromium/fuchsia/engine/browser/cast_streaming_session_client.h new file mode 100644 index 00000000000..f502a77e9b6 --- /dev/null +++ b/chromium/fuchsia/engine/browser/cast_streaming_session_client.h @@ -0,0 +1,57 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FUCHSIA_ENGINE_BROWSER_CAST_STREAMING_SESSION_CLIENT_H_ +#define FUCHSIA_ENGINE_BROWSER_CAST_STREAMING_SESSION_CLIENT_H_ + +#include <fuchsia/web/cpp/fidl.h> + +#include "fuchsia/cast_streaming/public/cast_streaming_session.h" +#include "fuchsia/engine/cast_streaming_session.mojom.h" +#include "mojo/public/cpp/bindings/associated_remote.h" +#include "mojo/public/cpp/bindings/remote.h" + +// Owns the CastStreamingSession and sends buffers to the renderer process via +// a Mojo service. +class CastStreamingSessionClient + : public cast_streaming::CastStreamingSession::Client { + public: + explicit CastStreamingSessionClient( + fidl::InterfaceRequest<fuchsia::web::MessagePort> message_port_request); + ~CastStreamingSessionClient() final; + + CastStreamingSessionClient(const CastStreamingSessionClient&) = delete; + CastStreamingSessionClient& operator=(const CastStreamingSessionClient&) = + delete; + + void StartMojoConnection(mojo::AssociatedRemote<mojom::CastStreamingReceiver> + cast_streaming_receiver); + + private: + // Handler for |cast_streaming_receiver_| disconnect. + void OnMojoDisconnect(); + + // Callback for mojom::CastStreamingReceiver::EnableReceiver() + void OnReceiverEnabled(); + + // cast_streaming::CastStreamingSession::Client implementation. + void OnInitializationSuccess( + base::Optional<cast_streaming::CastStreamingSession::AudioStreamInfo> + audio_stream_info, + base::Optional<cast_streaming::CastStreamingSession::VideoStreamInfo> + video_stream_info) final; + void OnInitializationFailure() final; + void OnAudioBufferReceived(media::mojom::DecoderBufferPtr buffer) final; + void OnVideoBufferReceived(media::mojom::DecoderBufferPtr buffer) final; + void OnReceiverSessionEnded() final; + + fidl::InterfaceRequest<fuchsia::web::MessagePort> message_port_request_; + mojo::AssociatedRemote<mojom::CastStreamingReceiver> cast_streaming_receiver_; + cast_streaming::CastStreamingSession cast_streaming_session_; + + mojo::Remote<mojom::CastStreamingBufferReceiver> audio_remote_; + mojo::Remote<mojom::CastStreamingBufferReceiver> video_remote_; +}; + +#endif // FUCHSIA_ENGINE_BROWSER_CAST_STREAMING_SESSION_CLIENT_H_ diff --git a/chromium/fuchsia/engine/browser/context_impl.cc b/chromium/fuchsia/engine/browser/context_impl.cc index 6c8d4641fb9..d7a12f55e7c 100644 --- a/chromium/fuchsia/engine/browser/context_impl.cc +++ b/chromium/fuchsia/engine/browser/context_impl.cc @@ -11,8 +11,10 @@ #include "base/bind.h" #include "base/fuchsia/fuchsia_logging.h" #include "content/public/browser/browser_context.h" +#include "content/public/browser/browser_thread.h" #include "content/public/browser/storage_partition.h" #include "content/public/browser/web_contents.h" +#include "fuchsia/cast_streaming/public/cast_streaming_session.h" #include "fuchsia/engine/browser/frame_impl.h" #include "fuchsia/engine/browser/web_engine_devtools_controller.h" @@ -27,6 +29,10 @@ ContextImpl::ContextImpl(content::BrowserContext* browser_context, DCHECK(browser_context_); DCHECK(devtools_controller_); devtools_controller_->OnContextCreated(); + + cast_streaming::CastStreamingSession::SetNetworkContextGetter( + base::BindRepeating(&ContextImpl::GetNetworkContext, + base::Unretained(this))); } ContextImpl::~ContextImpl() { @@ -130,3 +136,9 @@ FrameImpl* ContextImpl::GetFrameImplForTest( return nullptr; } + +network::mojom::NetworkContext* ContextImpl::GetNetworkContext() { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + return content::BrowserContext::GetDefaultStoragePartition(browser_context_) + ->GetNetworkContext(); +} diff --git a/chromium/fuchsia/engine/browser/context_impl.h b/chromium/fuchsia/engine/browser/context_impl.h index 48ee4a49b9a..53b4218a0b8 100644 --- a/chromium/fuchsia/engine/browser/context_impl.h +++ b/chromium/fuchsia/engine/browser/context_impl.h @@ -20,6 +20,12 @@ class BrowserContext; class WebContents; } // namespace content +namespace network { +namespace mojom { +class NetworkContext; +} // namespace mojom +} // namespace network + class FrameImpl; class WebEngineDevToolsController; @@ -68,6 +74,9 @@ class WEB_ENGINE_EXPORT ContextImpl : public fuchsia::web::Context { } private: + // Returns the NetworkContext from the default StoragePartition. + network::mojom::NetworkContext* GetNetworkContext(); + // Reference to the browser implementation for this Context. content::BrowserContext* const browser_context_; diff --git a/chromium/fuchsia/engine/browser/cookie_manager_impl.cc b/chromium/fuchsia/engine/browser/cookie_manager_impl.cc index e7362ae5618..d5c05f4e74b 100644 --- a/chromium/fuchsia/engine/browser/cookie_manager_impl.cc +++ b/chromium/fuchsia/engine/browser/cookie_manager_impl.cc @@ -67,12 +67,13 @@ class CookiesIteratorImpl : public fuchsia::web::CookiesIterator, } // Same as above except it takes CookieStatusList instead of just CookieList. CookiesIteratorImpl( - const std::vector<net::CookieWithStatus>& cookies_with_statuses, + const std::vector<net::CookieWithAccessResult>& + cookies_with_access_results, fidl::InterfaceRequest<fuchsia::web::CookiesIterator> iterator) : CookiesIteratorImpl(std::move(iterator)) { - for (const auto& cookie_with_status : cookies_with_statuses) { - queued_cookies_[cookie_with_status.cookie.UniqueKey()] = - ConvertCanonicalCookie(cookie_with_status.cookie, + for (const auto& cookie_with_access_result : cookies_with_access_results) { + queued_cookies_[cookie_with_access_result.cookie.UniqueKey()] = + ConvertCanonicalCookie(cookie_with_access_result.cookie, net::CookieChangeCause::INSERTED); } } @@ -159,12 +160,12 @@ void OnAllCookiesReceived( void OnCookiesAndExcludedReceived( fidl::InterfaceRequest<fuchsia::web::CookiesIterator> iterator, - const std::vector<net::CookieWithStatus>& cookies_with_statuses, - const std::vector<net::CookieWithStatus>& excluded_cookies) { + const std::vector<net::CookieWithAccessResult>& cookies_with_access_results, + const std::vector<net::CookieWithAccessResult>& excluded_cookies) { // Since CookieOptions::set_return_excluded_cookies() is not used when calling // the Mojo GetCookieList() API, |excluded_cookies| should be empty. DCHECK(excluded_cookies.empty()); - new CookiesIteratorImpl(cookies_with_statuses, std::move(iterator)); + new CookiesIteratorImpl(cookies_with_access_results, std::move(iterator)); } } // namespace diff --git a/chromium/fuchsia/engine/browser/cookie_manager_impl_unittest.cc b/chromium/fuchsia/engine/browser/cookie_manager_impl_unittest.cc index 93f28165f04..d756548fe92 100644 --- a/chromium/fuchsia/engine/browser/cookie_manager_impl_unittest.cc +++ b/chromium/fuchsia/engine/browser/cookie_manager_impl_unittest.cc @@ -17,6 +17,7 @@ #include "fuchsia/base/result_receiver.h" #include "fuchsia/engine/browser/cookie_manager_impl.h" #include "mojo/public/cpp/bindings/remote.h" +#include "net/cookies/cookie_inclusion_status.h" #include "services/network/network_service.h" #include "services/network/public/mojom/cookie_manager.mojom.h" #include "services/network/public/mojom/network_context.mojom.h" @@ -74,7 +75,7 @@ class CookieManagerImplTest : public testing::Test { net::CookieOptions options; mojo_cookie_manager_->SetCanonicalCookie( *CreateCookie(name, value), GURL(kTestCookieUrl), options, - base::BindOnce([](net::CanonicalCookie::CookieInclusionStatus status) { + base::BindOnce([](net::CookieInclusionStatus status) { EXPECT_TRUE(status.IsInclude()); })); } diff --git a/chromium/fuchsia/engine/browser/event_filter.cc b/chromium/fuchsia/engine/browser/event_filter.cc index 2a9351273bf..7ad83ac534e 100644 --- a/chromium/fuchsia/engine/browser/event_filter.cc +++ b/chromium/fuchsia/engine/browser/event_filter.cc @@ -6,6 +6,7 @@ #include <limits> +#include "base/notreached.h" #include "ui/events/event.h" namespace { diff --git a/chromium/fuchsia/engine/browser/frame_impl.cc b/chromium/fuchsia/engine/browser/frame_impl.cc index 6f9df2f15e3..317166e3c60 100644 --- a/chromium/fuchsia/engine/browser/frame_impl.cc +++ b/chromium/fuchsia/engine/browser/frame_impl.cc @@ -6,16 +6,16 @@ #include <fuchsia/ui/gfx/cpp/fidl.h> #include <lib/sys/cpp/component_context.h> +#include <lib/ui/scenic/cpp/view_ref_pair.h> #include <limits> #include "base/bind_helpers.h" -#include "base/fuchsia/default_context.h" #include "base/fuchsia/fuchsia_logging.h" +#include "base/fuchsia/process_context.h" #include "base/json/json_writer.h" #include "base/metrics/user_metrics.h" #include "base/strings/strcat.h" #include "base/strings/utf_string_conversions.h" -#include "base/task/post_task.h" #include "base/threading/thread_task_runner_handle.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_task_traits.h" @@ -34,13 +34,16 @@ #include "content/public/common/was_activated_option.mojom.h" #include "fuchsia/base/mem_buffer_util.h" #include "fuchsia/base/message_port.h" +#include "fuchsia/cast_streaming/public/cast_streaming.h" #include "fuchsia/engine/browser/accessibility_bridge.h" +#include "fuchsia/engine/browser/cast_streaming_session_client.h" #include "fuchsia/engine/browser/context_impl.h" #include "fuchsia/engine/browser/event_filter.h" #include "fuchsia/engine/browser/frame_layout_manager.h" #include "fuchsia/engine/browser/frame_window_tree_host.h" #include "fuchsia/engine/browser/media_player_impl.h" #include "fuchsia/engine/browser/web_engine_devtools_controller.h" +#include "fuchsia/engine/common/cast_streaming.h" #include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/system/platform_handle.h" #include "net/base/net_errors.h" @@ -475,8 +478,8 @@ void FrameImpl::DestroyWindowTreeHost() { // Allows posted focus events to process before the FocusController is torn // down. - base::DeleteSoon(FROM_HERE, {content::BrowserThread::UI}, - std::move(focus_controller_)); + content::GetUIThreadTaskRunner({})->DeleteSoon(FROM_HERE, + std::move(focus_controller_)); } void FrameImpl::CloseAndDestroyFrame(zx_status_t error) { @@ -495,7 +498,81 @@ void FrameImpl::OnMediaPlayerDisconnect() { media_player_ = nullptr; } +bool FrameImpl::MaybeHandleCastStreamingMessage( + std::string* origin, + fuchsia::web::WebMessage* message, + PostMessageCallback* callback) { + if (!IsCastStreamingEnabled()) + return false; + + if (!cast_streaming::IsCastStreamingAppOrigin(*origin)) + return false; + + fuchsia::web::Frame_PostMessage_Result result; + if (cast_streaming_session_client_ || + !cast_streaming::IsValidCastStreamingMessage(*message)) { + // The Cast Streaming MessagePort should only be set once and |message| + // should be a valid Cast Streaming Message. + result.set_err(fuchsia::web::FrameError::INVALID_ORIGIN); + (*callback)(std::move(result)); + return true; + } + + cast_streaming_session_client_ = std::make_unique<CastStreamingSessionClient>( + std::move((*message->mutable_outgoing_transfer())[0].message_port())); + result.set_response(fuchsia::web::Frame_PostMessage_Response()); + (*callback)(std::move(result)); + return true; +} + +void FrameImpl::MaybeInjectBeforeLoadScripts( + content::NavigationHandle* navigation_handle) { + if (before_load_scripts_.empty()) + return; + + mojo::AssociatedRemote<mojom::OnLoadScriptInjector> + before_load_script_injector; + navigation_handle->GetRenderFrameHost() + ->GetRemoteAssociatedInterfaces() + ->GetInterface(&before_load_script_injector); + + // Provision the renderer's ScriptInjector with the scripts scoped to this + // page's origin. + before_load_script_injector->ClearOnLoadScripts(); + for (uint64_t script_id : before_load_scripts_order_) { + const OriginScopedScript& script = before_load_scripts_[script_id]; + if (IsOriginWhitelisted(navigation_handle->GetURL(), script.origins())) { + // TODO(crbug.com/1060846): Stop using handle<shared_buffer>. + before_load_script_injector->AddOnLoadScript( + mojo::WrapReadOnlySharedMemoryRegion(script.script().Duplicate())); + } + } +} + +void FrameImpl::MaybeStartCastStreaming( + content::NavigationHandle* navigation_handle) { + if (!IsCastStreamingEnabled() || !cast_streaming_session_client_) + return; + + mojo::AssociatedRemote<mojom::CastStreamingReceiver> cast_streaming_receiver; + navigation_handle->GetRenderFrameHost() + ->GetRemoteAssociatedInterfaces() + ->GetInterface(&cast_streaming_receiver); + cast_streaming_session_client_->StartMojoConnection( + std::move(cast_streaming_receiver)); +} + void FrameImpl::CreateView(fuchsia::ui::views::ViewToken view_token) { + scenic::ViewRefPair view_ref_pair = scenic::ViewRefPair::New(); + CreateViewWithViewRef(std::move(view_token), + std::move(view_ref_pair.control_ref), + std::move(view_ref_pair.view_ref)); +} + +void FrameImpl::CreateViewWithViewRef( + fuchsia::ui::views::ViewToken view_token, + fuchsia::ui::views::ViewRefControl control_ref, + fuchsia::ui::views::ViewRef view_ref) { if (IsHeadless()) { LOG(WARNING) << "CreateView() called on a HEADLESS Context."; CloseAndDestroyFrame(ZX_ERR_INVALID_ARGS); @@ -505,10 +582,13 @@ void FrameImpl::CreateView(fuchsia::ui::views::ViewToken view_token) { // If a View to this Frame is already active then disconnect it. DestroyWindowTreeHost(); - InitWindowTreeHost(std::move(view_token)); + scenic::ViewRefPair view_ref_pair; + view_ref_pair.control_ref = std::move(control_ref); + view_ref_pair.view_ref = std::move(view_ref); + InitWindowTreeHost(std::move(view_token), std::move(view_ref_pair)); fuchsia::accessibility::semantics::SemanticsManagerPtr semantics_manager = - base::fuchsia::ComponentContextForCurrentProcess() + base::ComponentContextForProcess() ->svc() ->Connect<fuchsia::accessibility::semantics::SemanticsManager>(); accessibility_bridge_ = std::make_unique<AccessibilityBridge>( @@ -619,6 +699,9 @@ void FrameImpl::RemoveBeforeLoadJavaScript(uint64_t id) { void FrameImpl::PostMessage(std::string origin, fuchsia::web::WebMessage message, PostMessageCallback callback) { + if (MaybeHandleCastStreamingMessage(&origin, &message, &callback)) + return; + constexpr char kWildcardOrigin[] = "*"; fuchsia::web::Frame_PostMessage_Result result; @@ -718,7 +801,8 @@ void FrameImpl::EnableHeadlessRendering() { return; } - InitWindowTreeHost(fuchsia::ui::views::ViewToken()); + scenic::ViewRefPair view_ref_pair = scenic::ViewRefPair::New(); + InitWindowTreeHost(fuchsia::ui::views::ViewToken(), std::move(view_ref_pair)); gfx::Rect bounds(kHeadlessWindowSize); if (semantics_manager_for_test_) { @@ -744,11 +828,12 @@ void FrameImpl::DisableHeadlessRendering() { DestroyWindowTreeHost(); } -void FrameImpl::InitWindowTreeHost(fuchsia::ui::views::ViewToken view_token) { +void FrameImpl::InitWindowTreeHost(fuchsia::ui::views::ViewToken view_token, + scenic::ViewRefPair view_ref_pair) { DCHECK(!window_tree_host_); window_tree_host_ = std::make_unique<FrameWindowTreeHost>( - std::move(view_token), web_contents_.get()); + std::move(view_token), std::move(view_ref_pair), web_contents_.get()); window_tree_host_->InitHost(); root_window()->AddPreTargetHandler(&event_filter_); @@ -863,7 +948,7 @@ void FrameImpl::SetPermissionState( void FrameImpl::CloseContents(content::WebContents* source) { DCHECK_EQ(source, web_contents_.get()); - context_->DestroyFrame(this); + CloseAndDestroyFrame(ZX_OK); } void FrameImpl::SetBlockMediaLoading(bool blocked) { @@ -980,30 +1065,13 @@ bool FrameImpl::CheckMediaAccessPermission( void FrameImpl::ReadyToCommitNavigation( content::NavigationHandle* navigation_handle) { - if (before_load_scripts_.empty()) - return; - if (!navigation_handle->IsInMainFrame() || navigation_handle->IsSameDocument() || navigation_handle->IsErrorPage()) { return; } - mojo::AssociatedRemote<mojom::OnLoadScriptInjector> - before_load_script_injector; - navigation_handle->GetRenderFrameHost() - ->GetRemoteAssociatedInterfaces() - ->GetInterface(&before_load_script_injector); - - // Provision the renderer's ScriptInjector with the scripts scoped to this - // page's origin. - before_load_script_injector->ClearOnLoadScripts(); - for (uint64_t script_id : before_load_scripts_order_) { - const OriginScopedScript& script = before_load_scripts_[script_id]; - if (IsOriginWhitelisted(navigation_handle->GetURL(), script.origins())) { - before_load_script_injector->AddOnLoadScript( - mojo::WrapReadOnlySharedMemoryRegion(script.script().Duplicate())); - } - } + MaybeInjectBeforeLoadScripts(navigation_handle); + MaybeStartCastStreaming(navigation_handle); } void FrameImpl::DidFinishLoad(content::RenderFrameHost* render_frame_host, diff --git a/chromium/fuchsia/engine/browser/frame_impl.h b/chromium/fuchsia/engine/browser/frame_impl.h index 1a852488172..98574ac9b82 100644 --- a/chromium/fuchsia/engine/browser/frame_impl.h +++ b/chromium/fuchsia/engine/browser/frame_impl.h @@ -7,6 +7,7 @@ #include <fuchsia/web/cpp/fidl.h> #include <lib/fidl/cpp/binding_set.h> +#include <lib/ui/scenic/cpp/view_ref_pair.h> #include <lib/zx/channel.h> #include <list> @@ -35,6 +36,7 @@ namespace content { class FromRenderFrameHost; } // namespace content +class CastStreamingSessionClient; class ContextImpl; class FrameWindowTreeHost; class FrameLayoutManager; @@ -84,6 +86,9 @@ class FrameImpl : public fuchsia::web::Frame, void set_handle_actions_for_test(bool handle) { accessibility_bridge_->set_handle_actions_for_test(handle); } + CastStreamingSessionClient* cast_streaming_session_client_for_test() { + return cast_streaming_session_client_.get(); + } private: FRIEND_TEST_ALL_PREFIXES(FrameImplTest, DelayedNavigationEventAck); @@ -130,7 +135,8 @@ class FrameImpl : public fuchsia::web::Frame, // Initializes WindowTreeHost for the view with the specified |view_token|. // |view_token| may be uninitialized in headless mode. - void InitWindowTreeHost(fuchsia::ui::views::ViewToken view_token); + void InitWindowTreeHost(fuchsia::ui::views::ViewToken view_token, + scenic::ViewRefPair view_ref_pair); // Destroys the WindowTreeHost along with its view or other associated // resources. @@ -139,8 +145,25 @@ class FrameImpl : public fuchsia::web::Frame, // Destroys |this| and sends the FIDL |error| to the client. void CloseAndDestroyFrame(zx_status_t error); + // Determines whether |message| is a Cast Streaming message and if so, handles + // it. Returns whether it handled the message, regardless of whether that was + // successful. If true is returned, |callback| has been called. Returns false + // immediately if Cast Streaming support is not enabled. Called by + // PostMessage(). + bool MaybeHandleCastStreamingMessage(std::string* origin, + fuchsia::web::WebMessage* message, + PostMessageCallback* callback); + + void MaybeInjectBeforeLoadScripts( + content::NavigationHandle* navigation_handle); + + void MaybeStartCastStreaming(content::NavigationHandle* navigation_handle); + // fuchsia::web::Frame implementation. void CreateView(fuchsia::ui::views::ViewToken view_token) override; + void CreateViewWithViewRef(fuchsia::ui::views::ViewToken view_token, + fuchsia::ui::views::ViewRefControl control_ref, + fuchsia::ui::views::ViewRef view_ref) override; void GetMediaPlayer(fidl::InterfaceRequest<fuchsia::media::sessions2::Player> player) override; void GetNavigationController( @@ -272,6 +295,7 @@ class FrameImpl : public fuchsia::web::Frame, gfx::Size render_size_override_; std::unique_ptr<MediaPlayerImpl> media_player_; + std::unique_ptr<CastStreamingSessionClient> cast_streaming_session_client_; fidl::Binding<fuchsia::web::Frame> binding_; media_control::MediaBlocker media_blocker_; diff --git a/chromium/fuchsia/engine/browser/frame_impl_browsertest.cc b/chromium/fuchsia/engine/browser/frame_impl_browsertest.cc index bccb5200db3..5d19e3757d5 100644 --- a/chromium/fuchsia/engine/browser/frame_impl_browsertest.cc +++ b/chromium/fuchsia/engine/browser/frame_impl_browsertest.cc @@ -24,6 +24,7 @@ #include "fuchsia/base/test_navigation_listener.h" #include "fuchsia/base/url_request_rewrite_test_util.h" #include "fuchsia/engine/browser/frame_impl.h" +#include "fuchsia/engine/switches.h" #include "fuchsia/engine/test/test_data.h" #include "fuchsia/engine/test/web_engine_browser_test.h" #include "net/test/embedded_test_server/embedded_test_server.h" @@ -237,9 +238,9 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, ContextDeletedBeforeFrameWithView) { fuchsia::web::FramePtr frame = CreateFrame(); EXPECT_TRUE(frame); - auto view_tokens = scenic::NewViewTokenPair(); + auto view_tokens = scenic::ViewTokenPair::New(); - frame->CreateView(std::move(view_tokens.first)); + frame->CreateView(std::move(view_tokens.view_token)); base::RunLoop().RunUntilIdle(); base::RunLoop run_loop; @@ -1191,18 +1192,14 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, PostMessagePassMessagePort) { "messageport"); fuchsia::web::MessagePortPtr message_port; - fuchsia::web::WebMessage msg; { - fuchsia::web::OutgoingTransferable outgoing; - outgoing.set_message_port(message_port.NewRequest()); - std::vector<fuchsia::web::OutgoingTransferable> outgoing_vector; - outgoing_vector.push_back(std::move(outgoing)); - msg.set_outgoing_transfer(std::move(outgoing_vector)); - msg.set_data(cr_fuchsia::MemBufferFromString("hi", "test")); cr_fuchsia::ResultReceiver<fuchsia::web::Frame_PostMessage_Result> post_result; frame->PostMessage( - post_message_url.GetOrigin().spec(), std::move(msg), + post_message_url.GetOrigin().spec(), + cr_fuchsia::CreateWebMessageWithMessagePortRequest( + message_port.NewRequest(), + cr_fuchsia::MemBufferFromString("hi", "test")), cr_fuchsia::CallbackToFitFunction(post_result.GetReceiveCallback())); base::RunLoop run_loop; @@ -1216,6 +1213,7 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, PostMessagePassMessagePort) { } { + fuchsia::web::WebMessage msg; msg.set_data(cr_fuchsia::MemBufferFromString("ping", "test")); cr_fuchsia::ResultReceiver<fuchsia::web::MessagePort_PostMessage_Result> post_result; @@ -1254,18 +1252,14 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, PostMessageMessagePortDisconnected) { "messageport"); fuchsia::web::MessagePortPtr message_port; - fuchsia::web::WebMessage msg; { - fuchsia::web::OutgoingTransferable outgoing; - outgoing.set_message_port(message_port.NewRequest()); - std::vector<fuchsia::web::OutgoingTransferable> outgoing_vector; - outgoing_vector.push_back(std::move(outgoing)); - msg.set_outgoing_transfer(std::move(outgoing_vector)); - msg.set_data(cr_fuchsia::MemBufferFromString("hi", "test")); cr_fuchsia::ResultReceiver<fuchsia::web::Frame_PostMessage_Result> post_result; frame->PostMessage( - post_message_url.GetOrigin().spec(), std::move(msg), + post_message_url.GetOrigin().spec(), + cr_fuchsia::CreateWebMessageWithMessagePortRequest( + message_port.NewRequest(), + cr_fuchsia::MemBufferFromString("hi", "test")), cr_fuchsia::CallbackToFitFunction(post_result.GetReceiveCallback())); base::RunLoop run_loop; @@ -1312,19 +1306,15 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, PostMessageUseContentProvidedPort) { "messageport"); fuchsia::web::MessagePortPtr incoming_message_port; - fuchsia::web::WebMessage msg; { fuchsia::web::MessagePortPtr message_port; - fuchsia::web::OutgoingTransferable outgoing; - outgoing.set_message_port(message_port.NewRequest()); - std::vector<fuchsia::web::OutgoingTransferable> outgoing_vector; - outgoing_vector.push_back(std::move(outgoing)); - msg.set_outgoing_transfer(std::move(outgoing_vector)); - msg.set_data(cr_fuchsia::MemBufferFromString("hi", "test")); cr_fuchsia::ResultReceiver<fuchsia::web::Frame_PostMessage_Result> post_result; frame->PostMessage( - "*", std::move(msg), + "*", + cr_fuchsia::CreateWebMessageWithMessagePortRequest( + message_port.NewRequest(), + cr_fuchsia::MemBufferFromString("hi", "test")), cr_fuchsia::CallbackToFitFunction(post_result.GetReceiveCallback())); base::RunLoop run_loop; @@ -1348,6 +1338,7 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, PostMessageUseContentProvidedPort) { base::RunLoop run_loop; cr_fuchsia::ResultReceiver<fuchsia::web::MessagePort_PostMessage_Result> post_result(run_loop.QuitClosure()); + fuchsia::web::WebMessage msg; msg.set_data(cr_fuchsia::MemBufferFromString("ping", "test")); incoming_message_port->PostMessage( std::move(msg), @@ -1360,20 +1351,16 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, PostMessageUseContentProvidedPort) { // that all the "ack pings" are ready to be consumed. { fuchsia::web::MessagePortPtr ack_message_port; - fuchsia::web::WebMessage msg; - fuchsia::web::OutgoingTransferable outgoing; - outgoing.set_message_port(ack_message_port.NewRequest()); - std::vector<fuchsia::web::OutgoingTransferable> outgoing_vector; - outgoing_vector.push_back(std::move(outgoing)); - msg.set_outgoing_transfer(std::move(outgoing_vector)); - msg.set_data(cr_fuchsia::MemBufferFromString("hi", "test")); // Quit the runloop only after we've received a WebMessage AND a PostMessage // result. cr_fuchsia::ResultReceiver<fuchsia::web::Frame_PostMessage_Result> post_result; frame->PostMessage( - "*", std::move(msg), + "*", + cr_fuchsia::CreateWebMessageWithMessagePortRequest( + ack_message_port.NewRequest(), + cr_fuchsia::MemBufferFromString("hi", "test")), cr_fuchsia::CallbackToFitFunction(post_result.GetReceiveCallback())); base::RunLoop run_loop; cr_fuchsia::ResultReceiver<fuchsia::web::WebMessage> receiver( @@ -1422,18 +1409,15 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, PostMessageBadOriginDropped) { // PostMessage() to invalid origins should be ignored. We pass in a // MessagePort but nothing should happen to it. fuchsia::web::MessagePortPtr unused_message_port; - fuchsia::web::OutgoingTransferable unused_outgoing; - unused_outgoing.set_message_port(unused_message_port.NewRequest()); - std::vector<fuchsia::web::OutgoingTransferable> unused_outgoing_vector; - unused_outgoing_vector.push_back(std::move(unused_outgoing)); - msg.set_outgoing_transfer(std::move(unused_outgoing_vector)); - msg.set_data(cr_fuchsia::MemBufferFromString("bad origin, bad!", "test")); - cr_fuchsia::ResultReceiver<fuchsia::web::Frame_PostMessage_Result> unused_post_result; - frame->PostMessage("https://example.com", std::move(msg), - cr_fuchsia::CallbackToFitFunction( - unused_post_result.GetReceiveCallback())); + frame->PostMessage( + "https://example.com", + cr_fuchsia::CreateWebMessageWithMessagePortRequest( + unused_message_port.NewRequest(), + cr_fuchsia::MemBufferFromString("bad origin, bad!", "test")), + cr_fuchsia::CallbackToFitFunction( + unused_post_result.GetReceiveCallback())); cr_fuchsia::ResultReceiver<fuchsia::web::WebMessage> unused_message_read; bad_origin_incoming_message_port->ReceiveMessage( cr_fuchsia::CallbackToFitFunction( @@ -1446,17 +1430,13 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, PostMessageBadOriginDropped) { // discarded. fuchsia::web::MessagePortPtr incoming_message_port; fuchsia::web::MessagePortPtr message_port; - fuchsia::web::OutgoingTransferable outgoing; - outgoing.set_message_port(message_port.NewRequest()); - std::vector<fuchsia::web::OutgoingTransferable> outgoing_vector; - outgoing_vector.push_back(std::move(outgoing)); - msg.set_outgoing_transfer(std::move(outgoing_vector)); - msg.set_data(cr_fuchsia::MemBufferFromString("good origin", "test")); - cr_fuchsia::ResultReceiver<fuchsia::web::Frame_PostMessage_Result> post_result; frame->PostMessage( - "*", std::move(msg), + "*", + cr_fuchsia::CreateWebMessageWithMessagePortRequest( + message_port.NewRequest(), + cr_fuchsia::MemBufferFromString("good origin", "test")), cr_fuchsia::CallbackToFitFunction(post_result.GetReceiveCallback())); base::RunLoop run_loop; cr_fuchsia::ResultReceiver<fuchsia::web::WebMessage> receiver( @@ -1696,6 +1676,11 @@ class RequestMonitoringFrameImplBrowserTest : public FrameImplTest { embedded_test_server()->StartAndReturnHandle()); } + void SetUpCommandLine(base::CommandLine* command_line) override { + // Needed for UrlRequestRewriteAddHeaders. + command_line->AppendSwitchNative(switches::kCorsExemptHeaders, "Test"); + } + std::map<GURL, net::test_server::HttpRequest> accumulated_requests_; private: diff --git a/chromium/fuchsia/engine/browser/frame_window_tree_host.cc b/chromium/fuchsia/engine/browser/frame_window_tree_host.cc index 5fc20eb54cd..4ad2732c543 100644 --- a/chromium/fuchsia/engine/browser/frame_window_tree_host.cc +++ b/chromium/fuchsia/engine/browser/frame_window_tree_host.cc @@ -51,13 +51,14 @@ class FrameWindowTreeHost::WindowParentingClientImpl FrameWindowTreeHost::FrameWindowTreeHost( fuchsia::ui::views::ViewToken view_token, + scenic::ViewRefPair view_ref_pair, content::WebContents* web_contents) : web_contents_(web_contents) { CreateCompositor(); ui::PlatformWindowInitProperties properties; properties.view_token = std::move(view_token); - properties.view_ref_pair = scenic::ViewRefPair::New(); + properties.view_ref_pair = std::move(view_ref_pair); view_ref_ = DupViewRef(properties.view_ref_pair.view_ref); CreateAndSetPlatformWindow(std::move(properties)); diff --git a/chromium/fuchsia/engine/browser/frame_window_tree_host.h b/chromium/fuchsia/engine/browser/frame_window_tree_host.h index 17fe15f5c5a..0e517bcf5d1 100644 --- a/chromium/fuchsia/engine/browser/frame_window_tree_host.h +++ b/chromium/fuchsia/engine/browser/frame_window_tree_host.h @@ -19,6 +19,7 @@ class FrameWindowTreeHost : public aura::WindowTreeHostPlatform { public: // |web_contents| must to outlive |FrameWindowTreeHost|. FrameWindowTreeHost(fuchsia::ui::views::ViewToken view_token, + scenic::ViewRefPair view_ref_pair, content::WebContents* web_contents); ~FrameWindowTreeHost() final; diff --git a/chromium/fuchsia/engine/browser/media_resource_provider_service.cc b/chromium/fuchsia/engine/browser/media_resource_provider_service.cc index c3e36e13202..154a96304cc 100644 --- a/chromium/fuchsia/engine/browser/media_resource_provider_service.cc +++ b/chromium/fuchsia/engine/browser/media_resource_provider_service.cc @@ -8,7 +8,7 @@ #include <lib/sys/cpp/component_context.h> #include "base/bind.h" -#include "base/fuchsia/default_context.h" +#include "base/fuchsia/process_context.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/frame_service_base.h" #include "content/public/browser/provision_fetcher_factory.h" @@ -79,7 +79,7 @@ void MediaResourceProviderImpl::CreateCdm( void MediaResourceProviderImpl::CreateAudioConsumer( fidl::InterfaceRequest<fuchsia::media::AudioConsumer> request) { - auto factory = base::fuchsia::ComponentContextForCurrentProcess() + auto factory = base::ComponentContextForProcess() ->svc() ->Connect<fuchsia::media::SessionAudioConsumerFactory>(); factory->CreateAudioConsumer( @@ -100,7 +100,7 @@ void MediaResourceProviderImpl::CreateAudioCapturer( return; } - auto factory = base::fuchsia::ComponentContextForCurrentProcess() + auto factory = base::ComponentContextForProcess() ->svc() ->Connect<fuchsia::media::Audio>(); factory->CreateAudioCapturer(std::move(request), /*loopback=*/false); @@ -114,7 +114,7 @@ class WidevineHandler : public media::FuchsiaCdmManager::KeySystemHandler { void CreateCdm( fidl::InterfaceRequest<fuchsia::media::drm::ContentDecryptionModule> request) override { - auto widevine = base::fuchsia::ComponentContextForCurrentProcess() + auto widevine = base::ComponentContextForProcess() ->svc() ->Connect<fuchsia::media::drm::Widevine>(); widevine->CreateContentDecryptionModule(std::move(request)); @@ -123,7 +123,7 @@ class WidevineHandler : public media::FuchsiaCdmManager::KeySystemHandler { fuchsia::media::drm::ProvisionerPtr CreateProvisioner() override { fuchsia::media::drm::ProvisionerPtr provisioner; - auto widevine = base::fuchsia::ComponentContextForCurrentProcess() + auto widevine = base::ComponentContextForProcess() ->svc() ->Connect<fuchsia::media::drm::Widevine>(); widevine->CreateProvisioner(provisioner.NewRequest()); @@ -140,7 +140,7 @@ class PlayreadyHandler : public media::FuchsiaCdmManager::KeySystemHandler { void CreateCdm( fidl::InterfaceRequest<fuchsia::media::drm::ContentDecryptionModule> request) override { - auto playready = base::fuchsia::ComponentContextForCurrentProcess() + auto playready = base::ComponentContextForProcess() ->svc() ->Connect<fuchsia::media::drm::PlayReady>(); playready->CreateContentDecryptionModule(std::move(request)); diff --git a/chromium/fuchsia/engine/browser/navigation_controller_impl.cc b/chromium/fuchsia/engine/browser/navigation_controller_impl.cc index 4c95d83979f..79879065f9d 100644 --- a/chromium/fuchsia/engine/browser/navigation_controller_impl.cc +++ b/chromium/fuchsia/engine/browser/navigation_controller_impl.cc @@ -15,36 +15,6 @@ #include "net/http/http_util.h" #include "ui/base/page_transition_types.h" -namespace { - -void UpdateNavigationStateFromNavigationEntry( - content::NavigationEntry* entry, - content::WebContents* web_contents, - fuchsia::web::NavigationState* navigation_state) { - DCHECK(entry); - DCHECK(web_contents); - DCHECK(navigation_state); - - navigation_state->set_title(base::UTF16ToUTF8(entry->GetTitleForDisplay())); - navigation_state->set_url(entry->GetURL().spec()); - - switch (entry->GetPageType()) { - case content::PageType::PAGE_TYPE_NORMAL: - case content::PageType::PAGE_TYPE_INTERSTITIAL: - navigation_state->set_page_type(fuchsia::web::PageType::NORMAL); - break; - case content::PageType::PAGE_TYPE_ERROR: - navigation_state->set_page_type(fuchsia::web::PageType::ERROR); - break; - } - - navigation_state->set_can_go_back(web_contents->GetController().CanGoBack()); - navigation_state->set_can_go_forward( - web_contents->GetController().CanGoForward()); -} - -} // namespace - NavigationControllerImpl::NavigationControllerImpl( content::WebContents* web_contents) : web_contents_(web_contents), weak_factory_(this) { @@ -88,19 +58,48 @@ void NavigationControllerImpl::SetEventListener( } } -void NavigationControllerImpl::OnNavigationEntryChanged() { - fuchsia::web::NavigationState new_state; - new_state.set_is_main_document_loaded(is_main_document_loaded_); - UpdateNavigationStateFromNavigationEntry( - web_contents_->GetController().GetVisibleEntry(), web_contents_, - &new_state); - if (new_state.page_type() != fuchsia::web::PageType::ERROR && - uncommitted_load_error_) { +fuchsia::web::NavigationState +NavigationControllerImpl::GetVisibleNavigationState() const { + content::NavigationEntry* const entry = + web_contents_->GetController().GetVisibleEntry(); + if (!entry) + return fuchsia::web::NavigationState(); + + fuchsia::web::NavigationState state; + + // Populate some fields directly from the NavigationEntry. + state.set_title(base::UTF16ToUTF8(entry->GetTitleForDisplay())); + state.set_url(entry->GetURL().spec()); + + if (web_contents_->IsCrashed()) { + // TODO(https:://crbug.com/1092506): Add an explicit crashed indicator to + // NavigationState, separate from PageType::ERROR. + state.set_page_type(fuchsia::web::PageType::ERROR); + } else if (uncommitted_load_error_) { // If there was a loading error which prevented the navigation entry from - // being committed, then reflect the error in |new_state|. - new_state.set_page_type(fuchsia::web::PageType::ERROR); + // being committed, then report PageType::ERROR. + state.set_page_type(fuchsia::web::PageType::ERROR); + } else { + switch (entry->GetPageType()) { + case content::PageType::PAGE_TYPE_NORMAL: + case content::PageType::PAGE_TYPE_INTERSTITIAL: + state.set_page_type(fuchsia::web::PageType::NORMAL); + break; + case content::PageType::PAGE_TYPE_ERROR: + state.set_page_type(fuchsia::web::PageType::ERROR); + break; + } } + state.set_is_main_document_loaded(is_main_document_loaded_); + state.set_can_go_back(web_contents_->GetController().CanGoBack()); + state.set_can_go_forward(web_contents_->GetController().CanGoForward()); + + return state; +} + +void NavigationControllerImpl::OnNavigationEntryChanged() { + fuchsia::web::NavigationState new_state = GetVisibleNavigationState(); DiffNavigationEntries(previous_navigation_state_, new_state, &pending_navigation_event_); previous_navigation_state_ = std::move(new_state); @@ -209,17 +208,7 @@ void NavigationControllerImpl::Reload(fuchsia::web::ReloadType type) { void NavigationControllerImpl::GetVisibleEntry( fuchsia::web::NavigationController::GetVisibleEntryCallback callback) { - content::NavigationEntry* entry = - web_contents_->GetController().GetVisibleEntry(); - if (!entry) { - callback({}); - return; - } - - fuchsia::web::NavigationState state; - state.set_is_main_document_loaded(is_main_document_loaded_); - UpdateNavigationStateFromNavigationEntry(entry, web_contents_, &state); - callback(std::move(state)); + callback(GetVisibleNavigationState()); } void NavigationControllerImpl::TitleWasSet(content::NavigationEntry* entry) { @@ -242,6 +231,14 @@ void NavigationControllerImpl::DidFinishLoad( OnNavigationEntryChanged(); } +void NavigationControllerImpl::RenderProcessGone( + base::TerminationStatus status) { + // If the current RenderProcess terminates then trigger a NavigationState + // change to let the caller know that something is wrong. + LOG(WARNING) << "RenderProcess gone, TerminationStatus=" << status; + OnNavigationEntryChanged(); +} + void NavigationControllerImpl::DidStartNavigation( content::NavigationHandle* navigation_handle) { uncommitted_load_error_ = false; diff --git a/chromium/fuchsia/engine/browser/navigation_controller_impl.h b/chromium/fuchsia/engine/browser/navigation_controller_impl.h index 1d48ad27976..9a34c7f3d0a 100644 --- a/chromium/fuchsia/engine/browser/navigation_controller_impl.h +++ b/chromium/fuchsia/engine/browser/navigation_controller_impl.h @@ -33,6 +33,11 @@ class NavigationControllerImpl : public fuchsia::web::NavigationController, fidl::InterfaceHandle<fuchsia::web::NavigationEventListener> listener); private: + // Returns a NavigationState reflecting the current state of |web_contents_|'s + // visible navigation entry, taking into account |is_main_document_loaded_| + // and |uncommitted_load_error_| states. + fuchsia::web::NavigationState GetVisibleNavigationState() const; + // Processes the most recent changes to the browser's navigation state and // triggers the publishing of change events. void OnNavigationEntryChanged(); @@ -56,6 +61,7 @@ class NavigationControllerImpl : public fuchsia::web::NavigationController, void DocumentAvailableInMainFrame() final; void DidFinishLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url) final; + void RenderProcessGone(base::TerminationStatus status) final; void DidStartNavigation(content::NavigationHandle* navigation_handle) final; void DidFinishNavigation(content::NavigationHandle* navigation_handle) final; diff --git a/chromium/fuchsia/engine/browser/web_engine_browser_context.cc b/chromium/fuchsia/engine/browser/web_engine_browser_context.cc index de9ce2c7b40..03a6e9fa3a7 100644 --- a/chromium/fuchsia/engine/browser/web_engine_browser_context.cc +++ b/chromium/fuchsia/engine/browser/web_engine_browser_context.cc @@ -12,7 +12,6 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/path_service.h" -#include "base/task/post_task.h" #include "components/keyed_service/core/simple_key_map.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" @@ -67,8 +66,8 @@ WebEngineBrowserContext::~WebEngineBrowserContext() { NotifyWillBeDestroyed(this); if (resource_context_) { - base::DeleteSoon(FROM_HERE, {content::BrowserThread::IO}, - std::move(resource_context_)); + content::GetIOThreadTaskRunner({})->DeleteSoon( + FROM_HERE, std::move(resource_context_)); } ShutdownStoragePartitions(); diff --git a/chromium/fuchsia/engine/browser/web_engine_content_browser_client.cc b/chromium/fuchsia/engine/browser/web_engine_content_browser_client.cc index 6d77b2eb8bf..0fb644e3883 100644 --- a/chromium/fuchsia/engine/browser/web_engine_content_browser_client.cc +++ b/chromium/fuchsia/engine/browser/web_engine_content_browser_client.cc @@ -11,9 +11,9 @@ #include "base/stl_util.h" #include "base/strings/string_split.h" #include "components/version_info/version_info.h" -#include "content/public/browser/cors_exempt_headers.h" #include "content/public/browser/devtools_manager_delegate.h" #include "content/public/browser/network_service_instance.h" +#include "content/public/common/content_switches.h" #include "content/public/common/user_agent.h" #include "content/public/common/web_preferences.h" #include "fuchsia/base/fuchsia_dir_scheme.h" @@ -153,13 +153,16 @@ void WebEngineContentBrowserClient:: void WebEngineContentBrowserClient::AppendExtraCommandLineSwitches( base::CommandLine* command_line, int child_process_id) { + // TODO(https://crbug.com/1083520): Pass based on process type. constexpr char const* kSwitchesToCopy[] = { switches::kContentDirectories, switches::kCorsExemptHeaders, switches::kDisableSoftwareVideoDecoders, + switches::kEnableCastStreamingReceiver, switches::kEnableProtectedVideoBuffers, switches::kEnableWidevine, switches::kForceProtectedVideoOutputBuffers, + switches::kMaxDecodedImageSizeMb, switches::kPlayreadyKeySystem, }; @@ -206,8 +209,4 @@ void WebEngineContentBrowserClient::ConfigureNetworkContextParams( // starting with the headers passed in via // |CreateContextParams.cors_exempt_headers|. network_context_params->cors_exempt_header_list = cors_exempt_headers_; - - // Exempt the minimal headers needed for CORS preflight checks (Purpose, - // X-Requested-With). - content::UpdateCorsExemptHeader(network_context_params); } diff --git a/chromium/fuchsia/engine/browser/web_engine_net_log_observer.cc b/chromium/fuchsia/engine/browser/web_engine_net_log_observer.cc index 66f454574e2..c24b7215ab9 100644 --- a/chromium/fuchsia/engine/browser/web_engine_net_log_observer.cc +++ b/chromium/fuchsia/engine/browser/web_engine_net_log_observer.cc @@ -20,7 +20,8 @@ namespace { std::unique_ptr<base::DictionaryValue> GetWebEngineConstants() { std::unique_ptr<base::DictionaryValue> constants_dict = - net::GetNetConstants(); + base::DictionaryValue::From( + base::Value::ToUniquePtrValue(net::GetNetConstants())); base::DictionaryValue dict; dict.SetKey("name", base::Value("WebEngine")); |