org.chromium.chrome.browser.IntentHandler Java Examples

The following examples show how to use org.chromium.chrome.browser.IntentHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 7 votes vote down vote up
/**
 * Used to check whether an incoming intent can be handled by the
 * current {@link CustomTabContentHandler}.
 * @return Whether the active {@link CustomTabContentHandler} has handled the intent.
 */
public static boolean handleInActiveContentIfNeeded(Intent intent) {
    if (sActiveContentHandler == null) return false;

    if (sActiveContentHandler.shouldIgnoreIntent(intent)) {
        Log.w(TAG, "Incoming intent to Custom Tab was ignored.");
        return false;
    }

    CustomTabsSessionToken session = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
    if (session == null || !session.equals(sActiveContentHandler.getSession())) return false;

    String url = IntentHandler.getUrlFromIntent(intent);
    if (TextUtils.isEmpty(url)) return false;
    sActiveContentHandler.loadUrlAndTrackFromTimestamp(new LoadUrlParams(url),
            IntentHandler.getTimestampFromIntent(intent));
    return true;
}
 
Example #2
Source File: CustomTabActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Used to check whether an incoming intent can be handled by the
 * current {@link CustomTabContentHandler}.
 * @return Whether the active {@link CustomTabContentHandler} has handled the intent.
 */
public static boolean handleInActiveContentIfNeeded(Intent intent) {
    if (sActiveContentHandler == null) return false;

    if (sActiveContentHandler.shouldIgnoreIntent(intent)) {
        Log.w(TAG, "Incoming intent to Custom Tab was ignored.");
        return false;
    }

    CustomTabsSessionToken session = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
    if (session == null || !session.equals(sActiveContentHandler.getSession())) return false;

    String url = IntentHandler.getUrlFromIntent(intent);
    if (TextUtils.isEmpty(url)) return false;
    sActiveContentHandler.loadUrlAndTrackFromTimestamp(new LoadUrlParams(url),
            IntentHandler.getTimestampFromIntent(intent));
    return true;
}
 
Example #3
Source File: CustomTabActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Used to check whether an incoming intent can be handled by the
 * current {@link CustomTabContentHandler}.
 * @return Whether the active {@link CustomTabContentHandler} has handled the intent.
 */
public static boolean handleInActiveContentIfNeeded(Intent intent) {
    if (sActiveContentHandler == null) return false;

    if (sActiveContentHandler.shouldIgnoreIntent(intent)) {
        Log.w(TAG, "Incoming intent to Custom Tab was ignored.");
        return false;
    }

    CustomTabsSessionToken session = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
    if (session == null || !session.equals(sActiveContentHandler.getSession())) return false;

    String url = IntentHandler.getUrlFromIntent(intent);
    if (TextUtils.isEmpty(url)) return false;
    sActiveContentHandler.loadUrlAndTrackFromTimestamp(new LoadUrlParams(url),
            IntentHandler.getTimestampFromIntent(intent));
    return true;
}
 
Example #4
Source File: ContextualSearchQuickActionControl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Sends the intent associated with the quick action if one is available.
 * @param tab The current tab, used to load a URL if the quick action should open inside
 *            Chrome.
 */
public void sendIntent(Tab tab) {
    if (mOpenQuickActionInChrome) {
        tab.loadUrl(new LoadUrlParams(mQuickActionUri));
        return;
    }

    if (mIntent == null) return;

    // Set the Browser application ID to us in case the user chooses Chrome
    // as the app from the intent picker.
    Context context = getContext();
    mIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());

    mIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (context instanceof ChromeTabbedActivity2) {
        // Set the window ID so the new tab opens in the correct window.
        mIntent.putExtra(IntentHandler.EXTRA_WINDOW_ID, 2);
    }

    IntentUtils.safeStartActivity(mContext, mIntent);
}
 
Example #5
Source File: ActivityDelegate.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Check whether or not the Intent contains an ID for document mode.
 * @param intent Intent to check.
 * @return ID for the document that has the given intent as base intent, or
 *         {@link Tab.INVALID_TAB_ID} if it couldn't be retrieved.
 */
