Enable right clicking on the applist doodle web contents and log the data.
[chromium-blink-merge.git] / content / renderer / presentation / presentation_dispatcher.cc
blob04b44eca6fe231e3e98c363f1f4b64339ad4ec8f
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/presentation/presentation_dispatcher.h"
7 #include "content/common/presentation/presentation_service.mojom.h"
8 #include "content/public/common/service_registry.h"
9 #include "content/public/renderer/render_frame.h"
10 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentationController.h"
12 namespace content {
14 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame)
15 : RenderFrameObserver(render_frame),
16 controller_(nullptr) {
19 PresentationDispatcher::~PresentationDispatcher() {
20 // Controller should be destroyed before the dispatcher when frame is
21 // destroyed.
22 DCHECK(!controller_);
25 void PresentationDispatcher::setController(
26 blink::WebPresentationController* controller) {
27 // There shouldn't be any swapping from one non-null controller to another.
28 DCHECK(controller != controller_ && (!controller || !controller_));
29 controller_ = controller;
30 // The controller is set to null when the frame is about to be detached.
31 // Nothing is listening for screen availability anymore but the Mojo service
32 // will know about the frame being detached anyway.
35 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) {
36 ConnectToPresentationServiceIfNeeded();
37 if (watched) {
38 presentation_service_->GetScreenAvailability(
39 mojo::String(),
40 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged,
41 base::Unretained(this)));
42 } else {
43 presentation_service_->OnScreenAvailabilityListenerRemoved();
47 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) {
48 if (!controller_)
49 return;
51 // Reset the callback to get the next event.
52 updateAvailableChangeWatched(controller_->isAvailableChangeWatched());
54 controller_->didChangeAvailability(available);
57 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() {
58 if (presentation_service_.get())
59 return;
61 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
62 &presentation_service_);
65 } // namespace content