org.chromium.chrome.browser.ChromeApplication Java Examples

The following examples show how to use org.chromium.chrome.browser.ChromeApplication. 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: PhysicalWebPreferenceFragment.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[],
                                       int[] grantResults) {
    switch (requestCode) {
        case REQUEST_ID:
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                PhysicalWebUma.onPrefsLocationGranted(getActivity());
                Log.d(TAG, "Location permission granted");
                PhysicalWeb.startPhysicalWeb(
                        (ChromeApplication) getActivity().getApplicationContext());
            } else {
                PhysicalWebUma.onPrefsLocationDenied(getActivity());
                Log.d(TAG, "Location permission denied");
            }
            break;
        default:
    }
}
 
Example #2
Source File: LayoutManagerDocument.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void changeTabs() {
    DocumentTabModelSelector selector =
            ChromeApplication.getDocumentTabModelSelector();
    TabModel tabModel = selector.getCurrentModel();
    int currentIndex = tabModel.index();
    if (mLastScroll == ScrollDirection.LEFT) {
        if (currentIndex < tabModel.getCount() - 1) {
            TabModelUtils.setIndex(tabModel, currentIndex + 1);
        }
    } else {
        if (currentIndex > 0) {
            TabModelUtils.setIndex(tabModel, currentIndex - 1);
        }
    }
}
 
Example #3
Source File: CustomTabsConnection.java    From delion with Apache License 2.0 6 votes vote down vote up
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) {
    ThreadUtils.assertOnUiThread();
    try {
        ChromeBrowserInitializer.getInstance(app).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Cannot do anything without the native library, and cannot show a
        // dialog to the user.
        System.exit(-1);
    }
    final Context context = app.getApplicationContext();
    final ChromeApplication chrome = (ChromeApplication) context;
    ChildProcessCreationParams.set(chrome.getChildProcessCreationParams());
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            ChildProcessLauncher.warmUp(context);
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    ChromeBrowserInitializer.initNetworkChangeNotifier(context);
    WarmupManager.getInstance().initializeViewHierarchy(
            context, R.layout.custom_tabs_control_container);
}
 
Example #4
Source File: TabWebContentsObserver.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void didFailLoad(boolean isProvisionalLoad, boolean isMainFrame, int errorCode,
        String description, String failingUrl, boolean wasIgnoredByHandler) {
    mTab.updateThemeColorIfNeeded(true);
    RewindableIterator<TabObserver> observers = mTab.getTabObservers();
    while (observers.hasNext()) {
        observers.next().onDidFailLoad(mTab, isProvisionalLoad, isMainFrame, errorCode,
                description, failingUrl);
    }

    if (isMainFrame) mTab.didFailPageLoad(errorCode);

    PolicyAuditor auditor =
            ((ChromeApplication) mTab.getApplicationContext()).getPolicyAuditor();
    auditor.notifyAuditEvent(mTab.getApplicationContext(), AuditEvent.OPEN_URL_FAILURE,
            failingUrl, description);
    if (errorCode == BLOCKED_BY_ADMINISTRATOR) {
        auditor.notifyAuditEvent(
                mTab.getApplicationContext(), AuditEvent.OPEN_URL_BLOCKED, failingUrl, "");
    }
}
 
Example #5
Source File: TabWebContentsObserver.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void didAttachInterstitialPage() {
    mTab.getInfoBarContainer().setVisibility(View.INVISIBLE);
    mTab.showRenderedPage();
    mTab.updateThemeColorIfNeeded(false);

    RewindableIterator<TabObserver> observers = mTab.getTabObservers();
    while (observers.hasNext()) {
        observers.next().onDidAttachInterstitialPage(mTab);
    }
    mTab.notifyLoadProgress(mTab.getProgress());

    mTab.updateFullscreenEnabledState();

    PolicyAuditor auditor =
            ((ChromeApplication) mTab.getApplicationContext()).getPolicyAuditor();
    auditor.notifyCertificateFailure(
            PolicyAuditor.nativeGetCertificateFailure(mTab.getWebContents()),
            mTab.getApplicationContext());
}
 