public static int getTabIdFromIntent(Intent intent) {
    if (intent == null || intent.getData() == null) return Tab.INVALID_TAB_ID;

    // Avoid AsyncTabCreationParams related flows early returning here.
    if (AsyncTabParamsManager.hasParamsWithTabToReparent()) {
        return IntentUtils.safeGetIntExtra(
                intent, IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
    }

    Uri data = intent.getData();
    if (!TextUtils.equals(data.getScheme(), UrlConstants.DOCUMENT_SCHEME)) {
        return Tab.INVALID_TAB_ID;
    }

    try {
        return Integer.parseInt(data.getHost());
    } catch (NumberFormatException e) {
        return Tab.INVALID_TAB_ID;
    }
}
 
Example #6
Source File: TabDelegate.java    From delion with Apache License 2.0 6 votes vote down vote up
private Intent createNewTabIntent(AsyncTabCreationParams asyncParams, int parentId) {
    int assignedTabId = TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID);
    AsyncTabParamsManager.add(assignedTabId, asyncParams);

    Intent intent = new Intent(
            Intent.ACTION_VIEW, Uri.parse(asyncParams.getLoadUrlParams().getUrl()));
    intent.setClass(ContextUtils.getApplicationContext(), ChromeLauncherActivity.class);
    intent.putExtra(IntentHandler.EXTRA_TAB_ID, assignedTabId);
    intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito);
    intent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parentId);

    Activity parentActivity = ActivityDelegate.getActivityForTabId(parentId);
    if (parentActivity != null && parentActivity.getIntent() != null) {
        intent.putExtra(IntentHandler.EXTRA_PARENT_INTENT, parentActivity.getIntent());
    }

    if (asyncParams.getRequestId() != null) {
        intent.putExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA,
                asyncParams.getRequestId().intValue());
    }

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}
 
Example #7
Source File: ActivityDelegate.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Check whether or not the Intent contains an ID for document mode.
 * @param intent Intent to check.
 * @return ID for the document that has the given intent as base intent, or
 *         {@link Tab.INVALID_TAB_ID} if it couldn't be retrieved.
 */
public static int getTabIdFromIntent(Intent intent) {
    if (intent == null || intent.getData() == null) return Tab.INVALID_TAB_ID;

    // Avoid AsyncTabCreationParams related flows early returning here.
    if (AsyncTabParamsManager.hasParamsWithTabToReparent()) {
        return IntentUtils.safeGetIntExtra(
                intent, IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
    }

    Uri data = intent.getData();
    if (!TextUtils.equals(data.getScheme(), UrlConstants.DOCUMENT_SCHEME)) {
        return Tab.INVALID_TAB_ID;
    }

    try {
        return Integer.parseInt(data.getHost());
    } catch (NumberFormatException e) {
        return Tab.INVALID_TAB_ID;
    }
}
 
Example #8
Source File: BookmarkUtils.java    From delion with Apache License 2.0 6 votes vote down vote up
private static void openUrl(Activity activity, String url, ComponentName componentName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID,
            activity.getApplicationContext().getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (componentName != null) {
        intent.setComponent(componentName);
    } else {
        // If the bookmark manager is shown in a tab on a phone (rather than in a separate
        // activity) the component name may be null. Send the intent through
        // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
        intent.setClass(activity, ChromeLauncherActivity.class);
    }

    IntentHandler.startActivityForTrustedIntent(intent, activity);
}
 
Example #9
Source File: BookmarkUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static void openUrl(Activity activity, String url, ComponentName componentName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID,
            activity.getApplicationContext().getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);

    if (componentName != null) {
        intent.setComponent(componentName);
    } else {
        // If the bookmark manager is shown in a tab on a phone (rather than in a separate
        // activity) the component name may be null. Send the intent through
        // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
        intent.setClass(activity, ChromeLauncherActivity.class);
    }

    IntentHandler.startActivityForTrustedIntent(intent);
}
 
Example #10
Source File: NewTabPageUma.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Records how much time elapsed from start until the search box became available to the user.
 */
public static void recordSearchAvailableLoadTime(ChromeActivity activity) {
    // Log the time it took for the search box to be displayed at startup, based on the
    // timestamp on the intent for the activity. If the user has interacted with the
    // activity already, it's not a startup, and the timestamp on the activity would not be
    // relevant either.
    if (activity.getLastUserInteractionTime() != 0) return;
    long timeFromIntent = SystemClock.elapsedRealtime()
            - IntentHandler.getTimestampFromIntent(activity.getIntent());
    if (activity.hadWarmStart()) {
        RecordHistogram.recordMediumTimesHistogram(
                "NewTabPage.SearchAvailableLoadTime2.WarmStart", timeFromIntent,
                TimeUnit.MILLISECONDS);
    } else {
        RecordHistogram.recordMediumTimesHistogram(
                "NewTabPage.SearchAvailableLoadTime2.ColdStart", timeFromIntent,
                TimeUnit.MILLISECONDS);
    }
}
 
