Search in sources :

Example 36 with CalledByNative

use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.

the class Tab method openNewTab.

@CalledByNative
protected void openNewTab(String url, String extraHeaders, ResourceRequestBody postData, int disposition, boolean hasParent, boolean isRendererInitiated) {
    if (isClosing())
        return;
    boolean incognito = isIncognito();
    TabLaunchType tabLaunchType = TabLaunchType.FROM_LONGPRESS_FOREGROUND;
    Tab parentTab = hasParent ? this : null;
    switch(disposition) {
        // fall through
        case WindowOpenDisposition.NEW_WINDOW:
        case WindowOpenDisposition.NEW_FOREGROUND_TAB:
            break;
        // fall through
        case WindowOpenDisposition.NEW_POPUP:
        case WindowOpenDisposition.NEW_BACKGROUND_TAB:
            tabLaunchType = TabLaunchType.FROM_LONGPRESS_BACKGROUND;
            break;
        case WindowOpenDisposition.OFF_THE_RECORD:
            assert incognito;
            incognito = true;
            break;
        default:
            assert false;
    }
    // is not accessible, then we can't open a new tab.
    if (shouldIgnoreNewTab(url, incognito) || getTabModelSelector() == null)
        return;
    LoadUrlParams loadUrlParams = new LoadUrlParams(url);
    loadUrlParams.setVerbatimHeaders(extraHeaders);
    loadUrlParams.setPostData(postData);
    loadUrlParams.setIsRendererInitiated(isRendererInitiated);
    getTabModelSelector().openNewTab(loadUrlParams, tabLaunchType, parentTab, incognito);
}
Also used : LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) TabLaunchType(org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 37 with CalledByNative

use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.

the class TabWebContentsDelegateAndroid method addNewContents.

@CalledByNative
public boolean addNewContents(WebContents sourceWebContents, WebContents webContents, int disposition, Rect initialPosition, boolean userGesture) {
    assert mWebContentsUrlMapping.first == webContents;
    TabCreator tabCreator = mTab.getActivity().getTabCreator(mTab.isIncognito());
    assert tabCreator != null;
    // Grab the URL, which might not be available via the Tab.
    String url = mWebContentsUrlMapping.second;
    mWebContentsUrlMapping = null;
    // Skip opening a new Tab if it doesn't make sense.
    if (mTab.isClosing())
        return false;
    // Creating new Tabs asynchronously requires starting a new Activity to create the Tab,
    // so the Tab returned will always be null.  There's no way to know synchronously
    // whether the Tab is created, so assume it's always successful.
    boolean createdSuccessfully = tabCreator.createTabWithWebContents(mTab, webContents, mTab.getId(), TabLaunchType.FROM_LONGPRESS_FOREGROUND, url);
    boolean success = tabCreator.createsTabsAsynchronously() || createdSuccessfully;
    if (success && disposition == WindowOpenDisposition.NEW_POPUP) {
        PolicyAuditor auditor = ((ChromeApplication) mTab.getApplicationContext()).getPolicyAuditor();
        auditor.notifyAuditEvent(mTab.getApplicationContext(), AuditEvent.OPEN_POPUP_URL_SUCCESS, url, "");
    }
    return success;
}
Also used : ChromeApplication(org.chromium.chrome.browser.ChromeApplication) TabCreator(org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator) PolicyAuditor(org.chromium.chrome.browser.policy.PolicyAuditor) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 38 with CalledByNative

use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.

the class OAuth2TokenService method getSystemAccountNames.

/**
     * Called by native to list the activite account names in the OS.
     */
@VisibleForTesting
@CalledByNative
public static String[] getSystemAccountNames(Context context) {
    AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
    java.util.List<String> accountNames = accountManagerHelper.getGoogleAccountNames();
    return accountNames.toArray(new String[accountNames.size()]);
}
Also used : AccountManagerHelper(org.chromium.components.signin.AccountManagerHelper) VisibleForTesting(org.chromium.base.VisibleForTesting) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 39 with CalledByNative

use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.

the class OAuth2TokenService method getOAuth2AuthToken.

/**
     * Called by native to retrieve OAuth2 tokens.
     *
     * @param username The native username (full address).
     * @param scope The scope to get an auth token for (without Android-style 'oauth2:' prefix).
     * @param nativeCallback The pointer to the native callback that should be run upon completion.
     */
@CalledByNative
public static void getOAuth2AuthToken(Context context, String username, String scope, final long nativeCallback) {
    Account account = getAccountOrNullFromUsername(context, username);
    if (account == null) {
        ThreadUtils.postOnUiThread(new Runnable() {

            @Override
            public void run() {
                nativeOAuth2TokenFetched(null, false, nativeCallback);
            }
        });
        return;
    }
    String oauth2Scope = OAUTH2_SCOPE_PREFIX + scope;
    AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
    accountManagerHelper.getAuthToken(account, oauth2Scope, new AccountManagerHelper.GetAuthTokenCallback() {

        @Override
        public void tokenAvailable(String token) {
            nativeOAuth2TokenFetched(token, false, nativeCallback);
        }

        @Override
        public void tokenUnavailable(boolean isTransientError) {
            nativeOAuth2TokenFetched(null, isTransientError, nativeCallback);
        }
    });
}
Also used : Account(android.accounts.Account) AccountManagerHelper(org.chromium.components.signin.AccountManagerHelper) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 40 with CalledByNative

use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.

the class PlatformUtil method launchExternalProtocol.

@CalledByNative
private static void launchExternalProtocol(String url) {
    Context context = ContextUtils.getApplicationContext();
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "cannot find activity to launch %s", url, e);
    }
}
Also used : Context(android.content.Context) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) CalledByNative(org.chromium.base.annotations.CalledByNative)

Aggregations

CalledByNative (org.chromium.base.annotations.CalledByNative)74 Activity (android.app.Activity)11 Context (android.content.Context)11 Intent (android.content.Intent)10 CastMediaRouteProvider (org.chromium.chrome.browser.media.router.cast.CastMediaRouteProvider)8 DownloadNotifier (org.chromium.chrome.browser.download.DownloadNotifier)6 View (android.view.View)5 TextView (android.widget.TextView)5 DownloadInfo (org.chromium.chrome.browser.download.DownloadInfo)5 SuppressLint (android.annotation.SuppressLint)4 PackageManager (android.content.pm.PackageManager)4 Bitmap (android.graphics.Bitmap)4 Paint (android.graphics.Paint)4 ScrollView (android.widget.ScrollView)4 ActivityManager (android.app.ActivityManager)3 ImageView (android.widget.ImageView)3 LinearLayout (android.widget.LinearLayout)3 VisibleForTesting (org.chromium.base.VisibleForTesting)3 Account (android.accounts.Account)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2