org.chromium.chrome.browser.WebContentsFactory Java Examples
The following examples show how to use
org.chromium.chrome.browser.WebContentsFactory.
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 delion with Apache License 2.0 | 5 votes |
private Tab createMainTab() { CustomTabsConnection customTabsConnection = CustomTabsConnection.getInstance(getApplication()); String url = getUrlToLoad(); // Get any referrer that has been explicitly set by the app. String referrerUrl = IntentHandler.getReferrerUrlIncludingExtraHeaders(getIntent(), this); if (referrerUrl == null) { Referrer referrer = customTabsConnection.getReferrerForSession(mSession); if (referrer != null) referrerUrl = referrer.getUrl(); } Tab tab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID), Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_EXTERNAL_APP, null, null); tab.setAppAssociatedWith(customTabsConnection.getClientPackageNameForSession(mSession)); mPrerenderedUrl = customTabsConnection.getPrerenderedUrl(mSession); WebContents webContents = customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl); mHasPrerendered = webContents != null; if (webContents == null) webContents = customTabsConnection.takeSpareWebContents(); if (webContents == null) webContents = WebContentsFactory.createWebContents(false, false); tab.initialize(webContents, getTabContentManager(), new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding()), false, false); tab.getTabRedirectHandler().updateIntent(getIntent()); tab.getView().requestFocus(); mTabObserver = new CustomTabObserver(getApplication(), mSession); tab.addObserver(mTabObserver); return tab; }
Example #2
Source File: SearchActivity.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void finishNativeInitialization() { super.finishNativeInitialization(); mTab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID), Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_EXTERNAL_APP, null, null); mTab.initialize(WebContentsFactory.createWebContents(false, false), null, new TabDelegateFactory(), false, false); mTab.loadUrl(new LoadUrlParams("about:blank")); mSearchBoxDataProvider.onNativeLibraryReady(mTab); mSearchBox.onNativeLibraryReady(); // Force the user to choose a search engine if they have to. final Callback<Boolean> deferredCallback = new Callback<Boolean>() { @Override public void onResult(Boolean result) { if (result == null || !result.booleanValue()) { Log.e(TAG, "User failed to select a default search engine."); finish(); return; } finishDeferredInitialization(); } }; if (!getActivityDelegate().showSearchEngineDialogIfNeeded(this, deferredCallback)) { mHandler.post(new Runnable() { @Override public void run() { finishDeferredInitialization(); } }); } }
Example #3
Source File: CustomTabActivity.java From 365browser with Apache License 2.0 | 5 votes |
private Tab createMainTab() { CustomTabsConnection connection = CustomTabsConnection.getInstance(getApplication()); String url = getUrlToLoad(); String referrerUrl = connection.getReferrer(mSession, getIntent()); Tab tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_EXTERNAL_APP, null, null); tab.setAppAssociatedWith(connection.getClientPackageNameForSession(mSession)); int webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS; WebContents webContents = connection.takePrerenderedUrl(mSession, url, referrerUrl); mUsingPrerender = webContents != null; if (mUsingPrerender) webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS; if (!mUsingPrerender) { webContents = WarmupManager.getInstance().takeSpareWebContents(false, false); if (webContents != null) webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS; } RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOnLaunch", webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX); if (webContents == null) { webContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false); } if (!mUsingPrerender) { connection.resetPostMessageHandlerForSession(mSession, webContents); } tab.initialize( webContents, getTabContentManager(), new CustomTabDelegateFactory( mIntentDataProvider.shouldEnableUrlBarHiding(), mIntentDataProvider.isOpenedByChrome(), getFullscreenManager().getBrowserVisibilityDelegate()), false, false); if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) { tab.enableEmbeddedMediaExperience(true); } initializeMainTab(tab); return tab; }
Example #4
Source File: CustomTabsConnection.java From delion with Apache License 2.0 | 4 votes |
/** Creates a spare {@link WebContents}, if none exists. */ private void createSpareWebContents() { ThreadUtils.assertOnUiThread(); if (mSpareWebContents != null) return; mSpareWebContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false); }
Example #5
Source File: Tab.java From delion with Apache License 2.0 | 4 votes |
/** * Initializes {@link Tab} with {@code webContents}. If {@code webContents} is {@code null} a * new {@link WebContents} will be created for this {@link Tab}. * @param webContents A {@link WebContents} object or {@code null} if one should be * created. * @param tabContentManager A {@link TabContentManager} instance or {@code null} if the web * content will be managed/displayed manually. * @param delegateFactory The {@link TabDelegateFactory} to be used for delegate creation. * @param initiallyHidden Only used if {@code webContents} is {@code null}. Determines * whether or not the newly created {@link WebContents} will be hidden * or not. * @param unfreeze Whether there should be an attempt to restore state at the end of * the initialization. */ public final void initialize(WebContents webContents, TabContentManager tabContentManager, TabDelegateFactory delegateFactory, boolean initiallyHidden, boolean unfreeze) { try { TraceEvent.begin("Tab.initialize"); mDelegateFactory = delegateFactory; initializeNative(); RevenueStats.getInstance().tabCreated(this); if (AppBannerManager.isEnabled()) { mAppBannerManager = mDelegateFactory.createAppBannerManager(this); if (mAppBannerManager != null) addObserver(mAppBannerManager); } mTopControlsVisibilityDelegate = mDelegateFactory.createTopControlsVisibilityDelegate(this); // Attach the TabContentManager if we have one. This will bind this Tab's content layer // to this manager. // TODO(dtrainor): Remove this and move to a pull model instead of pushing the layer. attachTabContentManager(tabContentManager); // If there is a frozen WebContents state or a pending lazy load, don't create a new // WebContents. if (getFrozenContentsState() != null || getPendingLoadParams() != null) { if (unfreeze) unfreezeContents(); return; } boolean creatingWebContents = webContents == null; if (creatingWebContents) { webContents = WebContentsFactory.createWebContents(isIncognito(), initiallyHidden); } ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webContents); if (contentViewCore == null) { initContentViewCore(webContents); } else { setContentViewCore(contentViewCore); } if (!creatingWebContents && webContents.isLoadingToDifferentDocument()) { didStartPageLoad(webContents.getUrl(), false); } } finally { if (mTimestampMillis == INVALID_TIMESTAMP) { mTimestampMillis = System.currentTimeMillis(); } TraceEvent.end("Tab.initialize"); } }
Example #6
Source File: CustomTabActivity.java From AndroidChromium with Apache License 2.0 | 4 votes |
private Tab createMainTab() { CustomTabsConnection customTabsConnection = CustomTabsConnection.getInstance(getApplication()); String url = getUrlToLoad(); // Get any referrer that has been explicitly set by the app. String referrerUrl = IntentHandler.getReferrerUrlIncludingExtraHeaders(getIntent(), this); if (referrerUrl == null) { Referrer referrer = customTabsConnection.getReferrerForSession(mSession); if (referrer != null) referrerUrl = referrer.getUrl(); } Tab tab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID), Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_EXTERNAL_APP, null, null); tab.setAppAssociatedWith(customTabsConnection.getClientPackageNameForSession(mSession)); mPrerenderedUrl = customTabsConnection.getPrerenderedUrl(mSession); int webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS; WebContents webContents = customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl); mHasPrerendered = webContents != null; if (mHasPrerendered) webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS; if (!mHasPrerendered) { webContents = WarmupManager.getInstance().takeSpareWebContents(false, false); if (webContents != null) webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS; } RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebcontentsStateOnLaunch", webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX); if (webContents == null) webContents = WebContentsFactory.createWebContents(false, false); if (!mHasPrerendered) { customTabsConnection.resetPostMessageHandlerForSession(mSession, webContents); } tab.initialize( webContents, getTabContentManager(), new CustomTabDelegateFactory( mIntentDataProvider.shouldEnableUrlBarHiding(), mIntentDataProvider.isOpenedByChrome(), getFullscreenManager().getBrowserVisibilityDelegate()), false, false); initializeMainTab(tab); return tab; }
Example #7
Source File: Tab.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Initializes {@link Tab} with {@code webContents}. If {@code webContents} is {@code null} a * new {@link WebContents} will be created for this {@link Tab}. * @param webContents A {@link WebContents} object or {@code null} if one should be * created. * @param tabContentManager A {@link TabContentManager} instance or {@code null} if the web * content will be managed/displayed manually. * @param delegateFactory The {@link TabDelegateFactory} to be used for delegate creation. * @param initiallyHidden Only used if {@code webContents} is {@code null}. Determines * whether or not the newly created {@link WebContents} will be hidden * or not. * @param unfreeze Whether there should be an attempt to restore state at the end of * the initialization. */ public final void initialize(WebContents webContents, TabContentManager tabContentManager, TabDelegateFactory delegateFactory, boolean initiallyHidden, boolean unfreeze) { try { TraceEvent.begin("Tab.initialize"); mDelegateFactory = delegateFactory; initializeNative(); RevenueStats.getInstance().tabCreated(this); mBrowserControlsVisibilityDelegate = mDelegateFactory.createBrowserControlsVisibilityDelegate(this); mBlimp = BlimpClientContextFactory .getBlimpClientContextForProfile( Profile.getLastUsedProfile().getOriginalProfile()) .isBlimpEnabled() && !mIncognito; // Attach the TabContentManager if we have one. This will bind this Tab's content layer // to this manager. // TODO(dtrainor): Remove this and move to a pull model instead of pushing the layer. attachTabContentManager(tabContentManager); // If there is a frozen WebContents state or a pending lazy load, don't create a new // WebContents. if (getFrozenContentsState() != null || getPendingLoadParams() != null) { if (unfreeze) unfreezeContents(); return; } if (isBlimpTab() && getBlimpContents() == null) { Profile profile = Profile.getLastUsedProfile(); if (mIncognito) profile = profile.getOffTheRecordProfile(); mBlimpContents = nativeInitBlimpContents( mNativeTabAndroid, profile, mWindowAndroid.getNativePointer()); if (mBlimpContents != null) { mBlimpContentsObserver = new TabBlimpContentsObserver(this); mBlimpContents.addObserver(mBlimpContentsObserver); } else { mBlimp = false; } } boolean creatingWebContents = webContents == null; if (creatingWebContents) { webContents = WarmupManager.getInstance().takeSpareWebContents( isIncognito(), initiallyHidden); if (webContents == null) { webContents = WebContentsFactory.createWebContents(isIncognito(), initiallyHidden); } } ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webContents); if (contentViewCore == null) { initContentViewCore(webContents); } else { setContentViewCore(contentViewCore); } if (!creatingWebContents && webContents.isLoadingToDifferentDocument()) { didStartPageLoad(webContents.getUrl(), false); } getAppBannerManager().setIsEnabledForTab(mDelegateFactory.canShowAppBanners(this)); } finally { if (mTimestampMillis == INVALID_TIMESTAMP) { mTimestampMillis = System.currentTimeMillis(); } TraceEvent.end("Tab.initialize"); } }
Example #8
Source File: Tab.java From 365browser with Apache License 2.0 | 4 votes |
/** * Initializes {@link Tab} with {@code webContents}. If {@code webContents} is {@code null} a * new {@link WebContents} will be created for this {@link Tab}. * @param webContents A {@link WebContents} object or {@code null} if one should be * created. * @param tabContentManager A {@link TabContentManager} instance or {@code null} if the web * content will be managed/displayed manually. * @param delegateFactory The {@link TabDelegateFactory} to be used for delegate creation. * @param initiallyHidden Only used if {@code webContents} is {@code null}. Determines * whether or not the newly created {@link WebContents} will be hidden * or not. * @param unfreeze Whether there should be an attempt to restore state at the end of * the initialization. */ public final void initialize(WebContents webContents, TabContentManager tabContentManager, TabDelegateFactory delegateFactory, boolean initiallyHidden, boolean unfreeze) { try { TraceEvent.begin("Tab.initialize"); mDelegateFactory = delegateFactory; initializeNative(); RevenueStats.getInstance().tabCreated(this); mBrowserControlsVisibilityDelegate = mDelegateFactory.createBrowserControlsVisibilityDelegate(this); // Attach the TabContentManager if we have one. This will bind this Tab's content layer // to this manager. // TODO(dtrainor): Remove this and move to a pull model instead of pushing the layer. attachTabContentManager(tabContentManager); // If there is a frozen WebContents state or a pending lazy load, don't create a new // WebContents. if (getFrozenContentsState() != null || getPendingLoadParams() != null) { if (unfreeze) unfreezeContents(); return; } boolean creatingWebContents = webContents == null; if (creatingWebContents) { webContents = WarmupManager.getInstance().takeSpareWebContents( isIncognito(), initiallyHidden); if (webContents == null) { webContents = WebContentsFactory.createWebContents(isIncognito(), initiallyHidden); } } ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webContents); if (contentViewCore == null) { initContentViewCore(webContents); } else { setContentViewCore(contentViewCore); } mContentViewCore.addImeEventObserver(new ImeEventObserver() { @Override public void onImeEvent() { // Some text was set in the page. Don't reuse it if a tab is // open from the same external application, we might lose some // user data. mAppAssociatedWith = null; } @Override public void onNodeAttributeUpdated(boolean editable, boolean password) { if (getFullscreenManager() == null) return; updateFullscreenEnabledState(); } }); if (!creatingWebContents && webContents.isLoadingToDifferentDocument()) { didStartPageLoad(webContents.getUrl(), false); } getAppBannerManager().setIsEnabledForTab(mDelegateFactory.canShowAppBanners(this)); } finally { if (mTimestampMillis == INVALID_TIMESTAMP) { mTimestampMillis = System.currentTimeMillis(); } TraceEvent.end("Tab.initialize"); } }
Example #9
Source File: ExternalPrerenderHandler.java From delion with Apache License 2.0 | 3 votes |
/** * Add a prerender for the given url and given content view dimensions. * <p> * The generated {@link WebContents} does not actually contain the prerendered contents but * must be used as the container that you load the prerendered URL into. * * @param profile The profile to use for the prerender. * @param url The url to prerender. * @param referrer The referrer for the prerender request. * @param width The width for the content view (render widget host view) for the prerender. * @param height The height for the content view (render widget host view) for the prerender. * @param prerenderOnCellular Whether the prerender should happen if the device has a cellular * connection. * @return The {@link WebContents} that is linked to this prerender. {@code null} if * unsuccessful. */ public WebContents addPrerender(Profile profile, String url, String referrer, int width, int height, boolean prerenderOnCellular) { WebContents webContents = WebContentsFactory.createWebContents(false, false); if (addPrerender(profile, webContents, url, referrer, width, height, prerenderOnCellular)) { return webContents; } if (webContents != null) webContents.destroy(); return null; }
Example #10
Source File: ExternalPrerenderHandler.java From AndroidChromium with Apache License 2.0 | 3 votes |
/** * Add a prerender for the given url and given content view dimensions. * <p> * The generated {@link WebContents} does not actually contain the prerendered contents but * must be used as the container that you load the prerendered URL into. * * @param profile The profile to use for the prerender. * @param url The url to prerender. * @param referrer The referrer for the prerender request. * @param bounds The bounds for the content view (render widget host view) for the prerender. * @param prerenderOnCellular Whether the prerender should happen if the device has a cellular * connection. * @return A Pair containing the dummy {@link WebContents} that is linked to this prerender * through session storage namespace id and will be replaced soon and the prerendering * {@link WebContents} that owned by the prerender manager. * {@code null} if unsuccessful. */ public Pair<WebContents, WebContents> addPrerender(Profile profile, String url, String referrer, Rect bounds, boolean prerenderOnCellular) { WebContents dummyWebContents = WebContentsFactory.createWebContents(false, false); WebContents prerenderingWebContents = addPrerender(profile, dummyWebContents, url, referrer, bounds, prerenderOnCellular); if (dummyWebContents == null) return null; if (prerenderingWebContents != null) { return Pair.create(dummyWebContents, prerenderingWebContents); } dummyWebContents.destroy(); return null; }
Example #11
Source File: ExternalPrerenderHandler.java From 365browser with Apache License 2.0 | 3 votes |
/** * Add a prerender for the given url and given content view dimensions. * <p> * The generated {@link WebContents} does not actually contain the prerendered contents but * must be used as the container that you load the prerendered URL into. * * @param profile The profile to use for the prerender. * @param url The url to prerender. * @param referrer The referrer for the prerender request. * @param bounds The bounds for the content view (render widget host view) for the prerender. * @param prerenderOnCellular Whether the prerender should happen if the device has a cellular * connection. * @return A Pair containing the dummy {@link WebContents} that is linked to this prerender * through session storage namespace id and will be replaced soon and the prerendering * {@link WebContents} that owned by the prerender manager. * {@code null} if unsuccessful. */ public Pair<WebContents, WebContents> addPrerender(Profile profile, String url, String referrer, Rect bounds, boolean prerenderOnCellular) { WebContents dummyWebContents = WebContentsFactory.createWebContents(false, false); WebContents prerenderingWebContents = addPrerender(profile, dummyWebContents, url, referrer, bounds, prerenderOnCellular); if (dummyWebContents == null) return null; if (prerenderingWebContents != null) { return Pair.create(dummyWebContents, prerenderingWebContents); } dummyWebContents.destroy(); return null; }