Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| 17 PresentationDispatcher::~PresentationDispatcher() {} | |
| 18 | |
| 19 void PresentationDispatcher::setController( | |
| 20 blink::WebPresentationController* controller) { | |
| 21 // Provide the service with the callback to get the next |availablechange| | |
| 22 // event if needed. | |
| 23 if (controller != nullptr && controller_ != controller) | |
| 24 updateAvailableChangeWatched(controller->isAvailableChangeWatched()); | |
| 25 controller_ = controller; | |
| 26 } | |
| 27 | |
| 28 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { | |
| 29 ConnectToPresentationServiceIfNeeded(); | |
| 30 if (watched) { | |
| 31 presentation_service_->GetScreenAvailability( | |
| 32 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, | |
| 33 base::Unretained(this))); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { | |
| 38 if (!controller_) | |
| 39 return; | |
| 40 | |
| 41 controller_->didChangeAvailability(available); | |
| 42 | |
| 43 // Reset the callback to get the next event. | |
| 44 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); | |
|
blundell
2015/01/26 10:31:08
You should call this before line 41 as you don't k
whywhat
2015/01/26 11:06:08
Done.
| |
| 45 } | |
| 46 | |
| 47 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | |
| 48 if (presentation_service_.get()) | |
| 49 return; | |
| 50 | |
| 51 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | |
| 52 &presentation_service_); | |
| 53 } | |
| 54 | |
| 55 } // namespace content | |
| OLD | NEW |