OSDN Git Service

Fix #1722851. Move the Browser's default home page to the resource so that we can...
authorGrace Kloba <klobag@google.com>
Tue, 26 May 2009 17:48:31 +0000 (10:48 -0700)
committerGrace Kloba <klobag@google.com>
Tue, 26 May 2009 17:48:31 +0000 (10:48 -0700)
res/values/strings.xml
src/com/android/browser/BrowserActivity.java
src/com/android/browser/BrowserSettings.java

index e91a6b6..7b50a2a 100644 (file)
     <!-- Do not translate.  Testing only -->
     <string name="dump_nav" translatable="false">Dump navigation cache</string>
 
+    <!-- The default homepage. If it starts with "http://www.google" and the
+            user signs up the device with a Google sites account, the site's
+            domain will be appended. -->
+    <string name="homepage_base">http://www.google.com/m?client=ms-{CID}</string>
+
     <!-- Bookmarks -->
     <string-array name="bookmarks" translatable="false">
         <item>Google</item>
index 5caee36..cf3528e 100644 (file)
@@ -190,6 +190,9 @@ public class BrowserActivity extends Activity
                 try {
                     if (mGls == null) return;
 
+                    if (!homepage.startsWith("http://www.google.")) return;
+                    if (homepage.indexOf('?') == -1) return;
+
                     String hostedUser = mGls.getAccount(GoogleLoginServiceConstants.PREFER_HOSTED);
                     String googleUser = mGls.getAccount(GoogleLoginServiceConstants.REQUIRE_GOOGLE);
 
@@ -209,8 +212,7 @@ public class BrowserActivity extends Activity
 
                     if (googleUser == null || !hostedUser.equals(googleUser)) {
                         String domain = hostedUser.substring(hostedUser.lastIndexOf('@')+1);
-                        homepage = "http://www.google.com/m/a/" + domain + "?client=ms-" +
-                            Partner.getString(BrowserActivity.this.getContentResolver(), Partner.CLIENT_ID);
+                        homepage = homepage.replace("?", "/a/" + domain + "?");
                     }
                 } catch (RemoteException ignore) {
                     // Login service died; carry on
index 0e2c5af..65985eb 100644 (file)
@@ -67,7 +67,7 @@ class BrowserSettings extends Observable {
     private boolean saveFormData = true;
     private boolean openInBackground = false;
     private String defaultTextEncodingName;
-    private String homeUrl = "http://www.google.com/m?client=ms-";
+    private String homeUrl = "";
     private boolean loginInitialized = false;
     private boolean autoFitPage = true;
     private boolean showDebugSettings = false;
@@ -199,7 +199,7 @@ class BrowserSettings extends Observable {
         // local directory.
         pluginsPath = ctx.getDir("plugins", 0).getPath();
 
-        homeUrl += Partner.getString(ctx.getContentResolver(), Partner.CLIENT_ID);
+        homeUrl = getFactoryResetHomeUrl(ctx);
 
         // Load the defaults from the xml
         // This call is TOO SLOW, need to manually keep the defaults
@@ -439,6 +439,17 @@ class BrowserSettings extends Observable {
         p.edit().clear().commit();
         PreferenceManager.setDefaultValues(context, R.xml.browser_preferences,
                 true);
+        // reset homeUrl
+        setHomePage(context, getFactoryResetHomeUrl(context));
+    }
+
+    private String getFactoryResetHomeUrl(Context context) {
+        String url = context.getResources().getString(R.string.homepage_base);
+        if (url.indexOf("{CID}") != -1) {
+            url = url.replace("{CID}", Partner.getString(context
+                    .getContentResolver(), Partner.CLIENT_ID));
+        }
+        return url;
     }
 
     // Private constructor that does nothing.