org.chromium.ui.base.WindowAndroid Java Examples

The following examples show how to use org.chromium.ui.base.WindowAndroid. 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: Tab.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an instance of a {@link Tab} that is fully detached from any activity.
 * Also performs general tab initialization as well as detached specifics.
 *
 * The current application context must allow the creation of a WindowAndroid.
 *
 * @return The newly created and initialized tab.
 */
public static Tab createDetached(TabDelegateFactory delegateFactory) {
    Context context = ContextUtils.getApplicationContext();
    WindowAndroid windowAndroid = new WindowAndroid(context);
    Tab tab = new Tab(INVALID_TAB_ID, INVALID_TAB_ID, false, context, windowAndroid,
            TabLaunchType.FROM_DETACHED, null, null);
    tab.initialize(null, null, delegateFactory, true, false);

    // Resize the webContent to avoid expensive post load resize when attaching the tab.
    Rect bounds = ExternalPrerenderHandler.estimateContentSize((Application) context, false);
    int width = bounds.right - bounds.left;
    int height = bounds.bottom - bounds.top;
    tab.getContentViewCore().onSizeChanged(width, height, 0, 0);

    tab.detach(null, null);
    return tab;
}
 
Example #2
Source File: LocationBarLayout.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onIntentCompleted(WindowAndroid window, int resultCode,
        ContentResolver contentResolver, Intent data) {
    if (resultCode != Activity.RESULT_OK) return;
    if (data.getExtras() == null) return;

    VoiceResult topResult = mAutocomplete.onVoiceResults(data.getExtras());
    if (topResult == null) return;

    String topResultQuery = topResult.getMatch();
    if (TextUtils.isEmpty(topResultQuery)) return;

    if (topResult.getConfidence() < VOICE_SEARCH_CONFIDENCE_NAVIGATE_THRESHOLD) {
        setSearchQuery(topResultQuery);
        return;
    }

    String url = AutocompleteController.nativeQualifyPartialURLQuery(topResultQuery);
    if (url == null) {
        url = TemplateUrlService.getInstance().getUrlForVoiceSearchQuery(
                topResultQuery);
    }
    loadUrl(url, PageTransition.TYPED);
}
 
Example #3
Source File: CompositorViewHolder.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * This is called when the native library are ready.
 */
public void onNativeLibraryReady(
        WindowAndroid windowAndroid, TabContentManager tabContentManager) {
    assert mLayerTitleCache == null : "Should be called once";

    if (DeviceClassManager.enableLayerDecorationCache()) {
        mLayerTitleCache = new LayerTitleCache(getContext());
    }

    mCompositorView.initNativeCompositor(
            SysUtils.isLowEndDevice(), windowAndroid, mLayerTitleCache, tabContentManager);

    if (mLayerTitleCache != null) {
        mLayerTitleCache.setResourceManager(getResourceManager());
    }

    if (mControlContainer != null) {
        mCompositorView.getResourceManager().getDynamicResourceLoader().registerResource(
                R.id.control_container, mControlContainer.getToolbarResourceAdapter());
    }
}
 
Example #4
Source File: ChildAccountService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@CalledByNative
private static void reauthenticateChildAccount(
        WindowAndroid windowAndroid, String accountName, final long nativeCallback) {
    ThreadUtils.assertOnUiThread();

    Activity activity = windowAndroid.getActivity().get();
    if (activity == null) {
        ThreadUtils.postOnUiThread(new Runnable() {
            @Override
            public void run() {
                nativeOnReauthenticationResult(nativeCallback, false);
            }
        });
        return;
    }

    Account account = AccountManagerHelper.createAccountFromName(accountName);
    AccountManagerHelper.get().updateCredentials(account, activity, new Callback<Boolean>() {
        @Override
        public void onResult(Boolean result) {
            nativeOnReauthenticationResult(nativeCallback, result);
        }
    });
}
 
