Merge "Sets umask to prevent world readable files"
diff --git a/res/layout/pref_homepage_buttons.xml b/res/layout/pref_homepage_buttons.xml
new file mode 100644
index 0000000..fe21beb
--- /dev/null
+++ b/res/layout/pref_homepage_buttons.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ This layout provides the structure for a browser tab. A tab contains the
+ WebView and any number of other UI elements specific to that tab.
+ Currently, the only such element is the Geolocation permissions prompt.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal">
+
+ <Button android:id="@+id/use_current"
+ android:text="@string/pref_use_current"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginRight="16dp" />
+
+ <Button android:id="@+id/use_default"
+ android:text="@string/pref_use_default"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+</LinearLayout>
diff --git a/res/layout/url_bar.xml b/res/layout/url_bar.xml
index ba93d1b..f695ae3 100644
--- a/res/layout/url_bar.xml
+++ b/res/layout/url_bar.xml
@@ -77,12 +77,13 @@
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true" />
- <ImageButton
+ <view class="com.android.browser.TitleBarXLarge$CustomCheck"
android:id="@+id/star"
- android:src="@drawable/ic_favorite_off_normal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
style="@style/HoloButton"
+ android:focusable="false"
+ android:button="@android:drawable/btn_star"
android:background="@drawable/browserbarbutton" />
</LinearLayout>
<LinearLayout
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index 79c3327..c4f3bd5 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -245,15 +245,23 @@
@Override
public void onPageStarted(Tab tab, String url, Bitmap favicon) {
- if (mXLargeScreenSize) {
- mTabBar.onPageStarted(tab, url, favicon);
- }
if (tab.inForeground()) {
resetLockIcon(tab, url);
setUrlTitle(tab, url, null);
setFavicon(tab, favicon);
}
+ if (mXLargeScreenSize) {
+ mTabBar.onPageStarted(tab, url, favicon);
+ }
+ }
+ @Override
+ public void bookmarkedStatusHasChanged(Tab tab) {
+ if (tab.inForeground() && mXLargeScreenSize) {
+ boolean isBookmark = tab.isBookmarkedSite();
+ ((TitleBarXLarge) mTitleBar).setCurrentUrlIsBookmark(isBookmark);
+ ((TitleBarXLarge) mFakeTitleBar).setCurrentUrlIsBookmark(isBookmark);
+ }
}
@Override
@@ -337,6 +345,7 @@
// Request focus on the top window.
mTabBar.onSetActiveTab(tab);
}
+ bookmarkedStatusHasChanged(tab);
resetTitleIconAndProgress(tab);
updateLockIconToLatest(tab);
tab.getTopWindow().requestFocus();
@@ -706,7 +715,7 @@
setUrlTitle(tab, item.getUrl(), item.getTitle());
setFavicon(tab, item.getFavicon());
} else {
- setUrlTitle(tab, null, null);
+ setUrlTitle(tab, null, mActivity.getString(R.string.new_tab));
setFavicon(tab, null);
}
}
@@ -850,12 +859,7 @@
@Override
public void setUrlTitle(Tab tab, String url, String title) {
if (TextUtils.isEmpty(title)) {
- if (TextUtils.isEmpty(url)) {
- title = mActivity.getResources()
- .getString(R.string.title_bar_loading);
- } else {
- title = url;
- }
+ title = url;
}
if (tab.isInVoiceSearchMode()) return;
if (tab.inForeground()) {
diff --git a/src/com/android/browser/BrowserHomepagePreference.java b/src/com/android/browser/BrowserHomepagePreference.java
index 9886053..80f7ec2 100644
--- a/src/com/android/browser/BrowserHomepagePreference.java
+++ b/src/com/android/browser/BrowserHomepagePreference.java
@@ -22,34 +22,28 @@
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.util.AttributeSet;
-import android.view.Gravity;
+import android.view.LayoutInflater;
import android.view.View;
+import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
-import android.widget.Button;
import android.widget.EditText;
-import android.widget.LinearLayout;
-import android.widget.Toast;
public class BrowserHomepagePreference extends EditTextPreference {
private String mCurrentPage;
- private AlertDialog mSetHomepageTo;
public BrowserHomepagePreference(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
- createSetHomepageToDialog();
}
public BrowserHomepagePreference(Context context, AttributeSet attrs) {
super(context, attrs);
- createSetHomepageToDialog();
}
public BrowserHomepagePreference(Context context) {
super(context);
- createSetHomepageToDialog();
}
@Override
@@ -58,66 +52,40 @@
super.onAddEditTextToDialogView(dialogView, editText);
// Now the EditText has a parent. Add a button to set to the current
// page.
- ViewGroup parent = (ViewGroup) editText.getParent();
- Button button = new Button(getContext());
- button.setText(R.string.pref_set_homepage_to);
- button.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- mSetHomepageTo.show();
- }
- });
- if (parent instanceof LinearLayout) {
- ((LinearLayout) parent).setGravity(Gravity.CENTER_HORIZONTAL);
- }
- parent.addView(button, ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
+ createButtons((ViewGroup) editText.getParent());
}
- private void createSetHomepageToDialog() {
- Context context = getContext();
- CharSequence[] setToChoices = new CharSequence[] {
- context.getText(R.string.pref_use_current),
- context.getText(R.string.pref_use_blank),
- context.getText(R.string.pref_use_default),
- };
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setTitle(R.string.pref_set_homepage_to);
- builder.setItems(setToChoices, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (which == 0) {
- getEditText().setText(mCurrentPage);
- } else if (which == 1) {
- getEditText().setText("about:blank");
- } else if (which == 2) {
- getEditText().setText(BrowserSettings
- .getFactoryResetHomeUrl(getContext()));
- }
- }
- });
- mSetHomepageTo = builder.create();
+ void createButtons(ViewGroup parent) {
+ LayoutInflater inflater = (LayoutInflater) getContext()
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ View v = inflater.inflate(R.layout.pref_homepage_buttons, parent);
+ v.findViewById(R.id.use_current).setOnClickListener(mOnClick);
+ v.findViewById(R.id.use_default).setOnClickListener(mOnClick);
}
+ OnClickListener mOnClick = new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.use_current:
+ getEditText().setText(mCurrentPage);
+ break;
+ case R.id.use_default:
+ getEditText().setText(
+ BrowserSettings.getFactoryResetHomeUrl(getContext()));
+ break;
+ }
+ }
+ };
+
@Override
protected void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
- String url = getEditText().getText().toString();
- if (url.length() > 0
- && !UrlUtils.ACCEPTED_URI_SCHEMA.matcher(url)
- .matches()) {
- int colon = url.indexOf(':');
- int space = url.indexOf(' ');
- if (colon == -1 && space == -1 && url.length() > 0) {
- // if no colon, no space, add "http://" to make it a url
- getEditText().setText("http://" + url);
- } else {
- // show an error toast and change the positiveResult to
- // false so that the bad url will not override the old url
- Toast.makeText(getContext(), R.string.bookmark_url_not_valid,
- Toast.LENGTH_SHORT).show();
- positiveResult = false;
- }
+ String url = getEditText().getText().toString().trim();
+ if (url.length() > 0) {
+ url = UrlUtils.smartUrlFilter(url);
}
+ getEditText().setText(url);
}
super.onDialogClosed(positiveResult);
}
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 61ef76b..1f091e2 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -337,7 +337,7 @@
// Set the default value for the Geolocation database path.
geolocationDatabasePath = mContext.getDir("geolocation", 0).getPath();
- if (p.getString(PREF_HOMEPAGE, "") == "") {
+ if (p.getString(PREF_HOMEPAGE, null) == null) {
// No home page preferences is set, set it to default.
setHomePage(mContext, getFactoryResetHomeUrl(mContext));
}
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 75dd913..7acdfe5 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -108,10 +108,6 @@
private static final int EMPTY_MENU = -1;
- // Keep this initial progress in sync with initialProgressValue (* 100)
- // in ProgressTracker.cpp
- private final static int INITIAL_PROGRESS = 10;
-
// activity requestCode
final static int PREFERENCES_PAGE = 3;
final static int FILE_SELECTED = 4;
@@ -564,7 +560,6 @@
Log.e(LOGTAG, "BrowserActivity is already paused.");
return;
}
- CookieManager.getInstance().flushCookieStore();
mActivityPaused = true;
Tab tab = mTabControl.getCurrentTab();
if (tab != null) {
@@ -750,10 +745,6 @@
mUi.onPageStarted(tab, url, favicon);
- // Show some progress so that the user knows the page is beginning to
- // load
- onProgressChanged(tab, INITIAL_PROGRESS);
-
// update the bookmark database for favicon
maybeUpdateFavicon(tab, null, url, favicon);
@@ -1035,6 +1026,11 @@
}
}
+ @Override
+ public void bookmarkedStatusHasChanged(Tab tab) {
+ mUi.bookmarkedStatusHasChanged(tab);
+ }
+
// end WebViewController
protected void pageUp() {
@@ -2247,7 +2243,6 @@
* @param url The URL to load.
*/
protected void loadUrl(WebView view, String url) {
- updateTitleBarForNewLoad(view, url);
view.loadUrl(url);
}
@@ -2258,7 +2253,6 @@
* @param data The UrlData being loaded.
*/
protected void loadUrlDataIn(Tab t, UrlData data) {
- updateTitleBarForNewLoad(t.getWebView(), data.mUrl);
data.loadIn(t);
}
@@ -2279,25 +2273,6 @@
}
/**
- * If the WebView is the top window, update the title bar to reflect
- * loading the new URL. i.e. set its text, clear the favicon (which
- * will be set once the page begins loading), and set the progress to
- * INITIAL_PROGRESS to show that the page has begun to load. Called
- * by loadUrl and loadUrlDataIn.
- * @param view The WebView that is starting a load.
- * @param url The URL that is being loaded.
- */
- private void updateTitleBarForNewLoad(WebView view, String url) {
- if (view == getCurrentTopWebView()) {
- // TODO we should come with a tab and not with a view
- Tab tab = mTabControl.getTabFromView(view);
- setUrlTitle(tab, url, null);
- mUi.setFavicon(tab, null);
- onProgressChanged(tab, INITIAL_PROGRESS);
- }
- }
-
- /**
* Sets a title composed of the URL and the title string.
* @param url The URL of the site being loaded.
* @param title The title of the site being loaded.
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 8a3bc27..3e79edb 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -25,12 +25,16 @@
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Message;
import android.os.SystemClock;
+import android.provider.BrowserContract;
import android.speech.RecognizerResultsIntent;
import android.util.Log;
import android.view.KeyEvent;
@@ -144,6 +148,14 @@
Bitmap mFavicon;
}
+ // Whether or not the currently shown page is a bookmarked site. Will be
+ // out of date when loading a new page until the mBookmarkAsyncTask returns.
+ private boolean mIsBookmarkedSite;
+ // Used to determine whether the current site is bookmarked.
+ private AsyncTask<Void, Void, Boolean> mBookmarkAsyncTask;
+
+ public boolean isBookmarkedSite() { return mIsBookmarkedSite; }
+
// Used for saving and restoring each Tab
static final String WEBVIEW = "webview";
static final String NUMTABS = "numTabs";
@@ -488,9 +500,42 @@
}
}
-
// finally update the UI in the activity if it is in the foreground
mWebViewController.onPageStarted(Tab.this, view, url, favicon);
+
+ final String urlInQuestion = url;
+ if (mBookmarkAsyncTask != null) {
+ mBookmarkAsyncTask.cancel(true);
+ }
+ mBookmarkAsyncTask = new AsyncTask<Void, Void, Boolean>() {
+ @Override
+ protected Boolean doInBackground(Void... unused) {
+ // Check to see if the site is bookmarked
+ Cursor cursor = null;
+ try {
+ cursor = mActivity.getContentResolver().query(
+ BrowserContract.Bookmarks.CONTENT_URI,
+ new String[] { BrowserContract.Bookmarks.URL },
+ BrowserContract.Bookmarks.URL + " == ?",
+ new String[] { urlInQuestion },
+ null);
+ return cursor.moveToFirst();
+ } catch (SQLiteException e) {
+ Log.e(LOGTAG, "Error checking for bookmark: " + e);
+ return false;
+ } finally {
+ if (cursor != null) cursor.close();
+ }
+ }
+ @Override
+ protected void onPostExecute(Boolean isBookmarked) {
+ if (this == mBookmarkAsyncTask) {
+ mIsBookmarkedSite = isBookmarked;
+ mWebViewController.bookmarkedStatusHasChanged(Tab.this);
+ }
+ }
+ };
+ mBookmarkAsyncTask.execute();
}
@Override
diff --git a/src/com/android/browser/TabBar.java b/src/com/android/browser/TabBar.java
index 69e0bd2..14b1845 100644
--- a/src/com/android/browser/TabBar.java
+++ b/src/com/android/browser/TabBar.java
@@ -454,7 +454,6 @@
mHasReceivedTitle = false;
TabViewData tvd = mTabMap.get(tab);
if (tvd != null) {
- tvd.setUrlAndTitle(url, null);
tvd.setFavicon(favicon);
tvd.setUrlAndTitle(url, mLoadingText);
}
diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java
index 6dabd76..bdef82e 100644
--- a/src/com/android/browser/TitleBar.java
+++ b/src/com/android/browser/TitleBar.java
@@ -320,13 +320,13 @@
/**
* Update the text displayed in the title bar.
- * @param title String to display. If null, the loading string will be
+ * @param title String to display. If null, the new tab string will be
* shown.
*/
@Override
void setDisplayTitle(String title) {
if (title == null) {
- mTitle.setText(R.string.title_bar_loading);
+ mTitle.setText(R.string.new_tab);
} else {
if (mInVoiceMode) {
// Add two spaces. The second one will be replaced with an
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index 0aa09db..cd3b230 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -26,9 +26,11 @@
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
+import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
+import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
@@ -48,7 +50,7 @@
private View mContainer;
private View mBackButton;
private View mForwardButton;
- private View mStar;
+ private CheckBox mStar;
private View mSearchButton;
private View mFocusContainer;
private View mUnfocusContainer;
@@ -82,7 +84,7 @@
// back/forward. Probably should be done inside onPageStarted.
mBackButton = findViewById(R.id.back);
mForwardButton = findViewById(R.id.forward);
- mStar = findViewById(R.id.star);
+ mStar = (CheckBox) findViewById(R.id.star);
mStopButton = (ImageView) findViewById(R.id.stop);
mSearchButton = findViewById(R.id.search);
mLockIcon = (ImageView) findViewById(R.id.lock);
@@ -106,6 +108,10 @@
mUnfocusContainer.setOnClickListener(this);
}
+ public void setCurrentUrlIsBookmark(boolean isBookmark) {
+ mStar.setChecked(isBookmark);
+ }
+
@Override
public void onClick(View v) {
if (mUnfocusContainer == v) {
@@ -237,4 +243,25 @@
mUrlUnfocused.setText(title);
}
+ /**
+ * Custom CheckBox which does not toggle when pressed. Used by mStar.
+ */
+ public static class CustomCheck extends CheckBox {
+ public CustomCheck(Context context) {
+ super(context);
+ }
+
+ public CustomCheck(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public CustomCheck(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ public void toggle() {
+ // Do nothing
+ }
+ }
}
diff --git a/src/com/android/browser/UI.java b/src/com/android/browser/UI.java
index e7f67f2..2bfec44 100644
--- a/src/com/android/browser/UI.java
+++ b/src/com/android/browser/UI.java
@@ -130,4 +130,5 @@
View getVideoLoadingProgressView();
+ void bookmarkedStatusHasChanged(Tab tab);
}
diff --git a/src/com/android/browser/WebViewController.java b/src/com/android/browser/WebViewController.java
index 11a6959..894bbec 100644
--- a/src/com/android/browser/WebViewController.java
+++ b/src/com/android/browser/WebViewController.java
@@ -107,4 +107,6 @@
void setupAutoFill(Message message);
+ void bookmarkedStatusHasChanged(Tab tab);
+
}
diff --git a/src/com/android/browser/preferences/PageContentPreferencesFragment.java b/src/com/android/browser/preferences/PageContentPreferencesFragment.java
index 1b5d0fe..4be14a6 100644
--- a/src/com/android/browser/preferences/PageContentPreferencesFragment.java
+++ b/src/com/android/browser/preferences/PageContentPreferencesFragment.java
@@ -72,29 +72,8 @@
}
if (pref.getKey().equals(BrowserSettings.PREF_HOMEPAGE)) {
- String value = (String) objValue;
- boolean needUpdate = value.indexOf(' ') != -1;
- if (needUpdate) {
- value = value.trim().replace(" ", "%20");
- }
- if (value.length() != 0 && Uri.parse(value).getScheme() == null) {
- value = "http://" + value;
- needUpdate = true;
- }
- // Set the summary value.
- pref.setSummary(value);
- if (needUpdate) {
- // Update through the EditText control as it has a cached copy
- // of the string and it will handle persisting the value
- ((EditTextPreference) pref).setText(value);
-
- // as we update the value above, we need to return false
- // here so that setText() is not called by EditTextPref
- // with the old value.
- return false;
- } else {
- return true;
- }
+ pref.setSummary((String) objValue);
+ return true;
} else if (pref.getKey().equals(BrowserSettings.PREF_TEXT_SIZE)) {
pref.setSummary(getVisualTextSizeName((String) objValue));
return true;