Search in sources :

Example 6 with Profile

use of org.chromium.chrome.browser.profiles.Profile in project AndroidChromium by JackyAndroid.

the class CustomTabToolbar method setUrlToPageUrl.

@Override
public void setUrlToPageUrl() {
    if (getCurrentTab() == null) {
        mUrlBar.setUrl("", null);
        return;
    }
    String url = getCurrentTab().getUrl().trim();
    // is "about:blank". We should not display it.
    if (NativePageFactory.isNativePageUrl(url, getCurrentTab().isIncognito()) || UrlConstants.ABOUT_BLANK.equals(url)) {
        mUrlBar.setUrl("", null);
        return;
    }
    String displayText = getToolbarDataProvider().getText();
    Pair<String, String> urlText = LocationBarLayout.splitPathFromUrlDisplayText(displayText);
    displayText = urlText.first;
    if (DomDistillerUrlUtils.isDistilledPage(url)) {
        if (isStoredArticle(url)) {
            Profile profile = getCurrentTab().getProfile();
            DomDistillerService domDistillerService = DomDistillerServiceFactory.getForProfile(profile);
            String originalUrl = domDistillerService.getUrlForEntry(DomDistillerUrlUtils.getValueForKeyInUrl(url, "entry_id"));
            displayText = DomDistillerTabUtils.getFormattedUrlFromOriginalDistillerUrl(originalUrl);
        } else if (DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url) != null) {
            String originalUrl = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
            displayText = DomDistillerTabUtils.getFormattedUrlFromOriginalDistillerUrl(originalUrl);
        }
    }
    if (mUrlBar.setUrl(url, displayText)) {
        mUrlBar.deEmphasizeUrl();
        mUrlBar.emphasizeUrl();
    }
}
Also used : DomDistillerService(org.chromium.components.dom_distiller.core.DomDistillerService) Profile(org.chromium.chrome.browser.profiles.Profile)

Example 7 with Profile

use of org.chromium.chrome.browser.profiles.Profile in project AndroidChromium by JackyAndroid.

the class Tab method initialize.

/**
     * Initializes {@link Tab} with {@code webContents}.  If {@code webContents} is {@code null} a
     * new {@link WebContents} will be created for this {@link Tab}.
     * @param webContents       A {@link WebContents} object or {@code null} if one should be
     *                          created.
     * @param tabContentManager A {@link TabContentManager} instance or {@code null} if the web
     *                          content will be managed/displayed manually.
     * @param delegateFactory   The {@link TabDelegateFactory} to be used for delegate creation.
     * @param initiallyHidden   Only used if {@code webContents} is {@code null}.  Determines
     *                          whether or not the newly created {@link WebContents} will be hidden
     *                          or not.
     * @param unfreeze          Whether there should be an attempt to restore state at the end of
     *                          the initialization.
     */
public final void initialize(WebContents webContents, TabContentManager tabContentManager, TabDelegateFactory delegateFactory, boolean initiallyHidden, boolean unfreeze) {
    try {
        TraceEvent.begin("Tab.initialize");
        mDelegateFactory = delegateFactory;
        initializeNative();
        RevenueStats.getInstance().tabCreated(this);
        mTopControlsVisibilityDelegate = mDelegateFactory.createTopControlsVisibilityDelegate(this);
        mBlimp = BlimpClientContextFactory.getBlimpClientContextForProfile(Profile.getLastUsedProfile().getOriginalProfile()).isBlimpEnabled() && !mIncognito;
        // Attach the TabContentManager if we have one.  This will bind this Tab's content layer
        // to this manager.
        // TODO(dtrainor): Remove this and move to a pull model instead of pushing the layer.
        attachTabContentManager(tabContentManager);
        // WebContents.
        if (getFrozenContentsState() != null || getPendingLoadParams() != null) {
            if (unfreeze)
                unfreezeContents();
            return;
        }
        if (isBlimpTab() && getBlimpContents() == null) {
            Profile profile = Profile.getLastUsedProfile();
            if (mIncognito)
                profile = profile.getOffTheRecordProfile();
            mBlimpContents = nativeInitBlimpContents(mNativeTabAndroid, profile, mWindowAndroid.getNativePointer());
            if (mBlimpContents != null) {
                getBlimpContents().addObserver(new TabBlimpContentsObserver(this));
            } else {
                mBlimp = false;
            }
        }
        boolean creatingWebContents = webContents == null;
        if (creatingWebContents) {
            webContents = WarmupManager.getInstance().takeSpareWebContents(isIncognito(), initiallyHidden);
            if (webContents == null) {
                webContents = WebContentsFactory.createWebContents(isIncognito(), initiallyHidden);
            }
        }
        ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webContents);
        if (contentViewCore == null) {
            initContentViewCore(webContents);
        } else {
            setContentViewCore(contentViewCore);
        }
        if (!creatingWebContents && webContents.isLoadingToDifferentDocument()) {
            didStartPageLoad(webContents.getUrl(), false);
        }
        getAppBannerManager().setIsEnabledForTab(mDelegateFactory.canShowAppBanners(this));
    } finally {
        if (mTimestampMillis == INVALID_TIMESTAMP) {
            mTimestampMillis = System.currentTimeMillis();
        }
        TraceEvent.end("Tab.initialize");
    }
}
Also used : ContentViewCore(org.chromium.content.browser.ContentViewCore) Profile(org.chromium.chrome.browser.profiles.Profile)