Example #5
Source File: CompositorView.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the {@link CompositorView}'s native parts (e.g. the rendering parts).
 * @param lowMemDevice         If this is a low memory device.
 * @param windowAndroid        A {@link WindowAndroid} instance.
 * @param layerTitleCache      A {@link LayerTitleCache} instance.
 * @param tabContentManager    A {@link TabContentManager} instance.
 */
public void initNativeCompositor(boolean lowMemDevice, WindowAndroid windowAndroid,
        LayerTitleCache layerTitleCache, TabContentManager tabContentManager) {
    mWindowAndroid = windowAndroid;
    mLayerTitleCache = layerTitleCache;
    mTabContentManager = tabContentManager;

    mNativeCompositorView = nativeInit(lowMemDevice,
            windowAndroid.getNativePointer(), layerTitleCache, tabContentManager);

    assert !getHolder().getSurface().isValid()
        : "Surface created before native library loaded.";
    getHolder().addCallback(this);

    // Cover the black surface before it has valid content.
    setBackgroundColor(Color.WHITE);
    setVisibility(View.VISIBLE);

    // Grab the Resource Manager
    mResourceManager = nativeGetResourceManager(mNativeCompositorView);
}
 
Example #6
Source File: LocationSettings.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@CalledByNative
private static void promptToEnableSystemLocationSetting(
        @LocationSettingsDialogContext int promptContext, WebContents webContents,
        final long nativeCallback) {
    WindowAndroid window = webContents.getTopLevelNativeWindow();
    if (window == null) {
        nativeOnLocationSettingsDialogOutcome(
                nativeCallback, LocationSettingsDialogOutcome.NO_PROMPT);
        return;
    }
    LocationUtils.getInstance().promptToEnableSystemLocationSetting(
            promptContext, window, new Callback<Integer>() {
                @Override
                public void onResult(Integer result) {
                    nativeOnLocationSettingsDialogOutcome(nativeCallback, result);
                }
            });
}
 
Example #7
Source File: AndroidPermissionRequester.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static SparseArray<String[]> generatePermissionsMapping(
        WindowAndroid windowAndroid, int[] contentSettingsTypes) {
    SparseArray<String[]> permissionsToRequest = new SparseArray<>();
    for (int i = 0; i < contentSettingsTypes.length; i++) {
        String[] permissions = PrefServiceBridge.getAndroidPermissionsForContentSetting(
                contentSettingsTypes[i]);
        if (permissions == null) continue;
        List<String> missingPermissions = new ArrayList<>();
        for (int j = 0; j < permissions.length; j++) {
            String permission = permissions[j];
            if (!windowAndroid.hasPermission(permission)) missingPermissions.add(permission);
        }
        if (!missingPermissions.isEmpty()) {
            permissionsToRequest.append(contentSettingsTypes[i],
                    missingPermissions.toArray(new String[missingPermissions.size()]));
        }
    }
    return permissionsToRequest;
}
 
Example #8
Source File: BluetoothChooserDialog.java    From delion with Apache License 2.0 6 votes vote down vote up
@CalledByNative
private static BluetoothChooserDialog create(WindowAndroid windowAndroid, String origin,
        int securityLevel, long nativeBluetoothChooserDialogPtr) {
    if (!LocationUtils.getInstance().hasAndroidLocationPermission(
                windowAndroid.getActivity().get())
            && !windowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // If we can't even ask for enough permission to scan for Bluetooth devices, don't open
        // the dialog.
        return null;
    }
    BluetoothChooserDialog dialog = new BluetoothChooserDialog(
            windowAndroid, origin, securityLevel, nativeBluetoothChooserDialogPtr);
    dialog.show();
    return dialog;
}
 
