use of org.chromium.content_public.browser.LoadUrlParams 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;
}
use of org.chromium.content_public.browser.LoadUrlParams in project AndroidChromium by JackyAndroid.
the class ReaderModeManager method createNewTab.
/**
* Open a link from the panel in a new tab.
* @param url The URL to load.
*/
public void createNewTab(String url) {
if (mChromeActivity == null)
return;
Tab currentTab = mTabModelSelector.getCurrentTab();
if (currentTab == null)
return;
TabCreatorManager.TabCreator tabCreator = mChromeActivity.getTabCreator(currentTab.isIncognito());
if (tabCreator == null)
return;
tabCreator.createNewTab(new LoadUrlParams(url, PageTransition.LINK), TabModel.TabLaunchType.FROM_LINK, mChromeActivity.getActivityTab());
}
use of org.chromium.content_public.browser.LoadUrlParams in project AndroidChromium by JackyAndroid.
the class OfflinePageDownloadBridge method openItem.
/**
* 'Opens' the offline page identified by the GUID.
* This is done by creating a new tab and navigating it to the saved local snapshot.
* No automatic redirection is happening based on the connection status.
* If the item with specified GUID is not found or can't be opened, nothing happens.
* @param guid GUID of the item to open.
* @param componentName If specified, targets a specific Activity to open the offline page in.
*/
@Override
public void openItem(String guid, @Nullable ComponentName componentName) {
OfflinePageDownloadItem item = getItem(guid);
if (item == null)
return;
LoadUrlParams params = new LoadUrlParams(item.getUrl());
Map<String, String> headers = new HashMap<String, String>();
headers.put("X-Chrome-offline", "persist=1 reason=download id=" + Long.toString(nativeGetOfflineIdByGuid(mNativeOfflinePageDownloadBridge, guid)));
params.setExtraHeaders(headers);
AsyncTabCreationParams asyncParams = componentName == null ? new AsyncTabCreationParams(params) : new AsyncTabCreationParams(params, componentName);
final TabDelegate tabDelegate = new TabDelegate(false);
tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI, Tab.INVALID_TAB_ID);
}
use of org.chromium.content_public.browser.LoadUrlParams 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.content_public.browser.LoadUrlParams in project AndroidChromium by JackyAndroid.
the class Tab method unfreezeContents.
/**
* Restores the WebContents from its saved state. This should only be called if the tab is
* frozen with a saved TabState, and NOT if it was frozen for a lazy load.
* @return Whether or not the restoration was successful.
*/
protected boolean unfreezeContents() {
try {
TraceEvent.begin("Tab.unfreezeContents");
assert mFrozenContentsState != null;
assert getContentViewCore() == null;
WebContents webContents = mFrozenContentsState.restoreContentsFromByteBuffer(isHidden());
if (webContents == null) {
// State restore failed, just create a new empty web contents as that is the best
// that can be done at this point. TODO(jcivelli) http://b/5910521 - we should show
// an error page instead of a blank page in that case (and the last loaded URL).
webContents = WebContentsFactory.createWebContents(isIncognito(), isHidden());
mTabUma = new TabUma(TabCreationState.FROZEN_ON_RESTORE_FAILED);
mFailedToRestore = true;
}
mFrozenContentsState = null;
initContentViewCore(webContents);
if (mFailedToRestore) {
String url = TextUtils.isEmpty(mUrl) ? UrlConstants.NTP_URL : mUrl;
loadUrl(new LoadUrlParams(url, PageTransition.GENERATED));
}
return !mFailedToRestore;
} finally {
TraceEvent.end("Tab.unfreezeContents");
}
}
Aggregations