"privacy_clear_geolocation_access";
private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
- "U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, " +
- "like Gecko) Version/4.0 Safari/530.17";
+ "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " +
+ "like Gecko) Version/5.0 Safari/533.16";
private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
- "CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 " +
- "(KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16";
+ "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
+ "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
+
+ private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
+ "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
+ "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
+
+ private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
+ "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
+ "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
// Value to truncate strings when adding them to a TextView within
// a ListView
s.setUserAgentString(DESKTOP_USERAGENT);
} else if (b.userAgent == 2) {
s.setUserAgentString(IPHONE_USERAGENT);
+ } else if (b.userAgent == 3) {
+ s.setUserAgentString(IPAD_USERAGENT);
+ } else if (b.userAgent == 4) {
+ s.setUserAgentString(FROYO_USERAGENT);
}
s.setUseWideViewPort(b.useWideViewPort);
s.setLoadsImagesAutomatically(b.loadsImagesAutomatically);
String searchEngineName = p.getString(PREF_SEARCH_ENGINE, null);
if (searchEngine == null || !searchEngine.getName().equals(searchEngineName)) {
if (searchEngine != null) {
+ if (searchEngine.supportsVoiceSearch()) {
+ // One or more tabs could have been in voice search mode.
+ // Clear it, since the new SearchEngine may not support
+ // it, or may handle it differently.
+ for (int i = 0; i < mTabControl.getTabCount(); i++) {
+ mTabControl.getTab(i).revertVoiceSearchMode();
+ }
+ }
searchEngine.close();
}
searchEngine = SearchEngines.get(ctx, searchEngineName);
Editor ed = PreferenceManager.
getDefaultSharedPreferences(context).edit();
ed.putString(PREF_HOMEPAGE, url);
- ed.commit();
+ ed.apply();
homeUrl = url;
}
/* package */ void clearFormData(Context context) {
WebViewDatabase.getInstance(context).clearFormData();
if (mTabControl != null) {
- mTabControl.getCurrentTopWebView().clearFormData();
+ WebView currentTopView = mTabControl.getCurrentTopWebView();
+ if (currentTopView != null) {
+ currentTopView.clearFormData();
+ }
}
}
reset();
SharedPreferences p =
PreferenceManager.getDefaultSharedPreferences(ctx);
- p.edit().clear().commit();
+ p.edit().clear().apply();
PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences,
true);
// reset homeUrl
// The Geolocation permissions prompt
private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
// Main WebView wrapper
- private View mContainer;
+ private LinearLayout mContainer;
// Main WebView
private WebView mMainView;
// Subwindow container
static final String CURRTAB = "currentTab";
static final String CURRURL = "currentUrl";
static final String CURRTITLE = "currentTitle";
- static final String CURRPICTURE = "currentPicture";
static final String CLOSEONEXIT = "closeonexit";
static final String PARENTTAB = "parentTab";
static final String APPID = "appid";
*/
private VoiceSearchData mVoiceSearchData;
/**
+ * Remove voice search mode from this tab.
+ */
+ public void revertVoiceSearchMode() {
+ if (mVoiceSearchData != null) {
+ mVoiceSearchData = null;
+ if (mInForeground) {
+ mActivity.revertVoiceTitleBar();
+ }
+ }
+ }
+ /**
* Return whether the tab is in voice search mode.
*/
public boolean isInVoiceSearchMode() {
return mVoiceSearchData != null;
}
/**
- * Return true if the voice search Intent came with a String identifying
- * that Google provided the Intent.
+ * Return true if the Tab is in voice search mode and the voice search
+ * Intent came with a String identifying that Google provided the Intent.
*/
public boolean voiceSearchSourceIsGoogle() {
return mVoiceSearchData != null && mVoiceSearchData.mSourceIsGoogle;
i.putExtra(LoggingEvents.EXTRA_FLUSH, true);
mActivity.sendBroadcast(i);
}
- mVoiceSearchData = null;
- if (mInForeground) {
- mActivity.revertVoiceTitleBar();
- }
+ revertVoiceSearchMode();
}
// We've started to load a new page. If there was a pending message
// return true if want to hijack the url to let another app to handle it
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
+ if (voiceSearchSourceIsGoogle()) {
+ // This method is called when the user clicks on a link.
+ // VoiceSearchMode is turned off when the user leaves the
+ // Google results page, so at this point the user must be on
+ // that page. If the user clicked a link on that page, assume
+ // that the voice search was effective, and broadcast an Intent
+ // so a receiver can take note of that fact.
+ Intent logIntent = new Intent(LoggingEvents.ACTION_LOG_EVENT);
+ logIntent.putExtra(LoggingEvents.EXTRA_EVENT,
+ LoggingEvents.VoiceSearch.RESULT_CLICKED);
+ mActivity.sendBroadcast(logIntent);
+ }
if (mInForeground) {
return mActivity.shouldOverrideUrlLoading(view, url);
} else {
} else if (url.startsWith("http://")) {
url = url.substring(4);
}
+ // Escape wildcards for LIKE operator.
+ url = url.replace("\\", "\\\\").replace("%", "\\%")
+ .replace("_", "\\_");
Cursor c = null;
try {
final ContentResolver cr
url = "%" + url;
String [] selArgs = new String[] { url };
String where = Browser.BookmarkColumns.URL
- + " LIKE ? AND "
+ + " LIKE ? ESCAPE '\\' AND "
+ Browser.BookmarkColumns.BOOKMARK + " = 0";
c = cr.query(Browser.BOOKMARKS_URI, new String[]
{ Browser.BookmarkColumns._ID }, where, selArgs,
}
@Override
+ public void onSelectionDone(WebView view) {
+ if (mInForeground) mActivity.closeDialogs();
+ }
+
+ @Override
+ public void onSelectionStart(WebView view) {
+ if (false && mInForeground) mActivity.showSelectDialog();
+ }
+
+ @Override
public void onShowCustomView(View view,
WebChromeClient.CustomViewCallback callback) {
if (mInForeground) mActivity.onShowCustomView(view, callback);
private static class SubWindowClient extends WebViewClient {
// The main WebViewClient.
private final WebViewClient mClient;
+ private final BrowserActivity mBrowserActivity;
- SubWindowClient(WebViewClient client) {
+ SubWindowClient(WebViewClient client, BrowserActivity activity) {
mClient = client;
+ mBrowserActivity = activity;
+ }
+ @Override
+ public void onPageStarted(WebView view, String url, Bitmap favicon) {
+ // Unlike the others, do not call mClient's version, which would
+ // change the progress bar. However, we do want to remove the
+ // find or select dialog.
+ mBrowserActivity.closeDialogs();
}
@Override
public void doUpdateVisitedHistory(WebView view, String url,
// The tab consists of a container view, which contains the main
// WebView, as well as any other UI elements associated with the tab.
- mContainer = mInflateService.inflate(R.layout.tab, null);
+ mContainer = (LinearLayout) mInflateService.inflate(R.layout.tab, null);
mDownloadListener = new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
*/
boolean createSubWindow() {
if (mSubView == null) {
+ mActivity.closeDialogs();
mSubViewContainer = mInflateService.inflate(
R.layout.browser_subwindow, null);
mSubView = (WebView) mSubViewContainer.findViewById(R.id.webview);
mSubView.setMapTrackballToArrowKeys(false);
// Enable the built-in zoom
mSubView.getSettings().setBuiltInZoomControls(true);
- mSubView.setWebViewClient(new SubWindowClient(mWebViewClient));
+ mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
+ mActivity));
mSubView.setWebChromeClient(new SubWindowChromeClient(
mWebChromeClient));
// Set a different DownloadListener for the mSubView, since it will
if (mSubView.copyBackForwardList().getSize() == 0) {
// This subwindow was opened for the sole purpose of
// downloading a file. Remove it.
- dismissSubWindow();
+ mActivity.dismissSubWindow(Tab.this);
}
}
});
*/
void dismissSubWindow() {
if (mSubView != null) {
+ mActivity.closeDialogs();
BrowserSettings.getInstance().deleteObserver(
mSubView.getSettings());
mSubView.destroy();
void removeSubWindow(ViewGroup content) {
if (mSubView != null) {
content.removeView(mSubViewContainer);
+ mActivity.closeDialogs();
}
}
(FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
wrapper.removeView(mMainView);
content.removeView(mContainer);
+ mActivity.closeDialogs();
removeSubWindow(content);
}
mSavedState = new Bundle();
final WebBackForwardList list = mMainView.saveState(mSavedState);
- if (list != null) {
- final File f = new File(mActivity.getTabControl().getThumbnailDir(),
- mMainView.hashCode() + "_pic.save");
- if (mMainView.savePicture(mSavedState, f)) {
- mSavedState.putString(CURRPICTURE, f.getPath());
- } else {
- // if savePicture returned false, we can't trust the contents,
- // and it may be large, so we delete it right away
- f.delete();
- }
- }
// Store some extra info for displaying the tab in the picker.
final WebHistoryItem item = list != null ? list.getCurrentItem() : null;
if (list == null) {
return false;
}
- if (b.containsKey(CURRPICTURE)) {
- final File f = new File(b.getString(CURRPICTURE));
- mMainView.restorePicture(b, f);
- f.delete();
- }
return true;
}
+
+ /*
+ * Opens the find and select text dialogs. Called by BrowserActivity.
+ */
+ WebView showDialog(WebDialog dialog) {
+ LinearLayout container;
+ WebView view;
+ if (mSubView != null) {
+ view = mSubView;
+ container = (LinearLayout) mSubViewContainer.findViewById(
+ R.id.inner_container);
+ } else {
+ view = mMainView;
+ container = mContainer;
+ }
+ dialog.show();
+ container.addView(dialog, 0, new LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT));
+ dialog.setWebView(view);
+ return view;
+ }
+
+ /*
+ * Close the find or select dialog. Called by BrowserActivity.closeDialog.
+ */
+ void closeDialog(WebDialog dialog) {
+ // The dialog may be attached to the subwindow. Ensure that the
+ // correct parent has it removed.
+ LinearLayout parent = (LinearLayout) dialog.getParent();
+ if (parent != null) parent.removeView(dialog);
+ }
}