Example #9
Source File: LocationBarLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onIntentCompleted(WindowAndroid window, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) return;
    if (data.getExtras() == null) return;

    VoiceResult topResult = mAutocomplete.onVoiceResults(data.getExtras());
    if (topResult == null) return;

    String topResultQuery = topResult.getMatch();
    if (TextUtils.isEmpty(topResultQuery)) return;

    if (topResult.getConfidence() < VOICE_SEARCH_CONFIDENCE_NAVIGATE_THRESHOLD) {
        setSearchQuery(topResultQuery);
        return;
    }

    String url = AutocompleteController.nativeQualifyPartialURLQuery(topResultQuery);
    if (url == null) {
        url = TemplateUrlService.getInstance().getUrlForVoiceSearchQuery(
                topResultQuery);
    }
    loadUrl(url, PageTransition.TYPED);
}
 
Example #10
Source File: AppBannerInfoBarDelegateAndroid.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private WindowAndroid.IntentCallback createIntentCallback(final AppData appData) {
    return new WindowAndroid.IntentCallback() {
        @Override
        public void onIntentCompleted(WindowAndroid window, int resultCode,
                ContentResolver contentResolver, Intent data) {
            boolean isInstalling = resultCode == Activity.RESULT_OK;
            if (isInstalling) {
                // Start monitoring the install.
                PackageManager pm =
                        getPackageManager(ContextUtils.getApplicationContext());
                mInstallTask = new InstallerDelegate(
                        Looper.getMainLooper(), pm, createInstallerDelegateObserver(),
                        appData.packageName());
                mInstallTask.start();
            }

            nativeOnInstallIntentReturned(mNativePointer, isInstalling);
        }
    };
}
 
Example #11
Source File: AppBannerInfoBarDelegateAndroid.java    From delion with Apache License 2.0 6 votes vote down vote up
private WindowAndroid.IntentCallback createIntentCallback(final AppData appData) {
    return new WindowAndroid.IntentCallback() {
        @Override
        public void onIntentCompleted(WindowAndroid window, int resultCode,
                ContentResolver contentResolver, Intent data) {
            boolean isInstalling = resultCode == Activity.RESULT_OK;
            if (isInstalling) {
                // Start monitoring the install.
                PackageManager pm =
                        getPackageManager(ContextUtils.getApplicationContext());
                mInstallTask = new InstallerDelegate(
                        Looper.getMainLooper(), pm, createInstallerDelegateObserver(),
                        appData.packageName());
                mInstallTask.start();
            }

            nativeOnInstallIntentReturned(mNativePointer, isInstalling);
        }
    };
}
 
Example #12
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 #13
Source File: LocationBarLayout.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onIntentCompleted(WindowAndroid window, int resultCode,
        ContentResolver contentResolver, Intent data) {
    if (resultCode != Activity.RESULT_OK) return;
    if (data.getExtras() == null) return;

    VoiceResult topResult = mAutocomplete.onVoiceResults(data.getExtras());
    if (topResult == null) return;

    String topResultQuery = topResult.getMatch();
    if (TextUtils.isEmpty(topResultQuery)) return;

    if (topResult.getConfidence() < VOICE_SEARCH_CONFIDENCE_NAVIGATE_THRESHOLD) {
        setSearchQuery(topResultQuery);
        return;
    }

    String url = AutocompleteController.nativeQualifyPartialURLQuery(topResultQuery);
    if (url == null) {
        url = TemplateUrlService.getInstance().getUrlForVoiceSearchQuery(
                topResultQuery);
    }
    loadUrl(url, PageTransition.TYPED);
}
 
Example #14
Source File: AutofillPopupBridge.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public AutofillPopupBridge(View anchorView, long nativeAutofillPopupViewAndroid,
        WindowAndroid windowAndroid) {
    mNativeAutofillPopup = nativeAutofillPopupViewAndroid;
    Activity activity = windowAndroid.getActivity().get();
    if (activity == null) {
        mAutofillPopup = null;
        mContext = null;
        // Clean up the native counterpart.  This is posted to allow the native counterpart
        // to fully finish the construction of this glue object before we attempt to delete it.
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                dismissed();
            }
        });
    } else {
        mAutofillPopup = new AutofillPopup(activity, anchorView, this);
        mContext = activity;
        mBrowserAccessibilityManager = ((ChromeActivity) activity)
                                               .getCurrentContentViewCore()
                                               .getBrowserAccessibilityManager();
    }
}
 