Example #6
Source File: TabWebContentsObserver.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void didFailLoad(boolean isProvisionalLoad, boolean isMainFrame, int errorCode,
        String description, String failingUrl, boolean wasIgnoredByHandler) {
    RewindableIterator<TabObserver> observers = mTab.getTabObservers();
    while (observers.hasNext()) {
        observers.next().onDidFailLoad(mTab, isProvisionalLoad, isMainFrame, errorCode,
                description, failingUrl);
    }

    if (isMainFrame) mTab.didFailPageLoad(errorCode);

    PolicyAuditor auditor =
            ((ChromeApplication) mTab.getApplicationContext()).getPolicyAuditor();
    auditor.notifyAuditEvent(mTab.getApplicationContext(), AuditEvent.OPEN_URL_FAILURE,
            failingUrl, description);
    if (errorCode == BLOCKED_BY_ADMINISTRATOR) {
        auditor.notifyAuditEvent(
                mTab.getApplicationContext(), AuditEvent.OPEN_URL_BLOCKED, failingUrl, "");
    }
}
 
Example #7
Source File: PhysicalWeb.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Perform various Physical Web operations that should happen on startup.
 * @param application An instance of {@link ChromeApplication}.
 */
public static void onChromeStart(ChromeApplication application) {
    // The PhysicalWebUma calls in this method should be called only when the native library is
    // loaded.  This is always the case on chrome startup.
    if (featureIsEnabled()
            && (isPhysicalWebPreferenceEnabled(application) || isOnboarding(application))) {
        boolean ignoreOtherClients =
                ChromeFeatureList.isEnabled(IGNORE_OTHER_CLIENTS_FEATURE_NAME);
        ContextUtils.getAppSharedPreferences().edit()
                .putBoolean(PREF_IGNORE_OTHER_CLIENTS, ignoreOtherClients)
                .apply();
        startPhysicalWeb(application);
        PhysicalWebUma.uploadDeferredMetrics(application);
    } else {
        stopPhysicalWeb(application);
    }
}
 
Example #8
Source File: TabWebContentsObserver.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void didAttachInterstitialPage() {
    mTab.getInfoBarContainer().setVisibility(View.INVISIBLE);
    mTab.showRenderedPage();
    mTab.updateThemeColorIfNeeded(false);

    RewindableIterator<TabObserver> observers = mTab.getTabObservers();
    while (observers.hasNext()) {
        observers.next().onDidAttachInterstitialPage(mTab);
    }
    mTab.notifyLoadProgress(mTab.getProgress());

    mTab.updateFullscreenEnabledState();

    PolicyAuditor auditor =
            ((ChromeApplication) mTab.getApplicationContext()).getPolicyAuditor();
    auditor.notifyCertificateFailure(
            PolicyAuditor.nativeGetCertificateFailure(mTab.getWebContents()),
            mTab.getApplicationContext());
}
 
Example #9
Source File: LayoutManagerDocument.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void changeTabs() {
    DocumentTabModelSelector selector =
            ChromeApplication.getDocumentTabModelSelector();
    TabModel tabModel = selector.getCurrentModel();
    int currentIndex = tabModel.index();
    if (mLastScroll == ScrollDirection.LEFT) {
        if (currentIndex < tabModel.getCount() - 1) {
            TabModelUtils.setIndex(tabModel, currentIndex + 1);
        }
    } else {
        if (currentIndex > 0) {
            TabModelUtils.setIndex(tabModel, currentIndex - 1);
        }
    }
}
 
Example #10
Source File: DomDistillerUIUtils.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * A static method for native code to open the external feedback form UI.
 * @param webContents The WebContents containing the distilled content.
 * @param url The URL to report feedback for.
 * @param good True if the feedback is good and false if not.
 */