Example #11
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * @return The URL that should be used from this intent. If it is a WebLite url, it may be
 *         overridden if the Data Reduction Proxy is using Lo-Fi previews.
 */
private String getUrlToLoad() {
    String url = IntentHandler.getUrlFromIntent(getIntent());

    // Intents fired for media viewers have an additional file:// URI passed along so that the
    // tab can display the actual filename to the user when it is loaded.
    if (mIntentDataProvider.isMediaViewer()) {
        String mediaViewerUrl = mIntentDataProvider.getMediaViewerUrl();
        if (!TextUtils.isEmpty(mediaViewerUrl)) {
            Uri mediaViewerUri = Uri.parse(mediaViewerUrl);
            if (UrlConstants.FILE_SCHEME.equals(mediaViewerUri.getScheme())) {
                url = mediaViewerUrl;
            }
        }
    }

    if (!TextUtils.isEmpty(url)) {
        url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(url);
    }

    return url;
}
 
Example #12
Source File: IntentWithGesturesHandler.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a new token for the intent that has user gesture. This will
 * invalidate the token on the previously launched intent with user gesture.
 *
 * @param intent Intent with user gesture.
 */
public void onNewIntentWithGesture(Intent intent) {
    if (mSecureRandomInitializer != null) {
        try {
            mSecureRandom = mSecureRandomInitializer.get();
        } catch (InterruptedException | ExecutionException e) {
            Log.e(TAG, "Error fetching SecureRandom", e);
        }
        mSecureRandomInitializer = null;
    }
    if (mSecureRandom == null) return;
    mIntentToken = new byte[32];
    mSecureRandom.nextBytes(mIntentToken);
    intent.putExtra(EXTRA_USER_GESTURE_TOKEN, mIntentToken);
    mUri = IntentHandler.getUrlFromIntent(intent);
}
 
Example #13
Source File: BookmarkUtils.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a bookmark and reports UMA.
 * @param model Bookmarks model to manage the bookmark.
 * @param activity Activity requesting to open the bookmark.
 * @param bookmarkId ID of the bookmark to be opened.
 * @param launchLocation Location from which the bookmark is being opened.
 * @return Whether the bookmark was successfully opened.
 */
public static boolean openBookmark(BookmarkModel model, Activity activity,
        BookmarkId bookmarkId, int launchLocation) {
    if (model.getBookmarkById(bookmarkId) == null) return false;

    String url = model.getBookmarkById(bookmarkId).getUrl();

    NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARK);
    RecordHistogram.recordEnumeratedHistogram(
            "Stars.LaunchLocation", launchLocation, BookmarkLaunchLocation.COUNT);

    if (DeviceFormFactor.isTablet(activity)) {
        // For tablets, the bookmark manager is open in a tab in the ChromeActivity. Use
        // the ComponentName of the ChromeActivity passed into this method.
        openUrl(activity, url, activity.getComponentName());
    } else {
        // For phones, the bookmark manager is a separate activity. When the activity is
        // launched, an intent extra is set specifying the parent component.
        ComponentName parentComponent = IntentUtils.safeGetParcelableExtra(
                activity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
        openUrl(activity, url, parentComponent);
    }

    return true;
}
 
Example #14
Source File: BookmarkUtils.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private static void openUrl(Activity activity, String url, ComponentName componentName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID,
            activity.getApplicationContext().getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);

    if (componentName != null) {
        intent.setComponent(componentName);
    } else {
        // If the bookmark manager is shown in a tab on a phone (rather than in a separate
        // activity) the component name may be null. Send the intent through
        // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
        intent.setClass(activity, ChromeLauncherActivity.class);
    }

    IntentHandler.startActivityForTrustedIntent(intent, activity);
}
 
Example #15
Source File: ContextualSearchQuickActionControl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Sends the intent associated with the quick action if one is available.
 */
