Search in sources :

Example 1 with TabDelegate

use of org.chromium.chrome.browser.tabmodel.document.TabDelegate in project AndroidChromium by JackyAndroid.

the class ChromeApplication method getDocumentTabModelSelector.

/**
     * Returns the Singleton instance of the DocumentTabModelSelector.
     * TODO(dfalcantara): Find a better place for this once we differentiate between activity and
     *                    application-level TabModelSelectors.
     * @return The DocumentTabModelSelector for the application.
     */
@SuppressFBWarnings("LI_LAZY_INIT_STATIC")
public static DocumentTabModelSelector getDocumentTabModelSelector() {
    ThreadUtils.assertOnUiThread();
    if (sDocumentTabModelSelector == null) {
        ActivityDelegateImpl activityDelegate = new ActivityDelegateImpl(DocumentActivity.class, IncognitoDocumentActivity.class);
        sDocumentTabModelSelector = new DocumentTabModelSelector(activityDelegate, new StorageDelegate(), new TabDelegate(false), new TabDelegate(true));
    }
    return sDocumentTabModelSelector;
}
Also used : StorageDelegate(org.chromium.chrome.browser.tabmodel.document.StorageDelegate) DocumentTabModelSelector(org.chromium.chrome.browser.tabmodel.document.DocumentTabModelSelector) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate) ActivityDelegateImpl(org.chromium.chrome.browser.tabmodel.document.ActivityDelegateImpl) SuppressFBWarnings(org.chromium.base.annotations.SuppressFBWarnings)

Example 2 with TabDelegate

use of org.chromium.chrome.browser.tabmodel.document.TabDelegate in project AndroidChromium by JackyAndroid.