Example 8 with Profile

use of org.chromium.chrome.browser.profiles.Profile in project AndroidChromium by JackyAndroid.

the class ToolbarManager method refreshSelectedTab.

/**
     * Triggered when the selected tab has changed.
     */
private void refreshSelectedTab() {
    Tab tab = null;
    if (mPreselectedTabId != Tab.INVALID_TAB_ID) {
        tab = mTabModelSelector.getTabById(mPreselectedTabId);
    }
    if (tab == null)
        tab = mTabModelSelector.getCurrentTab();
    boolean wasIncognito = mToolbarModel.isIncognito();
    Tab previousTab = mToolbarModel.getTab();
    boolean isIncognito = tab != null ? tab.isIncognito() : mTabModelSelector.isIncognitoSelected();
    mToolbarModel.setTab(tab, isIncognito);
    updateCurrentTabDisplayStatus();
    if (previousTab != tab || wasIncognito != isIncognito) {
        if (previousTab != tab) {
            if (previousTab != null) {
                previousTab.removeObserver(mTabObserver);
                previousTab.setIsAllowedToReturnToExternalApp(false);
            }
            if (tab != null)
                tab.addObserver(mTabObserver);
        }
        int defaultPrimaryColor = isIncognito ? ApiCompatibilityUtils.getColor(mToolbar.getResources(), R.color.incognito_primary_color) : ApiCompatibilityUtils.getColor(mToolbar.getResources(), R.color.default_primary_color);
        int primaryColor = tab != null ? tab.getThemeColor() : defaultPrimaryColor;
        updatePrimaryColor(primaryColor, false);
        mToolbar.onTabOrModelChanged();
        if (tab != null && tab.getWebContents() != null && tab.getWebContents().isLoadingToDifferentDocument()) {
            mToolbar.onNavigatedToDifferentPage();
        }
        // Ensure the URL bar loses focus if the tab it was interacting with is changed from
        // underneath it.
        setUrlBarFocus(false);
        // needed, we will refocus the omnibox and make the cursor visible here.
        if (shouldShowCusrsorInLocationBar()) {
            mToolbar.getLocationBar().showUrlBarCursorWithoutFocusAnimations();
        }
    }
    Profile profile = mTabModelSelector.getModel(isIncognito).getProfile();
    if (mCurrentProfile != profile) {
        if (mBookmarkBridge != null)
            mBookmarkBridge.destroy();
        mBookmarkBridge = new BookmarkBridge(profile);
        mBookmarkBridge.addObserver(mBookmarksObserver);
        mAppMenuPropertiesDelegate.setBookmarkBridge(mBookmarkBridge);
        mLocationBar.setAutocompleteProfile(profile);
        mCurrentProfile = profile;
    }
    updateButtonStatus();
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) BookmarkBridge(org.chromium.chrome.browser.bookmarks.BookmarkBridge) Profile(org.chromium.chrome.browser.profiles.Profile)

Example 9 with Profile

use of org.chromium.chrome.browser.profiles.Profile in project AndroidChromium by JackyAndroid.

the class BluetoothChooserDialog method show.

/**
     * Show the BluetoothChooserDialog.
     */
