Move creation dummy Webview for loading native libraries to
Preloader constructor

 - Remove all the hacks to intialize CookieManager since
   we already loaded native libraries in Preloader

Change-Id: I7489d1692b45a86c1582d14e2281bbfa6ae0d74a
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index e3f31c0..fc70a76 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -137,9 +137,6 @@
     // add for carrier feature
     private static Context sResPackageCtx;
 
-    //Determine if WebView is Initialized or not
-    private boolean mWebViewInitialized;
-
     public static void initialize(final Context context) {
         sInstance = new BrowserSettings(context);
     }
@@ -164,7 +161,6 @@
             Log.e("Res_Update", "Create Res Apk Failed");
         }
         BackgroundHandler.execute(mSetup);
-        mWebViewInitialized = false;
     }
 
     public void setController(Controller controller) {
@@ -198,10 +194,6 @@
         }
     }
 
-    public void initializeCookieSettings() {
-        CookieManager.getInstance().setAcceptCookie(acceptCookies());
-        mWebViewInitialized = true;
-    }
     private Runnable mSetup = new Runnable() {
 
         @Override
@@ -445,9 +437,8 @@
 
     private void syncSharedSettings() {
         mNeedsSharedSync = false;
-        if (mWebViewInitialized) {
-            CookieManager.getInstance().setAcceptCookie(acceptCookies());
-        }
+        CookieManager.getInstance().setAcceptCookie(acceptCookies());
+
         if (mController != null) {
             mController.setShouldShowErrorConsole(enableJavascriptConsole());
         }
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index c0ffd83..e3a7308 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -267,11 +267,6 @@
         mIntentHandler = new IntentHandler(mActivity, this);
         mPageDialogsHandler = new PageDialogsHandler(mActivity, this);
 
-        // Creating dummy Webview for browser to force loading of library;
-        // in order for CookieManager calls to be invoked properly and
-        // awBrowserContext to be initialized
-        (mFactory.createWebView(false)).destroy();
-
         startHandler();
         mBookmarksObserver = new ContentObserver(mHandler) {
             @Override
@@ -319,7 +314,6 @@
         final long currentTabId =
                 mTabControl.canRestoreState(icicle, restoreIncognitoTabs);
 
-        mSettings.initializeCookieSettings();
         if (currentTabId == -1) {
             // Not able to restore so we go ahead and clear session cookies.  We
             // must do this before trying to login the user as we don't want to
diff --git a/src/com/android/browser/Preloader.java b/src/com/android/browser/Preloader.java
index 7d8c367..99909b3 100644
--- a/src/com/android/browser/Preloader.java
+++ b/src/com/android/browser/Preloader.java
@@ -54,6 +54,10 @@
         mSession = null;
         mFactory = new BrowserWebViewFactory(context);
 
+        // Creating dummy Webview for browser to force loading of library;
+        // This will thereby prevent any singleton calls invoked directly
+        // even without the webview creation
+        (mFactory.instantiateWebView(null, android.R.attr.webViewStyle, false)).destroy();
     }
 
     private PreloaderSession getSession(String id) {