Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/customtabs/origin_verifier.h" | |
| 6 | |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "base/android/jni_string.h" | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/browser/android/digital_asset_links/digital_asset_links_handler .h" | |
| 11 #include "chrome/browser/browser_process.h" | |
| 12 #include "chrome/browser/profiles/profile_android.h" | |
| 13 #include "chrome/browser/profiles/profile_manager.h" | |
| 14 #include "content/public/browser/browser_thread.h" | |
| 15 #include "jni/OriginVerifier_jni.h" | |
| 16 | |
| 17 using base::android::ConvertJavaStringToUTF16; | |
| 18 using base::android::JavaParamRef; | |
| 19 | |
| 20 namespace customtabs { | |
| 21 | |
| 22 OriginVerifier::OriginVerifier(JNIEnv* env, jobject obj, jobject jprofile) { | |
| 23 jobject_.Reset(env, obj); | |
| 24 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | |
| 25 DCHECK(profile); | |
| 26 asset_link_handler_ = | |
| 27 base::MakeUnique<digital_asset_links::DigitalAssetLinksHandler>( | |
| 28 profile->GetRequestContext()); | |
| 29 } | |
| 30 | |
| 31 OriginVerifier::~OriginVerifier() {} | |
| 32 | |
| 33 void OriginVerifier::VerifyOrigin(JNIEnv* env, | |
| 34 const JavaParamRef<jobject>& obj, | |
| 35 const JavaParamRef<jstring>& j_package_name, | |
| 36 const JavaParamRef<jstring>& j_fingerprint, | |
| 37 const JavaParamRef<jstring>& j_origin) { | |
| 38 if (!j_package_name || !j_fingerprint || !j_origin) | |
| 39 return; | |
| 40 | |
| 41 std::string package_name = ConvertJavaStringToUTF8(env, j_package_name); | |
| 42 std::string fingerprint = ConvertJavaStringToUTF8(env, j_fingerprint); | |
| 43 std::string origin = ConvertJavaStringToUTF8(env, j_origin); | |
| 44 | |
| 45 // Multiple calls here will end up resetting the callback on the handler side | |
| 46 // and cancelling previous requests. | |
| 47 // If during the request this verifier gets killed, the handler and the | |
| 48 // UrlFetcher making the request will also get killed, so we won't get any | |
| 49 // dangling callback reference issues. | |
| 50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 51 asset_link_handler_->CheckDigitalAssetLinkRelationship( | |
|
nyquist
2017/04/27 04:38:25
DigitalAssetLinksHandler::CheckDigitalAssetLinkRel
Yusuf
2017/04/27 18:31:06
Done.
| |
| 52 base::Bind(&customtabs::OriginVerifier::OnRelationshipCheckComplete, | |
| 53 base::Unretained(this)), | |
| 54 origin, package_name, fingerprint, | |
| 55 "delegate_permission/common.use_as_origin"); | |
| 56 } | |
| 57 | |
| 58 void OriginVerifier::OnRelationshipCheckComplete( | |
| 59 std::unique_ptr<base::DictionaryValue> response) { | |
| 60 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 61 | |
| 62 bool verified = false; | |
| 63 | |
| 64 if (response) { | |
| 65 response->GetBoolean( | |
| 66 digital_asset_links::kDigitalAssetLinksCheckResponseKeyLinked, | |
| 67 &verified); | |
| 68 } | |
| 69 Java_OriginVerifier_originVerified(env, jobject_, verified); | |
| 70 } | |
| 71 | |
| 72 void OriginVerifier::Destroy(JNIEnv* env, | |
| 73 const base::android::JavaRef<jobject>& obj) { | |
| 74 delete this; | |
| 75 } | |
| 76 | |
| 77 static jlong Init(JNIEnv* env, | |
| 78 const base::android::JavaParamRef<jobject>& obj, | |
| 79 const base::android::JavaParamRef<jobject>& jprofile) { | |
| 80 if (!g_browser_process) | |
| 81 return 0; | |
| 82 | |
| 83 OriginVerifier* native_verifier = new OriginVerifier(env, obj, jprofile); | |
| 84 return reinterpret_cast<intptr_t>(native_verifier); | |
| 85 } | |
| 86 | |
| 87 bool RegisterOriginVerifier(JNIEnv* env) { | |
| 88 return RegisterNativesImpl(env); | |
| 89 } | |
| 90 | |
| 91 } // namespace customtabs | |
| OLD | NEW |