@CalledByNative
public static void reportFeedbackWithWebContents(
        WebContents webContents, String url, final boolean good) {
    ThreadUtils.assertOnUiThread();
    // TODO(mdjones): It would be better to get the WebContents from the manager so that the
    // native code does not need to depend on RenderFrame.
    Activity activity = getActivityFromWebContents(webContents);
    if (activity == null) return;

    if (sFeedbackReporter == null) {
        ChromeApplication application = (ChromeApplication) activity.getApplication();
        sFeedbackReporter = application.createFeedbackReporter();
    }
    FeedbackCollector.create(activity, Profile.getLastUsedProfile(), url,
            new FeedbackCollector.FeedbackResult() {
                @Override
                public void onResult(FeedbackCollector collector) {
                    String quality =
                            good ? DISTILLATION_QUALITY_GOOD : DISTILLATION_QUALITY_BAD;
                    collector.add(DISTILLATION_QUALITY_KEY, quality);
                    sFeedbackReporter.reportFeedback(collector);
                }
            });
}
 
Example #11
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) {
    ThreadUtils.assertOnUiThread();
    try {
        ChromeBrowserInitializer.getInstance(app).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Cannot do anything without the native library, and cannot show a
        // dialog to the user.
        System.exit(-1);
    }
    final Context context = app.getApplicationContext();
    final ChromeApplication chrome = (ChromeApplication) context;
    ChildProcessCreationParams.set(chrome.getChildProcessCreationParams());
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            ChildProcessLauncher.warmUp(context);
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    ChromeBrowserInitializer.initNetworkChangeNotifier(context);
    WarmupManager.getInstance().initializeViewHierarchy(
            context, R.layout.custom_tabs_control_container, R.layout.custom_tabs_toolbar);
}
 
Example #12
Source File: LayoutManagerDocument.java    From delion with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void changeTabs() {
    DocumentTabModelSelector selector =
            ChromeApplication.getDocumentTabModelSelector();
    TabModel tabModel = selector.getCurrentModel();
    int currentIndex = tabModel.index();
    if (mLastScroll == ScrollDirection.LEFT) {
        if (currentIndex < tabModel.getCount() - 1) {
            TabModelUtils.setIndex(tabModel, currentIndex + 1);
        }
    } else {
        if (currentIndex > 0) {
            TabModelUtils.setIndex(tabModel, currentIndex - 1);
        }
    }
}
 
Example #13
Source File: LayoutManagerDocumentTabSwitcher.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void initLayoutTabFromHost(final int tabId) {
    if (getTabModelSelector() == null || getActiveLayout() == null) return;

    TabModelSelector selector = ChromeApplication.getDocumentTabModelSelector();
    Tab tab = selector.getTabById(tabId);
    if (tab == null) return;

    LayoutTab layoutTab = getExistingLayoutTab(tabId);
    if (layoutTab == null) return;

    if (mTitleCache != null && layoutTab.isTitleNeeded()) {
        mTitleCache.getUpdatedTitle(tab, "");
    }
    super.initLayoutTabFromHost(tabId);
}
 
Example #14
Source File: LayoutManagerDocumentTabSwitcher.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void init(TabModelSelector selector, TabCreatorManager creator,
        TabContentManager content, ViewGroup androidContentContainer,
        ContextualSearchManagementDelegate contextualSearchDelegate,
        ReaderModeManagerDelegate readerModeManagerDelegate,
        DynamicResourceLoader dynamicResourceLoader) {
    super.init(selector, creator, content, androidContentContainer, contextualSearchDelegate,
            readerModeManagerDelegate, dynamicResourceLoader);

    mTitleCache = mHost.getTitleCache();
    TabModelSelector documentTabSelector = ChromeApplication.getDocumentTabModelSelector();
    mOverviewListLayout.setTabModelSelector(documentTabSelector, content);
    mOverviewLayout.setTabModelSelector(documentTabSelector, content);

    // TODO(changwan): do we really need this?
    startShowing(getDefaultLayout(), false);
}
 
Example #15
Source File: HelpAndFeedback.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the singleton instance of HelpAndFeedback, creating it if needed.
 */
@SuppressFBWarnings("LI_LAZY_INIT_STATIC")
public static HelpAndFeedback getInstance(Context context) {
    ThreadUtils.assertOnUiThread();
    if (sInstance == null) {
        sInstance = ((ChromeApplication) context.getApplicationContext())
                .createHelpAndFeedback();
    }
    return sInstance;
}
 
