Java Code Examples for org.chromium.content.browser.ContentViewCore#getWindowAndroid()

The following examples show how to use org.chromium.content.browser.ContentViewCore#getWindowAndroid() . 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 vote down vote up
@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 vote down vote up
/**
 * 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 vote down vote up
/**
 * @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 vote down vote up
@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 vote down vote up
@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 vote down vote up
/**
 * @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 vote down vote up
@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: ColorChooserAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
public static ColorChooserAndroid createColorChooserAndroid(
        long nativeColorChooserAndroid,
        ContentViewCore contentViewCore,
        int initialColor,
        ColorSuggestion[] suggestions) {
    if (contentViewCore.getWindowAndroid() == null) return null;
    Context windowContext = contentViewCore.getWindowAndroid().getContext().get();
    if (WindowAndroid.activityFromContext(windowContext) == null) return null;
    ColorChooserAndroid chooser = new ColorChooserAndroid(nativeColorChooserAndroid,
            windowContext, initialColor, suggestions);
    chooser.openColorChooser();
    return chooser;
}
 
Example 9
Source File: ContextMenuHelper.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Starts showing a context menu for {@code view} based on {@code params}.
 * @param contentViewCore The {@link ContentViewCore} to show the menu to.
 * @param params          The {@link ContextMenuParams} that indicate what menu items to show.
 */
@CalledByNative
private void showContextMenu(final ContentViewCore contentViewCore, ContextMenuParams params) {
    if (params.isFile()) return;
    View view = contentViewCore.getContainerView();
    final WindowAndroid windowAndroid = contentViewCore.getWindowAndroid();

    if (view == null || view.getVisibility() != View.VISIBLE || view.getParent() == null
            || windowAndroid == null || windowAndroid.getActivity().get() == null
            || mPopulator == null) {
        return;
    }

    mCurrentContextMenuParams = params;
    mActivity = windowAndroid.getActivity().get();
    mCallback = new Callback<Integer>() {
        @Override
        public void onResult(Integer result) {
            mPopulator.onItemSelected(
                    ContextMenuHelper.this, mCurrentContextMenuParams, result);
        }
    };
    mOnMenuShown = new Runnable() {
        @Override
        public void run() {
            WebContents webContents = contentViewCore.getWebContents();
            RecordHistogram.recordBooleanHistogram("ContextMenu.Shown", webContents != null);
        }
    };
    mOnMenuClosed = new Runnable() {
        @Override
        public void run() {
            if (mNativeContextMenuHelper == 0) return;
            nativeOnContextMenuClosed(mNativeContextMenuHelper);
        }
    };

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT_MENU)) {
        List<Pair<Integer, List<ContextMenuItem>>> items =
                mPopulator.buildContextMenu(null, mActivity, mCurrentContextMenuParams);
        if (items.isEmpty()) {
            ThreadUtils.postOnUiThread(mOnMenuClosed);
            return;
        }

        final ContextMenuUi menuUi = new TabularContextMenuUi(new Runnable() {
            @Override
            public void run() {
                shareImageDirectly(ShareHelper.getLastShareComponentName());
            }
        });
        menuUi.displayMenu(mActivity, mCurrentContextMenuParams, items, mCallback, mOnMenuShown,
                mOnMenuClosed);
        if (mCurrentContextMenuParams.isImage()) {
            getThumbnail(new Callback<Bitmap>() {
                @Override
                public void onResult(Bitmap result) {
                    ((TabularContextMenuUi) menuUi).onImageThumbnailRetrieved(result);
                }
            });
        }
        return;
    }

    // The Platform Context Menu requires the listener within this hepler since this helper and
    // provides context menu for us to show.
    view.setOnCreateContextMenuListener(this);
    if (view.showContextMenu()) {
        mOnMenuShown.run();
        windowAndroid.addContextMenuCloseListener(new OnCloseContextMenuListener() {
            @Override
            public void onContextMenuClosed() {
                mOnMenuClosed.run();
                windowAndroid.removeContextMenuCloseListener(this);
            }
        });
    }
}