Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: chrome/browser/media/android/router/media_router_dialog_controller_android.cc

Issue 1294133002: [Presentation API, MediaRouter] Routing from media sink selection to route creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media-router-discovery-2
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
10 #include "chrome/browser/media/router/media_router.h"
11 #include "chrome/browser/media/router/media_router_factory.h"
9 #include "chrome/browser/media/router/media_source.h" 12 #include "chrome/browser/media/router/media_source.h"
13 #include "chrome/browser/sessions/session_tab_helper.h"
10 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_delegate.h" 16 #include "content/public/browser/web_contents_delegate.h"
13 #include "jni/ChromeMediaRouterDialogController_jni.h" 17 #include "jni/ChromeMediaRouterDialogController_jni.h"
14 18
15 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
16 media_router::MediaRouterDialogControllerAndroid); 20 media_router::MediaRouterDialogControllerAndroid);
17 21
22 using base::android::ConvertJavaStringToUTF8;
18 using content::WebContents; 23 using content::WebContents;
19 24
20 namespace media_router { 25 namespace media_router {
21 26
22 // static 27 // static
23 MediaRouterDialogControllerAndroid* 28 MediaRouterDialogControllerAndroid*
24 MediaRouterDialogControllerAndroid::GetOrCreateForWebContents( 29 MediaRouterDialogControllerAndroid::GetOrCreateForWebContents(
25 WebContents* web_contents) { 30 WebContents* web_contents) {
26 DCHECK(web_contents); 31 DCHECK(web_contents);
27 // This call does nothing if the controller already exists. 32 // This call does nothing if the controller already exists.
28 MediaRouterDialogControllerAndroid::CreateForWebContents(web_contents); 33 MediaRouterDialogControllerAndroid::CreateForWebContents(web_contents);
29 return MediaRouterDialogControllerAndroid::FromWebContents(web_contents); 34 return MediaRouterDialogControllerAndroid::FromWebContents(web_contents);
30 } 35 }
31 36
37 void MediaRouterDialogControllerAndroid::OnSinkSelected(
38 JNIEnv* env, jobject obj, jstring jsink_id) {
39 scoped_ptr<CreatePresentationSessionRequest>
40 request(PassPresentationRequest());
41 const std::string& source_id = request->media_source().id();
42 const GURL& origin = request->frame_url().GetOrigin();
43
44 std::vector<MediaRouteResponseCallback> route_response_callbacks;
45 route_response_callbacks.push_back(
46 base::Bind(&CreatePresentationSessionRequest::HandleRouteResponse,
47 base::Passed(&request)));
48
49 MediaRouter* router = static_cast<MediaRouterAndroid*>(
50 MediaRouterFactory::GetApiForBrowserContext(
51 initiator()->GetBrowserContext()));
52 DCHECK(router);
53 router->CreateRoute(source_id,
54 ConvertJavaStringToUTF8(env, jsink_id),
55 origin,
56 SessionTabHelper::IdForTab(initiator()),
57 route_response_callbacks);
58 }
59
60 void MediaRouterDialogControllerAndroid::OnDialogDismissed(
61 JNIEnv* env, jobject obj) {
62 scoped_ptr<CreatePresentationSessionRequest> request(
63 PassPresentationRequest());
64
65 // If OnDialogDismissed is called after OnSinkSelected, do nothing.
66 if (!request)
67 return;
68
69 request->MaybeInvokeErrorCallback(
70 content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, ""));
mlamouri (slow - plz ping) 2015/08/18 13:44:01 Can we have a better error type and message?
whywhat 2015/08/18 14:23:15 Yes :)
71 }
72
32 MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid( 73 MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid(
33 WebContents* web_contents) 74 WebContents* web_contents)
34 : MediaRouterDialogController(web_contents) { 75 : MediaRouterDialogController(web_contents) {
35 JNIEnv* env = base::android::AttachCurrentThread(); 76 JNIEnv* env = base::android::AttachCurrentThread();
36 java_dialog_controller_.Reset(Java_ChromeMediaRouterDialogController_create( 77 java_dialog_controller_.Reset(Java_ChromeMediaRouterDialogController_create(
37 env, 78 env,
38 reinterpret_cast<jlong>(this), 79 reinterpret_cast<jlong>(this),
39 base::android::GetApplicationContext())); 80 base::android::GetApplicationContext()));
40 } 81 }
41 82
42 // static 83 // static
43 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) { 84 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) {
44 bool ret = RegisterNativesImpl(env); 85 bool ret = RegisterNativesImpl(env);
45 // No native calls to register yet. 86 DCHECK(g_ChromeMediaRouterDialogController_clazz);
46 // DCHECK(g_ChromeMediaRouterDialogController_clazz);
47 return ret; 87 return ret;
48 } 88 }
49 89
50 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() { 90 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() {
51 } 91 }
52 92
53 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() { 93 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() {
54 JNIEnv* env = base::android::AttachCurrentThread(); 94 JNIEnv* env = base::android::AttachCurrentThread();
55 95
56 scoped_ptr<CreatePresentationSessionRequest> presentation_request(
57 PassPresentationRequest());
58
59 ScopedJavaLocalRef<jstring> jsource_urn = 96 ScopedJavaLocalRef<jstring> jsource_urn =
60 base::android::ConvertUTF8ToJavaString( 97 base::android::ConvertUTF8ToJavaString(env, GetMediaSourceId());
61 env, presentation_request->media_source().id());
62 98
63 Java_ChromeMediaRouterDialogController_createDialog( 99 Java_ChromeMediaRouterDialogController_createDialog(
64 env, java_dialog_controller_.obj(), jsource_urn.obj()); 100 env, java_dialog_controller_.obj(), jsource_urn.obj());
65 } 101 }
66 102
67 void MediaRouterDialogControllerAndroid::CloseMediaRouterDialog() { 103 void MediaRouterDialogControllerAndroid::CloseMediaRouterDialog() {
68 JNIEnv* env = base::android::AttachCurrentThread(); 104 JNIEnv* env = base::android::AttachCurrentThread();
69 105
70 Java_ChromeMediaRouterDialogController_closeDialog( 106 Java_ChromeMediaRouterDialogController_closeDialog(
71 env, java_dialog_controller_.obj()); 107 env, java_dialog_controller_.obj());
72 } 108 }
73 109
74 bool MediaRouterDialogControllerAndroid::IsShowingMediaRouterDialog() const { 110 bool MediaRouterDialogControllerAndroid::IsShowingMediaRouterDialog() const {
75 JNIEnv* env = base::android::AttachCurrentThread(); 111 JNIEnv* env = base::android::AttachCurrentThread();
76 return Java_ChromeMediaRouterDialogController_isShowingDialog( 112 return Java_ChromeMediaRouterDialogController_isShowingDialog(
77 env, java_dialog_controller_.obj()); 113 env, java_dialog_controller_.obj());
78 } 114 }
79 115
80 } // namespace media_router 116 } // namespace media_router
81 117
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698