use of org.chromium.chrome.browser.profiles.Profile in project AndroidChromium by JackyAndroid.
the class LocationBarLayout method setUrlToPageUrl.
/**
* Sets the displayed URL to be the URL of the page currently showing.
*
* <p>The URL is converted to the most user friendly format (removing HTTP:// for example).
*
* <p>If the current tab is null, the URL text will be cleared.
*/
@Override
public void setUrlToPageUrl() {
String url = getCurrentTabUrl();
// Once they stop editing the URL, the current tab's URL will automatically be filled in.
if (mUrlBar.hasFocus()) {
if (mUrlFocusedWithoutAnimations && !NewTabPage.isNTPUrl(url)) {
// If we did not run the focus animations, then the user has not typed any text.
// So, clear the focus and accept whatever URL the page is currently attempting to
// display.
setUrlBarFocus(false);
} else {
return;
}
}
if (getCurrentTab() == null) {
setUrlBarText("", null);
return;
}
// Profile may be null if switching to a tab that has not yet been initialized.
Profile profile = getCurrentTab().getProfile();
if (profile != null)
mOmniboxPrerender.clear(profile);
mOriginalUrl = url;
if (NativePageFactory.isNativePageUrl(url, getCurrentTab().isIncognito()) || NewTabPage.isNTPUrl(url)) {
// Don't show anything for Chrome URLs.
setUrlBarText(null, "");
return;
}
if (setUrlBarText(url, mToolbarDataProvider.getText())) {
mUrlBar.deEmphasizeUrl();
emphasizeUrl();
}
updateCustomSelectionActionModeCallback();
}
use of org.chromium.chrome.browser.profiles.Profile in project AndroidChromium by JackyAndroid.
the class WarmupManager method prefetchDnsForUrlInBackground.
/**
* Launches a background DNS query for a given URL.
*
* @param url URL from which the domain to query is extracted.
*/
private void prefetchDnsForUrlInBackground(final String url) {
mDnsRequestsInFlight.add(url);
new AsyncTask<String, Void, Void>() {
@Override
protected Void doInBackground(String... params) {
try {
InetAddress.getByName(new URL(url).getHost());
} catch (MalformedURLException e) {
// We don't do anything with the result of the request, it
// is only here to warm up the cache, thus ignoring the
// exception is fine.
} catch (UnknownHostException e) {
// As above.
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mDnsRequestsInFlight.remove(url);
if (mPendingPreconnectWithProfile.containsKey(url)) {
Profile profile = mPendingPreconnectWithProfile.get(url);
mPendingPreconnectWithProfile.remove(url);
maybePreconnectUrlAndSubResources(profile, url);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
}
use of org.chromium.chrome.browser.profiles.Profile in project AndroidChromium by JackyAndroid.
the class CustomTabsConnection method preconnectUrls.
private boolean preconnectUrls(List<Bundle> likelyBundles) {
boolean atLeastOneUrl = false;
if (likelyBundles == null)
return false;
WarmupManager warmupManager = WarmupManager.getInstance();
Profile profile = Profile.getLastUsedProfile();
for (Bundle bundle : likelyBundles) {
Uri uri;
try {
uri = IntentUtils.safeGetParcelable(bundle, CustomTabsService.KEY_URL);
} catch (ClassCastException e) {
continue;
}
String url = checkAndConvertUri(uri);
if (url != null) {
warmupManager.maybePreconnectUrlAndSubResources(profile, url);
atLeastOneUrl = true;
}
}
return atLeastOneUrl;
}
use of org.chromium.chrome.browser.profiles.Profile in project AndroidChromium by JackyAndroid.
the class SignInPreference method update.
/**
* Updates the title, summary, and image based on the current sign-in state.
*/
private void update() {
String title;
String summary;
String fragment;
Account account = ChromeSigninController.get(getContext()).getSignedInUser();
if (account == null) {
title = getContext().getString(R.string.sign_in_to_chrome);
summary = getContext().getString(R.string.sign_in_to_chrome_summary);
fragment = null;
} else {
summary = SyncPreference.getSyncStatusSummary(getContext());
fragment = AccountManagementFragment.class.getName();
title = AccountManagementFragment.getCachedUserName(account.name);
if (title == null) {
final Profile profile = Profile.getLastUsedProfile();
String cachedName = ProfileDownloader.getCachedFullName(profile);
Bitmap cachedBitmap = ProfileDownloader.getCachedAvatar(profile);
if (TextUtils.isEmpty(cachedName) || cachedBitmap == null) {
AccountManagementFragment.startFetchingAccountInformation(getContext(), profile, account.name);
}
title = TextUtils.isEmpty(cachedName) ? account.name : cachedName;
}
}
setTitle(title);
setSummary(summary);
setFragment(fragment);
updateSyncStatusIcon();
ChromeSigninController signinController = ChromeSigninController.get(getContext());
boolean enabled = signinController.isSignedIn() || SigninManager.get(getContext()).isSignInAllowed();
if (mViewEnabled != enabled) {
mViewEnabled = enabled;
notifyChanged();
}
if (!enabled)
setFragment(null);
if (SigninManager.get(getContext()).isSigninDisabledByPolicy()) {
setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId());
} else {
Resources resources = getContext().getResources();
Bitmap bitmap = AccountManagementFragment.getUserPicture(signinController.getSignedInAccountName(), resources);
setIcon(new BitmapDrawable(resources, bitmap));
}
setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (!AccountSigninActivity.startIfAllowed(getContext(), SigninAccessPoint.SETTINGS)) {
return false;
}
setEnabled(false);
return true;
}
});
if (account == null && enabled) {
RecordUserAction.record("Signin_Impression_FromSettings");
}
}
use of org.chromium.chrome.browser.profiles.Profile in project AndroidChromium by JackyAndroid.
the class IncognitoTabModel method destroyIncognitoIfNecessary.
/**
* Destroys the Incognito profile when all Incognito tabs have been closed. Also resets the
* delegate TabModel to be a stub EmptyTabModel.
*/
protected void destroyIncognitoIfNecessary() {
ThreadUtils.assertOnUiThread();
if (!isEmpty() || mDelegateModel instanceof EmptyTabModel || mIsAddingTab) {
return;
}
Profile profile = getProfile();
mDelegateModel.destroy();
// model selector as the profile is shared between them.
if (profile != null && !mDelegate.doIncognitoTabsExist()) {
IncognitoNotificationManager.dismissIncognitoNotification();
profile.destroyWhenAppropriate();
}
mDelegateModel = EmptyTabModel.getInstance();
}
Aggregations