Search in sources :

Example 1 with Profile

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();
}
Also used : Profile(org.chromium.chrome.browser.profiles.Profile)

Example 2 with Profile

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);
}
Also used : MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) URL(java.net.URL) Profile(org.chromium.chrome.browser.profiles.Profile)

Example 3 with Profile

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;
}
Also used : WarmupManager(org.chromium.chrome.browser.WarmupManager) Bundle(android.os.Bundle) Uri(android.net.Uri) Profile(org.chromium.chrome.browser.profiles.Profile)

Example 4 with Profile

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");
    }
}
Also used : Account(android.accounts.Account) Bitmap(android.graphics.Bitmap) ChromeSigninController(org.chromium.components.signin.ChromeSigninController) Preference(android.preference.Preference) AccountManagementFragment(org.chromium.chrome.browser.signin.AccountManagementFragment) Resources(android.content.res.Resources) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Profile(org.chromium.chrome.browser.profiles.Profile)

Example 5 with Profile

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();
}
Also used : Profile(org.chromium.chrome.browser.profiles.Profile)

Aggregations

Profile (org.chromium.chrome.browser.profiles.Profile)10 SpannableString (android.text.SpannableString)2 VisibleForTesting (org.chromium.base.VisibleForTesting)2 SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)2 Account (android.accounts.Account)1 IntentFilter (android.content.IntentFilter)1 Resources (android.content.res.Resources)1 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Preference (android.preference.Preference)1 View (android.view.View)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 WarmupManager (org.chromium.chrome.browser.WarmupManager)1 BookmarkBridge (org.chromium.chrome.browser.bookmarks.BookmarkBridge)1 AccountManagementFragment (org.chromium.chrome.browser.signin.AccountManagementFragment)1 Tab (org.chromium.chrome.browser.tab.Tab)1