| 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_dialog_controller_and
roid.h" | 5 #include "chrome/browser/media/android/router/media_router_dialog_controller_and
roid.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "chrome/browser/media/android/router/media_router_android.h" | 9 #include "chrome/browser/media/android/router/media_router_android.h" |
| 10 #include "chrome/browser/media/router/media_router.h" | 10 #include "chrome/browser/media/router/media_router.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 TakeCreateConnectionRequest(); | 82 TakeCreateConnectionRequest(); |
| 83 DCHECK(request); | 83 DCHECK(request); |
| 84 | 84 |
| 85 request->InvokeErrorCallback(content::PresentationError( | 85 request->InvokeErrorCallback(content::PresentationError( |
| 86 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | 86 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, |
| 87 "Dialog closed.")); | 87 "Dialog closed.")); |
| 88 } | 88 } |
| 89 | 89 |
| 90 MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid( | 90 MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid( |
| 91 WebContents* web_contents) | 91 WebContents* web_contents) |
| 92 : MediaRouterDialogController(web_contents), | 92 : MediaRouterDialogController(web_contents) { |
| 93 MediaRoutesObserver(MediaRouterFactory::GetApiForBrowserContext( | |
| 94 initiator()->GetBrowserContext())) { | |
| 95 JNIEnv* env = base::android::AttachCurrentThread(); | 93 JNIEnv* env = base::android::AttachCurrentThread(); |
| 96 java_dialog_controller_.Reset(Java_ChromeMediaRouterDialogController_create( | 94 java_dialog_controller_.Reset(Java_ChromeMediaRouterDialogController_create( |
| 97 env, | 95 env, |
| 98 reinterpret_cast<jlong>(this), | 96 reinterpret_cast<jlong>(this), |
| 99 base::android::GetApplicationContext())); | 97 base::android::GetApplicationContext())); |
| 100 } | 98 } |
| 101 | 99 |
| 102 // static | 100 // static |
| 103 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) { | 101 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) { |
| 104 return RegisterNativesImpl(env); | 102 return RegisterNativesImpl(env); |
| 105 } | 103 } |
| 106 | 104 |
| 107 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() { | 105 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() { |
| 108 } | 106 } |
| 109 | 107 |
| 110 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() { | 108 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() { |
| 111 JNIEnv* env = base::android::AttachCurrentThread(); | 109 JNIEnv* env = base::android::AttachCurrentThread(); |
| 112 | 110 |
| 113 const MediaSource::Id source_id = | 111 const MediaSource::Id source_id = |
| 114 create_connection_request()->presentation_request().GetMediaSource().id(); | 112 create_connection_request()->presentation_request().GetMediaSource().id(); |
| 115 ScopedJavaLocalRef<jstring> jsource_urn = | 113 ScopedJavaLocalRef<jstring> jsource_urn = |
| 116 base::android::ConvertUTF8ToJavaString(env, source_id); | 114 base::android::ConvertUTF8ToJavaString(env, source_id); |
| 117 | 115 |
| 118 // If it's a single route with the same source, show the controller dialog | 116 // If it's a single route with the same source, show the controller dialog |
| 119 // instead of the device picker. | 117 // instead of the device picker. |
| 120 // TODO(avayvod): maybe this logic should be in | 118 // TODO(avayvod): maybe this logic should be in |
| 121 // PresentationServiceDelegateImpl: if the route exists for the same frame | 119 // PresentationServiceDelegateImpl: if the route exists for the same frame |
| 122 // and tab, show the route controller dialog, if not, show the device picker. | 120 // and tab, show the route controller dialog, if not, show the device picker. |
| 123 if (single_existing_route_.get() && | 121 MediaRouterAndroid* router = static_cast<MediaRouterAndroid*>( |
| 124 single_existing_route_->media_source().id() == source_id) { | 122 MediaRouterFactory::GetApiForBrowserContext( |
| 123 initiator()->GetBrowserContext())); |
| 124 const MediaRoute* matching_route = router->FindRouteBySource(source_id); |
| 125 if (matching_route) { |
| 125 ScopedJavaLocalRef<jstring> jmedia_route_id = | 126 ScopedJavaLocalRef<jstring> jmedia_route_id = |
| 126 base::android::ConvertUTF8ToJavaString( | 127 base::android::ConvertUTF8ToJavaString( |
| 127 env, single_existing_route_->media_route_id()); | 128 env, matching_route->media_route_id()); |
| 128 | 129 |
| 129 Java_ChromeMediaRouterDialogController_openRouteControllerDialog( | 130 Java_ChromeMediaRouterDialogController_openRouteControllerDialog( |
| 130 env, java_dialog_controller_.obj(), jsource_urn.obj(), | 131 env, java_dialog_controller_.obj(), jsource_urn.obj(), |
| 131 jmedia_route_id.obj()); | 132 jmedia_route_id.obj()); |
| 132 return; | 133 return; |
| 133 } | 134 } |
| 134 | 135 |
| 135 Java_ChromeMediaRouterDialogController_openRouteChooserDialog( | 136 Java_ChromeMediaRouterDialogController_openRouteChooserDialog( |
| 136 env, java_dialog_controller_.obj(), jsource_urn.obj()); | 137 env, java_dialog_controller_.obj(), jsource_urn.obj()); |
| 137 } | 138 } |
| 138 | 139 |
| 139 void MediaRouterDialogControllerAndroid::CloseMediaRouterDialog() { | 140 void MediaRouterDialogControllerAndroid::CloseMediaRouterDialog() { |
| 140 JNIEnv* env = base::android::AttachCurrentThread(); | 141 JNIEnv* env = base::android::AttachCurrentThread(); |
| 141 | 142 |
| 142 Java_ChromeMediaRouterDialogController_closeDialog( | 143 Java_ChromeMediaRouterDialogController_closeDialog( |
| 143 env, java_dialog_controller_.obj()); | 144 env, java_dialog_controller_.obj()); |
| 144 } | 145 } |
| 145 | 146 |
| 146 bool MediaRouterDialogControllerAndroid::IsShowingMediaRouterDialog() const { | 147 bool MediaRouterDialogControllerAndroid::IsShowingMediaRouterDialog() const { |
| 147 JNIEnv* env = base::android::AttachCurrentThread(); | 148 JNIEnv* env = base::android::AttachCurrentThread(); |
| 148 return Java_ChromeMediaRouterDialogController_isShowingDialog( | 149 return Java_ChromeMediaRouterDialogController_isShowingDialog( |
| 149 env, java_dialog_controller_.obj()); | 150 env, java_dialog_controller_.obj()); |
| 150 } | 151 } |
| 151 | 152 |
| 152 void MediaRouterDialogControllerAndroid::OnRoutesUpdated( | |
| 153 const std::vector<MediaRoute>& routes) { | |
| 154 if (routes.size() != 1) { | |
| 155 single_existing_route_.reset(); | |
| 156 return; | |
| 157 } | |
| 158 | |
| 159 if (single_existing_route_.get() && | |
| 160 single_existing_route_->media_route_id() == routes[0].media_route_id()) { | |
| 161 return; | |
| 162 } | |
| 163 | |
| 164 single_existing_route_.reset(new MediaRoute(routes[0])); | |
| 165 } | |
| 166 | |
| 167 } // namespace media_router | 153 } // namespace media_router |
| 168 | 154 |
| OLD | NEW |