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