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_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" |
| 11 #include "chrome/browser/media/router/media_router_factory.h" | 11 #include "chrome/browser/media/router/media_router_factory.h" |
| 12 #include "chrome/browser/media/router/media_source.h" | 12 #include "chrome/browser/media/router/media_source.h" |
| 13 #include "chrome/browser/media/router/media_source_helper.h" | |
| 14 #include "chrome/browser/media/router/presentation_request.h" | |
| 13 #include "chrome/browser/sessions/session_tab_helper.h" | 15 #include "chrome/browser/sessions/session_tab_helper.h" |
| 14 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_delegate.h" | 18 #include "content/public/browser/web_contents_delegate.h" |
| 17 #include "jni/ChromeMediaRouterDialogController_jni.h" | 19 #include "jni/ChromeMediaRouterDialogController_jni.h" |
| 18 | 20 |
| 19 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 20 media_router::MediaRouterDialogControllerAndroid); | 22 media_router::MediaRouterDialogControllerAndroid); |
| 21 | 23 |
| 22 using base::android::ConvertJavaStringToUTF8; | 24 using base::android::ConvertJavaStringToUTF8; |
| 23 using content::WebContents; | 25 using content::WebContents; |
| 24 | 26 |
| 25 namespace media_router { | 27 namespace media_router { |
| 26 | 28 |
| 27 // static | 29 // static |
| 28 MediaRouterDialogControllerAndroid* | 30 MediaRouterDialogControllerAndroid* |
| 29 MediaRouterDialogControllerAndroid::GetOrCreateForWebContents( | 31 MediaRouterDialogControllerAndroid::GetOrCreateForWebContents( |
| 30 WebContents* web_contents) { | 32 WebContents* web_contents) { |
| 31 DCHECK(web_contents); | 33 DCHECK(web_contents); |
| 32 // This call does nothing if the controller already exists. | 34 // This call does nothing if the controller already exists. |
| 33 MediaRouterDialogControllerAndroid::CreateForWebContents(web_contents); | 35 MediaRouterDialogControllerAndroid::CreateForWebContents(web_contents); |
| 34 return MediaRouterDialogControllerAndroid::FromWebContents(web_contents); | 36 return MediaRouterDialogControllerAndroid::FromWebContents(web_contents); |
| 35 } | 37 } |
| 36 | 38 |
| 37 void MediaRouterDialogControllerAndroid::OnSinkSelected( | 39 void MediaRouterDialogControllerAndroid::OnSinkSelected( |
| 38 JNIEnv* env, jobject obj, jstring jsink_id) { | 40 JNIEnv* env, jobject obj, jstring jsink_id) { |
| 39 scoped_ptr<CreatePresentationSessionRequest> | 41 scoped_ptr<CreatePresentationSessionRequest> create_session_request( |
| 40 request(TakePresentationRequest()); | 42 TakePresentationRequest()); |
| 41 | 43 |
| 42 const std::string& source_id = request->media_source().id(); | 44 const PresentationRequest& presentation_request = |
| 43 const GURL& origin = request->frame_url().GetOrigin(); | 45 create_session_request->presentation_request(); |
| 46 const MediaSource::Id source_id( | |
|
mark a. foltz
2015/10/20 20:15:25
I actually preferred the previous code, where you
imcheng
2015/10/24 00:41:19
It's because now the CreateSessionRequest now hold
| |
| 47 MediaSourceForPresentationUrl(presentation_request.presentation_url()) | |
| 48 .id()); | |
| 49 const GURL origin(presentation_request.frame_url().GetOrigin()); | |
| 44 | 50 |
| 45 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 51 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 46 route_response_callbacks.push_back( | 52 route_response_callbacks.push_back( |
| 47 base::Bind(&CreatePresentationSessionRequest::HandleRouteResponse, | 53 base::Bind(&CreatePresentationSessionRequest::HandleRouteResponse, |
| 48 base::Passed(&request))); | 54 base::Passed(&create_session_request))); |
| 49 | 55 |
| 50 MediaRouter* router = MediaRouterFactory::GetApiForBrowserContext( | 56 MediaRouter* router = MediaRouterFactory::GetApiForBrowserContext( |
| 51 initiator()->GetBrowserContext()); | 57 initiator()->GetBrowserContext()); |
| 52 router->CreateRoute(source_id, ConvertJavaStringToUTF8(env, jsink_id), origin, | 58 router->CreateRoute(source_id, ConvertJavaStringToUTF8(env, jsink_id), origin, |
| 53 SessionTabHelper::IdForTab(initiator()), | 59 SessionTabHelper::IdForTab(initiator()), |
| 54 route_response_callbacks); | 60 route_response_callbacks); |
| 55 } | 61 } |
| 56 | 62 |
| 57 void MediaRouterDialogControllerAndroid::OnRouteClosed( | 63 void MediaRouterDialogControllerAndroid::OnRouteClosed( |
| 58 JNIEnv* env, | 64 JNIEnv* env, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) { | 106 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) { |
| 101 return RegisterNativesImpl(env); | 107 return RegisterNativesImpl(env); |
| 102 } | 108 } |
| 103 | 109 |
| 104 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() { | 110 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() { |
| 105 } | 111 } |
| 106 | 112 |
| 107 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() { | 113 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() { |
| 108 JNIEnv* env = base::android::AttachCurrentThread(); | 114 JNIEnv* env = base::android::AttachCurrentThread(); |
| 109 | 115 |
| 116 const std::string& presentation_url = | |
| 117 create_session_request()->presentation_request().presentation_url(); | |
| 110 const MediaSource::Id& media_source_id = | 118 const MediaSource::Id& media_source_id = |
| 111 presentation_request()->media_source().id(); | 119 MediaSourceForPresentationUrl(presentation_url).id(); |
| 112 ScopedJavaLocalRef<jstring> jsource_urn = | 120 ScopedJavaLocalRef<jstring> jsource_urn = |
| 113 base::android::ConvertUTF8ToJavaString(env, media_source_id); | 121 base::android::ConvertUTF8ToJavaString(env, media_source_id); |
| 114 | 122 |
| 115 // If it's a single route with the same source, show the controller dialog | 123 // If it's a single route with the same source, show the controller dialog |
| 116 // instead of the device picker. | 124 // instead of the device picker. |
| 117 // TODO(avayvod): maybe this logic should be in | 125 // TODO(avayvod): maybe this logic should be in |
| 118 // PresentationServiceDelegateImpl: if the route exists for the same frame | 126 // PresentationServiceDelegateImpl: if the route exists for the same frame |
| 119 // and tab, show the route controller dialog, if not, show the device picker. | 127 // and tab, show the route controller dialog, if not, show the device picker. |
| 120 if (single_existing_route_.get() && | 128 if (single_existing_route_.get() && |
| 121 single_existing_route_->media_source().id() == media_source_id) { | 129 single_existing_route_->media_source().id() == media_source_id) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 if (single_existing_route_.get() && | 164 if (single_existing_route_.get() && |
| 157 single_existing_route_->media_route_id() == routes[0].media_route_id()) { | 165 single_existing_route_->media_route_id() == routes[0].media_route_id()) { |
| 158 return; | 166 return; |
| 159 } | 167 } |
| 160 | 168 |
| 161 single_existing_route_.reset(new MediaRoute(routes[0])); | 169 single_existing_route_.reset(new MediaRoute(routes[0])); |
| 162 } | 170 } |
| 163 | 171 |
| 164 } // namespace media_router | 172 } // namespace media_router |
| 165 | 173 |
| OLD | NEW |