Commit 5e8a48c4 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Move API Tab.getProfile handler to Profile

Moves the internal job handling API to Profile class
where it suits better. The API is still present; it will
be refactored by updating the call sites to use a helper
method in other CL.

Bug: 925242, 995903
Change-Id: I292adc2bb9d4bddaccc6857ad33d7b9444c51b53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1830255Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701433}
parent c1e1d106
...@@ -622,8 +622,7 @@ public class Tab { ...@@ -622,8 +622,7 @@ public class Tab {
* @return The profile associated with this tab. * @return The profile associated with this tab.
*/ */
public Profile getProfile() { public Profile getProfile() {
if (mNativeTabAndroid == 0) return null; return Profile.fromWebContents(getWebContents());
return TabJni.get().getProfileAndroid(mNativeTabAndroid, Tab.this);
} }
/** /**
...@@ -1898,7 +1897,6 @@ public class Tab { ...@@ -1898,7 +1897,6 @@ public class Tab {
void releaseWebContents(long nativeTabAndroid, Tab caller); void releaseWebContents(long nativeTabAndroid, Tab caller);
void onPhysicalBackingSizeChanged( void onPhysicalBackingSizeChanged(
long nativeTabAndroid, Tab caller, WebContents webContents, int width, int height); long nativeTabAndroid, Tab caller, WebContents webContents, int width, int height);
Profile getProfileAndroid(long nativeTabAndroid, Tab caller);
int loadUrl(long nativeTabAndroid, Tab caller, String url, String initiatorOrigin, int loadUrl(long nativeTabAndroid, Tab caller, String url, String initiatorOrigin,
String extraHeaders, ResourceRequestBody postData, int transition, String extraHeaders, ResourceRequestBody postData, int transition,
String referrerUrl, int referrerPolicy, boolean isRendererInitiated, String referrerUrl, int referrerPolicy, boolean isRendererInitiated,
......
...@@ -10,6 +10,7 @@ import org.chromium.base.annotations.NativeMethods; ...@@ -10,6 +10,7 @@ import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryProcessType; import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.chrome.browser.cookies.CookiesFetcher; import org.chromium.chrome.browser.cookies.CookiesFetcher;
import org.chromium.content_public.browser.BrowserStartupController; import org.chromium.content_public.browser.BrowserStartupController;
import org.chromium.content_public.browser.WebContents;
/** /**
* Wrapper that allows passing a Profile reference around in the Java layer. * Wrapper that allows passing a Profile reference around in the Java layer.
...@@ -35,6 +36,14 @@ public class Profile { ...@@ -35,6 +36,14 @@ public class Profile {
return (Profile) ProfileJni.get().getLastUsedProfile(); return (Profile) ProfileJni.get().getLastUsedProfile();
} }
/**
* @param webContents {@link WebContents} object.
* @return {@link Profile} object associated with the given WebContents.
*/
public static Profile fromWebContents(WebContents webContents) {
return (Profile) ProfileJni.get().fromWebContents(webContents);
}
/** /**
* Destroys the Profile. Destruction is delayed until all associated * Destroys the Profile. Destruction is delayed until all associated
* renderers have been killed, so the profile might not be destroyed upon returning from * renderers have been killed, so the profile might not be destroyed upon returning from
...@@ -109,6 +118,7 @@ public class Profile { ...@@ -109,6 +118,7 @@ public class Profile {
@NativeMethods @NativeMethods
interface Natives { interface Natives {
Object getLastUsedProfile(); Object getLastUsedProfile();
Object fromWebContents(WebContents webContents);
void destroyWhenAppropriate(long nativeProfileAndroid, Profile caller); void destroyWhenAppropriate(long nativeProfileAndroid, Profile caller);
Object getOriginalProfile(long nativeProfileAndroid, Profile caller); Object getOriginalProfile(long nativeProfileAndroid, Profile caller);
Object getOffTheRecordProfile(long nativeProfileAndroid, Profile caller); Object getOffTheRecordProfile(long nativeProfileAndroid, Profile caller);
......
...@@ -323,19 +323,6 @@ void TabAndroid::OnPhysicalBackingSizeChanged( ...@@ -323,19 +323,6 @@ void TabAndroid::OnPhysicalBackingSizeChanged(
web_contents->GetNativeView()->OnPhysicalBackingSizeChanged(size); web_contents->GetNativeView()->OnPhysicalBackingSizeChanged(size);
} }
base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetProfileAndroid(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {
Profile* profile = GetProfile();
if (!profile)
return base::android::ScopedJavaLocalRef<jobject>();
ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile);
if (!profile_android)
return base::android::ScopedJavaLocalRef<jobject>();
return profile_android->GetJavaObject();
}
TabAndroid::TabLoadStatus TabAndroid::LoadUrl( TabAndroid::TabLoadStatus TabAndroid::LoadUrl(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jobject>& obj, const JavaParamRef<jobject>& obj,
......
...@@ -133,9 +133,6 @@ class TabAndroid { ...@@ -133,9 +133,6 @@ class TabAndroid {
const base::android::JavaParamRef<jobject>& jweb_contents, const base::android::JavaParamRef<jobject>& jweb_contents,
jint width, jint width,
jint height); jint height);
base::android::ScopedJavaLocalRef<jobject> GetProfileAndroid(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
TabLoadStatus LoadUrl( TabLoadStatus LoadUrl(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "chrome/browser/profiles/profile_destroyer.h" #include "chrome/browser/profiles/profile_destroyer.h"
#include "chrome/browser/profiles/profile_key_android.h" #include "chrome/browser/profiles/profile_key_android.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "content/public/browser/web_contents.h"
using base::android::AttachCurrentThread; using base::android::AttachCurrentThread;
using base::android::JavaParamRef; using base::android::JavaParamRef;
...@@ -124,6 +125,23 @@ ScopedJavaLocalRef<jobject> JNI_Profile_GetLastUsedProfile(JNIEnv* env) { ...@@ -124,6 +125,23 @@ ScopedJavaLocalRef<jobject> JNI_Profile_GetLastUsedProfile(JNIEnv* env) {
return ProfileAndroid::GetLastUsedProfile(env); return ProfileAndroid::GetLastUsedProfile(env);
} }
// static
ScopedJavaLocalRef<jobject> JNI_Profile_FromWebContents(
JNIEnv* env,
const JavaParamRef<jobject>& jweb_contents) {
auto* web_contents = content::WebContents::FromJavaWebContents(jweb_contents);
if (!web_contents)
return ScopedJavaLocalRef<jobject>();
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
if (!profile)
return ScopedJavaLocalRef<jobject>();
ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile);
if (!profile_android)
return ScopedJavaLocalRef<jobject>();
return profile_android->GetJavaObject();
}
ProfileAndroid::ProfileAndroid(Profile* profile) ProfileAndroid::ProfileAndroid(Profile* profile)
: profile_(profile) { : profile_(profile) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment