OSDN Git Service

am bcd20b3: Import clean-up in BrowserProvider.
authorBjorn Bringert <bringert@android.com>
Thu, 30 Apr 2009 16:20:54 +0000 (09:20 -0700)
committerThe Android Open Source Project <initial-contribution@android.com>
Thu, 30 Apr 2009 16:20:54 +0000 (09:20 -0700)
Merge commit 'bcd20b33a57c6505eb610c9d0bad2aa643bc2dfc'

* commit 'bcd20b33a57c6505eb610c9d0bad2aa643bc2dfc':
  Import clean-up in BrowserProvider.

res/values/strings.xml
res/xml/browser_preferences.xml
src/com/android/browser/BrowserActivity.java
src/com/android/browser/BrowserDownloadAdapter.java
src/com/android/browser/BrowserDownloadPage.java
src/com/android/browser/BrowserHomepagePreference.java
src/com/android/browser/BrowserProvider.java
src/com/android/browser/BrowserSettings.java
src/com/android/browser/FetchUrlMimeType.java
src/com/android/browser/FindDialog.java
src/com/android/browser/TabControl.java

index 98142ac..82e4602 100644 (file)
     <string name="pref_content_autofit">Auto-fit pages</string>
     <!-- Settings summary -->
     <string name="pref_content_autofit_summary">Format Web pages to fit the screen</string>
+    <!-- Settings label for enabling a mode where the browser is always set to landscape mode -->
+    <string name="pref_content_landscape_only">Landscape only display</string>
+    <!-- Settings summary -->
+    <string name="pref_content_landscape_only_summary">Always read pages in the wider, landscape screen orientation</string>
     <!-- Settings screen, section title -->
     <string name="pref_privacy_title">Privacy settings</string>
     <!-- Settings label -->
index fdfa839..79dfb92 100644 (file)
                 android:summary="@string/pref_content_autofit_summary" />  
 
         <CheckBoxPreference
+                android:key="landscape_only"
+                android:defaultValue="false"
+                android:title="@string/pref_content_landscape_only"
+                android:summary="@string/pref_content_landscape_only_summary" />
+
+        <CheckBoxPreference
                 android:key="enable_javascript"
                 android:defaultValue="true"
                 android:title="@string/pref_content_javascript" />     
index 9d5130f..46b3960 100644 (file)
@@ -1095,8 +1095,10 @@ public class BrowserActivity extends Activity
         super.onDestroy();
         // Remove the current tab and sub window
         TabControl.Tab t = mTabControl.getCurrentTab();
-        dismissSubWindow(t);
-        removeTabFromContentView(t);
+        if (t != null) {
+            dismissSubWindow(t);
+            removeTabFromContentView(t);
+        }
         // Destroy all the tabs
         mTabControl.destroy();
         WebIconDatabase.getInstance().close();
@@ -1875,7 +1877,7 @@ public class BrowserActivity extends Activity
     // the given Message. If the tab overview is already showing (i.e. this
     // method is called from TabListener.onClick(), the method will animate
     // away from the tab overview.
-    private void openTabAndShow(String url, final Message msg,
+    private TabControl.Tab openTabAndShow(String url, final Message msg,
             boolean closeOnExit, String appId) {
         final boolean newTab = mTabControl.getTabCount() != TabControl.MAX_TABS;
         final TabControl.Tab currentTab = mTabControl.getCurrentTab();
@@ -1904,9 +1906,10 @@ public class BrowserActivity extends Activity
                 }
                 // Animate from the Tab overview after any animations have
                 // finished.
-                sendAnimateFromOverview(
-                        mTabControl.createNewTab(closeOnExit, appId, url), true,
-                        url, delay, msg);
+                final TabControl.Tab tab = mTabControl.createNewTab(
+                        closeOnExit, appId, url);
+                sendAnimateFromOverview(tab, true, url, delay, msg);
+                return tab;
             }
         } else if (url != null) {
             // We should not have a msg here.
@@ -1921,6 +1924,7 @@ public class BrowserActivity extends Activity
                 currentTab.getWebView().loadUrl(url);
             }
         }
+        return currentTab;
     }
 
     private Animation createTabAnimation(final AnimatingView view,
@@ -2140,14 +2144,15 @@ public class BrowserActivity extends Activity
         mTabListener = null;
     }
 
