Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: content/renderer/presentation/presentation_dispatcher.cc

Issue 839773002: Plumbing from WebPresentationClient to the Presentation Mojo service for (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated comment Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "content/renderer/presentation/presentation_dispatcher.h"
6
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/WebPresentationController.h"
11
12 namespace content {
13
14 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame)
15 : RenderFrameObserver(render_frame),
16 controller_(nullptr) {
17 }
18
19 PresentationDispatcher::~PresentationDispatcher() {
20 // Controller should be destroyed before the dispatcher when frame is
21 // destroyed.
22 DCHECK(!controller_);
23 }
24
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.
33 }
34
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();
44 }
45 }
46
47 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) {
48 if (!controller_)
49 return;
50
51 // Reset the callback to get the next event.
52 updateAvailableChangeWatched(controller_->isAvailableChangeWatched());
53
54 controller_->didChangeAvailability(available);
55 }
56
57 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() {
58 if (presentation_service_.get())
59 return;
60
61 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
62 &presentation_service_);
63 }
64
65 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.h ('k') | content/renderer/render_frame_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698