| 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/presentation_request.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/browser/web_contents_delegate.h" | 16 #include "content/public/browser/web_contents_delegate.h" |
| 16 #include "jni/ChromeMediaRouterDialogController_jni.h" | 17 #include "jni/ChromeMediaRouterDialogController_jni.h" |
| 17 | 18 |
| 18 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 19 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 19 media_router::MediaRouterDialogControllerAndroid); | 20 media_router::MediaRouterDialogControllerAndroid); |
| 20 | 21 |
| 21 using base::android::ConvertJavaStringToUTF8; | 22 using base::android::ConvertJavaStringToUTF8; |
| 22 using content::WebContents; | 23 using content::WebContents; |
| 23 | 24 |
| 24 namespace media_router { | 25 namespace media_router { |
| 25 | 26 |
| 26 // static | 27 // static |
| 27 MediaRouterDialogControllerAndroid* | 28 MediaRouterDialogControllerAndroid* |
| 28 MediaRouterDialogControllerAndroid::GetOrCreateForWebContents( | 29 MediaRouterDialogControllerAndroid::GetOrCreateForWebContents( |
| 29 WebContents* web_contents) { | 30 WebContents* web_contents) { |
| 30 DCHECK(web_contents); | 31 DCHECK(web_contents); |
| 31 // This call does nothing if the controller already exists. | 32 // This call does nothing if the controller already exists. |
| 32 MediaRouterDialogControllerAndroid::CreateForWebContents(web_contents); | 33 MediaRouterDialogControllerAndroid::CreateForWebContents(web_contents); |
| 33 return MediaRouterDialogControllerAndroid::FromWebContents(web_contents); | 34 return MediaRouterDialogControllerAndroid::FromWebContents(web_contents); |
| 34 } | 35 } |
| 35 | 36 |
| 36 void MediaRouterDialogControllerAndroid::OnSinkSelected( | 37 void MediaRouterDialogControllerAndroid::OnSinkSelected( |
| 37 JNIEnv* env, jobject obj, jstring jsink_id) { | 38 JNIEnv* env, jobject obj, jstring jsink_id) { |
| 38 scoped_ptr<CreatePresentationSessionRequest> | 39 scoped_ptr<CreatePresentationConnectionRequest> create_connection_request = |
| 39 request(TakePresentationRequest()); | 40 TakeCreateConnectionRequest(); |
| 40 | 41 const PresentationRequest& presentation_request = |
| 41 const std::string& source_id = request->media_source().id(); | 42 create_connection_request->presentation_request(); |
| 42 const GURL& origin = request->frame_url().GetOrigin(); | 43 const MediaSource::Id source_id = presentation_request.GetMediaSource().id(); |
| 44 const GURL origin = presentation_request.frame_url().GetOrigin(); |
| 43 | 45 |
| 44 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 46 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 45 route_response_callbacks.push_back( | 47 route_response_callbacks.push_back( |
| 46 base::Bind(&CreatePresentationSessionRequest::HandleRouteResponse, | 48 base::Bind(&CreatePresentationConnectionRequest::HandleRouteResponse, |
| 47 base::Passed(&request))); | 49 base::Passed(&create_connection_request))); |
| 48 | 50 |
| 49 MediaRouter* router = MediaRouterFactory::GetApiForBrowserContext( | 51 MediaRouter* router = MediaRouterFactory::GetApiForBrowserContext( |
| 50 initiator()->GetBrowserContext()); | 52 initiator()->GetBrowserContext()); |
| 51 router->CreateRoute( | 53 router->CreateRoute( |
| 52 source_id, | 54 source_id, |
| 53 ConvertJavaStringToUTF8(env, jsink_id), | 55 ConvertJavaStringToUTF8(env, jsink_id), |
| 54 origin, | 56 origin, |
| 55 initiator(), | 57 initiator(), |
| 56 route_response_callbacks); | 58 route_response_callbacks); |
| 57 } | 59 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 69 | 71 |
| 70 CancelPresentationRequest(); | 72 CancelPresentationRequest(); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void MediaRouterDialogControllerAndroid::OnDialogCancelled( | 75 void MediaRouterDialogControllerAndroid::OnDialogCancelled( |
| 74 JNIEnv* env, jobject obj) { | 76 JNIEnv* env, jobject obj) { |
| 75 CancelPresentationRequest(); | 77 CancelPresentationRequest(); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void MediaRouterDialogControllerAndroid::CancelPresentationRequest() { | 80 void MediaRouterDialogControllerAndroid::CancelPresentationRequest() { |
| 79 scoped_ptr<CreatePresentationSessionRequest> request( | 81 scoped_ptr<CreatePresentationConnectionRequest> request = |
| 80 TakePresentationRequest()); | 82 TakeCreateConnectionRequest(); |
| 81 | |
| 82 DCHECK(request); | 83 DCHECK(request); |
| 83 | 84 |
| 84 request->InvokeErrorCallback(content::PresentationError( | 85 request->InvokeErrorCallback(content::PresentationError( |
| 85 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | 86 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, |
| 86 "Dialog closed.")); | 87 "Dialog closed.")); |
| 87 } | 88 } |
| 88 | 89 |
| 89 MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid( | 90 MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid( |
| 90 WebContents* web_contents) | 91 WebContents* web_contents) |
| 91 : MediaRouterDialogController(web_contents), | 92 : MediaRouterDialogController(web_contents), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 102 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) { | 103 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) { |
| 103 return RegisterNativesImpl(env); | 104 return RegisterNativesImpl(env); |
| 104 } | 105 } |
| 105 | 106 |
| 106 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() { | 107 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() { |
| 107 } | 108 } |
| 108 | 109 |
| 109 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() { | 110 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() { |
| 110 JNIEnv* env = base::android::AttachCurrentThread(); | 111 JNIEnv* env = base::android::AttachCurrentThread(); |
| 111 | 112 |
| 112 const MediaSource::Id& media_source_id = | 113 const MediaSource::Id source_id = |
| 113 presentation_request()->media_source().id(); | 114 create_connection_request()->presentation_request().GetMediaSource().id(); |
| 114 ScopedJavaLocalRef<jstring> jsource_urn = | 115 ScopedJavaLocalRef<jstring> jsource_urn = |
| 115 base::android::ConvertUTF8ToJavaString(env, media_source_id); | 116 base::android::ConvertUTF8ToJavaString(env, source_id); |
| 116 | 117 |
| 117 // If it's a single route with the same source, show the controller dialog | 118 // If it's a single route with the same source, show the controller dialog |
| 118 // instead of the device picker. | 119 // instead of the device picker. |
| 119 // TODO(avayvod): maybe this logic should be in | 120 // TODO(avayvod): maybe this logic should be in |
| 120 // PresentationServiceDelegateImpl: if the route exists for the same frame | 121 // PresentationServiceDelegateImpl: if the route exists for the same frame |
| 121 // and tab, show the route controller dialog, if not, show the device picker. | 122 // and tab, show the route controller dialog, if not, show the device picker. |
| 122 if (single_existing_route_.get() && | 123 if (single_existing_route_.get() && |
| 123 single_existing_route_->media_source().id() == media_source_id) { | 124 single_existing_route_->media_source().id() == source_id) { |
| 124 ScopedJavaLocalRef<jstring> jmedia_route_id = | 125 ScopedJavaLocalRef<jstring> jmedia_route_id = |
| 125 base::android::ConvertUTF8ToJavaString( | 126 base::android::ConvertUTF8ToJavaString( |
| 126 env, single_existing_route_->media_route_id()); | 127 env, single_existing_route_->media_route_id()); |
| 127 | 128 |
| 128 Java_ChromeMediaRouterDialogController_openRouteControllerDialog( | 129 Java_ChromeMediaRouterDialogController_openRouteControllerDialog( |
| 129 env, java_dialog_controller_.obj(), jsource_urn.obj(), | 130 env, java_dialog_controller_.obj(), jsource_urn.obj(), |
| 130 jmedia_route_id.obj()); | 131 jmedia_route_id.obj()); |
| 131 return; | 132 return; |
| 132 } | 133 } |
| 133 | 134 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 158 if (single_existing_route_.get() && | 159 if (single_existing_route_.get() && |
| 159 single_existing_route_->media_route_id() == routes[0].media_route_id()) { | 160 single_existing_route_->media_route_id() == routes[0].media_route_id()) { |
| 160 return; | 161 return; |
| 161 } | 162 } |
| 162 | 163 |
| 163 single_existing_route_.reset(new MediaRoute(routes[0])); | 164 single_existing_route_.reset(new MediaRoute(routes[0])); |
| 164 } | 165 } |
| 165 | 166 |
| 166 } // namespace media_router | 167 } // namespace media_router |
| 167 | 168 |
| OLD | NEW |