summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/presentation/presentation.cc
blob: 385e1def64a0a6a3ca3ee3b208c3771480a55566 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// 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/presentation.h"

#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame.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"
#include "third_party/blink/renderer/modules/presentation/presentation_request.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

Presentation::Presentation(LocalFrame* frame) : ContextClient(frame) {}

// static
Presentation* Presentation::Create(LocalFrame* frame) {
  DCHECK(frame);
  Presentation* presentation = MakeGarbageCollected<Presentation>(frame);
  PresentationController* controller = PresentationController::From(*frame);
  DCHECK(controller);
  controller->SetPresentation(presentation);
  return presentation;
}

void Presentation::Trace(blink::Visitor* visitor) {
  visitor->Trace(default_request_);
  visitor->Trace(receiver_);
  ScriptWrappable::Trace(visitor);
  ContextClient::Trace(visitor);
}

PresentationRequest* Presentation::defaultRequest() const {
  return default_request_;
}

void Presentation::setDefaultRequest(PresentationRequest* request) {
  default_request_ = request;

  if (!GetFrame())
    return;

  PresentationController* controller =
      PresentationController::From(*GetFrame());
  if (!controller)
    return;
  controller->GetPresentationService()->SetDefaultPresentationUrls(
      request ? request->Urls() : WTF::Vector<KURL>());
}

PresentationReceiver* Presentation::receiver() {
  if (!GetFrame() || !GetFrame()->GetSettings() ||
      !GetFrame()->GetSettings()->GetPresentationReceiver()) {
    return nullptr;
  }

  if (!receiver_)
    receiver_ = MakeGarbageCollected<PresentationReceiver>(GetFrame());

  return receiver_;
}

}  // namespace blink