-    private void openTab(String url) {
+    private TabControl.Tab openTab(String url) {
         if (mSettings.openInBackground()) {
             TabControl.Tab t = mTabControl.createNewTab();
             if (t != null) {
                 t.getWebView().loadUrl(url);
             }
+            return t;
         } else {
-            openTabAndShow(url, null, false, null);
+            return openTabAndShow(url, null, false, null);
         }
     }
 
@@ -2581,7 +2586,12 @@ public class BrowserActivity extends Activity
                             loadURL(getTopWindow(), url);
                             break;
                         case R.id.open_newtab_context_menu_id:
-                            openTab(url);
+                            final TabControl.Tab parent = mTabControl
+                                    .getCurrentTab();
+                            final TabControl.Tab newTab = openTab(url);
+                            if (newTab != parent) {
+                                parent.addChildTab(newTab);
+                            }
                             break;
                         case R.id.bookmark_context_menu_id:
                             Intent intent = new Intent(BrowserActivity.this,
@@ -3241,8 +3251,11 @@ public class BrowserActivity extends Activity
                 // openTabAndShow will dispatch the message after creating the
                 // new WebView. This will prevent another request from coming
                 // in during the animation.
-                openTabAndShow(null, msg, false, null);
-                parent.addChildTab(mTabControl.getCurrentTab());
+                final TabControl.Tab newTab = openTabAndShow(null, msg, false,
+                        null);
+                if (newTab != parent) {
+                    parent.addChildTab(newTab);
+                }
                 WebView.WebViewTransport transport =
                         (WebView.WebViewTransport) msg.obj;
                 transport.setWebView(mTabControl.getCurrentWebView());
@@ -3534,19 +3547,19 @@ public class BrowserActivity extends Activity
         String cookies = CookieManager.getInstance().getCookie(url);
 
         ContentValues values = new ContentValues();
-        values.put(Downloads.URI, uri.toString());
-        values.put(Downloads.COOKIE_DATA, cookies);
-        values.put(Downloads.USER_AGENT, userAgent);
-        values.put(Downloads.NOTIFICATION_PACKAGE,
+        values.put(Downloads.COLUMN_URI, uri.toString());
+        values.put(Downloads.COLUMN_COOKIE_DATA, cookies);
+        values.put(Downloads.COLUMN_USER_AGENT, userAgent);
+        values.put(Downloads.COLUMN_NOTIFICATION_PACKAGE,
                 getPackageName());
-        values.put(Downloads.NOTIFICATION_CLASS,
+        values.put(Downloads.COLUMN_NOTIFICATION_CLASS,
                 BrowserDownloadPage.class.getCanonicalName());
-        values.put(Downloads.VISIBILITY, Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
-        values.put(Downloads.MIMETYPE, mimetype);
-        values.put(Downloads.FILENAME_HINT, filename);
-        values.put(Downloads.DESCRIPTION, uri.getHost());
+        values.put(Downloads.COLUMN_VISIBILITY, Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
+        values.put(Downloads.COLUMN_MIME_TYPE, mimetype);
+        values.put(Downloads.COLUMN_FILE_NAME_HINT, filename);
+        values.put(Downloads.COLUMN_DESCRIPTION, uri.getHost());
         if (contentLength > 0) {
-            values.put(Downloads.TOTAL_BYTES, contentLength);
+            values.put(Downloads.COLUMN_TOTAL_BYTES, contentLength);
         }
         if (mimetype == null) {
             // We must have long pressed on a link or image to download it. We
@@ -4224,13 +4237,19 @@ public class BrowserActivity extends Activity
         AnimatingView(Context ctxt, TabControl.Tab t) {
             super(ctxt);
             mTab = t;
-            // Use the top window in the animation since the tab overview will
-            // display the top window in each cell.
-            final WebView w = t.getTopWindow();
-            mPicture = w.capturePicture();
-            mScale = w.getScale() / w.getWidth();
-            mScrollX = w.getScrollX();
-            mScrollY = w.getScrollY();
+            if (t != null && t.getTopWindow() != null) {
+                // Use the top window in the animation since the tab overview
+                // will display the top window in each cell.
+                final WebView w = t.getTopWindow();
+                mPicture = w.capturePicture();
+                mScale = w.getScale() / w.getWidth();
+                mScrollX = w.getScrollX();
+                mScrollY = w.getScrollY();
+            } else {
+                mPicture = null;
+                mScale = 1.0f;
+                mScrollX = mScrollY = 0;
+            }
         }
 
         @Override
@@ -4389,7 +4408,7 @@ public class BrowserActivity extends Activity
       return 0;
     }
 
-    static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile(
+    protected static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile(
             "(?i)" + // switch on case insensitive matching
             "(" +    // begin group for schema
             "(?:http|https|file):\\/\\/" +
index 38b83fe..16cb982 100644 (file)
@@ -60,14 +60,14 @@ public class BrowserDownloadAdapter extends ResourceCursorAdapter {
     public BrowserDownloadAdapter(Context context, int layout, Cursor c) {
         super(context, layout, c);
         mFilenameColumnId = c.getColumnIndexOrThrow(Downloads._DATA);
-        mTitleColumnId = c.getColumnIndexOrThrow(Downloads.TITLE);
-        mDescColumnId = c.getColumnIndexOrThrow(Downloads.DESCRIPTION);
-        mStatusColumnId = c.getColumnIndexOrThrow(Downloads.STATUS);
-        mTotalBytesColumnId = c.getColumnIndexOrThrow(Downloads.TOTAL_BYTES);
+        mTitleColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_TITLE);
+        mDescColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_DESCRIPTION);
+        mStatusColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_STATUS);
+        mTotalBytesColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_TOTAL_BYTES);
         mCurrentBytesColumnId = 
-            c.getColumnIndexOrThrow(Downloads.CURRENT_BYTES);
-        mMimetypeColumnId = c.getColumnIndexOrThrow(Downloads.MIMETYPE);
-        mDateColumnId = c.getColumnIndexOrThrow(Downloads.LAST_MODIFICATION);
+            c.getColumnIndexOrThrow(Downloads.COLUMN_CURRENT_BYTES);
+        mMimetypeColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_MIME_TYPE);
+        mDateColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_LAST_MODIFICATION);
     }
 
     @Override
@@ -106,7 +106,7 @@ public class BrowserDownloadAdapter extends ResourceCursorAdapter {
                 // We have a filename, so we can build a title from that
                 title = new File(fullFilename).getName();
                 ContentValues values = new ContentValues();
-                values.put(Downloads.TITLE, title);
+                values.put(Downloads.COLUMN_TITLE, title);
                 // assume "_id" is the first column for the cursor 
                 context.getContentResolver().update(
                         ContentUris.withAppendedId(Downloads.CONTENT_URI,
index 4397337..9776834 100644 (file)
@@ -73,22 +73,22 @@ public class BrowserDownloadPage extends Activity
         mListView.setEmptyView(v);
         
         mDownloadCursor = managedQuery(Downloads.CONTENT_URI, 
-                new String [] {"_id", Downloads.TITLE, Downloads.STATUS,
-                Downloads.TOTAL_BYTES, Downloads.CURRENT_BYTES, 
-                Downloads._DATA, Downloads.DESCRIPTION, 
-                Downloads.MIMETYPE, Downloads.LAST_MODIFICATION,
-                Downloads.VISIBILITY}, 
+                new String [] {"_id", Downloads.COLUMN_TITLE, Downloads.COLUMN_STATUS,
+                Downloads.COLUMN_TOTAL_BYTES, Downloads.COLUMN_CURRENT_BYTES, 
+                Downloads._DATA, Downloads.COLUMN_DESCRIPTION, 
+                Downloads.COLUMN_MIME_TYPE, Downloads.COLUMN_LAST_MODIFICATION,
+                Downloads.COLUMN_VISIBILITY}, 
                 null, null);
         
         // only attach everything to the listbox if we can access
         // the download database. Otherwise, just show it empty
         if (mDownloadCursor != null) {
             mStatusColumnId = 
-                    mDownloadCursor.getColumnIndexOrThrow(Downloads.STATUS);
+                    mDownloadCursor.getColumnIndexOrThrow(Downloads.COLUMN_STATUS);
             mIdColumnId =
                     mDownloadCursor.getColumnIndexOrThrow(Downloads._ID);
             mTitleColumnId = 
-                    mDownloadCursor.getColumnIndexOrThrow(Downloads.TITLE);
+                    mDownloadCursor.getColumnIndexOrThrow(Downloads.COLUMN_TITLE);
             
             // Create a list "controller" for the data
             mDownloadAdapter = new BrowserDownloadAdapter(this, 
@@ -403,7 +403,7 @@ public class BrowserDownloadPage extends Activity
                 mDownloadCursor.getColumnIndexOrThrow(Downloads._DATA);
         String filename = mDownloadCursor.getString(filenameColumnId);
         int mimetypeColumnId =
-                mDownloadCursor.getColumnIndexOrThrow(Downloads.MIMETYPE);
+                mDownloadCursor.getColumnIndexOrThrow(Downloads.COLUMN_MIME_TYPE);
         String mimetype = mDownloadCursor.getString(mimetypeColumnId);
         Uri path = Uri.parse(filename);
         // If there is no scheme, then it must be a file
@@ -453,13 +453,13 @@ public class BrowserDownloadPage extends Activity
     private void hideCompletedDownload() {
         int status = mDownloadCursor.getInt(mStatusColumnId);
 
-        int visibilityColumn = mDownloadCursor.getColumnIndexOrThrow(Downloads.VISIBILITY);
+        int visibilityColumn = mDownloadCursor.getColumnIndexOrThrow(Downloads.COLUMN_VISIBILITY);
         int visibility = mDownloadCursor.getInt(visibilityColumn);
 
         if (Downloads.isStatusCompleted(status) &&
                 visibility == Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) {
             ContentValues values = new ContentValues();
-            values.put(Downloads.VISIBILITY, Downloads.VISIBILITY_VISIBLE);
+            values.put(Downloads.COLUMN_VISIBILITY, Downloads.VISIBILITY_VISIBLE);
             getContentResolver().update(
                     ContentUris.withAppendedId(Downloads.CONTENT_URI,
                     mDownloadCursor.getLong(mIdColumnId)), values, null, null);
index d4708c3..7324f24 100644 (file)
@@ -50,8 +50,8 @@ public class BrowserHomepagePreference extends EditTextPreference implements
         if (dialog != null) {
             String url = s.toString();
             dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(
-                    url.length() == 0 || url.equals("about:blank") ||
-                    Regex.WEB_URL_PATTERN.matcher(url).matches());
+                url.length() == 0 || 
+                BrowserActivity.ACCEPTED_URI_SCHEMA.matcher(url).matches());
         }
     }
 
index 3a00ffa..8c30873 100644 (file)
@@ -481,7 +481,8 @@ public class BrowserProvider extends ContentProvider {
                 myArgs = null;
             } else {
                 String like = selectionArgs[0] + "%";
-                if (selectionArgs[0].startsWith("http")) {
+                if (selectionArgs[0].startsWith("http")
+                        || selectionArgs[0].startsWith("file")) {
                     myArgs = new String[1];
                     myArgs[0] = like;
                     suggestSelection = selection;
index 0e2c5af..e47ed60 100644 (file)
@@ -53,7 +53,9 @@ import java.util.Observable;
  */
 class BrowserSettings extends Observable {
 
-    // Public variables for settings
+    private static final String DEFAULT_HOME_URL =
+            "http://www.google.com/m?client=ms-";
+    // Private variables for settings
     // NOTE: these defaults need to be kept in sync with the XML
     // until the performance of PreferenceManager.setDefaultValues()
     // is improved.
@@ -67,10 +69,14 @@ 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 landscapeOnly = false;
     private boolean showDebugSettings = false;
+    // The Browser always enables Application Caches.
+    private boolean appCacheEnabled = true;
+    private String appCachePath;  // default value set in loadFromDb().
 
     // Development settings
     public WebSettings.LayoutAlgorithm layoutAlgorithm =
@@ -179,6 +185,9 @@ class BrowserSettings extends Observable {
             s.setSupportMultipleWindows(true);
             // Turn off file access
             s.setAllowFileAccess(false);
+            // Turn on Application Caches.
+            s.setAppCachePath(b.appCachePath);
+            s.setAppCacheEnabled(b.appCacheEnabled);
         }
     }
 
@@ -198,8 +207,11 @@ class BrowserSettings extends Observable {
         // Set the default value for the plugins path to the application's
         // local directory.
         pluginsPath = ctx.getDir("plugins", 0).getPath();
+        // Set the default value for the Application Caches path.
+        appCachePath = ctx.getDir("appcache", 0).getPath();
 
-        homeUrl += Partner.getString(ctx.getContentResolver(), Partner.CLIENT_ID);
+        homeUrl = DEFAULT_HOME_URL +
+                Partner.getString(ctx.getContentResolver(), Partner.CLIENT_ID);
 
         // Load the defaults from the xml
         // This call is TOO SLOW, need to manually keep the defaults
@@ -220,6 +232,9 @@ class BrowserSettings extends Observable {
         pluginsEnabled = p.getBoolean("enable_plugins",
                 pluginsEnabled);
         pluginsPath = p.getString("plugins_path", pluginsPath);
+        appCacheEnabled = p.getBoolean("enable_appcache",
+            appCacheEnabled);
+        appCachePath = p.getString("appcache_path", appCachePath);
         javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
             "block_popup_windows",
             !javaScriptCanOpenWindowsAutomatically);
@@ -237,6 +252,14 @@ class BrowserSettings extends Observable {
         textSize = WebSettings.TextSize.valueOf(
                 p.getString(PREF_TEXT_SIZE, textSize.name()));
         autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
+        boolean landscapeOnlyTemp =
+                p.getBoolean("landscape_only", landscapeOnly);
+        if (landscapeOnlyTemp != landscapeOnly) {
+            landscapeOnly = landscapeOnlyTemp;
+            mTabControl.getBrowserActivity().setRequestedOrientation(
+                    landscapeOnly ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+                    : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
+        }
         useWideViewPort = true; // use wide view port for either setting
         if (autoFitPage) {
             layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
@@ -433,12 +456,14 @@ class BrowserSettings extends Observable {
         db.clearHttpAuthUsernamePassword();
     }
 
-    /*package*/ void resetDefaultPreferences(Context context) {
+    /*package*/ void resetDefaultPreferences(Context ctx) {
         SharedPreferences p =
-            PreferenceManager.getDefaultSharedPreferences(context);
+            PreferenceManager.getDefaultSharedPreferences(ctx);
         p.edit().clear().commit();
-        PreferenceManager.setDefaultValues(context, R.xml.browser_preferences,
+        PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences,
                 true);
+        setHomePage(ctx, DEFAULT_HOME_URL +
+                Partner.getString(ctx.getContentResolver(), Partner.CLIENT_ID));
     }
 
     // Private constructor that does nothing.
index 8578643..c585dbb 100644 (file)
@@ -58,7 +58,7 @@ class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
         mValues = values[0];
 
         // Check to make sure we have a URI to download
-        String uri = mValues.getAsString(Downloads.URI);
+        String uri = mValues.getAsString(Downloads.COLUMN_URI);
         if (uri == null || uri.length() == 0) {
             return null;
         }
@@ -66,15 +66,15 @@ class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
         // User agent is likely to be null, though the AndroidHttpClient
         // seems ok with that.
         AndroidHttpClient client = AndroidHttpClient.newInstance(
-                mValues.getAsString(Downloads.USER_AGENT));
+                mValues.getAsString(Downloads.COLUMN_USER_AGENT));
         HttpHead request = new HttpHead(uri);
 
-        String cookie = mValues.getAsString(Downloads.COOKIE_DATA);
+        String cookie = mValues.getAsString(Downloads.COLUMN_COOKIE_DATA);
         if (cookie != null && cookie.length() > 0) {
             request.addHeader("Cookie", cookie);
         }
 
-        String referer = mValues.getAsString(Downloads.REFERER);
+        String referer = mValues.getAsString(Downloads.COLUMN_REFERER);
         if (referer != null && referer.length() > 0) {
             request.addHeader("Referer", referer);
         }
@@ -111,19 +111,19 @@ class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
    @Override
     public void onPostExecute(String mimeType) {
        if (mimeType != null) {
-           String url = mValues.getAsString(Downloads.URI);
+           String url = mValues.getAsString(Downloads.COLUMN_URI);
            if (mimeType.equalsIgnoreCase("text/plain") ||
                    mimeType.equalsIgnoreCase("application/octet-stream")) {
                String newMimeType =
                        MimeTypeMap.getSingleton().getMimeTypeFromExtension(
                            MimeTypeMap.getFileExtensionFromUrl(url));
                if (newMimeType != null) {
-                   mValues.put(Downloads.MIMETYPE, newMimeType);
+                   mValues.put(Downloads.COLUMN_MIME_TYPE, newMimeType);
                }
            }
            String filename = URLUtil.guessFileName(url,
                    null, mimeType);
-           mValues.put(Downloads.FILENAME_HINT, filename);
+           mValues.put(Downloads.COLUMN_FILE_NAME_HINT, filename);
        }
 
        // Start the download
index 6e9574c..3482b85 100644 (file)
@@ -143,23 +143,14 @@ import android.widget.TextView;
         mBrowserActivity.closeFind();
         mWebView.clearMatches();
     }
-    
+
     @Override
     public boolean dispatchKeyEvent(KeyEvent event) {
-        int code = event.getKeyCode();
-        boolean up = event.getAction() == KeyEvent.ACTION_UP;
-        switch (code) {
-            case KeyEvent.KEYCODE_DPAD_CENTER:
-            case KeyEvent.KEYCODE_ENTER:
-                if (!mEditText.hasFocus()) {
-                    break;
-                }
-                if (up) {
-                    findNext();
-                }
-                return true;
-            default:
-                break;
+        if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
+                && event.getAction() == KeyEvent.ACTION_UP
+                && mEditText.hasFocus()) {
+            findNext();
+            return true;
         }
         return super.dispatchKeyEvent(event);
     }
index 581d144..9de0198 100644 (file)
@@ -446,6 +446,9 @@ class TabControl {
      * @return index of Tab or -1 if not found
      */
     int getTabIndex(Tab tab) {
+        if (tab == null) {
+            return -1;
+        }
         return mTabs.indexOf(tab);
     }