// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.chrome.browser;

import android.os.Build;

import org.chromium.base.CalledByNative;
import org.chromium.chrome.browser.preferences.LocationSettings;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.ProtectedContentPreferences;
import org.chromium.chrome.browser.preferences.autofill.AutofillPreferences;
import org.chromium.chrome.browser.preferences.password.ManageSavedPasswordsPreferences;
import org.chromium.content.app.ContentApplication;

/**
 * Basic application functionality that should be shared among all browser applications that use
 * chrome layer.
 */
public abstract class ChromiumApplication extends ContentApplication {

    /**
     * Returns the class name of the Settings activity.
     */
    public abstract String getSettingsActivityName();

    /**
     * Opens a protected content settings page, if available.
     */
    @CalledByNative
    protected void openProtectedContentSettings() {
        assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
        PreferencesLauncher.launchSettingsPage(this,
                ProtectedContentPreferences.class.getName());
    }

    @CalledByNative
    protected void showAutofillSettings() {
        PreferencesLauncher.launchSettingsPage(this,
                AutofillPreferences.class.getName());
    }

    @CalledByNative
    protected void showPasswordSettings() {
        PreferencesLauncher.launchSettingsPage(this,
                ManageSavedPasswordsPreferences.class.getName());
    }

    /**
     * Returns an instance of LocationSettings to be installed as a singleton.
     */
    public LocationSettings createLocationSettings() {
        return new LocationSettings(this);
    }

    /**
     * Opens the UI to clear browsing data.
     * @param tab The tab that triggered the request.
     */
    @CalledByNative
    protected void openClearBrowsingData(Tab tab) {}

    /**
     * @return Whether parental controls are enabled.  Returning true will disable
     *         incognito mode.
     */
    @CalledByNative
    protected abstract boolean areParentalControlsEnabled();

    // TODO(yfriedman): This is too widely available. Plumb this through ChromeNetworkDelegate
    // instead.
    protected abstract PKCS11AuthenticationManager getPKCS11AuthenticationManager();

    /**
     * @return The user agent string of Chrome.
     */
    public static String getBrowserUserAgent() {
        return nativeGetBrowserUserAgent();
    }

    private static native String nativeGetBrowserUserAgent();
}

@@ -197,16 +197,48 @@
 owser;%0A%0A
+import android.content.Context;%0A
 import a
@@ -296,16 +296,116 @@
 Native;%0A
+import org.chromium.base.ThreadUtils;%0Aimport org.chromium.base.library_loader.ProcessInitException;%0A
 import o
@@ -822,16 +822,78 @@
 ication;
+%0Aimport org.chromium.content.browser.BrowserStartupController;
 %0A%0A/**%0A *
@@ -1907,32 +1907,1110 @@
 Name());%0A    %7D%0A%0A
+    /**%0A     * For extending classes to carry out tasks that initialize the browser process.%0A     * Should be called almost immediately after the native library has loaded to initialize things%0A     * that really, really have to be set up early.  Avoid putting any long tasks here.%0A     */%0A    public void initializeProcess() %7B %7D%0A%0A    /**%0A     * Start the browser process asynchronously. This will set up a queue of UI%0A     * thread tasks to initialize the browser process.%0A     *%0A     * Note that this can only be called on the UI thread.%0A     *%0A     * @param callback the callback to be called when browser startup is complete.%0A     * @throws ProcessInitException%0A     */%0A    public void startChromeBrowserProcessesAsync(BrowserStartupController.StartupCallback callback)%0A            throws ProcessInitException %7B%0A        assert ThreadUtils.runningOnUiThread() : %22Tried to start the browser on the wrong thread%22;%0A        Context applicationContext = getApplicationContext();%0A        BrowserStartupController.get(applicationContext).startBrowserProcessesAsync(callback);%0A    %7D%0A%0A
     /**%0A     * R

Add process initialization APIs to ChromiumApplication