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);
}
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;
}
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()]);
}
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);
}
});
}
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);
}
}
Aggregations