Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/media/android/router/media_router_android.h" | 5 #include "chrome/browser/media/android/router/media_router_android.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 for (const auto& route : active_routes_) { | 68 for (const auto& route : active_routes_) { |
| 69 if (route.media_source().id() == source_id) | 69 if (route.media_source().id() == source_id) |
| 70 return &route; | 70 return &route; |
| 71 } | 71 } |
| 72 return nullptr; | 72 return nullptr; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void MediaRouterAndroid::CreateRoute( | 75 void MediaRouterAndroid::CreateRoute( |
| 76 const MediaSource::Id& source_id, | 76 const MediaSource::Id& source_id, |
| 77 const MediaSink::Id& sink_id, | 77 const MediaSink::Id& sink_id, |
| 78 const GURL& origin, | 78 const url::Origin& origin, |
| 79 content::WebContents* web_contents, | 79 content::WebContents* web_contents, |
| 80 const std::vector<MediaRouteResponseCallback>& callbacks, | 80 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 81 base::TimeDelta timeout, | 81 base::TimeDelta timeout, |
| 82 bool incognito) { | 82 bool incognito) { |
| 83 // TODO(avayvod): Implement timeouts (crbug.com/583036). | 83 // TODO(avayvod): Implement timeouts (crbug.com/583036). |
| 84 if (!origin.is_valid()) { | |
| 85 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( | |
| 86 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); | |
| 87 for (const MediaRouteResponseCallback& callback : callbacks) | |
| 88 callback.Run(*result); | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 std::string presentation_id = MediaRouterBase::CreatePresentationId(); | 84 std::string presentation_id = MediaRouterBase::CreatePresentationId(); |
| 93 | 85 |
| 94 int tab_id = -1; | 86 int tab_id = -1; |
| 95 TabAndroid* tab = web_contents | 87 TabAndroid* tab = web_contents |
| 96 ? TabAndroid::FromWebContents(web_contents) : nullptr; | 88 ? TabAndroid::FromWebContents(web_contents) : nullptr; |
| 97 if (tab) | 89 if (tab) |
| 98 tab_id = tab->GetAndroidId(); | 90 tab_id = tab->GetAndroidId(); |
| 99 | 91 |
| 100 bool is_incognito = web_contents | 92 bool is_incognito = web_contents |
| 101 && web_contents->GetBrowserContext()->IsOffTheRecord(); | 93 && web_contents->GetBrowserContext()->IsOffTheRecord(); |
| 102 | 94 |
| 103 int route_request_id = | 95 int route_request_id = |
| 104 route_requests_.Add(base::MakeUnique<MediaRouteRequest>( | 96 route_requests_.Add(base::MakeUnique<MediaRouteRequest>( |
| 105 MediaSource(source_id), presentation_id, callbacks)); | 97 MediaSource(source_id), presentation_id, callbacks)); |
| 106 | 98 |
| 107 JNIEnv* env = base::android::AttachCurrentThread(); | 99 JNIEnv* env = base::android::AttachCurrentThread(); |
| 108 ScopedJavaLocalRef<jstring> jsource_id = | 100 ScopedJavaLocalRef<jstring> jsource_id = |
| 109 base::android::ConvertUTF8ToJavaString(env, source_id); | 101 base::android::ConvertUTF8ToJavaString(env, source_id); |
| 110 ScopedJavaLocalRef<jstring> jsink_id = | 102 ScopedJavaLocalRef<jstring> jsink_id = |
| 111 base::android::ConvertUTF8ToJavaString(env, sink_id); | 103 base::android::ConvertUTF8ToJavaString(env, sink_id); |
| 112 ScopedJavaLocalRef<jstring> jpresentation_id = | 104 ScopedJavaLocalRef<jstring> jpresentation_id = |
| 113 base::android::ConvertUTF8ToJavaString(env, presentation_id); | 105 base::android::ConvertUTF8ToJavaString(env, presentation_id); |
| 114 ScopedJavaLocalRef<jstring> jorigin = | 106 ScopedJavaLocalRef<jstring> jorigin = |
| 115 base::android::ConvertUTF8ToJavaString(env, origin.spec()); | 107 base::android::ConvertUTF8ToJavaString(env, origin.GetURL().spec()); |
|
mark a. foltz
2017/01/24 04:04:17
Is it necessary to convert origin to a GURL, or ca
steimel
2017/01/25 19:01:10
Tested a few scenarios, and looks like they're not
mark a. foltz
2017/01/25 21:13:04
If case #1 returns the string "null" then things s
steimel
2017/01/25 22:25:26
Done.
| |
| 116 | 108 |
| 117 Java_ChromeMediaRouter_createRoute(env, java_media_router_, jsource_id, | 109 Java_ChromeMediaRouter_createRoute(env, java_media_router_, jsource_id, |
| 118 jsink_id, jpresentation_id, jorigin, | 110 jsink_id, jpresentation_id, jorigin, |
| 119 tab_id, is_incognito, route_request_id); | 111 tab_id, is_incognito, route_request_id); |
| 120 } | 112 } |
| 121 | 113 |
| 122 void MediaRouterAndroid::ConnectRouteByRouteId( | 114 void MediaRouterAndroid::ConnectRouteByRouteId( |
| 123 const MediaSource::Id& source, | 115 const MediaSource::Id& source, |
| 124 const MediaRoute::Id& route_id, | 116 const MediaRoute::Id& route_id, |
| 125 const GURL& origin, | 117 const url::Origin& origin, |
| 126 content::WebContents* web_contents, | 118 content::WebContents* web_contents, |
| 127 const std::vector<MediaRouteResponseCallback>& callbacks, | 119 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 128 base::TimeDelta timeout, | 120 base::TimeDelta timeout, |
| 129 bool incognito) { | 121 bool incognito) { |
| 130 NOTIMPLEMENTED(); | 122 NOTIMPLEMENTED(); |
| 131 } | 123 } |
| 132 | 124 |
| 133 void MediaRouterAndroid::JoinRoute( | 125 void MediaRouterAndroid::JoinRoute( |
| 134 const MediaSource::Id& source_id, | 126 const MediaSource::Id& source_id, |
| 135 const std::string& presentation_id, | 127 const std::string& presentation_id, |
| 136 const GURL& origin, | 128 const url::Origin& origin, |
| 137 content::WebContents* web_contents, | 129 content::WebContents* web_contents, |
| 138 const std::vector<MediaRouteResponseCallback>& callbacks, | 130 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 139 base::TimeDelta timeout, | 131 base::TimeDelta timeout, |
| 140 bool incognito) { | 132 bool incognito) { |
| 141 // TODO(avayvod): Implement timeouts (crbug.com/583036). | 133 // TODO(avayvod): Implement timeouts (crbug.com/583036). |
| 142 if (!origin.is_valid()) { | |
| 143 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( | |
| 144 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); | |
| 145 for (const MediaRouteResponseCallback& callback : callbacks) | |
| 146 callback.Run(*result); | |
| 147 return; | |
| 148 } | |
| 149 | |
| 150 int tab_id = -1; | 134 int tab_id = -1; |
| 151 TabAndroid* tab = web_contents | 135 TabAndroid* tab = web_contents |
| 152 ? TabAndroid::FromWebContents(web_contents) : nullptr; | 136 ? TabAndroid::FromWebContents(web_contents) : nullptr; |
| 153 if (tab) | 137 if (tab) |
| 154 tab_id = tab->GetAndroidId(); | 138 tab_id = tab->GetAndroidId(); |
| 155 | 139 |
| 156 DVLOG(2) << "JoinRoute: " << source_id << ", " << presentation_id << ", " | 140 DVLOG(2) << "JoinRoute: " << source_id << ", " << presentation_id << ", " |
| 157 << origin.spec() << ", " << tab_id; | 141 << origin.GetURL().spec() << ", " << tab_id; |
| 158 | 142 |
| 159 int request_id = route_requests_.Add(base::MakeUnique<MediaRouteRequest>( | 143 int request_id = route_requests_.Add(base::MakeUnique<MediaRouteRequest>( |
| 160 MediaSource(source_id), presentation_id, callbacks)); | 144 MediaSource(source_id), presentation_id, callbacks)); |
| 161 | 145 |
| 162 JNIEnv* env = base::android::AttachCurrentThread(); | 146 JNIEnv* env = base::android::AttachCurrentThread(); |
| 163 ScopedJavaLocalRef<jstring> jsource_id = | 147 ScopedJavaLocalRef<jstring> jsource_id = |
| 164 base::android::ConvertUTF8ToJavaString(env, source_id); | 148 base::android::ConvertUTF8ToJavaString(env, source_id); |
| 165 ScopedJavaLocalRef<jstring> jpresentation_id = | 149 ScopedJavaLocalRef<jstring> jpresentation_id = |
| 166 base::android::ConvertUTF8ToJavaString(env, presentation_id); | 150 base::android::ConvertUTF8ToJavaString(env, presentation_id); |
| 167 ScopedJavaLocalRef<jstring> jorigin = | 151 ScopedJavaLocalRef<jstring> jorigin = |
| 168 base::android::ConvertUTF8ToJavaString(env, origin.spec()); | 152 base::android::ConvertUTF8ToJavaString(env, origin.GetURL().spec()); |
| 169 | 153 |
| 170 Java_ChromeMediaRouter_joinRoute(env, java_media_router_, jsource_id, | 154 Java_ChromeMediaRouter_joinRoute(env, java_media_router_, jsource_id, |
| 171 jpresentation_id, jorigin, tab_id, | 155 jpresentation_id, jorigin, tab_id, |
| 172 request_id); | 156 request_id); |
| 173 } | 157 } |
| 174 | 158 |
| 175 void MediaRouterAndroid::TerminateRoute(const MediaRoute::Id& route_id) { | 159 void MediaRouterAndroid::TerminateRoute(const MediaRoute::Id& route_id) { |
| 176 JNIEnv* env = base::android::AttachCurrentThread(); | 160 JNIEnv* env = base::android::AttachCurrentThread(); |
| 177 ScopedJavaLocalRef<jstring> jroute_id = | 161 ScopedJavaLocalRef<jstring> jroute_id = |
| 178 base::android::ConvertUTF8ToJavaString(env, route_id); | 162 base::android::ConvertUTF8ToJavaString(env, route_id); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 MediaSink(ConvertJavaStringToUTF8(env, jsink_urn.obj()), | 325 MediaSink(ConvertJavaStringToUTF8(env, jsink_urn.obj()), |
| 342 ConvertJavaStringToUTF8(env, jsink_name.obj()), | 326 ConvertJavaStringToUTF8(env, jsink_name.obj()), |
| 343 MediaSink::GENERIC)); | 327 MediaSink::GENERIC)); |
| 344 } | 328 } |
| 345 | 329 |
| 346 std::string source_urn = ConvertJavaStringToUTF8(env, jsource_urn); | 330 std::string source_urn = ConvertJavaStringToUTF8(env, jsource_urn); |
| 347 auto it = sinks_observers_.find(source_urn); | 331 auto it = sinks_observers_.find(source_urn); |
| 348 if (it != sinks_observers_.end()) { | 332 if (it != sinks_observers_.end()) { |
| 349 // TODO(imcheng): Pass origins to OnSinksUpdated (crbug.com/594858). | 333 // TODO(imcheng): Pass origins to OnSinksUpdated (crbug.com/594858). |
| 350 for (auto& observer : *it->second) | 334 for (auto& observer : *it->second) |
| 351 observer.OnSinksUpdated(sinks_converted, std::vector<GURL>()); | 335 observer.OnSinksUpdated(sinks_converted, std::vector<url::Origin>()); |
| 352 } | 336 } |
| 353 } | 337 } |
| 354 | 338 |
| 355 void MediaRouterAndroid::OnRouteCreated( | 339 void MediaRouterAndroid::OnRouteCreated( |
| 356 JNIEnv* env, | 340 JNIEnv* env, |
| 357 const JavaParamRef<jobject>& obj, | 341 const JavaParamRef<jobject>& obj, |
| 358 const JavaParamRef<jstring>& jmedia_route_id, | 342 const JavaParamRef<jstring>& jmedia_route_id, |
| 359 const JavaParamRef<jstring>& jsink_id, | 343 const JavaParamRef<jstring>& jsink_id, |
| 360 jint jroute_request_id, | 344 jint jroute_request_id, |
| 361 jboolean jis_local) { | 345 jboolean jis_local) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 return; | 436 return; |
| 453 | 437 |
| 454 std::vector<RouteMessage> messages(1); | 438 std::vector<RouteMessage> messages(1); |
| 455 messages.front().type = RouteMessage::TEXT; | 439 messages.front().type = RouteMessage::TEXT; |
| 456 messages.front().text = ConvertJavaStringToUTF8(env, jmessage); | 440 messages.front().text = ConvertJavaStringToUTF8(env, jmessage); |
| 457 for (auto& observer : *it->second.get()) | 441 for (auto& observer : *it->second.get()) |
| 458 observer.OnMessagesReceived(messages); | 442 observer.OnMessagesReceived(messages); |
| 459 } | 443 } |
| 460 | 444 |
| 461 } // namespace media_router | 445 } // namespace media_router |
| OLD | NEW |