the class ClearBrowsingDataPreferences method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecordUserAction.record("ClearBrowsingData_DialogCreated");
    mMaxImportantSites = PrefServiceBridge.getMaxImportantSites();
    PrefServiceBridge.getInstance().requestInfoAboutOtherFormsOfBrowsingHistory(this);
    getActivity().setTitle(R.string.clear_browsing_data_title);
    addPreferencesFromResource(R.xml.clear_browsing_data_preferences);
    DialogOption[] options = getDialogOptions();
    mItems = new Item[options.length];
    for (int i = 0; i < options.length; i++) {
        boolean enabled = true;
        // It is possible to disable the deletion of browsing history.
        if (options[i] == DialogOption.CLEAR_HISTORY && !PrefServiceBridge.getInstance().canDeleteBrowsingHistory()) {
            enabled = false;
            PrefServiceBridge.getInstance().setBrowsingDataDeletionPreference(DialogOption.CLEAR_HISTORY.getDataType(), false);
        }
        mItems[i] = new Item(this, options[i], (ClearBrowsingDataCheckBoxPreference) findPreference(options[i].getPreferenceKey()), isOptionSelectedByDefault(options[i]), enabled);
    }
    // Not all checkboxes defined in the layout are necessarily handled by this class
    // or a particular subclass. Hide those that are not.
    EnumSet<DialogOption> unboundOptions = EnumSet.allOf(DialogOption.class);
    unboundOptions.removeAll(Arrays.asList(getDialogOptions()));
    for (DialogOption option : unboundOptions) {
        getPreferenceScreen().removePreference(findPreference(option.getPreferenceKey()));
    }
    // The time range selection spinner.
    SpinnerPreference spinner = (SpinnerPreference) findPreference(PREF_TIME_RANGE);
    spinner.setOnPreferenceChangeListener(this);
    TimePeriodSpinnerOption[] spinnerOptions = getTimePeriodSpinnerOptions();
    int selectedTimePeriod = PrefServiceBridge.getInstance().getBrowsingDataDeletionTimePeriod();
    int spinnerOptionIndex = -1;
    for (int i = 0; i < spinnerOptions.length; ++i) {
        if (spinnerOptions[i].getTimePeriod() == selectedTimePeriod) {
            spinnerOptionIndex = i;
            break;
        }
    }
    assert spinnerOptionIndex != -1;
    spinner.setOptions(spinnerOptions, spinnerOptionIndex);
    // The "Clear" button.
    ButtonPreference clearButton = (ButtonPreference) findPreference(PREF_CLEAR_BUTTON);
    clearButton.setOnPreferenceClickListener(this);
    clearButton.setShouldDisableView(true);
    // The general information footnote informs users about data that will not be deleted.
    // If the user is signed in, it also informs users about the behavior of synced deletions.
    // and we show an additional Google-specific footnote. This footnote informs users that they
    // will not be signed out of their Google account, and if the web history service indicates
    // that they have other forms of browsing history, then also about that.
    TextMessageWithLinkAndIconPreference google_summary = (TextMessageWithLinkAndIconPreference) findPreference(PREF_GOOGLE_SUMMARY);
    TextMessageWithLinkAndIconPreference general_summary = (TextMessageWithLinkAndIconPreference) findPreference(PREF_GENERAL_SUMMARY);
    google_summary.setLinkClickDelegate(new Runnable() {

        @Override
        public void run() {
            new TabDelegate(false).launchUrl(WEB_HISTORY_URL, TabLaunchType.FROM_CHROME_UI);
        }
    });
    general_summary.setLinkClickDelegate(new Runnable() {

        @Override
        public void run() {
            HelpAndFeedback.getInstance(getActivity()).show(getActivity(), getResources().getString(R.string.help_context_clear_browsing_data), Profile.getLastUsedProfile(), null);
        }
    });
    if (ChromeSigninController.get(getActivity()).isSignedIn()) {
        general_summary.setSummary(R.string.clear_browsing_data_footnote_sync_and_site_settings);
    } else {
        getPreferenceScreen().removePreference(google_summary);
        general_summary.setSummary(R.string.clear_browsing_data_footnote_site_settings);
    }
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.IMPORTANT_SITES_IN_CBD)) {
        PrefServiceBridge.fetchImportantSites(this);
    }
}
Also used : SpinnerPreference(org.chromium.chrome.browser.preferences.SpinnerPreference) TextMessageWithLinkAndIconPreference(org.chromium.chrome.browser.preferences.TextMessageWithLinkAndIconPreference) ButtonPreference(org.chromium.chrome.browser.preferences.ButtonPreference) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate) ClearBrowsingDataCheckBoxPreference(org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference)

Example 3 with TabDelegate

use of org.chromium.chrome.browser.tabmodel.document.TabDelegate in project AndroidChromium by JackyAndroid.

the class ServiceTabLauncher method launchTab.

/**
     * Launches the browser activity and launches a tab for |url|.
     *
     * @param context The context using which the URL is being loaded.
     * @param requestId Id of the request for launching this tab.
     * @param incognito Whether the tab should be launched in incognito mode.
     * @param url The URL which should be launched in a tab.
     * @param disposition The disposition requested by the navigation source.
     * @param referrerUrl URL of the referrer which is opening the page.
     * @param referrerPolicy The referrer policy to consider when applying the referrer.
     * @param extraHeaders Extra headers to apply when requesting the tab's URL.
     * @param postData Post-data to include in the tab URL's request body.
     */