Example #15
Source File: SigninPromoUtil.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * A convenience method to create an AccountSigninActivity, passing the access point as an
 * intent extra.
 * @param window WindowAndroid from which to get the Activity/Context.
 * @param accessPoint for metrics purposes.
 */
@CalledByNative
private static void openAccountSigninActivityForPromo(WindowAndroid window, int accessPoint) {
    Activity activity = window.getActivity().get();
    if (activity != null) {
        AccountSigninActivity.startIfAllowed(activity, accessPoint);
    }
}
 
Example #16
Source File: BluetoothChooserDialog.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the BluetoothChooserDialog.
 */
@VisibleForTesting
BluetoothChooserDialog(WindowAndroid windowAndroid, String origin, int securityLevel,
        long nativeBluetoothChooserDialogPtr) {
    mWindowAndroid = windowAndroid;
    mActivity = windowAndroid.getActivity().get();
    assert mActivity != null;
    mOrigin = origin;
    mSecurityLevel = securityLevel;
    mNativeBluetoothChooserDialogPtr = nativeBluetoothChooserDialogPtr;
    mAdapter = BluetoothAdapter.getDefaultAdapter();

    // Initialize icons.
    mConnectedIcon = getIconWithRowIconColorStateList(R.drawable.ic_bluetooth_connected);
    mConnectedIconDescription = mActivity.getString(R.string.bluetooth_device_connected);

    mSignalStrengthLevelIcon = new Drawable[] {
            getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_0_bar),
            getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_1_bar),
            getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_2_bar),
            getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_3_bar),
            getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_4_bar)};

    if (mAdapter == null) {
        Log.i(TAG, "BluetoothChooserDialog: Default Bluetooth adapter not found.");
    }
    mAdapterOffStatus =
            SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_adapter_off_help),
                    new SpanInfo("<link>", "</link>",
                            new BluetoothClickableSpan(LinkType.ADAPTER_OFF_HELP, mActivity)));
}
 
Example #17
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 #18
Source File: CompositorView.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the {@link CompositorView}'s native parts (e.g. the rendering parts).
 * @param lowMemDevice         If this is a low memory device.
 * @param windowAndroid        A {@link WindowAndroid} instance.
 * @param layerTitleCache      A {@link LayerTitleCache} instance.
 * @param tabContentManager    A {@link TabContentManager} instance.
 */
public void initNativeCompositor(boolean lowMemDevice, WindowAndroid windowAndroid,
        LayerTitleCache layerTitleCache, TabContentManager tabContentManager) {
    mWindowAndroid = windowAndroid;
    mLayerTitleCache = layerTitleCache;
    mTabContentManager = tabContentManager;

    mNativeCompositorView = nativeInit(lowMemDevice,
            windowAndroid.getNativePointer(), layerTitleCache, tabContentManager);

    assert !getHolder().getSurface().isValid()
        : "Surface created before native library loaded.";
    getHolder().addCallback(this);

    // Cover the black surface before it has valid content.
    setBackgroundColor(Color.WHITE);
    setVisibility(View.VISIBLE);

    mFramePresentationDelay = 0;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
        Display display =
                ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
        long presentationDeadline = display.getPresentationDeadlineNanos()
                / NANOSECONDS_PER_MILLISECOND;
        long vsyncPeriod = mWindowAndroid.getVsyncPeriodInMillis();
        mFramePresentationDelay = Math.min(3 * vsyncPeriod,
                ((presentationDeadline + vsyncPeriod - 1) / vsyncPeriod) * vsyncPeriod);
    }

    // Grab the Resource Manager
    mResourceManager = nativeGetResourceManager(mNativeCompositorView);
}
 