public void sendIntent() {
    if (mIntent == null) return;
    mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Set the Browser application ID to us in case the user chooses Chrome
    // as the app from the intent picker.
    Context context = getContext();
    mIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    mIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    if (context instanceof ChromeTabbedActivity2) {
        // Set the window ID so the new tab opens in the correct window.
        mIntent.putExtra(IntentHandler.EXTRA_WINDOW_ID, 2);
    }

    IntentUtils.safeStartActivity(mContext, mIntent);
}
 
Example #16
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void preInflationStartup() {
    // Parse the data from the Intent before calling super to allow the Intent to customize
    // the Activity parameters, including the background of the page.
    mIntentDataProvider = new CustomTabIntentDataProvider(getIntent(), this);

    super.preInflationStartup();
    mSession = mIntentDataProvider.getSession();
    supportRequestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
    CustomTabsConnection connection = CustomTabsConnection.getInstance(getApplication());
    mSpeculatedUrl = connection.getSpeculatedUrl(mSession);
    mHasSpeculated = !TextUtils.isEmpty(mSpeculatedUrl);
    if (getSavedInstanceState() == null
            && CustomTabsConnection.hasWarmUpBeenFinished(getApplication())) {
        initializeTabModels();
        mMainTab = getHiddenTab(connection);
        if (mMainTab == null) mMainTab = createMainTab();
        mIsFirstLoad = true;
        loadUrlInTab(mMainTab, new LoadUrlParams(getUrlToLoad()),
                IntentHandler.getTimestampFromIntent(getIntent()));
        mHasCreatedTabEarly = true;
    }
}
 
Example #17
Source File: HistoryManagerUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Opens the browsing history manager.
 *
 * @param activity The {@link ChromeActivity} that owns the {@link HistoryManager}.
 * @param tab The {@link Tab} to used to display the native page version of the
 *            {@link HistoryManager}.
 */
public static void showHistoryManager(ChromeActivity activity, Tab tab) {
    Context appContext = ContextUtils.getApplicationContext();
    if (activity.getBottomSheet() != null) {
        activity.getBottomSheetContentController().showContentAndOpenSheet(R.id.action_history);
    } else if (DeviceFormFactor.isTablet()) {
        // History shows up as a tab on tablets.
        LoadUrlParams params = new LoadUrlParams(UrlConstants.NATIVE_HISTORY_URL);
        tab.loadUrl(params);
    } else {
        Intent intent = new Intent();
        intent.setClass(appContext, HistoryActivity.class);
        intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getComponentName());
        activity.startActivity(intent);
    }
}
 
Example #18
Source File: CustomTabActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Loads the current tab with the given load params while taking client
 * referrer and extra headers into account.
 */
private void loadUrlInTab(final Tab tab, final LoadUrlParams params, long timeStamp) {
    Intent intent = getIntent();
    String url = getUrlToLoad();
    if (mHasPrerendered && UrlUtilities.urlsFragmentsDiffer(mPrerenderedUrl, url)) {
        mHasPrerendered = false;
        LoadUrlParams temporaryParams = new LoadUrlParams(mPrerenderedUrl);
        IntentHandler.addReferrerAndHeaders(temporaryParams, intent, this);
        tab.loadUrl(temporaryParams);
        params.setShouldReplaceCurrentEntry(true);
    }

    IntentHandler.addReferrerAndHeaders(params, intent, this);
    if (params.getReferrer() == null) {
        params.setReferrer(CustomTabsConnection.getInstance(getApplication())
                .getReferrerForSession(mSession));
    }
    // See ChromeTabCreator#getTransitionType(). This marks the navigation chain as starting
    // from an external intent (unless otherwise specified by an extra in the intent).
    params.setTransitionType(IntentHandler.getTransitionTypeFromIntent(this, intent,
            PageTransition.LINK | PageTransition.FROM_API));
    mTabObserver.trackNextPageLoadFromTimestamp(timeStamp);
    tab.loadUrl(params);
}
 
Example #19
Source File: ChromeLauncherActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Records metrics gleaned from the Intent.
 */
private void recordIntentMetrics() {
    Intent intent = getIntent();
    IntentHandler.ExternalAppId source =
            IntentHandler.determineExternalIntentSource(getPackageName(), intent);
    if (intent.getPackage() == null && source != IntentHandler.ExternalAppId.CHROME) {
        int flagsOfInterest = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
        int maskedFlags = intent.getFlags() & flagsOfInterest;
        sIntentFlagsHistogram.record(maskedFlags);
    }
    MediaNotificationUma.recordClickSource(intent);
}
 