Example #16
Source File: AccountsChangedReceiver.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("DM_EXIT")
private static void startBrowserIfNeededAndValidateAccounts(final Context context) {
    BrowserParts parts = new EmptyBrowserParts() {
        @Override
        public void finishNativeInitialization() {
            ThreadUtils.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    SigninHelper.get(context).validateAccountSettings(true);
                }
            });
        }

        @Override
        public void onStartupFailure() {
            // Startup failed. So notify SigninHelper of changed accounts via
            // shared prefs.
            SigninHelper.markAccountsChangedPref(context);
        }
    };
    try {
        ChromeBrowserInitializer.getInstance(context).handlePreNativeStartup(parts);
        ChromeBrowserInitializer.getInstance(context).handlePostNativeStartup(true, parts);
    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        ChromeApplication.reportStartupErrorAndExit(e);
    }
}
 
Example #17
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return The unique instance of ChromeCustomTabsConnection.
 * TODO(estevenson): Remove Application param.
 */
@SuppressFBWarnings("BC_UNCONFIRMED_CAST")
public static CustomTabsConnection getInstance(Application application) {
    if (sInstance.get() == null) {
        ((ChromeApplication) application).initCommandLine();
        sInstance.compareAndSet(null, AppHooks.get().createCustomTabsConnection());
    }
    return sInstance.get();
}
 
Example #18
Source File: RevenueStats.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the singleton instance of ExternalAuthUtils, creating it if needed.
 */
public static RevenueStats getInstance() {
    if (sInstance.get() == null) {
        ChromeApplication application =
                (ChromeApplication) ContextUtils.getApplicationContext();
        sInstance.compareAndSet(null, application.createRevenueStatsInstance());
    }
    return sInstance.get();
}
 
Example #19
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return The unique instance of ChromeCustomTabsConnection.
 */
@SuppressFBWarnings("BC_UNCONFIRMED_CAST")
public static CustomTabsConnection getInstance(Application application) {
    if (sInstance.get() == null) {
        ChromeApplication chromeApplication = (ChromeApplication) application;
        chromeApplication.initCommandLine();
        sInstance.compareAndSet(null, chromeApplication.createCustomTabsConnection());
    }
    return sInstance.get();
}
 
Example #20
Source File: MultiWindowUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the singleton instance of MultiWindowUtils, creating it if needed.
 */
public static MultiWindowUtils getInstance() {
    if (sInstance.get() == null) {
        ChromeApplication application =
                (ChromeApplication) ContextUtils.getApplicationContext();
        sInstance.compareAndSet(null, application.createMultiWindowUtils());
    }
    return sInstance.get();
}
 
Example #21
Source File: InstantAppsHandler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** @return The singleton instance of {@link InstantAppsHandler}. */
public static InstantAppsHandler getInstance() {
    synchronized (INSTANCE_LOCK) {
        if (sInstance == null) {
            Context appContext = ContextUtils.getApplicationContext();
            sInstance = ((ChromeApplication) appContext).createInstantAppsHandler();
        }
    }
    return sInstance;
}
 
Example #22
Source File: PhysicalWebBleClient.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Get a singleton instance of this class.
 * @return an instance of this class (or subclass).
 */
public static PhysicalWebBleClient getInstance() {
    if (sInstance == null) {
        sInstance = ((ChromeApplication) ContextUtils.getApplicationContext())
                .createPhysicalWebBleClient();
    }
    return sInstance;
}
 
Example #23
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void configureGoogleActivityControls() {
    Preference pref = findPreference(PREF_GOOGLE_ACTIVITY_CONTROLS);
    pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Activity activity = getActivity();
            ((ChromeApplication) (activity.getApplicationContext()))
                    .createGoogleActivityController()
                    .openWebAndAppActivitySettings(activity,
                            ChromeSigninController.get(activity).getSignedInAccountName());
            RecordUserAction.record("Signin_AccountSettings_GoogleActivityControlsClicked");
            return true;
        }
    });
}
 