Example #19
Source File: BluetoothChooserDialog.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static BluetoothChooserDialog create(WindowAndroid windowAndroid, String origin,
        int securityLevel, long nativeBluetoothChooserDialogPtr) {
    if (!LocationUtils.getInstance().hasAndroidLocationPermission()
            && !windowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // If we can't even ask for enough permission to scan for Bluetooth devices, don't open
        // the dialog.
        return null;
    }
    BluetoothChooserDialog dialog = new BluetoothChooserDialog(
            windowAndroid, origin, securityLevel, nativeBluetoothChooserDialogPtr);
    dialog.show();
    return dialog;
}
 
Example #20
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public CustomTabCreator(
        ChromeActivity activity, WindowAndroid nativeWindow, boolean incognito,
        boolean supportsUrlBarHiding, boolean isOpenedByChrome) {
    super(activity, nativeWindow, incognito);
    mSupportsUrlBarHiding = supportsUrlBarHiding;
    mIsOpenedByChrome = isOpenedByChrome;
    mVisibilityDelegate = activity.getFullscreenManager().getBrowserVisibilityDelegate();
}
 
Example #21
Source File: SigninPromoUtil.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * A convenience method to create an AccountSigninActivity, passing the access point as an
 * intent extra.
 * @param window WindowAndroid from which to get the Activity/Context.
 * @param accessPoint for metrics purposes.
 */
@CalledByNative
private static void openAccountSigninActivityForPromo(WindowAndroid window, int accessPoint) {
    Activity activity = window.getActivity().get();
    if (activity != null) {
        AccountSigninActivity.startIfAllowed(activity, accessPoint);
    }
}
 
Example #22
Source File: Tab.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a fresh tab. initialize() needs to be called afterwards to complete the second level
 * initialization.
 * @param initiallyHidden true iff the tab being created is initially in background
 */
public static Tab createLiveTab(int id, ChromeActivity activity, boolean incognito,
        WindowAndroid nativeWindow, TabLaunchType type, int parentId, boolean initiallyHidden) {
    return new Tab(id, parentId, incognito, activity, nativeWindow, type, initiallyHidden
            ? TabCreationState.LIVE_IN_BACKGROUND
            : TabCreationState.LIVE_IN_FOREGROUND, null);
}
 
Example #23
Source File: AutofillKeyboardAccessoryBridge.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes this object.
 * This function should be called at most one time.
 * @param nativeAutofillKeyboardAccessory Handle to the native counterpart.
 * @param windowAndroid The window on which to show the suggestions.
 */
@CalledByNative
private void init(long nativeAutofillKeyboardAccessory, WindowAndroid windowAndroid) {
    if (windowAndroid == null || windowAndroid.getActivity().get() == null) {
        nativeViewDismissed(nativeAutofillKeyboardAccessory);
        dismissed();
        return;
    }

    mNativeAutofillKeyboardAccessory = nativeAutofillKeyboardAccessory;
    mAccessoryView = new AutofillKeyboardAccessory(windowAndroid, this);
    mContext = windowAndroid.getActivity().get();
}
 
Example #24
Source File: GroupedPermissionInfoBar.java    From delion with Apache License 2.0 5 votes vote down vote up
GroupedPermissionInfoBar(String message, String buttonOk, String buttonCancel,
        int[] permissionIcons, String[] permissionText, WindowAndroid windowAndroid,
        int[] contentSettings) {
    super(0, null, message, null, buttonOk, buttonCancel);
    mPermissionIcons = permissionIcons;
    mPermissionText = permissionText;
    mWindowAndroid = windowAndroid;
    mContentSettings = contentSettings;
}
 
Example #25
Source File: ExternalNavigationDelegateImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Get a {@link Context} linked to this delegate with preference to {@link Activity}.
 * The tab this delegate associates with can swap the {@link Activity} it is hosted in and
 * during the swap, there might not be an available {@link Activity}.
 * @return The activity {@link Context} if it can be reached.
 *         Application {@link Context} if not.
 */