@CalledByNative
public static void launchTab(final Context context, final int requestId, final boolean incognito, final String url, final int disposition, final String referrerUrl, final int referrerPolicy, final String extraHeaders, final ResourceRequestBody postData) {
    final TabDelegate tabDelegate = new TabDelegate(incognito);
    // 1. Launch WebAPK if one matches the target URL.
    if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK)) {
        String webApkPackageName = WebApkValidator.queryWebApkPackage(context, url);
        if (webApkPackageName != null) {
            Intent intent = WebApkNavigationClient.createLaunchWebApkIntent(webApkPackageName, url);
            if (intent != null) {
                intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION);
                context.startActivity(intent);
                return;
            }
        }
    }
    // 2. Launch WebappActivity if one matches the target URL and was opened recently.
    // Otherwise, open the URL in a tab.
    FetchWebappDataStorageCallback callback = new FetchWebappDataStorageCallback() {

        @Override
        public void onWebappDataStorageRetrieved(final WebappDataStorage storage) {
            // been opened recently enough, open the URL in a tab.
            if (storage == null || !storage.wasLaunchedRecently()) {
                LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTransition.LINK);
                loadUrlParams.setPostData(postData);
                loadUrlParams.setVerbatimHeaders(extraHeaders);
                loadUrlParams.setReferrer(new Referrer(referrerUrl, referrerPolicy));
                AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlParams, requestId);
                tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI, Tab.INVALID_TAB_ID);
            } else {
                // The URL is within the scope of a recently launched standalone-capable web app
                // on the home screen, so open it a standalone web app frame. An AsyncTask is
                // used because WebappDataStorage.createWebappLaunchIntent contains a Bitmap
                // decode operation and should not be run on the UI thread.
                //
                // This currently assumes that the only source is notifications; any future use
                // which adds a different source will need to change this.
                new AsyncTask<Void, Void, Intent>() {

                    @Override
                    protected final Intent doInBackground(Void... nothing) {
                        return storage.createWebappLaunchIntent();
                    }

                    @Override
                    protected final void onPostExecute(Intent intent) {
                        // Replace the web app URL with the URL from the notification. This is
                        // within the webapp's scope, so it is valid.
                        intent.putExtra(ShortcutHelper.EXTRA_URL, url);
                        intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION);
                        tabDelegate.createNewStandaloneFrame(intent);
                    }
                }.execute();
            }
        }
    };
    WebappRegistry.getWebappDataStorageForUrl(url, callback);
}
Also used : FetchWebappDataStorageCallback(org.chromium.chrome.browser.webapps.WebappRegistry.FetchWebappDataStorageCallback) Referrer(org.chromium.content_public.common.Referrer) Intent(android.content.Intent) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) AsyncTabCreationParams(org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams) WebappDataStorage(org.chromium.chrome.browser.webapps.WebappDataStorage) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 4 with TabDelegate

use of org.chromium.chrome.browser.tabmodel.document.TabDelegate in project AndroidChromium by JackyAndroid.

the class BookmarkActionBar method onMenuItemClick.

@Override
public boolean onMenuItemClick(MenuItem menuItem) {
    SelectionDelegate<BookmarkId> selectionDelegate = mDelegate.getSelectionDelegate();
    if (menuItem.getItemId() == R.id.edit_menu_id) {
        BookmarkAddEditFolderActivity.startEditFolderActivity(getContext(), mCurrentFolder.getId());
        return true;
    } else if (menuItem.getItemId() == R.id.close_menu_id) {
        BookmarkUtils.finishActivityOnPhone(getContext());
        return true;
    } else if (menuItem.getItemId() == R.id.search_menu_id) {
        mDelegate.openSearchUI();
        return true;
    } else if (menuItem.getItemId() == R.id.selection_mode_edit_menu_id) {
        List<BookmarkId> list = selectionDelegate.getSelectedItems();
        assert list.size() == 1;
        BookmarkItem item = mDelegate.getModel().getBookmarkById(list.get(0));
        if (item.isFolder()) {
            BookmarkAddEditFolderActivity.startEditFolderActivity(getContext(), item.getId());
        } else {
            BookmarkUtils.startEditActivity(getContext(), item.getId());
        }
        return true;
    } else if (menuItem.getItemId() == R.id.selection_mode_move_menu_id) {
        List<BookmarkId> list = selectionDelegate.getSelectedItems();
        if (list.size() >= 1) {
            BookmarkFolderSelectActivity.startFolderSelectActivity(getContext(), list.toArray(new BookmarkId[list.size()]));
        }
        return true;
    } else if (menuItem.getItemId() == R.id.selection_mode_delete_menu_id) {
        mDelegate.getModel().deleteBookmarks(selectionDelegate.getSelectedItems().toArray(new BookmarkId[0]));
        return true;
    } else if (menuItem.getItemId() == R.id.selection_open_in_new_tab_id) {
        openBookmarksInNewTabs(selectionDelegate.getSelectedItems(), new TabDelegate(false), mDelegate.getModel());
        selectionDelegate.clearSelection();
        return true;
    } else if (menuItem.getItemId() == R.id.selection_open_in_incognito_tab_id) {
        openBookmarksInNewTabs(selectionDelegate.getSelectedItems(), new TabDelegate(true), mDelegate.getModel());
        selectionDelegate.clearSelection();
        return true;
    }
    assert false : "Unhandled menu click.";
    return false;
}
Also used : BookmarkId(org.chromium.components.bookmarks.BookmarkId) List(java.util.List) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate) BookmarkItem(org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem)