Example #20
Source File: CustomTabActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return The URL that should be used from this intent. If it is a WebLite url, it may be
 *         overridden if the Data Reduction Proxy is using Lo-Fi previews.
 */
private String getUrlToLoad() {
    String url = IntentHandler.getUrlFromIntent(getIntent());
    if (!TextUtils.isEmpty(url)) {
        url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(url);
    }
    return url;
}
 
Example #21
Source File: TabDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a tab in the "other" window in multi-window mode. This will only work if
 * {@link MultiWindowUtils#isOpenInOtherWindowSupported} is true for the given activity.
 *
 * @param loadUrlParams Parameters specifying the URL to load and other navigation details.
 * @param activity      The current {@link Activity}
 * @param parentId      The ID of the parent tab, or {@link Tab#INVALID_TAB_ID}.
 */
public void createTabInOtherWindow(LoadUrlParams loadUrlParams, Activity activity,
        int parentId) {
    Intent intent = createNewTabIntent(
            new AsyncTabCreationParams(loadUrlParams), parentId, false);

    Class<? extends Activity> targetActivity =
            MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(activity);
    if (targetActivity == null) return;

    MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, activity, targetActivity);
    IntentHandler.addTrustedIntentExtras(intent);
    MultiWindowUtils.onMultiInstanceModeStarted();
    activity.startActivity(intent);
}
 
Example #22
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean requiresFirstRunToBeCompleted(Intent intent) {
    // Custom Tabs can be used to open Chrome help pages before the ToS has been accepted.
    if (IntentHandler.isIntentChromeOrFirstParty(intent)
            && IntentUtils.safeGetBooleanExtra(
                       intent, CustomTabIntentDataProvider.EXTRA_IS_INFO_PAGE, false)) {
        return false;
    }

    return super.requiresFirstRunToBeCompleted(intent);
}
 
Example #23
Source File: VrShellDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * This is called every time ChromeActivity gets a new intent.
 */
public static void onNewIntent(Intent intent) {
    if (IntentUtils.safeGetBooleanExtra(intent, DAYDREAM_VR_EXTRA, false)
            && ChromeFeatureList.isEnabled(ChromeFeatureList.WEBVR_AUTOPRESENT)
            && activitySupportsAutopresentation(
                       ApplicationStatus.getLastTrackedFocusedActivity())
            && IntentHandler.isIntentFromTrustedApp(intent, DAYDREAM_HOME_PACKAGE)) {
        VrShellDelegate instance = getInstance();
        if (instance == null) return;
        instance.onAutopresentIntent();
    }
}
 
Example #24
Source File: SearchWidgetProvider.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    run(new Runnable() {
        @Override
        public void run() {
            if (IntentHandler.isIntentChromeOrFirstParty(intent)) {
                handleAction(intent);
            } else {
                SearchWidgetProvider.super.onReceive(context, intent);
            }
        }
    });
}
 
Example #25
Source File: SearchWidgetProvider.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Creates a trusted Intent that lets the user begin performing queries. */
private static Intent createStartQueryIntent(Context context, String action, int widgetId) {
    Intent intent = new Intent(action, Uri.parse(String.valueOf(widgetId)));
    intent.setClass(context, SearchWidgetProvider.class);
    IntentHandler.addTrustedIntentExtras(intent);
    return intent;
}
 
Example #26
Source File: CustomTabActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onResumeWithNative() {
    super.onResumeWithNative();

    if (getSavedInstanceState() != null || !mIsInitialResume) {
        if (mIntentDataProvider.isOpenedByChrome()) {
            RecordUserAction.record("ChromeGeneratedCustomTab.StartedReopened");
        } else {
            RecordUserAction.record("CustomTabs.StartedReopened");
        }
    } else {
        SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
        String lastUrl = preferences.getString(LAST_URL_PREF, null);
        if (lastUrl != null && lastUrl.equals(getUrlToLoad())) {
            RecordUserAction.record("CustomTabsMenuOpenSameUrl");
        } else {
            preferences.edit().putString(LAST_URL_PREF, getUrlToLoad()).apply();
        }

        if (mIntentDataProvider.isOpenedByChrome()) {
            RecordUserAction.record("ChromeGeneratedCustomTab.StartedInitially");
        } else {
            ExternalAppId externalId =
                    IntentHandler.determineExternalIntentSource(getPackageName(), getIntent());
            RecordHistogram.recordEnumeratedHistogram("CustomTabs.ClientAppId",
                    externalId.ordinal(), ExternalAppId.INDEX_BOUNDARY.ordinal());

            RecordUserAction.record("CustomTabs.StartedInitially");
        }
    }
    mIsInitialResume = false;
}
 
