Index: content/renderer/presentation/presentation_dispatcher.cc |
diff --git a/content/renderer/presentation/presentation_dispatcher.cc b/content/renderer/presentation/presentation_dispatcher.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bbabb127781a79d38cb0a2179b7a4a74ab8d9e5c |
--- /dev/null |
+++ b/content/renderer/presentation/presentation_dispatcher.cc |
@@ -0,0 +1,55 @@ |
+// Copyright 2015 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 "content/renderer/presentation/presentation_dispatcher.h" |
+ |
+#include "content/common/presentation/presentation_service.mojom.h" |
+#include "content/public/common/service_registry.h" |
+#include "content/public/renderer/render_frame.h" |
+#include "third_party/WebKit/public/platform/WebPresentationController.h" |
+ |
+namespace content { |
+ |
+PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
+ : RenderFrameObserver(render_frame) {} |
+ |
+PresentationDispatcher::~PresentationDispatcher() {} |
+ |
+void PresentationDispatcher::setController( |
+ blink::WebPresentationController* controller) { |
+ // Provide the service with the callback to get the next |availablechange| |
+ // event if needed. |
+ if (controller != nullptr && controller_ != controller) |
+ updateAvailableChangeWatched(controller->isAvailableChangeWatched()); |
+ controller_ = controller; |
+} |
+ |
+void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { |
+ ConnectToPresentationServiceIfNeeded(); |
+ if (watched) { |
+ presentation_service_->GetScreenAvailability( |
+ base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, |
+ base::Unretained(this))); |
+ } |
+} |
+ |
+void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { |
+ if (!controller_) |
+ return; |
+ |
+ controller_->didChangeAvailability(available); |
+ |
+ // Reset the callback to get the next event. |
+ 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.
|
+} |
+ |
+void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
+ if (presentation_service_.get()) |
+ return; |
+ |
+ render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
+ &presentation_service_); |
+} |
+ |
+} // namespace content |