@VisibleForTesting
void show() {
    // Emphasize the origin.
    Profile profile = Profile.getLastUsedProfile();
    SpannableString origin = new SpannableString(mOrigin);
    OmniboxUrlEmphasizer.emphasizeUrl(origin, mActivity.getResources(), profile, mSecurityLevel, false, true, true);
    // Construct a full string and replace the origin text with emphasized version.
    SpannableString title = new SpannableString(mActivity.getString(R.string.bluetooth_dialog_title, mOrigin));
    int start = title.toString().indexOf(mOrigin);
    TextUtils.copySpansFrom(origin, 0, origin.length(), Object.class, title, start);
    String message = mActivity.getString(R.string.bluetooth_not_found);
    SpannableString noneFound = SpanApplier.applySpans(message, new SpanInfo("<link>", "</link>", new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mActivity)));
    SpannableString searching = SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_searching), new SpanInfo("<link>", "</link>", new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)));
    String positiveButton = mActivity.getString(R.string.bluetooth_confirm_button);
    SpannableString statusIdleNoneFound = SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_not_seeing_it_idle_none_found), new SpanInfo("<link>", "</link>", new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)));
    SpannableString statusActive = SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_not_seeing_it), new SpanInfo("<link>", "</link>", new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)));
    SpannableString statusIdleSomeFound = SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_not_seeing_it_idle_some_found), new SpanInfo("<link1>", "</link1>", new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)), new SpanInfo("<link2>", "</link2>", new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mActivity)));
    ItemChooserDialog.ItemChooserLabels labels = new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive, statusIdleNoneFound, statusIdleSomeFound, positiveButton);
    mItemChooserDialog = new ItemChooserDialog(mActivity, this, labels);
    mActivity.registerReceiver(mLocationModeBroadcastReceiver, new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
    mIsLocationModeChangedReceiverRegistered = true;
}
Also used : SpannableString(android.text.SpannableString) IntentFilter(android.content.IntentFilter) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) SpannableString(android.text.SpannableString) Profile(org.chromium.chrome.browser.profiles.Profile) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 10 with Profile

use of org.chromium.chrome.browser.profiles.Profile in project AndroidChromium by JackyAndroid.

the class UsbChooserDialog method show.

/**
     * Shows the UsbChooserDialog.
     *
     * @param activity Activity which is used for launching a dialog.
     * @param origin The origin for the site wanting to connect to the USB device.
     * @param securityLevel The security level of the connection to the site wanting to connect to
     *                      the USB device. For valid values see SecurityStateModel::SecurityLevel.
     */
@VisibleForTesting
void show(Activity activity, String origin, int securityLevel) {
    // Emphasize the origin.
    Profile profile = Profile.getLastUsedProfile();
    SpannableString originSpannableString = new SpannableString(origin);
    OmniboxUrlEmphasizer.emphasizeUrl(originSpannableString, activity.getResources(), profile, securityLevel, false, /* isInternalPage */
    true, /* useDarkColors */
    true);
    // Construct a full string and replace the origin text with emphasized version.
    SpannableString title = new SpannableString(activity.getString(R.string.usb_chooser_dialog_prompt, origin));
    int start = title.toString().indexOf(origin);
    TextUtils.copySpansFrom(originSpannableString, 0, originSpannableString.length(), Object.class, title, start);
    String searching = "";
    String noneFound = activity.getString(R.string.usb_chooser_dialog_no_devices_found_prompt);
    SpannableString statusActive = SpanApplier.applySpans(activity.getString(R.string.usb_chooser_dialog_footnote_text), new SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {

        @Override
        public void onClick(View view) {
            if (mNativeUsbChooserDialogPtr == 0) {
                return;
            }
            nativeLoadUsbHelpPage(mNativeUsbChooserDialogPtr);
            // Get rid of the highlight background on selection.
            view.invalidate();
        }
    }));
    SpannableString statusIdleNoneFound = statusActive;
    SpannableString statusIdleSomeFound = statusActive;
    String positiveButton = activity.getString(R.string.usb_chooser_dialog_connect_button_text);
    ItemChooserDialog.ItemChooserLabels labels = new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive, statusIdleNoneFound, statusIdleSomeFound, positiveButton);
    mItemChooserDialog = new ItemChooserDialog(activity, this, labels);
}
Also used : SpannableString(android.text.SpannableString) NoUnderlineClickableSpan(org.chromium.ui.text.NoUnderlineClickableSpan) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) SpannableString(android.text.SpannableString) View(android.view.View) Profile(org.chromium.chrome.browser.profiles.Profile) VisibleForTesting(org.chromium.base.VisibleForTesting)

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