Example #27
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a hidden tab and initiates a navigation.
 */
private void launchUrlInHiddenTab(
        final CustomTabsSessionToken session, final String url, final Bundle extras) {
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            Intent extrasIntent = new Intent();
            if (extras != null) extrasIntent.putExtras(extras);
            if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null) return;

            Tab tab = Tab.createDetached(new CustomTabDelegateFactory(false, false, null));

            // Updating post message as soon as we have a valid WebContents.
            mClientManager.resetPostMessageHandlerForSession(
                    session, tab.getContentViewCore().getWebContents());

            LoadUrlParams loadParams = new LoadUrlParams(url);
            String referrer = getReferrer(session, extrasIntent);
            if (referrer != null && !referrer.isEmpty()) {
                loadParams.setReferrer(
                        new Referrer(referrer, Referrer.REFERRER_POLICY_DEFAULT));
            }
            mSpeculation = SpeculationParams.forHiddenTab(session, url, tab, referrer, extras);
            mSpeculation.tab.loadUrl(loadParams);
        }
    });
}
 
Example #28
Source File: HistoryManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
Intent getOpenUrlIntent(String url, Boolean isIncognito, boolean createNewTab) {
    // Construct basic intent.
    Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    viewIntent.putExtra(Browser.EXTRA_APPLICATION_ID,
            mActivity.getApplicationContext().getPackageName());
    viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Determine component or class name.
    ComponentName component;
    if (DeviceFormFactor.isTablet()) {
        component = mActivity.getComponentName();
    } else {
        component = IntentUtils.safeGetParcelableExtra(
                mActivity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
    }
    if (component != null) {
        viewIntent.setComponent(component);
    } else {
        viewIntent.setClass(mActivity, ChromeLauncherActivity.class);
    }

    // Set other intent extras.
    if (isIncognito != null) {
        viewIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, isIncognito);
    }
    if (createNewTab) viewIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);

    return viewIntent;
}
 
Example #29
Source File: DownloadUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Opens a file in Chrome or in another app if appropriate.
 * @param file path to the file to open.
 * @param mimeType mime type of the file.
 * @param isOffTheRecord whether we are in an off the record context.
 * @return whether the file could successfully be opened.
 */
public static boolean openFile(File file, String mimeType, boolean isOffTheRecord) {
    Context context = ContextUtils.getApplicationContext();
    Intent viewIntent = createViewIntentForDownloadItem(Uri.fromFile(file), mimeType);
    DownloadManagerService service = DownloadManagerService.getDownloadManagerService(context);

    // Check if Chrome should open the file itself.
    if (service.isDownloadOpenableInBrowser(isOffTheRecord, mimeType)) {
        // Share URIs use the content:// scheme when able, which looks bad when displayed
        // in the URL bar.
        Uri fileUri = Uri.fromFile(file);
        Uri shareUri = getUriForItem(file);
        String normalizedMimeType = Intent.normalizeMimeType(mimeType);

        Intent intent =
                getMediaViewerIntentForDownloadItem(fileUri, shareUri, normalizedMimeType);
        IntentHandler.startActivityForTrustedIntent(intent, context);
        return true;
    }

    // Check if any apps can open the file.
    try {
        context.startActivity(viewIntent);
        return true;
    } catch (ActivityNotFoundException e) {
        // Can't launch the Intent.
        Toast.makeText(context, context.getString(R.string.download_cant_open_file),
                     Toast.LENGTH_SHORT)
                .show();
        return false;
    }
}
 
Example #30
Source File: CustomTabsConnectionService.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private boolean isFirstRunDone() {
    if (mBindIntent == null) return true;
    boolean showLightweightFre =
            IntentHandler.determineExternalIntentSource(this.getPackageName(), mBindIntent)
            != ExternalAppId.GSA;
    boolean firstRunNecessary =
            FirstRunFlowSequencer.checkIfFirstRunIsNecessary(
                    getApplicationContext(), mBindIntent, showLightweightFre)
            != null;
    if (!firstRunNecessary) {
        mBindIntent = null;
        return true;
    }
    return false;
}