Java Code Examples for org.chromium.content.browser.ContentViewCore#fromWebContents()
The following examples show how to use
org.chromium.content.browser.ContentViewCore#fromWebContents() .
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: PaymentRequestFactory.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override public PaymentRequest createImpl() { if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEB_PAYMENTS)) { return new InvalidPaymentRequest(); } if (mWebContents == null) return new InvalidPaymentRequest(); ContentViewCore contentViewCore = ContentViewCore.fromWebContents(mWebContents); if (contentViewCore == null) return new InvalidPaymentRequest(); WindowAndroid window = contentViewCore.getWindowAndroid(); if (window == null) return new InvalidPaymentRequest(); Activity context = window.getActivity().get(); if (context == null) return new InvalidPaymentRequest(); return new PaymentRequestImpl(context, mWebContents); }
Example 2
Source File: PaymentRequestImpl.java From delion with Apache License 2.0 | 5 votes |
/** * Builds the PaymentRequest service implementation. * * @param webContents The web contents that have invoked the PaymentRequest API. */ public PaymentRequestImpl(WebContents webContents) { if (webContents == null) return; ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webContents); if (contentViewCore == null) return; WindowAndroid window = contentViewCore.getWindowAndroid(); if (window == null) return; mContext = window.getActivity().get(); if (mContext == null) return; mMerchantName = webContents.getTitle(); // The feature is available only in secure context, so it's OK to not show HTTPS. mOrigin = UrlUtilities.formatUrlForSecurityDisplay(webContents.getVisibleUrl(), false); final FaviconHelper faviconHelper = new FaviconHelper(); float scale = mContext.getResources().getDisplayMetrics().density; faviconHelper.getLocalFaviconImageForURL(Profile.getLastUsedProfile(), webContents.getVisibleUrl(), (int) (FAVICON_SIZE_DP * scale + 0.5f), new FaviconHelper.FaviconImageCallback() { @Override public void onFaviconAvailable(Bitmap bitmap, String iconUrl) { faviconHelper.destroy(); if (bitmap == null) return; if (mUI == null) { mFavicon = bitmap; return; } mUI.setTitleBitmap(bitmap); } }); mApps = PaymentAppFactory.create(webContents); }
Example 3
Source File: DomDistillerUIUtils.java From delion with Apache License 2.0 | 5 votes |
/** * @param webContents The WebContents to get the Activity from. * @return The Activity associated with the WebContents. */ private static Activity getActivityFromWebContents(WebContents webContents) { if (webContents == null) return null; ContentViewCore contentView = ContentViewCore.fromWebContents(webContents); if (contentView == null) return null; WindowAndroid window = contentView.getWindowAndroid(); if (window == null) return null; return window.getActivity().get(); }
Example 4
Source File: LocationSettings.java From delion with Apache License 2.0 | 5 votes |
@CalledByNative private static boolean canSitesRequestLocationPermission(WebContents webContents) { ContentViewCore cvc = ContentViewCore.fromWebContents(webContents); if (cvc == null) return false; WindowAndroid windowAndroid = cvc.getWindowAndroid(); if (windowAndroid == null) return false; Context context = windowAndroid.getApplicationContext(); LocationUtils locationUtils = LocationUtils.getInstance(); if (!locationUtils.isSystemLocationSettingEnabled(context)) return false; return locationUtils.hasAndroidLocationPermission(context) || windowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION); }
Example 5
Source File: ShareServiceImpl.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Nullable private static Activity activityFromWebContents(@Nullable WebContents webContents) { if (webContents == null) return null; ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webContents); if (contentViewCore == null) return null; WindowAndroid window = contentViewCore.getWindowAndroid(); if (window == null) return null; return window.getActivity().get(); }
Example 6
Source File: DomDistillerUIUtils.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * @param webContents The WebContents to get the Activity from. * @return The Activity associated with the WebContents. */ private static Activity getActivityFromWebContents(WebContents webContents) { if (webContents == null) return null; ContentViewCore contentView = ContentViewCore.fromWebContents(webContents); if (contentView == null) return null; WindowAndroid window = contentView.getWindowAndroid(); if (window == null) return null; return window.getActivity().get(); }
Example 7
Source File: LocationSettings.java From AndroidChromium with Apache License 2.0 | 5 votes |
@CalledByNative private static boolean canSitesRequestLocationPermission(WebContents webContents) { ContentViewCore cvc = ContentViewCore.fromWebContents(webContents); if (cvc == null) return false; WindowAndroid windowAndroid = cvc.getWindowAndroid(); if (windowAndroid == null) return false; LocationUtils locationUtils = LocationUtils.getInstance(); if (!locationUtils.isSystemLocationSettingEnabled()) return false; return locationUtils.hasAndroidLocationPermission() || windowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION); }
Example 8
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 9
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 10
Source File: PermissionUpdateInfoBarDelegate.java From AndroidChromium with Apache License 2.0 | 4 votes |
private PermissionUpdateInfoBarDelegate( long nativePtr, WebContents webContents, String[] permissions) { mNativePtr = nativePtr; mAndroidPermisisons = permissions; mContentViewCore = ContentViewCore.fromWebContents(webContents); }
Example 11
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 12
Source File: PermissionUpdateInfoBarDelegate.java From 365browser with Apache License 2.0 | 4 votes |
private PermissionUpdateInfoBarDelegate( long nativePtr, WebContents webContents, String[] permissions) { mNativePtr = nativePtr; mAndroidPermisisons = permissions; mContentViewCore = ContentViewCore.fromWebContents(webContents); }