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 @@
#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/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/remoteplayback/html_media_element_remote_playback.h"
#include "third_party/blink/renderer/modules/remoteplayback/remote_playback.h"
......@@ -231,9 +231,10 @@ void ModulesInitializer::OnClearWindowObjectInMainWorld(
DOMWindowStorageController::From(window);
if (RuntimeEnabledFeatures::PresentationEnabled() &&
settings.GetPresentationReceiver()) {
// We eagerly create PresentationReceiver so that the frame creating the
// presentation can offer a connection to the presentation receiver.
PresentationReceiver::From(document);
// We eagerly create Presentation and associated PresentationReceiver so
// that the frame creating the presentation can offer a connection to the
// presentation receiver.
Presentation::presentation(*window.navigator());
}
ManifestManager::From(window);
......
......@@ -6,8 +6,6 @@ import("//third_party/blink/renderer/modules/modules.gni")
blink_modules_sources("presentation") {
sources = [
"navigator_presentation.cc",
"navigator_presentation.h",
"presentation.cc",
"presentation.h",
"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 @@
// https://w3c.github.io/presentation-api/#interface-navigatorpresentation
[
ImplementedAs=NavigatorPresentation,
ImplementedAs=Presentation,
RuntimeEnabled=Presentation
] partial interface Navigator {
[SameObject, SecureContext] readonly attribute Presentation presentation;
......
......@@ -7,6 +7,7 @@
#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_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/modules/presentation/presentation_controller.h"
#include "third_party/blink/renderer/modules/presentation/presentation_receiver.h"
......@@ -16,24 +17,32 @@
namespace blink {
Presentation::Presentation(LocalDOMWindow* window)
: ExecutionContextClient(window) {}
// static
const char Presentation::kSupplementName[] = "Presentation";
// static
Presentation* Presentation::Create(LocalDOMWindow* window) {
DCHECK(window);
Presentation* presentation = MakeGarbageCollected<Presentation>(window);
PresentationController* controller = PresentationController::From(*window);
DCHECK(controller);
controller->SetPresentation(presentation);
Presentation* Presentation::presentation(Navigator& navigator) {
if (!navigator.DomWindow())
return nullptr;
auto* presentation = Supplement<Navigator>::From<Presentation>(navigator);
if (!presentation) {
presentation = MakeGarbageCollected<Presentation>(navigator);
ProvideTo(navigator, presentation);
}
return presentation;
}
Presentation::Presentation(Navigator& navigator)
: Supplement<Navigator>(navigator) {
PresentationController::From(*navigator.DomWindow())->SetPresentation(this);
MaybeInitReceiver();
}
void Presentation::Trace(Visitor* visitor) const {
visitor->Trace(default_request_);
visitor->Trace(receiver_);
ScriptWrappable::Trace(visitor);
ExecutionContextClient::Trace(visitor);
Supplement<Navigator>::Trace(visitor);
}
PresentationRequest* Presentation::defaultRequest() const {
......@@ -43,25 +52,25 @@ PresentationRequest* Presentation::defaultRequest() const {
void Presentation::setDefaultRequest(PresentationRequest* request) {
default_request_ = request;
if (!GetExecutionContext())
LocalDOMWindow* window = GetSupplementable()->DomWindow();
if (!window)
return;
PresentationController* controller =
PresentationController::FromContext(GetExecutionContext());
PresentationController* controller = PresentationController::From(*window);
controller->GetPresentationService()->SetDefaultPresentationUrls(
request ? request->Urls() : WTF::Vector<KURL>());
}
PresentationReceiver* Presentation::receiver() {
LocalDOMWindow* window = To<LocalDOMWindow>(GetExecutionContext());
if (!window ||
!window->GetFrame()->GetSettings()->GetPresentationReceiver()) {
return nullptr;
}
if (!receiver_)
void Presentation::MaybeInitReceiver() {
LocalDOMWindow* window = GetSupplementable()->DomWindow();
if (!receiver_ && window &&
window->GetFrame()->GetSettings()->GetPresentationReceiver()) {
receiver_ = MakeGarbageCollected<PresentationReceiver>(window);
}
}
PresentationReceiver* Presentation::receiver() {
MaybeInitReceiver();
return receiver_;
}
......
......@@ -9,10 +9,11 @@
#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/heap.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class LocalDOMWindow;
class Navigator;
class PresentationReceiver;
class PresentationRequest;
......@@ -21,13 +22,13 @@ class PresentationRequest;
// See https://w3c.github.io/presentation-api/#navigatorpresentation for
// details.
class Presentation final : public ScriptWrappable,
public ExecutionContextClient {
public Supplement<Navigator> {
DEFINE_WRAPPERTYPEINFO();
public:
static Presentation* Create(LocalDOMWindow*);
explicit Presentation(LocalDOMWindow*);
static const char kSupplementName[];
static Presentation* presentation(Navigator&);
explicit Presentation(Navigator&);
void Trace(Visitor*) const override;
......@@ -37,6 +38,8 @@ class Presentation final : public ScriptWrappable,
PresentationReceiver* receiver();
private:
void MaybeInitReceiver();
// Default PresentationRequest used by the embedder.
Member<PresentationRequest> default_request_;
......
......@@ -7,19 +7,10 @@
#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_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/frame/deprecation.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_list.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
namespace blink {
......@@ -41,18 +32,6 @@ PresentationReceiver::PresentationReceiver(LocalDOMWindow* window)
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) {
if (!connection_list_property_) {
connection_list_property_ = MakeGarbageCollected<ConnectionListProperty>(
......
......@@ -21,7 +21,6 @@
namespace blink {
class Document;
class PresentationConnectionList;
class ReceiverPresentationConnection;
......@@ -41,8 +40,6 @@ class MODULES_EXPORT PresentationReceiver final
explicit PresentationReceiver(LocalDOMWindow*);
~PresentationReceiver() override = default;
static PresentationReceiver* From(Document&);
// PresentationReceiver.idl implementation
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