protected final Context getAvailableContext() {
    if (mTab.getWindowAndroid() == null) return mApplicationContext;
    Context activityContext = WindowAndroid.activityFromContext(
            mTab.getWindowAndroid().getContext().get());
    if (activityContext == null) return mApplicationContext;
    return activityContext;
}
 
Example #26
Source File: CardUnmaskBridge.java    From delion with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static CardUnmaskBridge create(long nativeUnmaskPrompt, String title,
        String instructions, String confirmButtonLabel, int iconId,
        boolean shouldRequestExpirationDate, boolean canStoreLocally,
        boolean defaultToStoringLocally, WindowAndroid windowAndroid) {
    return new CardUnmaskBridge(nativeUnmaskPrompt, title, instructions, confirmButtonLabel,
            iconId, shouldRequestExpirationDate, canStoreLocally, defaultToStoringLocally,
            windowAndroid);
}
 
Example #27
Source File: ConfirmInfoBar.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Specifies the {@link ContentSettingsType}s that are controlled by this InfoBar.
 *
 * @param windowAndroid The WindowAndroid that will be used to check for the necessary
 *                      permissions.
 * @param contentSettings The list of {@link ContentSettingsType}s whose access is guarded
 *                        by this InfoBar.
 */
protected void setContentSettings(
        WindowAndroid windowAndroid, int[] contentSettings) {
    mWindowAndroid = windowAndroid;
    assert windowAndroid != null
            : "A WindowAndroid must be specified to request access to content settings";

    mContentSettingsToPermissionsMap = generatePermissionsMapping(contentSettings);
}
 
Example #28
Source File: UsbChooserDialog.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static UsbChooserDialog create(WindowAndroid windowAndroid, String origin,
        int securityLevel, long nativeUsbChooserDialogPtr) {
    Activity activity = windowAndroid.getActivity().get();
    if (activity == null) {
        return null;
    }

    UsbChooserDialog dialog = new UsbChooserDialog(nativeUsbChooserDialogPtr);
    dialog.show(activity, origin, securityLevel);
    return dialog;
}
 
Example #29
Source File: ContentViewCore.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void addDisplayAndroidObserverIfNeeded() {
    if (!mAttachedToWindow) return;
    WindowAndroid windowAndroid = getWindowAndroid();
    if (windowAndroid != null) {
        DisplayAndroid display = windowAndroid.getDisplay();
        display.addObserver(this);
        onRotationChanged(display.getRotation());
        onDIPScaleChanged(display.getDipScale());
    }
}
 
Example #30
Source File: ScreenOrientationProvider.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
static void unlockOrientation(@Nullable WindowAndroid window) {
    // WindowAndroid may be null if the tab is being reparented.
    if (window == null) return;
    Activity activity = window.getActivity().get();

    // Locking orientation is only supported for web contents that have an associated activity.
    // Note that we can't just use the focused activity, as that would lead to bugs where
    // unlockOrientation unlocks a different activity to the one that was locked.
    if (activity == null) return;

    int defaultOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;

    // Activities opened from a shortcut may have EXTRA_ORIENTATION set. In
    // which case, we want to use that as the default orientation.
    int orientation = activity.getIntent().getIntExtra(
            ScreenOrientationConstants.EXTRA_ORIENTATION,
            ScreenOrientationValues.DEFAULT);
    defaultOrientation = getOrientationFromWebScreenOrientations(
            (byte) orientation, window, activity);

    try {
        if (defaultOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
            ActivityInfo info = activity.getPackageManager().getActivityInfo(
                    activity.getComponentName(), PackageManager.GET_META_DATA);
            defaultOrientation = info.screenOrientation;
        }
    } catch (PackageManager.NameNotFoundException e) {
        // Do nothing, defaultOrientation should be SCREEN_ORIENTATION_UNSPECIFIED.
    } finally {
        activity.setRequestedOrientation(defaultOrientation);
    }
}