Commit 26ae35fd authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Presentation supplement cleanup

Merge NavigatorPresentation and Presentation, so that Presentation
is the Supplement<Navigator>

Simplify eager initialization from ModulesInitializer. Currently,
ModulesInitializer calls PresentationReceiver::From(), which calls
NavigationPresenation::presentation() to initialize the
NavigatorPresentation, Presention, and PresentationReceiver. It then
reads the PresentationReceiver off the Presentation and returns it,
even though the return value is unused. After this CL,
ModulesInitializer calls Presention::presentation(), which
initializes both Presention and PresentationReceiver, and still
ignores the return result.

This also makes Presention explicitly aware of the conditional
initialization of PresentationReceiver based on Settings.

Change-Id: I4ee01f0b501eb1cb8a2c49de0ed62cfab75bd895
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518761Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825505}
parent fa3d087b
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
#include "third_party/blink/renderer/modules/mediastream/user_media_controller.h" #include "third_party/blink/renderer/modules/mediastream/user_media_controller.h"
#include "third_party/blink/renderer/modules/peerconnection/peer_connection_tracker.h" #include "third_party/blink/renderer/modules/peerconnection/peer_connection_tracker.h"
#include "third_party/blink/renderer/modules/picture_in_picture/picture_in_picture_controller_impl.h" #include "third_party/blink/renderer/modules/picture_in_picture/picture_in_picture_controller_impl.h"
#include "third_party/blink/renderer/modules/presentation/presentation_receiver.h" #include "third_party/blink/renderer/modules/presentation/presentation.h"
#include "third_party/blink/renderer/modules/push_messaging/push_messaging_client.h" #include "third_party/blink/renderer/modules/push_messaging/push_messaging_client.h"
#include "third_party/blink/renderer/modules/remoteplayback/html_media_element_remote_playback.h" #include "third_party/blink/renderer/modules/remoteplayback/html_media_element_remote_playback.h"
#include "third_party/blink/renderer/modules/remoteplayback/remote_playback.h" #include "third_party/blink/renderer/modules/remoteplayback/remote_playback.h"
...@@ -231,9 +231,10 @@ void ModulesInitializer::OnClearWindowObjectInMainWorld( ...@@ -231,9 +231,10 @@ void ModulesInitializer::OnClearWindowObjectInMainWorld(
DOMWindowStorageController::From(window); DOMWindowStorageController::From(window);
if (RuntimeEnabledFeatures::PresentationEnabled() && if (RuntimeEnabledFeatures::PresentationEnabled() &&
settings.GetPresentationReceiver()) { settings.GetPresentationReceiver()) {
// We eagerly create PresentationReceiver so that the frame creating the // We eagerly create Presentation and associated PresentationReceiver so
// presentation can offer a connection to the presentation receiver. // that the frame creating the presentation can offer a connection to the
PresentationReceiver::From(document); // presentation receiver.
Presentation::presentation(*window.navigator());
} }
ManifestManager::From(window); ManifestManager::From(window);
......
...@@ -6,8 +6,6 @@ import("//third_party/blink/renderer/modules/modules.gni") ...@@ -6,8 +6,6 @@ import("//third_party/blink/renderer/modules/modules.gni")
blink_modules_sources("presentation") { blink_modules_sources("presentation") {
sources = [ sources = [
"navigator_presentation.cc",
"navigator_presentation.h",
"presentation.cc", "presentation.cc",
"presentation.h", "presentation.h",
"presentation_availability.cc", "presentation_availability.cc",
......
// Copyright 2014 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 "third_party/blink/renderer/modules/presentation/navigator_presentation.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/modules/presentation/presentation.h"
namespace blink {
NavigatorPresentation::NavigatorPresentation() = default;
// static
const char NavigatorPresentation::kSupplementName[] = "NavigatorPresentation";
// static
NavigatorPresentation& NavigatorPresentation::From(Navigator& navigator) {
NavigatorPresentation* supplement =
Supplement<Navigator>::From<NavigatorPresentation>(navigator);
if (!supplement) {
supplement = MakeGarbageCollected<NavigatorPresentation>();
ProvideTo(navigator, supplement);
}
return *supplement;
}
// static
Presentation* NavigatorPresentation::presentation(Navigator& navigator) {
NavigatorPresentation& self = NavigatorPresentation::From(navigator);
if (!self.presentation_) {
if (!navigator.DomWindow())
return nullptr;
self.presentation_ = Presentation::Create(navigator.DomWindow());
}
return self.presentation_;
}
void NavigatorPresentation::Trace(Visitor* visitor) const {
visitor->Trace(presentation_);
Supplement<Navigator>::Trace(visitor);
}
} // namespace blink
// Copyright 2014 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 THIRD_PARTY_BLINK_RENDERER_MODULES_PRESENTATION_NAVIGATOR_PRESENTATION_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PRESENTATION_NAVIGATOR_PRESENTATION_H_
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class Navigator;
class Presentation;
class NavigatorPresentation final
: public GarbageCollected<NavigatorPresentation>,
public Supplement<Navigator> {
public:
static const char kSupplementName[];
static NavigatorPresentation& From(Navigator&);
static Presentation* presentation(Navigator&);
NavigatorPresentation();
void Trace(Visitor*) const override;
private:
Presentation* presentation();
Member<Presentation> presentation_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PRESENTATION_NAVIGATOR_PRESENTATION_H_
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// https://w3c.github.io/presentation-api/#interface-navigatorpresentation // https://w3c.github.io/presentation-api/#interface-navigatorpresentation
[ [
ImplementedAs=NavigatorPresentation, ImplementedAs=Presentation,
RuntimeEnabled=Presentation RuntimeEnabled=Presentation
] partial interface Navigator { ] partial interface Navigator {
[SameObject, SecureContext] readonly attribute Presentation presentation; [SameObject, SecureContext] readonly attribute Presentation presentation;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/frame/settings.h" #include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/modules/presentation/presentation_controller.h" #include "third_party/blink/renderer/modules/presentation/presentation_controller.h"
#include "third_party/blink/renderer/modules/presentation/presentation_receiver.h" #include "third_party/blink/renderer/modules/presentation/presentation_receiver.h"
...@@ -16,24 +17,32 @@ ...@@ -16,24 +17,32 @@
namespace blink { namespace blink {
Presentation::Presentation(LocalDOMWindow* window) // static
: ExecutionContextClient(window) {} const char Presentation::kSupplementName[] = "Presentation";
// static // static
Presentation* Presentation::Create(LocalDOMWindow* window) { Presentation* Presentation::presentation(Navigator& navigator) {
DCHECK(window); if (!navigator.DomWindow())
Presentation* presentation = MakeGarbageCollected<Presentation>(window); return nullptr;
PresentationController* controller = PresentationController::From(*window); auto* presentation = Supplement<Navigator>::From<Presentation>(navigator);
DCHECK(controller); if (!presentation) {
controller->SetPresentation(presentation); presentation = MakeGarbageCollected<Presentation>(navigator);
ProvideTo(navigator, presentation);
}
return presentation; return presentation;
} }
Presentation::Presentation(Navigator& navigator)
: Supplement<Navigator>(navigator) {
PresentationController::From(*navigator.DomWindow())->SetPresentation(this);
MaybeInitReceiver();
}
void Presentation::Trace(Visitor* visitor) const { void Presentation::Trace(Visitor* visitor) const {
visitor->Trace(default_request_); visitor->Trace(default_request_);
visitor->Trace(receiver_); visitor->Trace(receiver_);
ScriptWrappable::Trace(visitor); ScriptWrappable::Trace(visitor);
ExecutionContextClient::Trace(visitor); Supplement<Navigator>::Trace(visitor);
} }
PresentationRequest* Presentation::defaultRequest() const { PresentationRequest* Presentation::defaultRequest() const {
...@@ -43,25 +52,25 @@ PresentationRequest* Presentation::defaultRequest() const { ...@@ -43,25 +52,25 @@ PresentationRequest* Presentation::defaultRequest() const {
void Presentation::setDefaultRequest(PresentationRequest* request) { void Presentation::setDefaultRequest(PresentationRequest* request) {
default_request_ = request; default_request_ = request;
if (!GetExecutionContext()) LocalDOMWindow* window = GetSupplementable()->DomWindow();
if (!window)
return; return;
PresentationController* controller = PresentationController* controller = PresentationController::From(*window);
PresentationController::FromContext(GetExecutionContext());
controller->GetPresentationService()->SetDefaultPresentationUrls( controller->GetPresentationService()->SetDefaultPresentationUrls(
request ? request->Urls() : WTF::Vector<KURL>()); request ? request->Urls() : WTF::Vector<KURL>());
} }
PresentationReceiver* Presentation::receiver() { void Presentation::MaybeInitReceiver() {
LocalDOMWindow* window = To<LocalDOMWindow>(GetExecutionContext()); LocalDOMWindow* window = GetSupplementable()->DomWindow();
if (!window || if (!receiver_ && window &&
!window->GetFrame()->GetSettings()->GetPresentationReceiver()) { window->GetFrame()->GetSettings()->GetPresentationReceiver()) {
return nullptr;
}
if (!receiver_)
receiver_ = MakeGarbageCollected<PresentationReceiver>(window); receiver_ = MakeGarbageCollected<PresentationReceiver>(window);
}
}
PresentationReceiver* Presentation::receiver() {
MaybeInitReceiver();
return receiver_; return receiver_;
} }
......
...@@ -9,10 +9,11 @@ ...@@ -9,10 +9,11 @@
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink { namespace blink {
class LocalDOMWindow; class Navigator;
class PresentationReceiver; class PresentationReceiver;
class PresentationRequest; class PresentationRequest;
...@@ -21,13 +22,13 @@ class PresentationRequest; ...@@ -21,13 +22,13 @@ class PresentationRequest;
// See https://w3c.github.io/presentation-api/#navigatorpresentation for // See https://w3c.github.io/presentation-api/#navigatorpresentation for
// details. // details.
class Presentation final : public ScriptWrappable, class Presentation final : public ScriptWrappable,
public ExecutionContextClient { public Supplement<Navigator> {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
static Presentation* Create(LocalDOMWindow*); static const char kSupplementName[];
static Presentation* presentation(Navigator&);
explicit Presentation(LocalDOMWindow*); explicit Presentation(Navigator&);
void Trace(Visitor*) const override; void Trace(Visitor*) const override;
...@@ -37,6 +38,8 @@ class Presentation final : public ScriptWrappable, ...@@ -37,6 +38,8 @@ class Presentation final : public ScriptWrappable,
PresentationReceiver* receiver(); PresentationReceiver* receiver();
private: private:
void MaybeInitReceiver();
// Default PresentationRequest used by the embedder. // Default PresentationRequest used by the embedder.
Member<PresentationRequest> default_request_; Member<PresentationRequest> default_request_;
......
...@@ -7,19 +7,10 @@ ...@@ -7,19 +7,10 @@
#include "third_party/blink/public/common/browser_interface_broker_proxy.h" #include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/deprecation.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/modules/presentation/navigator_presentation.h"
#include "third_party/blink/renderer/modules/presentation/presentation.h"
#include "third_party/blink/renderer/modules/presentation/presentation_connection.h" #include "third_party/blink/renderer/modules/presentation/presentation_connection.h"
#include "third_party/blink/renderer/modules/presentation/presentation_connection_list.h" #include "third_party/blink/renderer/modules/presentation/presentation_connection_list.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
namespace blink { namespace blink {
...@@ -41,18 +32,6 @@ PresentationReceiver::PresentationReceiver(LocalDOMWindow* window) ...@@ -41,18 +32,6 @@ PresentationReceiver::PresentationReceiver(LocalDOMWindow* window)
presentation_receiver_receiver_.BindNewPipeAndPassRemote(task_runner)); presentation_receiver_receiver_.BindNewPipeAndPassRemote(task_runner));
} }
// static
PresentationReceiver* PresentationReceiver::From(Document& document) {
if (!document.IsInMainFrame() || !document.GetFrame()->DomWindow())
return nullptr;
Navigator& navigator = *document.GetFrame()->DomWindow()->navigator();
Presentation* presentation = NavigatorPresentation::presentation(navigator);
if (!presentation)
return nullptr;
return presentation->receiver();
}
ScriptPromise PresentationReceiver::connectionList(ScriptState* script_state) { ScriptPromise PresentationReceiver::connectionList(ScriptState* script_state) {
if (!connection_list_property_) { if (!connection_list_property_) {
connection_list_property_ = MakeGarbageCollected<ConnectionListProperty>( connection_list_property_ = MakeGarbageCollected<ConnectionListProperty>(
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
namespace blink { namespace blink {
class Document;
class PresentationConnectionList; class PresentationConnectionList;
class ReceiverPresentationConnection; class ReceiverPresentationConnection;
...@@ -41,8 +40,6 @@ class MODULES_EXPORT PresentationReceiver final ...@@ -41,8 +40,6 @@ class MODULES_EXPORT PresentationReceiver final
explicit PresentationReceiver(LocalDOMWindow*); explicit PresentationReceiver(LocalDOMWindow*);
~PresentationReceiver() override = default; ~PresentationReceiver() override = default;
static PresentationReceiver* From(Document&);
// PresentationReceiver.idl implementation // PresentationReceiver.idl implementation
ScriptPromise connectionList(ScriptState*); ScriptPromise connectionList(ScriptState*);
......
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