Example 5 with TabDelegate

use of org.chromium.chrome.browser.tabmodel.document.TabDelegate in project AndroidChromium by JackyAndroid.

the class DownloadUtils method showDownloadManager.

/**
     * Displays the download manager UI. Note the UI is different on tablets and on phones.
     * @return Whether the UI was shown.
     */
public static boolean showDownloadManager(@Nullable Activity activity, @Nullable Tab tab) {
    if (!isDownloadHomeEnabled())
        return false;
    // Figure out what tab was last being viewed by the user.
    if (activity == null)
        activity = ApplicationStatus.getLastTrackedFocusedActivity();
    if (tab == null && activity instanceof ChromeTabbedActivity) {
        tab = ((ChromeTabbedActivity) activity).getActivityTab();
    }
    Context appContext = ContextUtils.getApplicationContext();
    if (DeviceFormFactor.isTablet(appContext)) {
        // Download Home shows up as a tab on tablets.
        LoadUrlParams params = new LoadUrlParams(UrlConstants.DOWNLOADS_URL);
        if (tab == null || !tab.isInitialized()) {
            // Open a new tab, which pops Chrome into the foreground.
            TabDelegate delegate = new TabDelegate(false);
            delegate.createNewTab(params, TabLaunchType.FROM_CHROME_UI, null);
        } else {
            // Download Home shows up inside an existing tab, but only if the last Activity was
            // the ChromeTabbedActivity.
            tab.loadUrl(params);
            // Bring Chrome to the foreground, if possible.
            Intent intent = Tab.createBringTabToFrontIntent(tab.getId());
            if (intent != null) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                IntentUtils.safeStartActivity(appContext, intent);
            }
        }
    } else {
        // Download Home shows up as a new Activity on phones.
        Intent intent = new Intent();
        intent.setClass(appContext, DownloadActivity.class);
        if (tab != null)
            intent.putExtra(EXTRA_IS_OFF_THE_RECORD, tab.isIncognito());
        if (activity == null) {
            // Stands alone in its own task.
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            appContext.startActivity(intent);
        } else {
            // Sits on top of another Activity.
            intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getComponentName());
            activity.startActivity(intent);
        }
    }
    return true;
}
Also used : Context(android.content.Context) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate)

Aggregations

TabDelegate (org.chromium.chrome.browser.tabmodel.document.TabDelegate)8 LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)4 Intent (android.content.Intent)2 AsyncTabCreationParams (org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams)2 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 AlertDialog (android.support.v7.app.AlertDialog)1 SpannableString (android.text.SpannableString)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 TextView (android.widget.TextView)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CalledByNative (org.chromium.base.annotations.CalledByNative)1 SuppressFBWarnings (org.chromium.base.annotations.SuppressFBWarnings)1 ChromeTabbedActivity (org.chromium.chrome.browser.ChromeTabbedActivity)1 BookmarkItem (org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem)1 ButtonPreference (org.chromium.chrome.browser.preferences.ButtonPreference)1 ClearBrowsingDataCheckBoxPreference (org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference)1