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

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

Issue 978543002: [Presentation API] Plumbing the |defaultpresentationstart| event from Blink to browser/Mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/presentation/presentation_dispatcher.h" 5 #include "content/renderer/presentation/presentation_dispatcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/common/presentation/presentation_service.mojom.h" 8 #include "content/common/presentation/presentation_service.mojom.h"
9 #include "content/public/common/service_registry.h" 9 #include "content/public/common/service_registry.h"
10 #include "content/public/renderer/render_frame.h" 10 #include "content/public/renderer/render_frame.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // Nothing is listening for screen availability anymore but the Mojo service 54 // Nothing is listening for screen availability anymore but the Mojo service
55 // will know about the frame being detached anyway. 55 // will know about the frame being detached anyway.
56 } 56 }
57 57
58 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { 58 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) {
59 ConnectToPresentationServiceIfNeeded(); 59 ConnectToPresentationServiceIfNeeded();
60 if (watched) { 60 if (watched) {
61 presentation_service_->GetScreenAvailability( 61 presentation_service_->GetScreenAvailability(
62 mojo::String(), 62 mojo::String(),
63 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, 63 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged,
64 base::Unretained(this))); 64 base::Unretained(this)));
Peter Beverloo 2015/03/03 21:40:40 nit: indentation
whywhat 2015/03/05 20:26:14 Done.
65 } else { 65 } else {
66 presentation_service_->OnScreenAvailabilityListenerRemoved(); 66 presentation_service_->OnScreenAvailabilityListenerRemoved();
67 } 67 }
68 } 68 }
69 69
70 void PresentationDispatcher::updateDefaultPresentationStartWatched(
71 bool watched) {
72 ConnectToPresentationServiceIfNeeded();
73 if (watched) {
74 presentation_service_->WaitForDefaultPresentation(
75 base::Bind(&PresentationDispatcher::OnDefaultPresentationStarted,
76 base::Unretained(this)));
Peter Beverloo 2015/03/03 21:40:40 nit: indentation
whywhat 2015/03/05 20:26:14 Done.
77 } else {
78 presentation_service_->OnDefaultPresentationListenerRemoved();
79 }
80 }
81
70 void PresentationDispatcher::startSession( 82 void PresentationDispatcher::startSession(
71 const blink::WebString& presentationUrl, 83 const blink::WebString& presentationUrl,
72 const blink::WebString& presentationId, 84 const blink::WebString& presentationId,
73 blink::WebPresentationSessionClientCallbacks* callback) { 85 blink::WebPresentationSessionClientCallbacks* callback) {
74 DCHECK(callback); 86 DCHECK(callback);
75 ConnectToPresentationServiceIfNeeded(); 87 ConnectToPresentationServiceIfNeeded();
76 88
77 // The dispatcher owns the service so |this| will be valid when 89 // The dispatcher owns the service so |this| will be valid when
78 // OnSessionCreated() is called. |callback| needs to be alive and also needs 90 // OnSessionCreated() is called. |callback| needs to be alive and also needs
79 // to be destroyed so we transfer its ownership to the mojo callback. 91 // to be destroyed so we transfer its ownership to the mojo callback.
(...skipping 26 matching lines...) Expand all
106 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { 118 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) {
107 if (!controller_) 119 if (!controller_)
108 return; 120 return;
109 121
110 // Reset the callback to get the next event. 122 // Reset the callback to get the next event.
111 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); 123 updateAvailableChangeWatched(controller_->isAvailableChangeWatched());
112 124
113 controller_->didChangeAvailability(available); 125 controller_->didChangeAvailability(available);
114 } 126 }
115 127
128 void PresentationDispatcher::OnDefaultPresentationStarted(
129 presentation::PresentationSessionInfoPtr session_info) {
130 if (!controller_)
131 return;
132
133 // Reset the callback to get the next event.
134 updateDefaultPresentationStartWatched(
135 controller_->isDefaultPresentationStartWatched());
136
137 DCHECK(!session_info.is_null());
138 PresentationSessionDispatcher* session_dispatcher =
139 new PresentationSessionDispatcher(session_info.Pass());
140 presentation_session_dispatchers_.push_back(session_dispatcher);
141 controller_->didStartDefaultPresentation(
142 new PresentationSessionClient(session_dispatcher));
143 }
144
116 void PresentationDispatcher::OnSessionCreated( 145 void PresentationDispatcher::OnSessionCreated(
117 blink::WebPresentationSessionClientCallbacks* callback, 146 blink::WebPresentationSessionClientCallbacks* callback,
118 presentation::PresentationSessionInfoPtr session_info, 147 presentation::PresentationSessionInfoPtr session_info,
119 presentation::PresentationErrorPtr error) { 148 presentation::PresentationErrorPtr error) {
120 DCHECK(callback); 149 DCHECK(callback);
121 if (!error.is_null()) { 150 if (!error.is_null()) {
122 DCHECK(session_info.is_null()); 151 DCHECK(session_info.is_null());
123 callback->onError(new blink::WebPresentationError( 152 callback->onError(new blink::WebPresentationError(
124 GetWebPresentationErrorTypeFromMojo(error->errorType), 153 GetWebPresentationErrorTypeFromMojo(error->errorType),
125 blink::WebString::fromUTF8(error->message))); 154 blink::WebString::fromUTF8(error->message)));
126 return; 155 return;
127 } 156 }
128 157
129 DCHECK(!session_info.is_null()); 158 DCHECK(!session_info.is_null());
130 PresentationSessionDispatcher* session_dispatcher = 159 PresentationSessionDispatcher* session_dispatcher =
131 new PresentationSessionDispatcher(session_info.Pass()); 160 new PresentationSessionDispatcher(session_info.Pass());
132 presentation_session_dispatchers_.push_back(session_dispatcher); 161 presentation_session_dispatchers_.push_back(session_dispatcher);
133 callback->onSuccess(new PresentationSessionClient(session_dispatcher)); 162 callback->onSuccess(new PresentationSessionClient(session_dispatcher));
134 } 163 }
135 164
136 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { 165 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() {
137 if (presentation_service_.get()) 166 if (presentation_service_.get())
138 return; 167 return;
139 168
140 render_frame()->GetServiceRegistry()->ConnectToRemoteService( 169 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
141 &presentation_service_); 170 &presentation_service_);
142 } 171 }
143 172
144 } // namespace content 173 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698