Example #24
Source File: LocationSettings.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the singleton instance of LocationSettings, creating it if needed.
 */
@SuppressFBWarnings("LI_LAZY_INIT_STATIC")
public static LocationSettings getInstance() {
    ThreadUtils.assertOnUiThread();
    if (sInstance == null) {
        ChromeApplication application =
                (ChromeApplication) ContextUtils.getApplicationContext();
        sInstance = application.createLocationSettings();
    }
    return sInstance;
}
 
Example #25
Source File: GSAServiceClient.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance of this class.
 *
 * @param context Appliation context.
 * @param onMessageReceived optional callback when a message is received.
 */
GSAServiceClient(Context context, Callback<Bundle> onMessageReceived) {
    mContext = context.getApplicationContext();
    mOnMessageReceived = onMessageReceived;
    mHandler = new IncomingHandler();
    mMessenger = new Messenger(mHandler);
    mConnection = new GSAServiceConnection();
    mGsaHelper = ((ChromeApplication) mContext.getApplicationContext())
            .createGsaHelper();
}
 
Example #26
Source File: ChildAccountFeedbackReporter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
public static void reportFeedback(Activity activity, final String description, String url) {
    ThreadUtils.assertOnUiThread();
    if (sFeedbackReporter == null) {
        ChromeApplication application = (ChromeApplication) activity.getApplication();
        sFeedbackReporter = application.createFeedbackReporter();
    }
    FeedbackCollector.create(activity, Profile.getLastUsedProfile(), url,
            new FeedbackCollector.FeedbackResult() {
                @Override
                public void onResult(FeedbackCollector collector) {
                    collector.setDescription(description);
                    sFeedbackReporter.reportFeedback(collector);
                }
            });
}
 
Example #27
Source File: ExternalAuthUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the singleton instance of ExternalAuthUtils, creating it if needed.
 */
public static ExternalAuthUtils getInstance() {
    if (sInstance.get() == null) {
        ChromeApplication application =
                (ChromeApplication) ContextUtils.getApplicationContext();
        sInstance.compareAndSet(null, application.createExternalAuthUtils());
    }
    return sInstance.get();
}
 
Example #28
Source File: Tab.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onSSLStateUpdated(Tab tab) {
    PolicyAuditor auditor =
            ((ChromeApplication) getApplicationContext()).getPolicyAuditor();
    auditor.notifyCertificateFailure(
            PolicyAuditor.nativeGetCertificateFailure(getWebContents()),
            getApplicationContext());
    updateFullscreenEnabledState();
    updateThemeColorIfNeeded(false);
}
 
Example #29
Source File: InterceptNavigationDelegateImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new instance of {@link InterceptNavigationDelegateImpl} with the given
 * {@link ExternalNavigationHandler}.
 */
public InterceptNavigationDelegateImpl(ExternalNavigationHandler externalNavHandler, Tab tab) {
    mTab = tab;
    mExternalNavHandler = externalNavHandler;
    mAuthenticatorHelper = ((ChromeApplication) mTab.getApplicationContext())
            .createAuthenticatorNavigationInterceptor(mTab);
}
 
Example #30
Source File: WebApkActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes {@link ChildProcessCreationParams} as a WebAPK's renderer process if
 * {@link isForWebApk}} is true; as Chrome's child process otherwise.
 * @param isForWebApk: Whether the {@link ChildProcessCreationParams} is initialized as a
 *                     WebAPK renderer process.
 */
private void initializeChildProcessCreationParams(boolean isForWebApk) {
    // TODO(hanxi): crbug.com/664530. WebAPKs shouldn't use a global ChildProcessCreationParams.
    ChromeApplication chrome = (ChromeApplication) ContextUtils.getApplicationContext();
    ChildProcessCreationParams params = chrome.getChildProcessCreationParams();
    if (isForWebApk) {
        boolean isExternalService = false;
        params = new ChildProcessCreationParams(getWebappInfo().webApkPackageName(),
                isExternalService, LibraryProcessType.PROCESS_CHILD);
    }
    ChildProcessCreationParams.set(params);
}