From 9b1e988e881319bc0c4a7642653685781269d866 Mon Sep 17 00:00:00 2001 From: Bijan Amirzada Date: Wed, 26 Feb 2014 17:15:46 -0800 Subject: Added modified files to consume SWE Change-Id: I959781dad2a983de6be6ab07f418006a5708c976 --- Android.mk | 55 +- AndroidManifest.xml | 161 ++++-- assets/html/flashtest.html | 2 +- proguard.flags | 8 +- res/layout-land/nav_screen.xml | 2 +- res/layout-sw600dp/pick_bookmark.xml | 2 +- res/layout-sw600dp/title_bar_autologin.xml | 4 +- res/layout-sw600dp/title_bar_nav.xml | 6 +- res/layout-sw600dp/title_bar_snapshot.xml | 6 +- res/layout/bookmark_list.xml | 4 +- res/layout/bookmark_sync_wizard.xml | 2 +- res/layout/bookmark_thumbnail.xml | 5 +- res/layout/bookmarks.xml | 2 +- res/layout/bookmarks_header.xml | 2 +- res/layout/browser_add_bookmark_content.xml | 6 +- res/layout/browser_tab_crash.xml | 2 +- res/layout/custom_screen.xml | 4 +- res/layout/error_console.xml | 2 +- res/layout/geolocation_permissions_prompt.xml | 4 +- res/layout/nav_screen.xml | 2 +- res/layout/pick_bookmark.xml | 2 +- res/layout/snapshots.xml | 2 +- res/layout/tab_bar.xml | 2 +- res/layout/title_bar.xml | 2 +- res/layout/title_bar_autologin.xml | 4 +- res/layout/title_bar_nav.xml | 6 +- res/layout/title_bar_snapshot.xml | 4 +- res/layout/webview_preview.xml | 2 +- res/menu/browser.xml | 2 +- res/mipmap-hdpi/ic_launcher_browser.png | Bin 13975 -> 3998 bytes res/mipmap-mdpi/ic_launcher_browser.png | Bin 7151 -> 2398 bytes res/mipmap-xhdpi/ic_launcher_browser.png | Bin 21981 -> 4963 bytes res/mipmap-xxhdpi/ic_launcher_browser.png | Bin 37607 -> 7017 bytes res/values-en-rGB/strings.xml | 1 + res/values/bools.xml | 2 +- res/values/strings.xml | 35 +- res/xml-sw600dp/advanced_preferences.xml | 9 +- res/xml-sw600dp/bookmarkthumbnailwidget_info.xml | 2 +- res/xml/accessibility_preferences.xml | 18 +- res/xml/advanced_preferences.xml | 9 +- res/xml/bookmarkthumbnailwidget_info.xml | 2 +- res/xml/general_preferences.xml | 4 +- res/xml/preference_headers.xml | 12 +- res/xml/privacy_security_preferences.xml | 12 +- .../swe/browser/AccountsChangedReceiver.java | 10 +- .../android/swe/browser/ActivityController.java | 2 +- src/com/android/swe/browser/AddBookmarkFolder.java | 24 +- src/com/android/swe/browser/AddBookmarkPage.java | 21 +- src/com/android/swe/browser/AddNewBookmark.java | 4 +- .../swe/browser/AutoFillProfileDatabase.java | 154 ------ .../swe/browser/AutoFillSettingsFragment.java | 18 +- src/com/android/swe/browser/AutofillHandler.java | 245 +-------- src/com/android/swe/browser/AutologinBar.java | 7 +- src/com/android/swe/browser/BackgroundHandler.java | 2 +- src/com/android/swe/browser/BaseUi.java | 22 +- src/com/android/swe/browser/BookmarkItem.java | 14 +- src/com/android/swe/browser/BookmarkSearch.java | 2 +- src/com/android/swe/browser/BookmarkUtils.java | 8 +- src/com/android/swe/browser/Bookmarks.java | 17 +- src/com/android/swe/browser/BookmarksLoader.java | 5 +- src/com/android/swe/browser/BreadCrumbView.java | 9 +- src/com/android/swe/browser/Browser.java | 29 +- src/com/android/swe/browser/BrowserActivity.java | 50 +- .../android/swe/browser/BrowserBackupAgent.java | 8 +- .../swe/browser/BrowserBookmarksAdapter.java | 9 +- .../swe/browser/BrowserBookmarksAdapterItem.java | 2 +- .../android/swe/browser/BrowserBookmarksPage.java | 17 +- .../android/swe/browser/BrowserHistoryPage.java | 19 +- .../swe/browser/BrowserPreferencesPage.java | 7 +- src/com/android/swe/browser/BrowserSettings.java | 144 ++++-- .../android/swe/browser/BrowserSnapshotPage.java | 5 +- src/com/android/swe/browser/BrowserUtils.java | 4 +- src/com/android/swe/browser/BrowserWebView.java | 27 +- .../android/swe/browser/BrowserWebViewFactory.java | 14 +- .../swe/browser/BrowserYesNoPreference.java | 8 +- .../swe/browser/CombinedBookmarksCallbacks.java | 2 +- src/com/android/swe/browser/ComboViewActivity.java | 17 +- src/com/android/swe/browser/Controller.java | 296 +++++++---- .../android/swe/browser/CrashRecoveryHandler.java | 2 +- src/com/android/swe/browser/DataController.java | 10 +- src/com/android/swe/browser/DataUri.java | 7 +- .../browser/DateSortedExpandableListAdapter.java | 4 +- .../android/swe/browser/DeviceAccountLogin.java | 4 +- src/com/android/swe/browser/DownloadHandler.java | 80 ++- src/com/android/swe/browser/DownloadSettings.java | 5 +- src/com/android/swe/browser/DownloadTouchIcon.java | 18 +- src/com/android/swe/browser/ErrorConsoleView.java | 7 +- src/com/android/swe/browser/EventLogTags.logtags | 2 +- src/com/android/swe/browser/FetchUrlMimeType.java | 26 +- .../swe/browser/GeolocationPermissionsPrompt.java | 4 +- .../android/swe/browser/GoogleAccountLogin.java | 10 +- src/com/android/swe/browser/HistoryItem.java | 4 +- .../swe/browser/HttpAuthenticationDialog.java | 4 +- src/com/android/swe/browser/IntentHandler.java | 21 +- src/com/android/swe/browser/KeyChainLookup.java | 4 +- src/com/android/swe/browser/LogTag.java | 11 +- src/com/android/swe/browser/MessagesReceiver.java | 4 +- src/com/android/swe/browser/NavScreen.java | 19 +- src/com/android/swe/browser/NavTabScroller.java | 14 +- src/com/android/swe/browser/NavTabView.java | 9 +- src/com/android/swe/browser/NavigationBarBase.java | 34 +- .../android/swe/browser/NavigationBarPhone.java | 13 +- .../android/swe/browser/NavigationBarTablet.java | 14 +- .../android/swe/browser/NetworkStateHandler.java | 11 +- src/com/android/swe/browser/NfcHandler.java | 2 +- .../android/swe/browser/OpenDownloadReceiver.java | 2 +- .../android/swe/browser/OptionsMenuHandler.java | 2 +- .../android/swe/browser/PageDialogsHandler.java | 46 +- src/com/android/swe/browser/PageProgressView.java | 2 +- src/com/android/swe/browser/Performance.java | 9 +- src/com/android/swe/browser/PhoneUi.java | 64 ++- src/com/android/swe/browser/PieControl.java | 17 +- src/com/android/swe/browser/PreferenceKeys.java | 3 +- src/com/android/swe/browser/PreloadController.java | 8 +- .../swe/browser/PreloadRequestReceiver.java | 4 +- .../android/swe/browser/PreloadedTabControl.java | 4 +- src/com/android/swe/browser/Preloader.java | 6 +- src/com/android/swe/browser/ShortcutActivity.java | 4 +- src/com/android/swe/browser/SnapshotBar.java | 5 +- src/com/android/swe/browser/SnapshotTab.java | 32 +- .../android/swe/browser/SuggestionsAdapter.java | 11 +- .../swe/browser/SystemAllowGeolocationOrigins.java | 7 +- src/com/android/swe/browser/Tab.java | 240 +++++---- src/com/android/swe/browser/TabBar.java | 4 +- src/com/android/swe/browser/TabControl.java | 19 +- src/com/android/swe/browser/TabScrollView.java | 5 +- src/com/android/swe/browser/TitleBar.java | 18 +- src/com/android/swe/browser/UI.java | 4 +- src/com/android/swe/browser/UiController.java | 6 +- src/com/android/swe/browser/UploadHandler.java | 12 +- .../android/swe/browser/UrlBarAutoShowManager.java | 6 +- src/com/android/swe/browser/UrlHandler.java | 147 +----- src/com/android/swe/browser/UrlInputView.java | 34 +- .../swe/browser/UrlSelectionActionMode.java | 4 +- src/com/android/swe/browser/UrlUtils.java | 2 +- src/com/android/swe/browser/WallpaperHandler.java | 4 +- .../android/swe/browser/WebStorageSizeManager.java | 9 +- src/com/android/swe/browser/WebViewController.java | 13 +- src/com/android/swe/browser/WebViewFactory.java | 4 +- src/com/android/swe/browser/WebViewProperties.java | 2 +- .../android/swe/browser/WebViewTimersControl.java | 6 +- src/com/android/swe/browser/XLargeUi.java | 11 +- .../swe/browser/addbookmark/FolderSpinner.java | 2 +- .../browser/addbookmark/FolderSpinnerAdapter.java | 4 +- .../swe/browser/homepages/HomeProvider.java | 248 ++++----- .../swe/browser/homepages/RequestHandler.java | 528 +++++++++---------- .../android/swe/browser/homepages/Template.java | 562 ++++++++++----------- .../browser/mynavigation/AddMyNavigationPage.java | 10 +- .../mynavigation/MyNavigationRequestHandler.java | 6 +- .../browser/mynavigation/MyNavigationTemplate.java | 4 +- .../swe/browser/mynavigation/MyNavigationUtil.java | 6 +- .../browser/platformsupport/SeekBarPreference.java | 18 +- .../AccessibilityPreferencesFragment.java | 20 +- .../preferences/AdvancedPreferencesFragment.java | 18 +- .../preferences/BandwidthPreferencesFragment.java | 8 +- .../preferences/DebugPreferencesFragment.java | 10 +- .../swe/browser/preferences/FontSizePreview.java | 10 +- .../preferences/GeneralPreferencesFragment.java | 14 +- .../preferences/InvertedContrastPreview.java | 18 +- .../preferences/LabPreferencesFragment.java | 10 +- .../preferences/NonformattingListPreference.java | 2 +- .../PrivacySecurityPreferencesFragment.java | 6 +- .../preferences/SeekBarSummaryPreference.java | 9 +- .../swe/browser/preferences/WebViewPreview.java | 6 +- .../preferences/WebsiteSettingsFragment.java | 13 +- .../swe/browser/provider/BrowserProvider.java | 8 +- .../swe/browser/provider/BrowserProvider2.java | 57 ++- .../swe/browser/provider/MyNavigationProvider.java | 14 +- .../browser/provider/SQLiteContentProvider.java | 2 +- .../swe/browser/provider/SnapshotProvider.java | 44 +- .../android/swe/browser/reflect/ReflectHelper.java | 163 ++++++ .../swe/browser/search/DefaultSearchEngine.java | 19 +- .../swe/browser/search/OpenSearchSearchEngine.java | 4 +- .../android/swe/browser/search/SearchEngine.java | 2 +- .../swe/browser/search/SearchEngineInfo.java | 4 +- .../swe/browser/search/SearchEnginePreference.java | 4 +- .../android/swe/browser/search/SearchEngines.java | 13 +- .../android/swe/browser/stub/NullController.java | 4 +- .../swe/browser/util/ThreadedCursorAdapter.java | 5 +- src/com/android/swe/browser/view/BasePieView.java | 2 +- .../swe/browser/view/BookmarkContainer.java | 2 +- .../swe/browser/view/BookmarkExpandableView.java | 40 +- .../swe/browser/view/CustomScreenLinearLayout.java | 2 +- .../browser/view/EventRedirectingFrameLayout.java | 2 +- src/com/android/swe/browser/view/PieItem.java | 4 +- src/com/android/swe/browser/view/PieListView.java | 4 +- src/com/android/swe/browser/view/PieMenu.java | 4 +- src/com/android/swe/browser/view/PieStackView.java | 4 +- src/com/android/swe/browser/view/ScrollerView.java | 271 ++++++---- .../android/swe/browser/view/SnapshotGridView.java | 2 +- .../android/swe/browser/view/StopProgressView.java | 8 +- .../widget/BookmarkThumbnailWidgetProvider.java | 8 +- .../widget/BookmarkThumbnailWidgetService.java | 51 +- .../browser/widget/BookmarkWidgetConfigure.java | 10 +- .../swe/browser/widget/BookmarkWidgetProxy.java | 4 +- swe_android_browser.gypi | 4 +- tests/AndroidManifest.xml | 10 +- .../android/browser/BrowserLaunchPerformance.java | 4 +- .../com/android/browser/BrowserProviderTests.java | 8 +- .../com/android/browser/IntentHandlerTests.java | 4 +- tests/src/com/android/browser/PopularUrlsTest.java | 9 +- .../com/android/browser/TestWebChromeClient.java | 11 +- .../src/com/android/browser/TestWebViewClient.java | 12 +- .../browser/WebStorageSizeManagerUnitTests.java | 2 +- .../android/browser/tests/BP1to2UpgradeTests.java | 18 +- .../android/browser/tests/BP2ProviderTests.java | 9 +- .../android/browser/tests/BP2UriObserverTests.java | 10 +- .../com/android/browser/tests/BookmarksTests.java | 8 +- .../browser/tests/utils/BP2TestCaseHelper.java | 11 +- .../browser/tests/utils/MockContentResolver2.java | 2 +- .../browser/tests/utils/MockObserverNode.java | 2 +- .../browser/tests/utils/ProviderTestCase3.java | 4 +- 212 files changed, 2834 insertions(+), 2341 deletions(-) delete mode 100644 src/com/android/swe/browser/AutoFillProfileDatabase.java create mode 100644 src/com/android/swe/browser/reflect/ReflectHelper.java diff --git a/Android.mk b/Android.mk index 06b02d67..138550eb 100644 --- a/Android.mk +++ b/Android.mk @@ -9,6 +9,17 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ android-support-v13 \ android-support-v4 \ +ifeq ($(ENABLE_SWE_ENGINE),true) +#Build swe_res +SWE_PATH = $(TARGET_OUT_INTERMEDIATES)/APPS/Browser_intermediates/swe + +SWE_BUILD := $(shell env -i ./packages/apps/Browser/tools/build_swe.sh $(SWE_PATH)) + +$(shell ln -s ../../../external/swe/src/out/Release/swe_test_apk/swe_res $(LOCAL_PATH)/.) +LOCAL_STATIC_JAVA_LIBRARIES += libsweengine +endif + + LOCAL_SRC_FILES := \ $(call all-java-files-under, src) \ src/com/android/browser/EventLogTags.logtags @@ -19,10 +30,50 @@ LOCAL_PROGUARD_FLAG_FILES := proguard.flags LOCAL_EMMA_COVERAGE_FILTER := *,-com.android.common.* +ifeq ($(ENABLE_SWE_ENGINE),true) +#symlink pak file from swe_res +$(shell ln -s ../swe_res/assets/webviewchromium.pak $(LOCAL_PATH)/assets/. -d) + +#package swe so's to apk +prebuilt_libs := \ + swe_res/lib/ + +prebuilt_swe_libs := \ + $(foreach _file, $(wildcard $(LOCAL_PATH)/swe_res/lib/*.so),\ + $(notdir $(basename $(_file)))) + +prebuilt_swe_libs_full_path := \ + $(foreach _file, $(wildcard $(LOCAL_PATH)/swe_res/lib/*.so),\ + $(addprefix swe_res/lib/,$(notdir $(_file)))) + +LOCAL_REQUIRED_MODULES := $(prebuilt_swe_libs) + +LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, swe_res/content_res/res swe_res/ui_res/res swe_res/swe_res/res res) +LOCAL_AAPT_FLAGS := --auto-add-overlay --extra-packages org.chromium.content:org.chromium.ui:org.codeaurora.swe + +$(echo $(SWE_BUILD)) +endif + # We need the sound recorder for the Media Capture API. -LOCAL_REQUIRED_MODULES := SoundRecorder +LOCAL_REQUIRED_MODULES += SoundRecorder include $(BUILD_PACKAGE) +ifeq ($(ENABLE_SWE_ENGINE),true) +################################################# +include $(CLEAR_VARS) +LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libsweengine:swe_res/jar/swe_engine.jar +include $(BUILD_MULTI_PREBUILT) +################################################ +endif + +ifeq ($(ENABLE_SWE_ENGINE),true) +##############adding external .so to system/lib ################## +include $(CLEAR_VARS) +LOCAL_MODULE_TAGS := optional +LOCAL_PREBUILT_LIBS := $(prebuilt_swe_libs_full_path) +include $(BUILD_MULTI_PREBUILT) +endif + # additionally, build tests in sub-folders in a separate .apk -include $(call all-makefiles-under,$(LOCAL_PATH)) +include $(call all-makefiles-under,$(LOCAL_PATH)) \ No newline at end of file diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 44413643..974052e6 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -16,13 +16,16 @@ */ --> - + - + - + @@ -47,21 +50,21 @@ - - + + + - - - + android:readPermission="com.android.swe.browser.permission.READ_HOMEPAGE" + android:writePermission="com.android.swe.browser.permission.WRITE_HOMEPAGE" /> - - @@ -173,14 +176,15 @@ - + - - @@ -204,7 +209,8 @@ - - - @@ -230,26 +236,26 @@ + android:name="com.android.swe.browser.BOOKMARK_APPWIDGET_UPDATE" /> - @@ -257,12 +263,11 @@ - - @@ -274,7 +279,7 @@ - + @@ -282,41 +287,119 @@ - + - + - - + - + + + + + + + + + + + + + + - + + + + + + + + + \ No newline at end of file diff --git a/assets/html/flashtest.html b/assets/html/flashtest.html index 8e1cf48f..081d7520 100644 --- a/assets/html/flashtest.html +++ b/assets/html/flashtest.html @@ -9,7 +9,7 @@ This is text above the plugin
lhs - +
diff --git a/proguard.flags b/proguard.flags index 3a6daefd..5354e1c3 100644 --- a/proguard.flags +++ b/proguard.flags @@ -1,6 +1,10 @@ # Most of the classes in this package are fragments only referenced from XML --keep class com.android.browser.preferences.* --keep class com.android.browser.BrowserActivity{ +-keep class com.android.swe.browser.preferences.* +-keep class com.android.swe.browser.BrowserActivity{ public void loadBookmarks(); public void loadHistory(); } +-keep class org.chromium.** {*;} +-keep class org.chromium.components.navigation_interception.** {*;} +-keep class org.chromium.components.web_contents_delegate_android.** {*;} +-keep class org.codeaurora.** {*;} diff --git a/res/layout-land/nav_screen.xml b/res/layout-land/nav_screen.xml index fdadd6a6..eb26fe44 100644 --- a/res/layout-land/nav_screen.xml +++ b/res/layout-land/nav_screen.xml @@ -20,7 +20,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/browser_background_holo"> - diff --git a/res/layout-sw600dp/pick_bookmark.xml b/res/layout-sw600dp/pick_bookmark.xml index b35dbb94..a6fced41 100644 --- a/res/layout-sw600dp/pick_bookmark.xml +++ b/res/layout-sw600dp/pick_bookmark.xml @@ -22,7 +22,7 @@ android:showDividers="middle" android:dividerPadding="16dip"> - - - + diff --git a/res/layout-sw600dp/title_bar_nav.xml b/res/layout-sw600dp/title_bar_nav.xml index a6b8a325..450029e0 100644 --- a/res/layout-sw600dp/title_bar_nav.xml +++ b/res/layout-sw600dp/title_bar_nav.xml @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. --> - @@ -67,7 +67,7 @@ android:layout_marginLeft="0dip" style="@style/HoloIcon" android:visibility="gone" /> - - + diff --git a/res/layout-sw600dp/title_bar_snapshot.xml b/res/layout-sw600dp/title_bar_snapshot.xml index a2cc9d01..252902c4 100644 --- a/res/layout-sw600dp/title_bar_snapshot.xml +++ b/res/layout-sw600dp/title_bar_snapshot.xml @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. --> - - + \ No newline at end of file diff --git a/res/layout/bookmark_list.xml b/res/layout/bookmark_list.xml index 4425a26c..808ef521 100644 --- a/res/layout/bookmark_list.xml +++ b/res/layout/bookmark_list.xml @@ -14,7 +14,7 @@ limitations under the License. --> - - + diff --git a/res/layout/bookmark_sync_wizard.xml b/res/layout/bookmark_sync_wizard.xml index 3a3d9dae..f6be517f 100644 --- a/res/layout/bookmark_sync_wizard.xml +++ b/res/layout/bookmark_sync_wizard.xml @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. --> - diff --git a/res/layout/bookmark_thumbnail.xml b/res/layout/bookmark_thumbnail.xml index cd7b9be0..00ad8ab9 100644 --- a/res/layout/bookmark_thumbnail.xml +++ b/res/layout/bookmark_thumbnail.xml @@ -14,7 +14,8 @@ limitations under the License. --> - - + diff --git a/res/layout/bookmarks.xml b/res/layout/bookmarks.xml index 09b442ec..59ef131b 100644 --- a/res/layout/bookmarks.xml +++ b/res/layout/bookmarks.xml @@ -19,7 +19,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="@dimen/combo_paddingTop"> - - - @@ -160,7 +160,7 @@ android:text="@string/containing_folder" android:textAppearance="?android:attr/textAppearanceMedium" /> - - + android:text="@string/browser_tab_crash_reload"/> - - + diff --git a/res/layout/error_console.xml b/res/layout/error_console.xml index e2396228..35e33cbf 100644 --- a/res/layout/error_console.xml +++ b/res/layout/error_console.xml @@ -33,7 +33,7 @@ android:visibility="gone" /> - - - + diff --git a/res/layout/nav_screen.xml b/res/layout/nav_screen.xml index c6557273..b3ececf3 100644 --- a/res/layout/nav_screen.xml +++ b/res/layout/nav_screen.xml @@ -20,7 +20,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/browser_background_holo"> - - diff --git a/res/layout/snapshots.xml b/res/layout/snapshots.xml index a02fbb9d..e049aa69 100644 --- a/res/layout/snapshots.xml +++ b/res/layout/snapshots.xml @@ -20,7 +20,7 @@ android:layout_height="match_parent" android:paddingTop="@dimen/combo_paddingTop"> - - - - - + diff --git a/res/layout/title_bar_nav.xml b/res/layout/title_bar_nav.xml index 2f1e0a27..d47b3168 100644 --- a/res/layout/title_bar_nav.xml +++ b/res/layout/title_bar_nav.xml @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. --> - @@ -71,7 +71,7 @@ android:contentDescription="@string/accessibility_button_stop" android:src="@drawable/ic_stop_holo_dark" style="@style/HoloButton" /> - - + diff --git a/res/layout/title_bar_snapshot.xml b/res/layout/title_bar_snapshot.xml index 0e2ab1ce..004716bc 100644 --- a/res/layout/title_bar_snapshot.xml +++ b/res/layout/title_bar_snapshot.xml @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. --> - - + diff --git a/res/layout/webview_preview.xml b/res/layout/webview_preview.xml index 8f8d810a..f0acf456 100644 --- a/res/layout/webview_preview.xml +++ b/res/layout/webview_preview.xml @@ -72,7 +72,7 @@ android:gravity="center" android:orientation="vertical" /> - + android:title="@string/find_on_page"/> "Display images on web pages" "Block pop-ups" "Enable JavaScript" + "Enable Memory Monitor" "Open in background" "Enable plug-ins" diff --git a/res/values/bools.xml b/res/values/bools.xml index 3c20f9ab..cc8ff5a5 100644 --- a/res/values/bools.xml +++ b/res/values/bools.xml @@ -14,7 +14,7 @@ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> false - true + false true true diff --git a/res/values/strings.xml b/res/values/strings.xml index 3db6ea7a..7227c079 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4,18 +4,21 @@ 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. --> + +]> - Browser + SWE Browser Choose file for upload New tab + + Oops, Snap ! + + Reload + + + Something unexpected happened when displaying this webpage. + Please reload or go to another page. + New incognito tab @@ -175,7 +187,7 @@ This URL can\'t be bookmarked. Bookmark last-viewed page Map - + @@ -299,6 +311,8 @@ Enable JavaScript + Enable Memory Monitor + Open in background Enable plug-ins @@ -722,7 +736,7 @@ Add - + Browser @@ -842,7 +856,7 @@ Touch to free up space. Clear stored data - + Delete all data stored by this website? OK @@ -956,6 +970,8 @@ Preview Local + + Find on page Request desktop site @@ -1091,4 +1107,7 @@ Receive a message from: %s. Activity Not Found to Handle Intent %s. - + + Security certificate + This certificate is valid. + \ No newline at end of file diff --git a/res/xml-sw600dp/advanced_preferences.xml b/res/xml-sw600dp/advanced_preferences.xml index 73f145b9..d8724b81 100644 --- a/res/xml-sw600dp/advanced_preferences.xml +++ b/res/xml-sw600dp/advanced_preferences.xml @@ -18,7 +18,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"> - + + - + android:configure="com.android.swe.browser.widget.BookmarkWidgetConfigure"> diff --git a/res/xml/accessibility_preferences.xml b/res/xml/accessibility_preferences.xml index 8eca9176..d77dd278 100644 --- a/res/xml/accessibility_preferences.xml +++ b/res/xml/accessibility_preferences.xml @@ -23,31 +23,31 @@ android:defaultValue="false" /> - - - - - - + diff --git a/res/xml/advanced_preferences.xml b/res/xml/advanced_preferences.xml index e292b7d8..b4daa4b6 100644 --- a/res/xml/advanced_preferences.xml +++ b/res/xml/advanced_preferences.xml @@ -18,7 +18,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"> - + + - + android:configure="com.android.swe.browser.widget.BookmarkWidgetConfigure"> diff --git a/res/xml/general_preferences.xml b/res/xml/general_preferences.xml index 6f42d3d7..aad8a62f 100644 --- a/res/xml/general_preferences.xml +++ b/res/xml/general_preferences.xml @@ -16,7 +16,7 @@ - diff --git a/res/xml/preference_headers.xml b/res/xml/preference_headers.xml index 2c80835b..484d305f 100644 --- a/res/xml/preference_headers.xml +++ b/res/xml/preference_headers.xml @@ -16,27 +16,27 @@ -
-
-
-
-
-
diff --git a/res/xml/privacy_security_preferences.xml b/res/xml/privacy_security_preferences.xml index 26336000..dba55149 100644 --- a/res/xml/privacy_security_preferences.xml +++ b/res/xml/privacy_security_preferences.xml @@ -17,14 +17,14 @@ - - - - - - 0) { - c.moveToFirst(); - - String fullName = c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.FULL_NAME)); - String email = c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.EMAIL_ADDRESS)); - String company = c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.COMPANY_NAME)); - String addressLine1 = c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.ADDRESS_LINE_1)); - String addressLine2 = c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.ADDRESS_LINE_2)); - String city = c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.CITY)); - String state = c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.STATE)); - String zip = c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.ZIP_CODE)); - String country = c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.COUNTRY)); - String phone = c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.PHONE_NUMBER)); - mAutoFillProfile = new AutoFillProfile(mAutoFillActiveProfileId, - fullName, email, company, addressLine1, addressLine2, city, - state, zip, country, phone); - } - c.close(); - autoFillDb.close(); - - // At this point we've loaded the profile if there was one, so let any thread - // waiting on initialization continue. - mLoaded.countDown(); - - // Synchronization note: strictly speaking, it's possible that mAutoFillProfile - // may get a value after we check below, but that's OK. This check is only an - // optimisation, and we do a proper synchronized check further down when it comes - // to actually setting the inferred profile. - if (mAutoFillProfile == null) { - // We did not load a profile from disk. Try to infer one from the user's - // "me" contact. - final Uri profileUri = Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI, - ContactsContract.Contacts.Data.CONTENT_DIRECTORY); - String name = getContactField(profileUri, - ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, - ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); - // Only attempt to read other data and set a profile if we could successfully - // get a name. - if (name != null) { - String email = getContactField(profileUri, - ContactsContract.CommonDataKinds.Email.ADDRESS, - ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); - String phone = getContactField(profileUri, - ContactsContract.CommonDataKinds.Phone.NUMBER, - ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); - String company = getContactField(profileUri, - ContactsContract.CommonDataKinds.Organization.COMPANY, - ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE); - - // Can't easily get structured postal address information (even using - // CommonDataKinds.StructuredPostal) so omit prepopulating that for now. - // When querying structured postal data, it often all comes back as a string - // inside the "street" field. - - synchronized(AutofillHandler.this) { - // Only use this profile if one hasn't been set inbetween the - // inital import and this thread getting to this point. - if (mAutoFillProfile == null) { - setAutoFillProfile(new AutoFillProfile(1, name, email, company, - null, null, null, null, null, null, phone), null); - } - } - } - } - } - - private String getContactField(Uri uri, String field, String itemType) { - String result = null; - - Cursor c = mContext.getContentResolver().query(uri, new String[] { field }, - ContactsContract.Data.MIMETYPE + "=?", new String[] { itemType }, null); - - if (c == null) { - return null; - } - - try { - // Just use the first returned value if we get more than one. - if (c.moveToFirst()) { - result = c.getString(0); - } - } finally { - c.close(); - } - return result; - } } - public synchronized void setAutoFillProfile(AutoFillProfile profile, Message msg) { - waitForLoad(); - int profileId = NO_AUTOFILL_PROFILE_SET; - if (profile != null) { - profileId = profile.getUniqueId(); - // Update the AutoFill DB with the new profile. - new SaveProfileToDbTask(msg).execute(profile); - } else { - // Delete the current profile. - if (mAutoFillProfile != null) { - new DeleteProfileFromDbTask(msg).execute(mAutoFillProfile.getUniqueId()); - } - } - // Make sure we set mAutoFillProfile before calling setActiveAutoFillProfileId - // Calling setActiveAutoFillProfileId will trigger an update of WebViews - // which will expect a new profile to be set + public synchronized void setAutoFillProfile(AutoFillProfile profile) { mAutoFillProfile = profile; - setActiveAutoFillProfileId(profileId); + if (profile == null) + setActiveAutoFillProfileId(""); + else + setActiveAutoFillProfileId(profile.getUniqueId()); } public synchronized AutoFillProfile getAutoFillProfile() { - waitForLoad(); return mAutoFillProfile; } - private synchronized void setActiveAutoFillProfileId(int activeProfileId) { + public synchronized String getAutoFillProfileId() { + return mAutoFillActiveProfileId; + } + + private synchronized void setActiveAutoFillProfileId(String activeProfileId) { + if (mAutoFillActiveProfileId.equals(activeProfileId)) { + return; + } mAutoFillActiveProfileId = activeProfileId; Editor ed = PreferenceManager. getDefaultSharedPreferences(mContext).edit(); - ed.putInt(PreferenceKeys.PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId); + ed.putString(PreferenceKeys.PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId); ed.apply(); } - - private abstract class AutoFillProfileDbTask extends AsyncTask { - AutoFillProfileDatabase mAutoFillProfileDb; - Message mCompleteMessage; - - public AutoFillProfileDbTask(Message msg) { - mCompleteMessage = msg; - } - - @Override - protected void onPostExecute(Void result) { - if (mCompleteMessage != null) { - mCompleteMessage.sendToTarget(); - } - mAutoFillProfileDb.close(); - } - - @Override - abstract protected Void doInBackground(T... values); - } - - - private class SaveProfileToDbTask extends AutoFillProfileDbTask { - public SaveProfileToDbTask(Message msg) { - super(msg); - } - - @Override - protected Void doInBackground(AutoFillProfile... values) { - mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext); - synchronized (AutofillHandler.this) { - assert mAutoFillActiveProfileId != NO_AUTOFILL_PROFILE_SET; - AutoFillProfile newProfile = values[0]; - mAutoFillProfileDb.addOrUpdateProfile(mAutoFillActiveProfileId, newProfile); - } - return null; - } - } - - private class DeleteProfileFromDbTask extends AutoFillProfileDbTask { - public DeleteProfileFromDbTask(Message msg) { - super(msg); - } - - @Override - protected Void doInBackground(Integer... values) { - mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext); - int id = values[0]; - assert id > 0; - mAutoFillProfileDb.dropProfile(id); - return null; - } - } } diff --git a/src/com/android/swe/browser/AutologinBar.java b/src/com/android/swe/browser/AutologinBar.java index e57d614b..41effff1 100644 --- a/src/com/android/swe/browser/AutologinBar.java +++ b/src/com/android/swe/browser/AutologinBar.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.util.AttributeSet; @@ -27,7 +27,8 @@ import android.widget.ProgressBar; import android.widget.Spinner; import android.widget.TextView; -import com.android.browser.DeviceAccountLogin.AutoLoginCallback; +import com.android.swe.browser.R; +import com.android.swe.browser.DeviceAccountLogin.AutoLoginCallback; public class AutologinBar extends LinearLayout implements OnClickListener, AutoLoginCallback { @@ -93,7 +94,7 @@ public class AutologinBar extends LinearLayout implements OnClickListener, DeviceAccountLogin login = tab.getDeviceAccountLogin(); if (login != null) { mAutoLoginHandler = login; - ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext, + ContextThemeWrapper wrapper = new ContextThemeWrapper(getContext(), android.R.style.Theme_Holo_Light); mAccountsAdapter = new ArrayAdapter(wrapper, android.R.layout.simple_spinner_item, login.getAccountNames()); diff --git a/src/com/android/swe/browser/BackgroundHandler.java b/src/com/android/swe/browser/BackgroundHandler.java index a0d9243e..640596cc 100644 --- a/src/com/android/swe/browser/BackgroundHandler.java +++ b/src/com/android/swe/browser/BackgroundHandler.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.os.HandlerThread; import android.os.Looper; diff --git a/src/com/android/swe/browser/BaseUi.java b/src/com/android/swe/browser/BaseUi.java index 959d2ec9..d1689f3e 100644 --- a/src/com/android/swe/browser/BaseUi.java +++ b/src/com/android/swe/browser/BaseUi.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.Context; @@ -44,16 +44,16 @@ import android.view.ViewGroup.LayoutParams; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; -import android.webkit.WebChromeClient; -import android.webkit.WebView; -import android.webkit.WebViewClassic; +import android.webkit.WebChromeClient.CustomViewCallback; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.Toast; -import com.android.browser.Tab.SecurityState; -import com.android.internal.view.menu.MenuBuilder; +import com.android.swe.browser.R; +import com.android.swe.browser.Tab.SecurityState; + +import org.codeaurora.swe.WebView; import java.util.List; @@ -94,7 +94,7 @@ public abstract class BaseUi implements UI { private FrameLayout mFixedTitlebarContainer; private View mCustomView; - private WebChromeClient.CustomViewCallback mCustomViewCallback; + private CustomViewCallback mCustomViewCallback; private int mOriginalOrientation; private LinearLayout mErrorConsoleContainer = null; @@ -521,7 +521,7 @@ public abstract class BaseUi implements UI { @Override public void showCustomView(View view, int requestedOrientation, - WebChromeClient.CustomViewCallback callback) { + CustomViewCallback callback) { // if a view already exists then immediately terminate the new one if (mCustomView != null) { callback.onCustomViewHidden(); @@ -756,12 +756,6 @@ public abstract class BaseUi implements UI { } } - protected Menu getMenu() { - MenuBuilder menu = new MenuBuilder(mActivity); - mActivity.getMenuInflater().inflate(R.menu.browser, menu); - return menu; - } - public void setFullscreen(boolean enabled) { Window win = mActivity.getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); diff --git a/src/com/android/swe/browser/BookmarkItem.java b/src/com/android/swe/browser/BookmarkItem.java index 85c1fff2..2cf16bee 100644 --- a/src/com/android/swe/browser/BookmarkItem.java +++ b/src/com/android/swe/browser/BookmarkItem.java @@ -14,7 +14,9 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; + +import com.android.swe.browser.R; import android.content.Context; import android.graphics.Bitmap; @@ -117,7 +119,7 @@ class BookmarkItem extends HorizontalScrollView { mTextView.setText(name); } - + /** * Set the new url for the bookmark item. * @param url The new url for the bookmark item. @@ -164,9 +166,9 @@ class BookmarkItem extends HorizontalScrollView { final ViewGroup.LayoutParams lp = child.getLayoutParams(); final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, - mPaddingLeft + mPaddingRight, lp.width); + getPaddingLeft() + getPaddingRight(), lp.width); final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, - mPaddingTop + mPaddingBottom, lp.height); + getPaddingTop() + getPaddingBottom(), lp.height); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); } @@ -184,10 +186,10 @@ class BookmarkItem extends HorizontalScrollView { final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, - mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin + getPaddingLeft() + getPaddingRight() + lp.leftMargin + lp.rightMargin + widthUsed, lp.width); final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, - mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin + getPaddingTop() + getPaddingBottom() + lp.topMargin + lp.bottomMargin + heightUsed, lp.height); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); diff --git a/src/com/android/swe/browser/BookmarkSearch.java b/src/com/android/swe/browser/BookmarkSearch.java index 4d3ca0f3..08ebc66f 100644 --- a/src/com/android/swe/browser/BookmarkSearch.java +++ b/src/com/android/swe/browser/BookmarkSearch.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.Intent; diff --git a/src/com/android/swe/browser/BookmarkUtils.java b/src/com/android/swe/browser/BookmarkUtils.java index 26e20722..c8f292ac 100644 --- a/src/com/android/swe/browser/BookmarkUtils.java +++ b/src/com/android/swe/browser/BookmarkUtils.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.ActivityManager; import android.app.AlertDialog; @@ -39,8 +39,10 @@ import android.graphics.drawable.PaintDrawable; import android.net.Uri; import android.os.Message; import android.provider.Browser; -import android.provider.BrowserContract; -import android.provider.BrowserContract.Bookmarks; + +import com.android.swe.browser.R; +import com.android.swe.browser.platformsupport.BrowserContract; +import com.android.swe.browser.platformsupport.BrowserContract.Bookmarks; public class BookmarkUtils { private final static String LOGTAG = "BookmarkUtils"; diff --git a/src/com/android/swe/browser/Bookmarks.java b/src/com/android/swe/browser/Bookmarks.java index 190ff9dd..d92532e7 100644 --- a/src/com/android/swe/browser/Bookmarks.java +++ b/src/com/android/swe/browser/Bookmarks.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.ContentResolver; import android.content.ContentUris; @@ -26,9 +26,12 @@ import android.graphics.Bitmap; import android.net.Uri; import android.os.AsyncTask; import android.preference.PreferenceManager; -import android.provider.BrowserContract; -import android.provider.BrowserContract.Combined; -import android.provider.BrowserContract.Images; + +import com.android.swe.browser.R; +import com.android.swe.browser.platformsupport.BrowserContract; +import com.android.swe.browser.platformsupport.BrowserContract.Combined; +import com.android.swe.browser.platformsupport.BrowserContract.Images; + import android.text.TextUtils; import android.util.Log; import android.webkit.WebIconDatabase; @@ -162,15 +165,15 @@ public class Bookmarks { if (cr == null || url == null) { return null; } - + // If originalUrl is null, just set it to url. if (originalUrl == null) { originalUrl = url; } - + // Look for both the original url and the actual url. This takes in to // account redirects. - + final String[] selArgs = new String[] { originalUrl, url }; final String[] projection = new String[] { Combined.URL }; return cr.query(Combined.CONTENT_URI, projection, QUERY_BOOKMARKS_WHERE, selArgs, null); diff --git a/src/com/android/swe/browser/BookmarksLoader.java b/src/com/android/swe/browser/BookmarksLoader.java index 8601c98b..803dc340 100644 --- a/src/com/android/swe/browser/BookmarksLoader.java +++ b/src/com/android/swe/browser/BookmarksLoader.java @@ -14,12 +14,13 @@ * limitations under the License */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.content.CursorLoader; import android.net.Uri; -import android.provider.BrowserContract.Bookmarks; + +import com.android.swe.browser.platformsupport.BrowserContract.Bookmarks; public class BookmarksLoader extends CursorLoader { public static final String ARG_ACCOUNT_TYPE = "acct_type"; diff --git a/src/com/android/swe/browser/BreadCrumbView.java b/src/com/android/swe/browser/BreadCrumbView.java index c3bff59f..cc2fc472 100644 --- a/src/com/android/swe/browser/BreadCrumbView.java +++ b/src/com/android/swe/browser/BreadCrumbView.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.content.res.TypedArray; @@ -34,6 +34,8 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.List; +import com.android.swe.browser.R; + /** * Simple bread crumb view * Use setController to receive callbacks from user interactions @@ -92,9 +94,8 @@ public class BreadCrumbView extends RelativeLayout implements OnClickListener { setGravity(Gravity.CENTER_VERTICAL); mUseBackButton = false; mCrumbs = new ArrayList(); - TypedArray a = mContext.obtainStyledAttributes(com.android.internal.R.styleable.Theme); - mSeparatorDrawable = a.getDrawable(com.android.internal.R.styleable.Theme_dividerVertical); - a.recycle(); + mSeparatorDrawable = ctx.getResources().getDrawable( + android.R.drawable.divider_horizontal_dark); float density = mContext.getResources().getDisplayMetrics().density; mDividerPadding = DIVIDER_PADDING * density; mCrumbPadding = (int) (CRUMB_PADDING * density); diff --git a/src/com/android/swe/browser/Browser.java b/src/com/android/swe/browser/Browser.java index add8bdd5..82d2b572 100644 --- a/src/com/android/swe/browser/Browser.java +++ b/src/com/android/swe/browser/Browser.java @@ -14,16 +14,20 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Application; +import android.content.Context; +import android.content.pm.PackageManager; import android.util.Log; -import android.webkit.CookieSyncManager; +import android.os.Process; -public class Browser extends Application { +import org.codeaurora.swe.CookieSyncManager; + +public class Browser extends Application { private final static String LOGTAG = "browser"; - + // Set to true to enable verbose logging. final static boolean LOGV_ENABLED = false; @@ -37,11 +41,18 @@ public class Browser extends Application { if (LOGV_ENABLED) Log.v(LOGTAG, "Browser.onCreate: this=" + this); - // create CookieSyncManager with current Context - CookieSyncManager.createInstance(this); - BrowserSettings.initialize(getApplicationContext()); - Preloader.initialize(getApplicationContext()); + // SWE: Avoid initializing databases for sandboxed processes. + // Must have INITIALIZE_DATABASE permission in AndroidManifest.xml only for browser process + final String INITIALIZE_DATABASE="com.android.swe.browser.permission.INITIALIZE_DATABASE"; + final Context context = getApplicationContext(); + if (context.checkPermission(INITIALIZE_DATABASE, + Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED) { + + // create CookieSyncManager with current Context + CookieSyncManager.createInstance(this); + BrowserSettings.initialize(getApplicationContext()); + Preloader.initialize(getApplicationContext()); + } } - } diff --git a/src/com/android/swe/browser/BrowserActivity.java b/src/com/android/swe/browser/BrowserActivity.java index a58e2a4b..a21b0e25 100644 --- a/src/com/android/swe/browser/BrowserActivity.java +++ b/src/com/android/swe/browser/BrowserActivity.java @@ -14,13 +14,15 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.app.AlertDialog; import android.app.KeyguardManager; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.res.Configuration; import android.os.Bundle; import android.os.Handler; @@ -35,22 +37,28 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.Window; -import android.webkit.WebSettings; -import android.webkit.WebView; import android.webkit.JavascriptInterface; -import com.android.browser.UI.ComboViews; -import com.android.browser.search.DefaultSearchEngine; -import com.android.browser.search.SearchEngine; -import com.android.browser.stub.NullController; - import com.google.common.annotations.VisibleForTesting; +import com.android.swe.browser.R; +import com.android.swe.browser.UI.ComboViews; +import com.android.swe.browser.search.DefaultSearchEngine; +import com.android.swe.browser.search.SearchEngine; +import com.android.swe.browser.stub.NullController; + +import org.chromium.content.browser.TracingIntentHandler; +import org.codeaurora.swe.WebSettings; +import org.codeaurora.swe.WebView; public class BrowserActivity extends Activity { public static final String ACTION_SHOW_BOOKMARKS = "show_bookmarks"; public static final String ACTION_SHOW_BROWSER = "show_browser"; public static final String ACTION_RESTART = "--restart--"; + private static final String ACTION_START_TRACE = + "org.chromium.content_shell.action.PROFILE_START"; + private static final String ACTION_STOP_TRACE = + "org.chromium.content_shell.action.PROFILE_STOP"; private static final String EXTRA_STATE = "state"; public static final String EXTRA_DISABLE_URL_OVERRIDE = "disable_url_override"; @@ -59,6 +67,8 @@ public class BrowserActivity extends Activity { private final static boolean LOGV_ENABLED = Browser.LOGV_ENABLED; private ActivityController mController = NullController.INSTANCE; + + private Handler mHandler = new Handler(); private UiController mUiController; @@ -75,6 +85,9 @@ public class BrowserActivity extends Activity { } }; + private BroadcastReceiver mReceiver; + + @Override public void onCreate(Bundle icicle) { if (LOGV_ENABLED) { @@ -170,6 +183,27 @@ public class BrowserActivity extends Activity { Log.v(LOGTAG, "BrowserActivity.onResume: this=" + this); } mController.onResume(); + IntentFilter intentFilter = new IntentFilter(ACTION_START_TRACE); + intentFilter.addAction(ACTION_STOP_TRACE); + mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + String extra = intent.getStringExtra("file"); + if (ACTION_START_TRACE.equals(action)) { + if (extra.isEmpty()) { + Log.e(LOGTAG, "Can not start tracing without specifing saving location"); + } else { + TracingIntentHandler.beginTracing(extra); + Log.i(LOGTAG, "start tracing"); + } + } else if (ACTION_STOP_TRACE.equals(action)) { + Log.i(LOGTAG, "stop tracing"); + TracingIntentHandler.endTracing(); + } + } + }; + registerReceiver(mReceiver, intentFilter); } @Override diff --git a/src/com/android/swe/browser/BrowserBackupAgent.java b/src/com/android/swe/browser/BrowserBackupAgent.java index 29504742..4d39a2be 100644 --- a/src/com/android/swe/browser/BrowserBackupAgent.java +++ b/src/com/android/swe/browser/BrowserBackupAgent.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.backup.BackupAgent; import android.app.backup.BackupDataInput; @@ -22,8 +22,10 @@ import android.app.backup.BackupDataOutput; import android.content.ContentValues; import android.database.Cursor; import android.os.ParcelFileDescriptor; -import android.provider.BrowserContract; -import android.provider.BrowserContract.Bookmarks; + +import com.android.swe.browser.platformsupport.BrowserContract; +import com.android.swe.browser.platformsupport.BrowserContract.Bookmarks; + import android.util.Log; import java.io.DataInputStream; diff --git a/src/com/android/swe/browser/BrowserBookmarksAdapter.java b/src/com/android/swe/browser/BrowserBookmarksAdapter.java index 5747112c..55155188 100644 --- a/src/com/android/swe/browser/BrowserBookmarksAdapter.java +++ b/src/com/android/swe/browser/BrowserBookmarksAdapter.java @@ -14,13 +14,12 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; -import android.provider.BrowserContract.Bookmarks; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -28,8 +27,10 @@ import android.widget.ImageView; import android.widget.ImageView.ScaleType; import android.widget.TextView; -import com.android.browser.util.ThreadedCursorAdapter; -import com.android.browser.view.BookmarkContainer; +import com.android.swe.browser.platformsupport.BrowserContract.Bookmarks; +import com.android.swe.browser.R; +import com.android.swe.browser.util.ThreadedCursorAdapter; +import com.android.swe.browser.view.BookmarkContainer; public class BrowserBookmarksAdapter extends ThreadedCursorAdapter { diff --git a/src/com/android/swe/browser/BrowserBookmarksAdapterItem.java b/src/com/android/swe/browser/BrowserBookmarksAdapterItem.java index 6b995787..7f37b785 100644 --- a/src/com/android/swe/browser/BrowserBookmarksAdapterItem.java +++ b/src/com/android/swe/browser/BrowserBookmarksAdapterItem.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.graphics.drawable.BitmapDrawable; diff --git a/src/com/android/swe/browser/BrowserBookmarksPage.java b/src/com/android/swe/browser/BrowserBookmarksPage.java index 0d310171..2aaff3ba 100644 --- a/src/com/android/swe/browser/BrowserBookmarksPage.java +++ b/src/com/android/swe/browser/BrowserBookmarksPage.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.app.Fragment; @@ -36,8 +36,6 @@ import android.graphics.BitmapFactory.Options; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; -import android.provider.BrowserContract; -import android.provider.BrowserContract.Accounts; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; @@ -50,15 +48,18 @@ import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; import android.widget.Toast; -import com.android.browser.provider.BrowserProvider2; -import com.android.browser.view.BookmarkExpandableView; -import com.android.browser.view.BookmarkExpandableView.BookmarkContextMenuInfo; +import com.android.swe.browser.R; +import com.android.swe.browser.platformsupport.BrowserContract; +import com.android.swe.browser.platformsupport.BrowserContract.Accounts; +import com.android.swe.browser.provider.BrowserProvider2; +import com.android.swe.browser.view.BookmarkExpandableView; +import com.android.swe.browser.view.BookmarkExpandableView.BookmarkContextMenuInfo; + +import java.util.HashMap; import org.json.JSONException; import org.json.JSONObject; -import java.util.HashMap; - interface BookmarksPageCallbacks { // Return true if handled boolean onBookmarkSelected(Cursor c, boolean isFolder); diff --git a/src/com/android/swe/browser/BrowserHistoryPage.java b/src/com/android/swe/browser/BrowserHistoryPage.java index 9493b85e..f30d1217 100644 --- a/src/com/android/swe/browser/BrowserHistoryPage.java +++ b/src/com/android/swe/browser/BrowserHistoryPage.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.app.AlertDialog; @@ -38,8 +38,6 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.provider.Browser; -import android.provider.BrowserContract; -import android.provider.BrowserContract.Combined; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; @@ -61,6 +59,11 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; +import com.android.swe.browser.R; +import com.android.swe.browser.platformsupport.BrowserContract; +import com.android.swe.browser.platformsupport.BrowserContract.Combined; +import com.android.swe.browser.reflect.ReflectHelper; + /** * Activity for displaying the browser's history, divided into * days of viewing. @@ -412,8 +415,14 @@ public class BrowserHistoryPage extends Fragment } return true; case R.id.share_link_context_menu_id: - Browser.sendString(activity, url, - activity.getText(R.string.choosertitle_sharevia).toString()); + Object[] params = {activity, + url, + activity.getText(R.string.choosertitle_sharevia).toString()}; + Class[] type = new Class[] { android.content.Context.class, + String.class, + String.class}; + ReflectHelper.invokeStaticMethod("android.provider.Browser","sendString", + type, params); return true; case R.id.copy_url_context_menu_id: copy(url); diff --git a/src/com/android/swe/browser/BrowserPreferencesPage.java b/src/com/android/swe/browser/BrowserPreferencesPage.java index 6e6da178..893f0569 100644 --- a/src/com/android/swe/browser/BrowserPreferencesPage.java +++ b/src/com/android/swe/browser/BrowserPreferencesPage.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.ActionBar; import android.content.Intent; @@ -22,8 +22,9 @@ import android.os.Bundle; import android.preference.PreferenceActivity; import android.view.MenuItem; -import com.android.browser.preferences.BandwidthPreferencesFragment; -import com.android.browser.preferences.DebugPreferencesFragment; +import com.android.swe.browser.R; +import com.android.swe.browser.preferences.BandwidthPreferencesFragment; +import com.android.swe.browser.preferences.DebugPreferencesFragment; import java.util.List; diff --git a/src/com/android/swe/browser/BrowserSettings.java b/src/com/android/swe/browser/BrowserSettings.java index 8d2d7b00..b3867ec0 100644 --- a/src/com/android/swe/browser/BrowserSettings.java +++ b/src/com/android/swe/browser/BrowserSettings.java @@ -14,9 +14,8 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; -import android.app.ActivityManager; import android.content.ContentResolver; import android.content.Context; import android.content.SharedPreferences; @@ -26,35 +25,23 @@ import android.content.res.AssetManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Build; -import android.os.Message; -import android.os.SystemProperties; import android.preference.PreferenceManager; import android.provider.Browser; import android.provider.Settings; import android.util.DisplayMetrics; import android.util.Log; -import android.util.Log; -import android.webkit.CookieManager; -import android.webkit.GeolocationPermissions; import android.webkit.WebIconDatabase; -import android.webkit.WebSettings; -import android.webkit.WebSettings.LayoutAlgorithm; -import android.webkit.WebSettings.PluginState; -import android.webkit.WebSettings.TextSize; -import android.webkit.WebSettings.ZoomDensity; -import android.webkit.WebSettingsClassic; -import android.webkit.WebSettingsClassic.AutoFillProfile; import android.webkit.WebStorage; -import android.webkit.WebView; import android.webkit.WebViewDatabase; -import com.android.browser.homepages.HomeProvider; -import com.android.browser.provider.BrowserProvider; -import com.android.browser.search.SearchEngine; -import com.android.browser.search.SearchEngines; +import com.android.swe.browser.R; +import com.android.swe.browser.homepages.HomeProvider; +import com.android.swe.browser.provider.BrowserProvider; +import com.android.swe.browser.reflect.ReflectHelper; +import com.android.swe.browser.search.SearchEngine; +import com.android.swe.browser.search.SearchEngines; import java.io.InputStream; -import java.lang.Class; import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.util.Iterator; @@ -62,6 +49,16 @@ import java.util.LinkedList; import java.util.Locale; import java.util.WeakHashMap; +import org.codeaurora.swe.AutoFillProfile; +import org.codeaurora.swe.CookieManager; +import org.codeaurora.swe.GeolocationPermissions; +import org.codeaurora.swe.WebSettings.LayoutAlgorithm; +import org.codeaurora.swe.WebSettings.PluginState; +import org.codeaurora.swe.WebSettings.TextSize; +import org.codeaurora.swe.WebSettings.ZoomDensity; +import org.codeaurora.swe.WebSettings; +import org.codeaurora.swe.WebView; + /** * Class for managing settings */ @@ -98,7 +95,6 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, }; private static final String TAG = "BrowserSettings"; - // The minimum min font size // Aka, the lower bounds for the min font size range // which is 1:5..24 @@ -141,6 +137,10 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, // add for carrier feature private static Context sResPackageCtx; + private android.os.CountDownTimer mCountDownTimer; + + //Determine if WebView is Initialized or not + private boolean mWebViewInitialized; public static void initialize(final Context context) { sInstance = new BrowserSettings(context); @@ -156,18 +156,17 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, mAutofillHandler = new AutofillHandler(mContext); mManagedSettings = new LinkedList>(); mCustomUserAgents = new WeakHashMap(); - mAutofillHandler.asyncLoadFromDb(); // add for carrier feature try { sResPackageCtx = context.createPackageContext( - "com.android.browser.res", + "com.android.swe.browser.res", Context.CONTEXT_IGNORE_SECURITY); } catch (Exception e) { Log.e("Res_Update", "Create Res Apk Failed"); } - BackgroundHandler.execute(mSetup); + mWebViewInitialized = false; } public void setController(Controller controller) { @@ -177,7 +176,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, } } - public void startManagingSettings(WebSettings settings) { + public void startManagingSettings(final WebSettings settings) { if (mNeedsSharedSync) { syncSharedSettings(); @@ -201,6 +200,10 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, } } + public void initializeCookieSettings() { + CookieManager.getInstance().setAcceptCookie(acceptCookies()); + mWebViewInitialized = true; + } private Runnable mSetup = new Runnable() { @Override @@ -210,9 +213,11 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, // the cost of one cached page is ~3M (measured using nytimes.com). For // low end devices, we only cache one page. For high end devices, we try // to cache more pages, currently choose 5. - if (ActivityManager.staticGetMemoryClass() > 16) { + + // SWE_TODO : assume a high-memory device + //if (ActivityManager.staticGetMemoryClass() > 16) { mPageCacheCapacity = 5; - } + //} mWebStorageSizeManager = new WebStorageSizeManager(mContext, new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()), new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath())); @@ -248,20 +253,23 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, mPrefs.edit().remove(PREF_TEXT_SIZE).apply(); } - // add for carrier homepage feature - String browserRes = SystemProperties.get("persist.env.c.browser.resource", "default"); + Object[] params = { new String("persist.env.c.browser.resource"), + new String("default")}; + Class[] type = new Class[] {String.class, String.class}; + String browserRes = (String)ReflectHelper.invokeStaticMethod( + "android.os.SystemProperties","get",type, params); if ("cu".equals(browserRes) || "cmcc".equals(browserRes)) { int resID = sResPackageCtx.getResources().getIdentifier( - "homepage_base", "string", "com.android.browser.res"); + "homepage_base", "string", "com.android.swe.browser.res"); sFactoryResetUrl = sResPackageCtx.getResources().getString(resID); } else if ("ct".equals(browserRes)) { int resID = sResPackageCtx.getResources().getIdentifier( - "homepage_base", "string", "com.android.browser.res"); + "homepage_base", "string", "com.android.swe.browser.res"); sFactoryResetUrl = sResPackageCtx.getResources().getString(resID); int pathID = sResPackageCtx.getResources().getIdentifier( - "homepage_path", "string", "com.android.browser.res"); + "homepage_path", "string", "com.android.swe.browser.res"); String path = sResPackageCtx.getResources().getString(pathID); Locale locale = Locale.getDefault(); path = path.replace("%y", locale.getLanguage().toLowerCase()); @@ -308,7 +316,6 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, "GBK").apply(); } } - if (sFactoryResetUrl.indexOf("{CID}") != -1) { sFactoryResetUrl = sFactoryResetUrl.replace("{CID}", BrowserProvider.getClientId(mContext.getContentResolver())); @@ -365,22 +372,18 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, Log.e(TAG, "plug in Load failed, err " + e); ua = mCustomUserAgents.get(settings); } - if (ua != null) { settings.setUserAgentString(ua); } else { settings.setUserAgentString(USER_AGENTS[getUserAgent()]); } - if (!(settings instanceof WebSettingsClassic)) return; - - WebSettingsClassic settingsClassic = (WebSettingsClassic) settings; + WebSettings settingsClassic = (WebSettings) settings; settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated()); settingsClassic.setShowVisualIndicator(enableVisualIndicator()); settingsClassic.setForceUserScalable(forceEnableUserScalable()); settingsClassic.setDoubleTapZoom(getDoubleTapZoom()); settingsClassic.setAutoFillEnabled(isAutofillEnabled()); - settingsClassic.setAutoFillProfile(getAutoFillProfile()); boolean useInverted = useInvertedRendering(); settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen, @@ -430,7 +433,8 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, settings.setAllowUniversalAccessFromFileURLs(false); settings.setAllowFileAccessFromFileURLs(false); - if (!(settings instanceof WebSettingsClassic)) return; + //if (!(settings instanceof WebSettingsClassic)) return; + /* WebSettingsClassic settingsClassic = (WebSettingsClassic) settings; settingsClassic.setPageCacheCapacity(getPageCacheCapacity()); @@ -442,11 +446,14 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, // buffering is always turned on, which is unnecessary. settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false"); settingsClassic.setWorkersEnabled(true); // This only affects V8. + */ } private void syncSharedSettings() { mNeedsSharedSync = false; - CookieManager.getInstance().setAcceptCookie(acceptCookies()); + if (mWebViewInitialized) { + CookieManager.getInstance().setAcceptCookie(acceptCookies()); + } if (mController != null) { mController.setShouldShowErrorConsole(enableJavascriptConsole()); } @@ -458,7 +465,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, Iterator> iter = mManagedSettings.iterator(); while (iter.hasNext()) { WeakReference ref = iter.next(); - WebSettings settings = ref.get(); + WebSettings settings = (WebSettings)ref.get(); if (settings == null) { iter.remove(); continue; @@ -618,18 +625,54 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, } public AutoFillProfile getAutoFillProfile() { + // query the profile from components autofill database 524 + if (mAutofillHandler.mAutoFillProfile == null && + !mAutofillHandler.mAutoFillActiveProfileId.equals("")) { + WebSettings settings = null; + // find a valid settings object + Iterator> iter = mManagedSettings.iterator(); + while (iter.hasNext()) { + WeakReference ref = iter.next(); + settings = (WebSettings)ref.get(); + if (settings != null) { + break; + } + } + if (settings != null) { + AutoFillProfile profile = + settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId); + mAutofillHandler.setAutoFillProfile(profile); + } + } return mAutofillHandler.getAutoFillProfile(); } - public void setAutoFillProfile(AutoFillProfile profile, Message msg) { - mAutofillHandler.setAutoFillProfile(profile, msg); - // Auto-fill will reuse the same profile ID when making edits to the profile, - // so we need to force a settings sync (otherwise the SharedPreferences - // manager will optimise out the call to onSharedPreferenceChanged(), as - // it thinks nothing has changed). - syncManagedSettings(); + public String getAutoFillProfileId() { + return mAutofillHandler.getAutoFillProfileId(); } + public void updateAutoFillProfile(AutoFillProfile profile) { + syncAutoFillProfile(profile); + } + + private void syncAutoFillProfile(AutoFillProfile profile) { + synchronized (mManagedSettings) { + Iterator> iter = mManagedSettings.iterator(); + while (iter.hasNext()) { + WeakReference ref = iter.next(); + WebSettings settings = (WebSettings)ref.get(); + if (settings == null) { + iter.remove(); + continue; + } + // update the profile only once. + settings.setAutoFillProfile(profile); + // Now we should have the guid + mAutofillHandler.setAutoFillProfile(profile); + break; + } + } + } public void toggleDebugSettings() { setDebugEnabled(!isDebugEnabled()); } @@ -717,7 +760,6 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, return mPrefs.getString(PREF_DOWNLOAD_PATH, DownloadHandler.getDefaultDownloadPath(mContext)); } - // ----------------------------- // getter/setters for accessibility_preferences.xml // ----------------------------- @@ -781,6 +823,10 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true); } + public boolean enableMemoryMonitor() { + return mPrefs.getBoolean(PREF_ENABLE_MEMORY_MONITOR, true); + } + // TODO: Cache public PluginState getPluginState() { String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON"); diff --git a/src/com/android/swe/browser/BrowserSnapshotPage.java b/src/com/android/swe/browser/BrowserSnapshotPage.java index 0d36c48f..9e1d948b 100644 --- a/src/com/android/swe/browser/BrowserSnapshotPage.java +++ b/src/com/android/swe/browser/BrowserSnapshotPage.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.animation.Animator; import android.animation.Animator.AnimatorListener; @@ -47,7 +47,8 @@ import android.widget.ImageView; import android.widget.ResourceCursorAdapter; import android.widget.TextView; -import com.android.browser.provider.SnapshotProvider.Snapshots; +import com.android.swe.browser.R; +import com.android.swe.browser.provider.SnapshotProvider.Snapshots; import java.text.DateFormat; import java.util.Date; diff --git a/src/com/android/swe/browser/BrowserUtils.java b/src/com/android/swe/browser/BrowserUtils.java index e1a36002..139b9f5f 100644 --- a/src/com/android/swe/browser/BrowserUtils.java +++ b/src/com/android/swe/browser/BrowserUtils.java @@ -27,7 +27,9 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.android.browser; +package com.android.swe.browser; + +import com.android.swe.browser.R; import android.app.AlertDialog; import android.content.Context; diff --git a/src/com/android/swe/browser/BrowserWebView.java b/src/com/android/swe/browser/BrowserWebView.java index 99e05875..f0d3f8b8 100644 --- a/src/com/android/swe/browser/BrowserWebView.java +++ b/src/com/android/swe/browser/BrowserWebView.java @@ -14,25 +14,22 @@ * the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.view.View; -import android.webkit.WebChromeClient; -import android.webkit.WebStorage; -import android.webkit.WebStorageClassic; -import android.webkit.WebView; -import android.webkit.WebViewClassic; -import android.webkit.WebViewClient; +import org.codeaurora.swe.WebChromeClient; +import org.codeaurora.swe.WebView; +import org.codeaurora.swe.WebViewClient; import java.util.Map; /** * Manage WebView scroll events */ -public class BrowserWebView extends WebView implements WebViewClassic.TitleBarDelegate { +public class BrowserWebView extends WebView implements WebView.TitleBarDelegate { public interface OnScrollChangedListener { void onScrollChanged(int l, int t, int oldl, int oldt); @@ -52,7 +49,8 @@ public class BrowserWebView extends WebView implements WebViewClassic.TitleBarDe */ public BrowserWebView(Context context, AttributeSet attrs, int defStyle, Map javascriptInterfaces, boolean privateBrowsing) { - super(context, attrs, defStyle, javascriptInterfaces, privateBrowsing); + super(context, attrs, defStyle, privateBrowsing); + this.setJavascriptInterfaces(javascriptInterfaces); } /** @@ -80,11 +78,6 @@ public class BrowserWebView extends WebView implements WebViewClassic.TitleBarDe super(context); } - public static boolean isClassic() { - // Using WebStorage for convenience of access in a static method. - return WebStorage.getInstance() instanceof WebStorageClassic; - } - @Override public void setWebChromeClient(WebChromeClient client) { mWebChromeClient = client; @@ -126,7 +119,7 @@ public class BrowserWebView extends WebView implements WebViewClassic.TitleBarDe } @Override - protected void onDraw(Canvas c) { + public void onDraw(Canvas c) { super.onDraw(c); if (!mBackgroundRemoved && getRootView().getBackground() != null) { mBackgroundRemoved = true; @@ -139,11 +132,11 @@ public class BrowserWebView extends WebView implements WebViewClassic.TitleBarDe } public void drawContent(Canvas c) { - onDraw(c); + //super.drawContent(c); } @Override - protected void onScrollChanged(int l, int t, int oldl, int oldt) { + public void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); if (mTitleBar != null) { mTitleBar.onScrollChanged(); diff --git a/src/com/android/swe/browser/BrowserWebViewFactory.java b/src/com/android/swe/browser/BrowserWebViewFactory.java index 441ac6af..b806164b 100644 --- a/src/com/android/swe/browser/BrowserWebViewFactory.java +++ b/src/com/android/swe/browser/BrowserWebViewFactory.java @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.content.pm.PackageManager; -import android.os.SystemProperties; import android.util.AttributeSet; import android.view.View; -import android.webkit.WebView; + +import com.android.swe.browser.reflect.ReflectHelper; + +import org.codeaurora.swe.WebView; /** * Web view factory class for creating {@link BrowserWebView}'s. @@ -63,7 +65,11 @@ public class BrowserWebViewFactory implements WebViewFactory { w.getSettings().setDisplayZoomControls(!supportsMultiTouch); // add for carrier homepage feature - String browserRes = SystemProperties.get("persist.env.c.browser.resource", "default"); + Object[] params = {new String("persist.env.c.browser.resource"), + new String("default")}; + Class[] type = new Class[] {String.class, String.class}; + String browserRes = (String)ReflectHelper.invokeStaticMethod( + "android.os.SystemProperties","get", type, params); if ("ct".equals(browserRes)) { w.getSettings().setJavaScriptEnabled(true); if (mContext instanceof BrowserActivity) { diff --git a/src/com/android/swe/browser/BrowserYesNoPreference.java b/src/com/android/swe/browser/BrowserYesNoPreference.java index d5d52058..af647094 100644 --- a/src/com/android/swe/browser/BrowserYesNoPreference.java +++ b/src/com/android/swe/browser/BrowserYesNoPreference.java @@ -14,14 +14,14 @@ * limitations under the License. */ -package com.android.browser; - -import com.android.internal.preference.YesNoPreference; +package com.android.swe.browser; import android.content.Context; +import android.preference.DialogPreference; import android.util.AttributeSet; +import android.util.Log; -class BrowserYesNoPreference extends YesNoPreference { +class BrowserYesNoPreference extends DialogPreference { // This is the constructor called by the inflater public BrowserYesNoPreference(Context context, AttributeSet attrs) { diff --git a/src/com/android/swe/browser/CombinedBookmarksCallbacks.java b/src/com/android/swe/browser/CombinedBookmarksCallbacks.java index cdffb6bf..9aa2d8fc 100644 --- a/src/com/android/swe/browser/CombinedBookmarksCallbacks.java +++ b/src/com/android/swe/browser/CombinedBookmarksCallbacks.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; public interface CombinedBookmarksCallbacks { void openUrl(String url); diff --git a/src/com/android/swe/browser/ComboViewActivity.java b/src/com/android/swe/browser/ComboViewActivity.java index 91d574e1..3d4543ab 100644 --- a/src/com/android/swe/browser/ComboViewActivity.java +++ b/src/com/android/swe/browser/ComboViewActivity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.ActionBar; import android.app.Activity; @@ -28,7 +28,8 @@ import android.support.v4.view.ViewPager; import android.view.Menu; import android.view.MenuItem; -import com.android.browser.UI.ComboViews; +import com.android.swe.browser.R; +import com.android.swe.browser.UI.ComboViews; import java.util.ArrayList; @@ -71,14 +72,10 @@ public class ComboViewActivity extends Activity implements CombinedBookmarksCall mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_bookmarks), BrowserBookmarksPage.class, args); - if (BrowserWebView.isClassic()) { - // TODO: history page should be able to work in Classic mode, but there's some - // provider name conflict. (Snapshot would never work in that mode though). - mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_history), - BrowserHistoryPage.class, args); - mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_snapshots), - BrowserSnapshotPage.class, args); - } + mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_history), + BrowserHistoryPage.class, args); + mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_snapshots), + BrowserSnapshotPage.class, args); if (savedInstanceState != null) { bar.setSelectedNavigationItem( diff --git a/src/com/android/swe/browser/Controller.java b/src/com/android/swe/browser/Controller.java index 00aac083..79b93e27 100644 --- a/src/com/android/swe/browser/Controller.java +++ b/src/com/android/swe/browser/Controller.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; -import android.app.ActivityManagerNative; + import android.app.AlertDialog; import android.app.Dialog; import android.app.DownloadManager; @@ -41,11 +41,12 @@ import android.database.sqlite.SQLiteException; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Rect; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.net.http.SslError; -import android.net.WebAddress; import android.net.wifi.WifiManager; import android.net.wifi.ScanResult; import android.os.AsyncTask; @@ -55,11 +56,8 @@ import android.os.Handler; import android.os.Message; import android.os.PowerManager; import android.os.PowerManager.WakeLock; -import android.os.SystemProperties; import android.preference.PreferenceActivity; import android.provider.Browser; -import android.provider.BrowserContract; -import android.provider.BrowserContract.Images; import android.provider.ContactsContract; import android.provider.ContactsContract.Intents.Insert; import android.provider.Settings; @@ -78,25 +76,30 @@ import android.view.MenuItem; import android.view.MenuItem.OnMenuItemClickListener; import android.view.MotionEvent; import android.view.View; -import android.webkit.CookieManager; -import android.webkit.CookieSyncManager; -import android.webkit.HttpAuthHandler; import android.webkit.MimeTypeMap; -import android.webkit.SslErrorHandler; import android.webkit.ValueCallback; -import android.webkit.WebChromeClient; +import android.webkit.WebChromeClient.CustomViewCallback; import android.webkit.WebIconDatabase; -import android.webkit.WebSettings; -import android.webkit.WebView; -import android.webkit.WebViewClassic; import android.widget.Toast; -import com.android.browser.IntentHandler.UrlData; -import com.android.browser.UI.ComboViews; -import com.android.browser.provider.BrowserProvider2.Thumbnails; -import com.android.browser.provider.SnapshotProvider.Snapshots; -import com.android.browser.mynavigation.AddMyNavigationPage; -import com.android.browser.mynavigation.MyNavigationUtil; +import org.codeaurora.swe.CookieManager; +import org.codeaurora.swe.CookieSyncManager; +import org.codeaurora.swe.HttpAuthHandler; +import org.codeaurora.swe.SslErrorHandler; +import org.codeaurora.swe.WebSettings; +import org.codeaurora.swe.WebView; + +import com.android.swe.browser.R; +import com.android.swe.browser.IntentHandler.UrlData; +import com.android.swe.browser.UI.ComboViews; +import com.android.swe.browser.mynavigation.AddMyNavigationPage; +import com.android.swe.browser.mynavigation.MyNavigationUtil; +import com.android.swe.browser.platformsupport.BrowserContract; +import com.android.swe.browser.platformsupport.WebAddress; +import com.android.swe.browser.platformsupport.BrowserContract.Images; +import com.android.swe.browser.provider.BrowserProvider2.Thumbnails; +import com.android.swe.browser.provider.SnapshotProvider.Snapshots; +import com.android.swe.browser.reflect.ReflectHelper; import java.io.ByteArrayOutputStream; import java.io.File; @@ -123,13 +126,18 @@ public class Controller private static final String SEND_APP_ID_EXTRA = "android.speech.extras.SEND_APPLICATION_ID_EXTRA"; private static final String INCOGNITO_URI = "browser:incognito"; + + private static final String PROP_NETSWITCH = "persist.env.browser.netswitch"; private static final String INTENT_WIFI_SELECTION_DATA_CONNECTION = "android.net.wifi.cmcc.WIFI_SELECTION_DATA_CONNECTION"; private static final String OFFLINE_PAGE = - "content://com.android.browser.mynavigation/websites"; + "content://com.android.swe.browser.mynavigation/websites"; private static final String INTENT_PICK_NETWORK = "android.net.wifi.cmcc.PICK_WIFI_NETWORK_AND_GPRS"; + + public final static String EXTRA_SHARE_SCREENSHOT = "share_screenshot"; + public final static String EXTRA_SHARE_FAVICON = "share_favicon"; // public message ids public final static int LOAD_URL = 1001; public final static int STOP_LOAD = 1002; @@ -257,6 +265,11 @@ public class Controller 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 @@ -282,7 +295,7 @@ public class Controller @Override public void start(final Intent intent) { - if (BrowserWebView.isClassic()) WebViewClassic.setShouldMonitorWebCoreThread(); + WebView.setShouldMonitorWebCoreThread(); // mCrashRecoverHandler has any previously saved state. mCrashRecoveryHandler.startRecovery(intent); } @@ -297,14 +310,14 @@ public class Controller Calendar yesterday = Calendar.getInstance(); yesterday.add(Calendar.DATE, -1); - final boolean restoreIncognitoTabs = !(lastActiveDate == null - || lastActiveDate.before(yesterday) - || lastActiveDate.after(today)); + // we dont want to ever recover incognito tabs + final boolean restoreIncognitoTabs = false; // Find out if we will restore any state and remember the tab. 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 @@ -343,10 +356,15 @@ public class Controller } else { urlData = IntentHandler.getUrlDataFromIntent(intent); } - Tab t = null; if (urlData.isEmpty()) { - if (SystemProperties.get("persist.env.c.browser.resource", "default").equals( + Object[] params = { new String("persist.env.c.browser.resource"), + new String("default")}; + Class[] type = new Class[] {String.class, String.class}; + String browserRes = (String)ReflectHelper.invokeStaticMethod( + "android.os.SystemProperties", "get", + type, params); + if (browserRes.equals( "cmcc")) { t = openTab(OFFLINE_PAGE, false, true, true); } else { @@ -391,8 +409,8 @@ public class Controller } // Read JavaScript flags if it exists. String jsFlags = getSettings().getJsEngineFlags(); - if (jsFlags.trim().length() != 0 && BrowserWebView.isClassic()) { - WebViewClassic.fromWebView(getCurrentWebView()).setJsFlags(jsFlags); + if (jsFlags.trim().length() != 0) { + getCurrentWebView().setJsFlags(jsFlags); } if (intent != null && BrowserActivity.ACTION_SHOW_BOOKMARKS.equals(intent.getAction())) { @@ -439,7 +457,10 @@ public class Controller @Override public void onSetWebView(Tab tab, WebView view) { - mUi.onSetWebView(tab, view); + if (tab.hasCrashed) + tab.showCrashView(); + else + mUi.onSetWebView(tab, view); } @Override @@ -549,8 +570,8 @@ public class Controller case R.id.save_link_context_menu_id: case R.id.download_context_menu_id: DownloadHandler.onDownloadStartNoStream( - mActivity, url, view.getSettings().getUserAgentString(), - null, null, null, view.isPrivateBrowsingEnabled(), 0); + mActivity, url, view.getSettings().getUserAgentString(), + null, null, null, view.isPrivateBrowsingEnabled(), 0); break; } break; @@ -580,7 +601,6 @@ public class Controller updateScreenshot(tab); } break; - case OPEN_MENU: if (!mOptionsMenuOpen && mActivity != null ) { mActivity.openOptionsMenu(); @@ -631,8 +651,8 @@ public class Controller send.setType("text/plain"); send.putExtra(Intent.EXTRA_TEXT, url); send.putExtra(Intent.EXTRA_SUBJECT, title); - send.putExtra(Browser.EXTRA_SHARE_FAVICON, favicon); - send.putExtra(Browser.EXTRA_SHARE_SCREENSHOT, screenshot); + send.putExtra(EXTRA_SHARE_FAVICON, favicon); + send.putExtra(EXTRA_SHARE_SCREENSHOT, screenshot); try { c.startActivity(Intent.createChooser(send, c.getString( R.string.choosertitle_sharevia))); @@ -755,6 +775,9 @@ public class Controller mUi.onVoiceResult(mVoiceResult); mVoiceResult = null; } + if (current != null && current.hasCrashed) { + current.showCrashView(); + } } private void releaseWakeLock() { @@ -886,7 +909,8 @@ public class Controller this.getContext().startActivity(intent); } } else { - if (ActivityManagerNative.isSystemReady()) { + if ((Boolean)ReflectHelper.invokeStaticMethod( + "ActivityManagerNative", "isSystemReady", null, null)) { try { Intent intent = new Intent(INTENT_PICK_NETWORK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -909,7 +933,6 @@ public class Controller } } } - // WebViewController @Override @@ -924,8 +947,13 @@ public class Controller // reset sync timer to avoid sync starts during loading a page CookieSyncManager.getInstance().resetSync(); - - if (SystemProperties.getBoolean(PROP_NETSWITCH, false)) { + Object[] params = {new String(PROP_NETSWITCH), + new Boolean(false)}; + Class[] type = new Class[] {String.class, boolean.class}; + Boolean result = (Boolean) ReflectHelper.invokeStaticMethod( + "android.os.SystemProperties", "getBoolean", + type, params); + if (result) { if (!mNetworkHandler.isNetworkUp()) { Log.d(LOGTAG, "onPageStarted() network unavailable"); if (mNetworkShouldNotify) { @@ -1017,7 +1045,7 @@ public class Controller if (!mHandler.hasMessages(UPDATE_BOOKMARK_THUMBNAIL, tab)) { mHandler.sendMessageDelayed(mHandler.obtainMessage( UPDATE_BOOKMARK_THUMBNAIL, 0, 0, tab), - 500); + 1500); } } } @@ -1069,9 +1097,39 @@ public class Controller // only check shortcut key when MENU is held return mActivity.getWindow().isShortcutKey(event.getKeyCode(), event); - } else { - return false; } + int keyCode = event.getKeyCode(); + // We need to send almost every key to WebKit. However: + // 1. We don't want to block the device on the renderer for + // some keys like menu, home, call. + // 2. There are no WebKit equivalents for some of these keys + // (see app/keyboard_codes_win.h) + // Note that these are not the same set as KeyEvent.isSystemKey: + // for instance, AKEYCODE_MEDIA_* will be dispatched to webkit. + if (keyCode == KeyEvent.KEYCODE_MENU || + keyCode == KeyEvent.KEYCODE_HOME || + keyCode == KeyEvent.KEYCODE_BACK || + keyCode == KeyEvent.KEYCODE_CALL || + keyCode == KeyEvent.KEYCODE_ENDCALL || + keyCode == KeyEvent.KEYCODE_POWER || + keyCode == KeyEvent.KEYCODE_HEADSETHOOK || + keyCode == KeyEvent.KEYCODE_CAMERA || + keyCode == KeyEvent.KEYCODE_FOCUS || + keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || + keyCode == KeyEvent.KEYCODE_VOLUME_MUTE || + keyCode == KeyEvent.KEYCODE_VOLUME_UP) { + return true; + } + + // We also have to intercept some shortcuts before we send them to the ContentView. + if (event.isCtrlPressed() && ( + keyCode == KeyEvent.KEYCODE_TAB || + keyCode == KeyEvent.KEYCODE_W || + keyCode == KeyEvent.KEYCODE_F4)) { + return true; + } + + return false; } @Override @@ -1096,6 +1154,7 @@ public class Controller || url.regionMatches(true, 0, "about:", 0, 6)) { return; } + DataController.getInstance(mActivity).updateVisitedHistory(url); mCrashRecoveryHandler.backupState(); } @@ -1106,7 +1165,11 @@ public class Controller new AsyncTask() { @Override public String[] doInBackground(Void... unused) { - return Browser.getVisitedHistory(mActivity.getContentResolver()); + Object[] params = {mActivity.getContentResolver()}; + Class[] type = new Class[] {ContentResolver.class}; + return (String[])ReflectHelper.invokeStaticMethod( + "android.provider.Browser","getVisitedHistory", + type, params); } @Override public void onPostExecute(String[] result) { @@ -1137,7 +1200,7 @@ public class Controller if (username != null && password != null) { handler.proceed(username, password); } else { - if (tab.inForeground() && !handler.suppressDialog()) { + if (tab.inForeground() /*&& !handler.suppressDialog()*/) { mPageDialogsHandler.showHttpAuthentication(tab, handler, host, realm); } else { handler.cancel(); @@ -1236,7 +1299,7 @@ public class Controller @Override public void showCustomView(Tab tab, View view, int requestedOrientation, - WebChromeClient.CustomViewCallback callback) { + CustomViewCallback callback) { if (tab.inForeground()) { if (mUi.isCustomViewShowing()) { callback.onCustomViewHidden(); @@ -1314,12 +1377,7 @@ public class Controller long id = intent.getLongExtra( ComboViewActivity.EXTRA_OPEN_SNAPSHOT, -1); if (id >= 0) { - if (BrowserWebView.isClassic()) { - createNewSnapshotTab(id, true); - } else { - Toast.makeText(mActivity, "Snapshot Tab requires WebViewClassic", - Toast.LENGTH_LONG).show(); - } + createNewSnapshotTab(id, true); } } break; @@ -1332,7 +1390,6 @@ public class Controller } } break; - case MY_NAVIGATION: if (intent == null || resultCode != Activity.RESULT_OK) { break; @@ -1343,7 +1400,6 @@ public class Controller getCurrentTopWebView().reload(); } break; - default: break; } @@ -1448,7 +1504,6 @@ public class Controller type == WebView.HitTestResult.EMAIL_TYPE); menu.setGroupVisible(R.id.GEO_MENU, type == WebView.HitTestResult.GEO_TYPE); - String itemUrl = null; String url = webview.getOriginalUrl(); if (url != null && url.equalsIgnoreCase(MyNavigationUtil.MY_NAVIGATION)) { @@ -1471,7 +1526,6 @@ public class Controller type == WebView.HitTestResult.SRC_ANCHOR_TYPE || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE); } - // Setup custom handling depending on the type switch (type) { case WebView.HitTestResult.PHONE_TYPE: @@ -1588,7 +1642,6 @@ public class Controller Log.e(LOGTAG, "mynavigation onCreateContextMenu itemUrl is null!"); } } - if (type == WebView.HitTestResult.SRC_ANCHOR_TYPE) { break; } @@ -1778,7 +1831,6 @@ public class Controller } }.execute(); } - /** * As the menu can be open when loading state changes * we must manually update the state of the stop/reload menu @@ -1875,7 +1927,6 @@ public class Controller uaSwitcher.setChecked(isDesktopUa); menu.setGroupVisible(R.id.LIVE_MENU, isLive); menu.setGroupVisible(R.id.SNAPSHOT_MENU, !isLive); - // history and snapshots item are the members of COMBO menu group, // so if show history item, only make snapshots item invisible. menu.findItem(R.id.snapshots_menu_id).setVisible(false); @@ -1937,6 +1988,11 @@ public class Controller if (isInLoad()) { stopLoading(); } else { + Tab currentTab = mTabControl.getCurrentTab(); + if (currentTab.hasCrashed) { + currentTab.replaceCrashView(getCurrentTopWebView(), + currentTab.getViewContainer()); + } getCurrentTopWebView().reload(); } break; @@ -1959,12 +2015,14 @@ public class Controller break; case R.id.exit_menu_id: - String ret = SystemProperties.get("persist.debug.browsermonkeytest"); + Object[] params = { new String("persist.debug.browsermonkeytest")}; + Class[] type = new Class[] {String.class}; + String ret = (String)ReflectHelper.invokeStaticMethod( + "android.os.SystemProperties","get", type, params); if (ret != null && ret.equals("enable")) break; showExitDialog(mActivity); return true; - case R.id.homepage_menu_id: Tab current = mTabControl.getCurrentTab(); loadUrl(current, mSettings.getHomePage()); @@ -2043,6 +2101,25 @@ public class Controller } break; + case R.id.about_menu_id: + { + /* SWE_TODO: Un-comment below to fix About + final Dialog dialog = new AlertDialog.Builder(getActivity()) + .setTitle(R.string.application_name) + .setMessage(R.string.about_text) + .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } + }) + .show(); + ((TextView)dialog.findViewById(android.R.id.message)) + .setMovementMethod(LinkMovementMethod.getInstance()); + */ + } + break; + default: return false; } @@ -2141,8 +2218,8 @@ public class Controller } private void goLive() { - Tab t = getCurrentTab(); - t.loadUrl(t.getUrl(), null); + SnapshotTab t = (SnapshotTab) getCurrentTab(); + t.loadUrl(t.getLiveUrl(), null); } private void showExitDialog(final Activity activity) { @@ -2173,7 +2250,6 @@ public class Controller }) .show(); } - @Override public void showPageInfo() { mPageDialogsHandler.showPageInfo(mTabControl.getCurrentTab(), false, null); @@ -2412,44 +2488,43 @@ public class Controller } static Bitmap createScreenshot(WebView view, int width, int height) { - if (view == null || view.getContentHeight() == 0 - || view.getContentWidth() == 0) { + if (view == null || width == 0 || height == 0) { return null; } - // We render to a bitmap 2x the desired size so that we can then - // re-scale it with filtering since canvas.scale doesn't filter - // This helps reduce aliasing at the cost of being slightly blurry - final int filter_scale = 2; - int scaledWidth = width * filter_scale; - int scaledHeight = height * filter_scale; - if (sThumbnailBitmap == null || sThumbnailBitmap.getWidth() != scaledWidth - || sThumbnailBitmap.getHeight() != scaledHeight) { + + Bitmap viewportBitmap = view.getViewportBitmap(); + if (viewportBitmap == null) { + return null; + } + + float aspectRatio = (float) width/height; + int viewportWidth = viewportBitmap.getWidth(); + int viewportHeight = viewportBitmap.getHeight(); + + //modify the size to attain the same aspect ratio of desired thumbnail size + if (viewportHeight > viewportWidth) { + viewportHeight= (int)Math.round(viewportWidth * aspectRatio); + } else { + viewportWidth = (int)Math.round(viewportHeight * aspectRatio); + } + + Rect srcRect = new Rect(0, 0, viewportWidth, viewportHeight); + Rect dstRect = new Rect(0, 0, width, height); + + if (sThumbnailBitmap == null || sThumbnailBitmap.getWidth() != width + || sThumbnailBitmap.getHeight() != height) { if (sThumbnailBitmap != null) { sThumbnailBitmap.recycle(); sThumbnailBitmap = null; } - sThumbnailBitmap = - Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.RGB_565); - } - Canvas canvas = new Canvas(sThumbnailBitmap); - int contentWidth = view.getContentWidth(); - float overviewScale = scaledWidth / (view.getScale() * contentWidth); - if (view instanceof BrowserWebView) { - int dy = -((BrowserWebView)view).getTitleHeight(); - canvas.translate(0, dy * overviewScale); + + sThumbnailBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); } - canvas.scale(overviewScale, overviewScale); + Canvas canvas = new Canvas(sThumbnailBitmap); + canvas.drawBitmap(viewportBitmap, srcRect, dstRect, new Paint(Paint.FILTER_BITMAP_FLAG)); - if (view instanceof BrowserWebView) { - ((BrowserWebView)view).drawContent(canvas); - } else { - view.draw(canvas); - } - Bitmap ret = Bitmap.createScaledBitmap(sThumbnailBitmap, - width, height, true); - canvas.setBitmap(null); - return ret; + return sThumbnailBitmap; } private void updateScreenshot(Tab tab) { @@ -2503,6 +2578,11 @@ public class Controller final Bitmap bm = createScreenshot(view, getDesiredThumbnailWidth(mActivity), getDesiredThumbnailHeight(mActivity)); if (bm == null) { + if (!mHandler.hasMessages(UPDATE_BOOKMARK_THUMBNAIL, tab)) { + mHandler.sendMessageDelayed(mHandler.obtainMessage( + UPDATE_BOOKMARK_THUMBNAIL, 0, 0, tab), + 500); + } return; } @@ -2640,7 +2720,7 @@ public class Controller } private static class SelectText implements OnMenuItemClickListener { - private WebViewClassic mWebView; + private WebView mWebView; @Override public boolean onMenuItemClick(MenuItem item) { @@ -2651,9 +2731,7 @@ public class Controller } public SelectText(WebView webView) { - if (BrowserWebView.isClassic()) { - mWebView = WebViewClassic.fromWebView(webView); - } + mWebView = webView; } } @@ -2684,6 +2762,7 @@ public class Controller mTabControl.setCurrentTab(tab); // the tab is guaranteed to have a webview after setCurrentTab mUi.setActiveTab(tab); + tab.setTimeStamp(); } } @@ -2829,9 +2908,21 @@ public class Controller private Tab createNewTab(boolean incognito, boolean setActive, boolean useCurrent) { Tab tab = null; + MemoryMonitor memMonitor = null; if (mTabControl.canCreateNewTab()) { + if (mSettings.enableMemoryMonitor()) { + Log.d(LOGTAG, " Memory Monitor Enabled ."); + memMonitor = MemoryMonitor.getInstance(mActivity.getApplicationContext(),this); + if (memMonitor != null) { + //Remove webview associated with the oldest tab + memMonitor.destroyLeastRecentlyActiveTab(); + } + } else { + Log.d(LOGTAG, " Memory Monitor disabled ."); + } tab = mTabControl.createNewTab(incognito); addTab(tab); + tab.setTimeStamp(); if (setActive) { setActiveTab(tab); } @@ -2964,6 +3055,9 @@ public class Controller if (tab != null) { dismissSubWindow(tab); tab.loadUrl(url, headers); + if (tab.hasCrashed) { + tab.replaceCrashView(tab.getWebView(), tab.getViewContainer()); + } mUi.onProgressChanged(tab); } } @@ -3131,15 +3225,15 @@ public class Controller } break; case KeyEvent.KEYCODE_A: - if (ctrl && BrowserWebView.isClassic()) { - WebViewClassic.fromWebView(webView).selectAll(); + if (ctrl) { + webView.selectAll(); return true; } break; // case KeyEvent.KEYCODE_B: // menu case KeyEvent.KEYCODE_C: - if (ctrl && BrowserWebView.isClassic()) { - WebViewClassic.fromWebView(webView).copySelection(); + if (ctrl ) { + webView.copySelection(); return true; } break; @@ -3254,7 +3348,7 @@ public class Controller @Override public void startVoiceRecognizer() { Intent voice = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); - voice.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, + voice.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); voice.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); mActivity.startActivityForResult(voice, VOICE_RESULT); diff --git a/src/com/android/swe/browser/CrashRecoveryHandler.java b/src/com/android/swe/browser/CrashRecoveryHandler.java index bcdf8b03..b542205f 100644 --- a/src/com/android/swe/browser/CrashRecoveryHandler.java +++ b/src/com/android/swe/browser/CrashRecoveryHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.content.Intent; diff --git a/src/com/android/swe/browser/DataController.java b/src/com/android/swe/browser/DataController.java index 909c2a3d..f2a44d63 100644 --- a/src/com/android/swe/browser/DataController.java +++ b/src/com/android/swe/browser/DataController.java @@ -15,7 +15,7 @@ */ -package com.android.browser; +package com.android.swe.browser; import android.content.ContentResolver; import android.content.ContentUris; @@ -27,11 +27,11 @@ import android.graphics.Bitmap; import android.net.Uri; import android.os.Handler; import android.os.Message; -import android.provider.BrowserContract; -import android.provider.BrowserContract.History; import android.util.Log; -import com.android.browser.provider.BrowserProvider2.Thumbnails; +import com.android.swe.browser.platformsupport.BrowserContract; +import com.android.swe.browser.platformsupport.BrowserContract.History; +import com.android.swe.browser.provider.BrowserProvider2.Thumbnails; import java.nio.ByteBuffer; import java.util.concurrent.BlockingQueue; @@ -244,7 +244,7 @@ public class DataController { ContentResolver cr = mContext.getContentResolver(); Cursor c = null; try { - c = cr.query(History.CONTENT_URI, new String[] { History._ID, History.VISITS }, + c = cr.query(History.CONTENT_URI, new String[] {History._ID, History.VISITS}, History.URL + "=?", new String[] { url }, null); if (c.moveToFirst()) { ContentValues values = new ContentValues(); diff --git a/src/com/android/swe/browser/DataUri.java b/src/com/android/swe/browser/DataUri.java index 642b0601..42c9daf6 100644 --- a/src/com/android/swe/browser/DataUri.java +++ b/src/com/android/swe/browser/DataUri.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import java.net.MalformedURLException; -import libcore.io.Base64; - +import android.util.Base64; /** * Class extracts the mime type and data from a data uri. * A data URI is of the form: @@ -46,7 +45,7 @@ public class DataUri { commaIndex); mData = uri.substring(commaIndex + 1).getBytes(); if (contentType.contains(BASE_64_ENCODING)) { - mData = Base64.decode(mData); + mData = Base64.decode(mData, Base64.DEFAULT); } int semiIndex = contentType.indexOf(';'); if (semiIndex > 0) { diff --git a/src/com/android/swe/browser/DateSortedExpandableListAdapter.java b/src/com/android/swe/browser/DateSortedExpandableListAdapter.java index a48efe67..ec7afe40 100644 --- a/src/com/android/swe/browser/DateSortedExpandableListAdapter.java +++ b/src/com/android/swe/browser/DateSortedExpandableListAdapter.java @@ -14,7 +14,9 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; + +import com.android.swe.browser.R; import android.content.Context; import android.database.Cursor; diff --git a/src/com/android/swe/browser/DeviceAccountLogin.java b/src/com/android/swe/browser/DeviceAccountLogin.java index 8d734c23..1946ff8c 100644 --- a/src/com/android/swe/browser/DeviceAccountLogin.java +++ b/src/com/android/swe/browser/DeviceAccountLogin.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.accounts.Account; import android.accounts.AccountManager; @@ -22,7 +22,7 @@ import android.accounts.AccountManagerCallback; import android.accounts.AccountManagerFuture; import android.app.Activity; import android.os.Bundle; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; public class DeviceAccountLogin implements AccountManagerCallback { diff --git a/src/com/android/swe/browser/DownloadHandler.java b/src/com/android/swe/browser/DownloadHandler.java index 1ce33da9..eac63cd4 100644 --- a/src/com/android/swe/browser/DownloadHandler.java +++ b/src/com/android/swe/browser/DownloadHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.app.AlertDialog; @@ -27,29 +27,28 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.media.MediaFile; import android.net.Uri; -import android.net.WebAddress; import android.os.Bundle; import android.os.Environment; import android.os.StatFs; import android.os.storage.StorageManager; -import android.os.storage.StorageVolume; -import android.text.TextUtils; import android.util.Log; -import android.webkit.CookieManager; +import org.codeaurora.swe.CookieManager; import android.webkit.URLUtil; import android.widget.Toast; -import java.io.File; +import com.android.swe.browser.R; +import com.android.swe.browser.platformsupport.WebAddress; +import com.android.swe.browser.reflect.ReflectHelper; +import java.io.File; /** * Handle download requests */ public class DownloadHandler { private static final boolean LOGD_ENABLED = - com.android.browser.Browser.LOGD_ENABLED; + com.android.swe.browser.Browser.LOGD_ENABLED; private static final String LOGTAG = "DLHandler"; private static String mInternalStorage; @@ -98,6 +97,7 @@ public class DownloadHandler { request.setDescription(webAddress.getHost()); // XXX: Have to use the old url since the cookies were stored using the // old percent-encoded url. + String cookies = CookieManager.getInstance().getCookie(url, privateBrowsing); request.addRequestHeader("cookie", cookies); request.addRequestHeader("User-Agent", userAgent); @@ -114,6 +114,24 @@ public class DownloadHandler { showStartDownloadToast(activity); } + private static boolean isAudioFileType(int fileType){ + Object[] params = { new Integer(fileType)}; + Class[] type = new Class[] {Integer.class}; + Boolean result = (Boolean) ReflectHelper.invokeStaticMethod("android.media.MediaFile", + "isAudioFileType", + type, params); + return result; + } + + private static boolean isVideoFileType(int fileType){ + Object[] params = { new Integer(fileType)}; + Class[] type = new Class[] {Integer.class}; + Boolean result = (Boolean) ReflectHelper.invokeStaticMethod("android.media.MediaFile", + "isVideoFileType", + type, params); + return result; + } + /** * Notify the host application a download should be done, or that * the data should be streamed if a streaming viewer is available. @@ -125,7 +143,6 @@ public class DownloadHandler { * @param referer The referer associated with the downloaded url * @param privateBrowsing If the request is coming from a private browsing tab. */ - public static boolean onDownloadStart(final Activity activity, final String url, final String userAgent, final String contentDisposition, final String mimetype, final String referer, final boolean privateBrowsing, final long contentLength) { @@ -134,7 +151,6 @@ public class DownloadHandler { if (contentDisposition == null || !contentDisposition.regionMatches( true, 0, "attachment", 0, 10)) { - // Add for Carrier Feature - When open an audio/video link, prompt a dialog // to let the user choose play or download operation. Uri uri = Uri.parse(url); @@ -144,12 +160,19 @@ public class DownloadHandler { // such as ogg audio file with mimetype "application/ogg". So we also check // file type by MediaFile.isAudioFileType() and MediaFile.isVideoFileType(). // For those file types other than audio or video, download it immediately. - int fileType = MediaFile.getFileTypeForMimeType(mimetype); + + //int fileType = MediaFile.getFileTypeForMimeType(mimetype); + Object[] params = { new Integer(mimetype)}; + Class[] type = new Class[] {Integer.class}; + Integer result = (Integer) ReflectHelper.invokeStaticMethod("android.media.MediaFile", + "getFileTypeForMimeType", + type, params); + int fileType = result.intValue(); if ("http".equalsIgnoreCase(scheme) && (mimetype.startsWith("audio/") || mimetype.startsWith("video/") || - MediaFile.isAudioFileType(fileType) || - MediaFile.isVideoFileType(fileType))) { + isAudioFileType(fileType) || + isVideoFileType(fileType))) { new AlertDialog.Builder(activity) .setTitle(R.string.application_name) .setIcon(R.drawable.default_video_poster) @@ -178,7 +201,6 @@ public class DownloadHandler { return true; } - // query the package manager to see if there's a registered handler // that matches. Intent intent = new Intent(Intent.ACTION_VIEW); @@ -560,7 +582,7 @@ public class DownloadHandler { phoneStorageDir = null; } - if (downloadPath.startsWith(sdCardDir)) { + if (sdCardDir != null && downloadPath.startsWith(sdCardDir)) { String sdCardLabel = activity.getResources().getString( R.string.download_path_sd_card_label); downloadPath = downloadPath.replace(sdCardDir, sdCardLabel); @@ -572,14 +594,30 @@ public class DownloadHandler { return downloadPath; } + private static boolean isRemovable(Object obj) { + return (Boolean) ReflectHelper.invokeMethod(obj, + "isRemovable", null, null); + } + + private static boolean allowMassStorage(Object obj) { + return (Boolean) ReflectHelper.invokeMethod(obj, + "allowMassStorage", null, null); + } + + private static String getPath(Object obj) { + return (String) ReflectHelper.invokeMethod(obj, + "getPath", null, null); + } + private static String getExternalStorageDirectory(Context context) { String sd = null; StorageManager mStorageManager = (StorageManager) context .getSystemService(Context.STORAGE_SERVICE); - StorageVolume[] volumes = mStorageManager.getVolumeList(); + Object[] volumes = (Object[]) ReflectHelper.invokeMethod( + mStorageManager, "getVolumeList", null, null); for (int i = 0; i < volumes.length; i++) { - if (volumes[i].isRemovable() && volumes[i].allowMassStorage()) { - sd = volumes[i].getPath(); + if (isRemovable(volumes[i]) && allowMassStorage(volumes[i])) { + sd = getPath(volumes[i]); } } return sd; @@ -588,6 +626,10 @@ public class DownloadHandler { private static String getExternalStorageState(Context context) { StorageManager mStorageManager = (StorageManager) context .getSystemService(Context.STORAGE_SERVICE); - return mStorageManager.getVolumeState(getExternalStorageDirectory(context)); + String path = getExternalStorageDirectory(context); + Object[] params = {path}; + Class[] type = new Class[] {String.class}; + return (String) ReflectHelper.invokeMethod("android.os.storage.StorageManager", + "getVolumeState", type, params); } } diff --git a/src/com/android/swe/browser/DownloadSettings.java b/src/com/android/swe/browser/DownloadSettings.java index 698fa886..0204aa6e 100644 --- a/src/com/android/swe/browser/DownloadSettings.java +++ b/src/com/android/swe/browser/DownloadSettings.java @@ -27,13 +27,16 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.android.browser; +package com.android.swe.browser; import java.io.File; import android.app.Activity; import android.content.Intent; import java.lang.Thread; + +import com.android.swe.browser.R; + import android.net.Uri; import android.os.Bundle; import android.os.Environment; diff --git a/src/com/android/swe/browser/DownloadTouchIcon.java b/src/com/android/swe/browser/DownloadTouchIcon.java index ba299b6d..e48d25f1 100644 --- a/src/com/android/swe/browser/DownloadTouchIcon.java +++ b/src/com/android/swe/browser/DownloadTouchIcon.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; @@ -34,9 +34,12 @@ import android.net.http.AndroidHttpClient; import android.os.AsyncTask; import android.os.Bundle; import android.os.Message; -import android.provider.BrowserContract; -import android.provider.BrowserContract.Images; -import android.webkit.WebView; + +import com.android.swe.browser.platformsupport.BrowserContract; +import com.android.swe.browser.platformsupport.BrowserContract.Images; +import com.android.swe.browser.reflect.ReflectHelper; + +import org.codeaurora.swe.WebView; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -115,7 +118,12 @@ class DownloadTouchIcon extends AsyncTask { try { client = AndroidHttpClient.newInstance(mUserAgent); - HttpHost httpHost = Proxy.getPreferredHttpHost(mContext, url); + //HttpHost httpHost = Proxy.getPreferredHttpHost(mContext, url); + Object[] params = { mContext, url}; + Class[] type = new Class[] {android.content.Context.class, String.class}; + HttpHost httpHost = (HttpHost) ReflectHelper.invokeStaticMethod( + "android.net.Proxy", "getPreferredHttpHost", + type, params); if (httpHost != null) { ConnRouteParams.setDefaultProxy(client.getParams(), httpHost); } diff --git a/src/com/android/swe/browser/ErrorConsoleView.java b/src/com/android/swe/browser/ErrorConsoleView.java index ca5fed46..7dd2a377 100644 --- a/src/com/android/swe/browser/ErrorConsoleView.java +++ b/src/com/android/swe/browser/ErrorConsoleView.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.database.DataSetObserver; @@ -25,7 +25,10 @@ import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.webkit.ConsoleMessage; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; + +import com.android.swe.browser.R; + import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; diff --git a/src/com/android/swe/browser/EventLogTags.logtags b/src/com/android/swe/browser/EventLogTags.logtags index b3834cf1..ed9830e7 100644 --- a/src/com/android/swe/browser/EventLogTags.logtags +++ b/src/com/android/swe/browser/EventLogTags.logtags @@ -1,6 +1,6 @@ # See system/core/logcat/event.logtags for a description of the format of this file. -option java_package com.android.browser +option java_package com.android.swe.browser # This event is logged when a user adds a new bookmark. This could just be a boolean, # but if lots of users add the same bookmark it could be a default bookmark on the browser. diff --git a/src/com/android/swe/browser/FetchUrlMimeType.java b/src/com/android/swe/browser/FetchUrlMimeType.java index 28bfc800..4a4d8914 100644 --- a/src/com/android/swe/browser/FetchUrlMimeType.java +++ b/src/com/android/swe/browser/FetchUrlMimeType.java @@ -14,26 +14,28 @@ * limitations under the License. */ -package com.android.browser; - -import org.apache.http.Header; -import org.apache.http.HttpHost; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpHead; -import org.apache.http.conn.params.ConnRouteParams; +package com.android.swe.browser; import android.app.Activity; import android.content.Context; -import android.net.Proxy; import android.net.Uri; import android.net.http.AndroidHttpClient; import android.text.TextUtils; import android.util.Log; -import android.webkit.CookieManager; import android.webkit.MimeTypeMap; +import com.android.swe.browser.reflect.ReflectHelper; + import java.io.IOException; +import org.apache.http.Header; +import org.apache.http.HttpHost; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpHead; +import org.apache.http.conn.params.ConnRouteParams; + +import org.codeaurora.swe.CookieManager; + /** * This class is used to pull down the http headers of a given URL so that * we can analyse the mimetype and make any correction needed before we give @@ -75,7 +77,10 @@ class FetchUrlMimeType extends Thread { AndroidHttpClient client = AndroidHttpClient.newInstance(mUserAgent); HttpHost httpHost; try { - httpHost = Proxy.getPreferredHttpHost(mContext, mUri); + Class argTypes[] = new Class[]{Context.class, String.class}; + Object args[] = new Object[]{mContext, mUri}; + httpHost = (HttpHost) ReflectHelper.invokeStaticMethod("android.net.Proxy", + "getPreferredHttpHost", argTypes, args); if (httpHost != null) { ConnRouteParams.setDefaultProxy(client.getParams(), httpHost); } @@ -85,7 +90,6 @@ class FetchUrlMimeType extends Thread { return; } HttpHead request = new HttpHead(mUri); - String cookies = CookieManager.getInstance().getCookie(mUri, mPrivateBrowsing); if (cookies != null && cookies.length() > 0) { request.addHeader("Cookie", cookies); diff --git a/src/com/android/swe/browser/GeolocationPermissionsPrompt.java b/src/com/android/swe/browser/GeolocationPermissionsPrompt.java index afbf39f0..790d0121 100755 --- a/src/com/android/swe/browser/GeolocationPermissionsPrompt.java +++ b/src/com/android/swe/browser/GeolocationPermissionsPrompt.java @@ -14,7 +14,9 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; + +import com.android.swe.browser.R; import android.content.Context; import android.net.Uri; diff --git a/src/com/android/swe/browser/GoogleAccountLogin.java b/src/com/android/swe/browser/GoogleAccountLogin.java index 2bd3c8c7..70ceaac6 100644 --- a/src/com/android/swe/browser/GoogleAccountLogin.java +++ b/src/com/android/swe/browser/GoogleAccountLogin.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.accounts.Account; import android.accounts.AccountManager; @@ -30,9 +30,9 @@ import android.net.Uri; import android.net.http.AndroidHttpClient; import android.os.Bundle; import android.util.Log; -import android.webkit.CookieSyncManager; -import android.webkit.WebView; -import android.webkit.WebViewClient; +import org.codeaurora.swe.CookieSyncManager; +import org.codeaurora.swe.WebView; +import org.codeaurora.swe.WebViewClient; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -40,6 +40,8 @@ import org.apache.http.HttpStatus; import org.apache.http.client.methods.HttpPost; import org.apache.http.util.EntityUtils; +import com.android.swe.browser.R; + public class GoogleAccountLogin implements Runnable, AccountManagerCallback, OnCancelListener { diff --git a/src/com/android/swe/browser/HistoryItem.java b/src/com/android/swe/browser/HistoryItem.java index 8154be79..cc6770eb 100644 --- a/src/com/android/swe/browser/HistoryItem.java +++ b/src/com/android/swe/browser/HistoryItem.java @@ -15,7 +15,9 @@ */ -package com.android.browser; +package com.android.swe.browser; + +import com.android.swe.browser.R; import android.content.Context; import android.provider.Browser; diff --git a/src/com/android/swe/browser/HttpAuthenticationDialog.java b/src/com/android/swe/browser/HttpAuthenticationDialog.java index 0c16632f..7a6d8978 100644 --- a/src/com/android/swe/browser/HttpAuthenticationDialog.java +++ b/src/com/android/swe/browser/HttpAuthenticationDialog.java @@ -13,7 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; + +import com.android.swe.browser.R; import android.app.AlertDialog; import android.content.Context; diff --git a/src/com/android/swe/browser/IntentHandler.java b/src/com/android/swe/browser/IntentHandler.java index 45520d65..ff48cb44 100644 --- a/src/com/android/swe/browser/IntentHandler.java +++ b/src/com/android/swe/browser/IntentHandler.java @@ -15,7 +15,7 @@ */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.app.SearchManager; @@ -31,9 +31,8 @@ import android.provider.MediaStore; import android.text.TextUtils; import android.util.Patterns; -import com.android.browser.UI.ComboViews; -import com.android.browser.search.SearchEngine; -import com.android.common.Search; +import com.android.swe.browser.UI.ComboViews; +import com.android.swe.browser.search.SearchEngine; import java.util.HashMap; import java.util.Iterator; @@ -172,18 +171,18 @@ public class IntentHandler { } } } else { - if (BrowserWebView.isClassic() && !urlData.isEmpty() + if (!urlData.isEmpty() && urlData.mUrl.startsWith("about:debug")) { if ("about:debug.dom".equals(urlData.mUrl)) { - current.getWebViewClassic().dumpDomTree(false); + current.getWebView().dumpDomTree(false); } else if ("about:debug.dom.file".equals(urlData.mUrl)) { - current.getWebViewClassic().dumpDomTree(true); + current.getWebView().dumpDomTree(true); } else if ("about:debug.render".equals(urlData.mUrl)) { - current.getWebViewClassic().dumpRenderTree(false); + current.getWebView().dumpRenderTree(false); } else if ("about:debug.render.file".equals(urlData.mUrl)) { - current.getWebViewClassic().dumpRenderTree(true); + current.getWebView().dumpRenderTree(true); } else if ("about:debug.display".equals(urlData.mUrl)) { - current.getWebViewClassic().dumpDisplayTree(); + current.getWebView().dumpDisplayTree(); } else if ("about:debug.nav".equals(urlData.mUrl)) { current.getWebView().debugDump(); } else { @@ -245,7 +244,7 @@ public class IntentHandler { String source = null; final Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA); if (appData != null) { - source = appData.getString(Search.SOURCE); + source = appData.getString("source"); } if (TextUtils.isEmpty(source)) { source = GOOGLE_SEARCH_SOURCE_UNKNOWN; diff --git a/src/com/android/swe/browser/KeyChainLookup.java b/src/com/android/swe/browser/KeyChainLookup.java index 4d5f694b..80f799e7 100644 --- a/src/com/android/swe/browser/KeyChainLookup.java +++ b/src/com/android/swe/browser/KeyChainLookup.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.os.AsyncTask; import android.security.KeyChain; import android.security.KeyChainException; -import android.webkit.ClientCertRequestHandler; +import org.codeaurora.swe.ClientCertRequestHandler; import java.security.PrivateKey; import java.security.cert.X509Certificate; diff --git a/src/com/android/swe/browser/LogTag.java b/src/com/android/swe/browser/LogTag.java index 38fea478..143f7f6a 100644 --- a/src/com/android/swe/browser/LogTag.java +++ b/src/com/android/swe/browser/LogTag.java @@ -14,12 +14,15 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.util.EventLog; public class LogTag { + public static final int BROWSER_BOOKMARK_ADDED = 70103; + public static final int BROWSER_PAGE_LOADED = 70104; + public static final int BROWSER_TIMEONPAGE = 70105; /** * Log when the user is adding a new bookmark. * @@ -27,7 +30,7 @@ public class LogTag { * @param where the location from where the bookmark was added */ public static void logBookmarkAdded(String url, String where) { - EventLog.writeEvent(EventLogTags.BROWSER_BOOKMARK_ADDED, url + "|" + EventLog.writeEvent(BROWSER_BOOKMARK_ADDED, url + "|" + where); } @@ -42,7 +45,7 @@ public class LogTag { * @param duration the time the browser spent loading the page. */ public static void logPageFinishedLoading(String url, long duration) { - EventLog.writeEvent(EventLogTags.BROWSER_PAGE_LOADED, url + "|" + EventLog.writeEvent(BROWSER_PAGE_LOADED, url + "|" + duration); } @@ -53,7 +56,7 @@ public class LogTag { * @param duration the time spent on the webpage. */ public static void logTimeOnPage(String url, long duration) { - EventLog.writeEvent(EventLogTags.BROWSER_TIMEONPAGE, url + "|" + EventLog.writeEvent(BROWSER_TIMEONPAGE, url + "|" + duration); } } diff --git a/src/com/android/swe/browser/MessagesReceiver.java b/src/com/android/swe/browser/MessagesReceiver.java index 876efdfb..9733725d 100644 --- a/src/com/android/swe/browser/MessagesReceiver.java +++ b/src/com/android/swe/browser/MessagesReceiver.java @@ -27,10 +27,12 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.android.browser; +package com.android.swe.browser; import org.w3c.dom.Text; +import com.android.swe.browser.R; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; diff --git a/src/com/android/swe/browser/NavScreen.java b/src/com/android/swe/browser/NavScreen.java index 1d2114e0..098ec4b1 100644 --- a/src/com/android/swe/browser/NavScreen.java +++ b/src/com/android/swe/browser/NavScreen.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.Context; @@ -36,10 +36,11 @@ import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.RelativeLayout; import android.widget.TextView; -import com.android.browser.NavTabScroller.OnLayoutListener; -import com.android.browser.NavTabScroller.OnRemoveListener; -import com.android.browser.TabControl.OnThumbnailUpdatedListener; -import com.android.browser.UI.ComboViews; +import com.android.swe.browser.R; +import com.android.swe.browser.NavTabScroller.OnLayoutListener; +import com.android.swe.browser.NavTabScroller.OnRemoveListener; +import com.android.swe.browser.TabControl.OnThumbnailUpdatedListener; +import com.android.swe.browser.UI.ComboViews; import java.util.HashMap; @@ -79,7 +80,7 @@ public class NavScreen extends RelativeLayout } protected void showMenu() { - PopupMenu popup = new PopupMenu(mContext, mMore); + PopupMenu popup = new PopupMenu(getContext(), mMore); Menu menu = popup.getMenu(); popup.getMenuInflater().inflate(R.menu.browser, menu); mUiController.updateMenuState(mUiController.getCurrentTab(), menu); @@ -114,8 +115,8 @@ public class NavScreen extends RelativeLayout } private void init() { - LayoutInflater.from(mContext).inflate(R.layout.nav_screen, this); - setContentDescription(mContext.getResources().getString( + LayoutInflater.from(getContext()).inflate(R.layout.nav_screen, this); + setContentDescription(getContext().getResources().getString( R.string.accessibility_transition_navscreen)); mBookmarks = (ImageButton) findViewById(R.id.bookmarks); mNewTab = (ImageButton) findViewById(R.id.newtab); @@ -126,7 +127,7 @@ public class NavScreen extends RelativeLayout mScroller = (NavTabScroller) findViewById(R.id.scroller); TabControl tc = mUiController.getTabControl(); mTabViews = new HashMap(tc.getTabCount()); - mAdapter = new TabAdapter(mContext, tc); + mAdapter = new TabAdapter(getContext(), tc); mScroller.setOrientation(mOrientation == Configuration.ORIENTATION_LANDSCAPE ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL); // update state for active tab diff --git a/src/com/android/swe/browser/NavTabScroller.java b/src/com/android/swe/browser/NavTabScroller.java index c940bf55..263c7114 100644 --- a/src/com/android/swe/browser/NavTabScroller.java +++ b/src/com/android/swe/browser/NavTabScroller.java @@ -14,7 +14,7 @@ * the License. */ -package com.android.browser; +package com.android.swe.browser; import android.animation.Animator; @@ -32,7 +32,7 @@ import android.view.animation.DecelerateInterpolator; import android.widget.BaseAdapter; import android.widget.LinearLayout; -import com.android.browser.view.ScrollerView; +import com.android.swe.browser.view.ScrollerView; /** * custom view for displaying tabs in the nav screen @@ -101,7 +101,7 @@ public class NavTabScroller extends ScrollerView { } protected int getScrollValue() { - return mHorizontal ? mScrollX : mScrollY; + return mHorizontal ? getScrollX() : getScrollY(); } protected void setScrollValue(int value) { @@ -183,7 +183,7 @@ public class NavTabScroller extends ScrollerView { } protected int getRelativeChildTop(int ix) { - return mContentView.getChildAt(ix).getTop() - mScrollY; + return mContentView.getChildAt(ix).getTop() - getScrollY(); } protected void handleDataChanged() { @@ -249,7 +249,7 @@ public class NavTabScroller extends ScrollerView { } else { sy = (v.getTop() + v.getBottom() - getHeight()) / 2; } - if ((sx != mScrollX) || (sy != mScrollY)) { + if ((sx != getScrollX()) || (sy != getScrollY())) { if (smooth) { smoothScrollTo(sx,sy); } else { @@ -413,8 +413,8 @@ public class NavTabScroller extends ScrollerView { @Override protected View findViewAt(int x, int y) { - x += mScrollX; - y += mScrollY; + x += getScrollX(); + y += getScrollY(); final int count = mContentView.getChildCount(); for (int i = count - 1; i >= 0; i--) { View child = mContentView.getChildAt(i); diff --git a/src/com/android/swe/browser/NavTabView.java b/src/com/android/swe/browser/NavTabView.java index b15e828f..83b4ca02 100644 --- a/src/com/android/swe/browser/NavTabView.java +++ b/src/com/android/swe/browser/NavTabView.java @@ -14,7 +14,7 @@ * the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.graphics.Bitmap; @@ -22,7 +22,10 @@ import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; + +import com.android.swe.browser.R; + import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -54,7 +57,7 @@ public class NavTabView extends LinearLayout { } private void init() { - LayoutInflater.from(mContext).inflate(R.layout.nav_tab_view, this); + LayoutInflater.from(getContext()).inflate(R.layout.nav_tab_view, this); mContent = (ViewGroup) findViewById(R.id.main); mClose = (ImageView) findViewById(R.id.closetab); mTitle = (TextView) findViewById(R.id.title); diff --git a/src/com/android/swe/browser/NavigationBarBase.java b/src/com/android/swe/browser/NavigationBarBase.java index daeb1dea..d39fa7c8 100644 --- a/src/com/android/swe/browser/NavigationBarBase.java +++ b/src/com/android/swe/browser/NavigationBarBase.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.SearchManager; import android.content.ActivityNotFoundException; @@ -23,7 +23,6 @@ import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; -import android.os.SystemProperties; import android.text.Editable; import android.text.TextWatcher; import android.util.AttributeSet; @@ -32,16 +31,19 @@ import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; -import android.webkit.WebView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.Toast; -import com.android.browser.UrlInputView.UrlInputListener; +import com.android.swe.browser.R; +import com.android.swe.browser.UrlInputView.UrlInputListener; +import com.android.swe.browser.reflect.ReflectHelper; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; +import org.codeaurora.swe.WebView; + public class NavigationBarBase extends LinearLayout implements OnClickListener, UrlInputListener, OnFocusChangeListener, TextWatcher { @@ -169,10 +171,12 @@ public class NavigationBarBase extends LinearLayout implements stopEditingUrl(); if (UrlInputView.TYPED.equals(source)) { String url = null; - boolean wap2estore = SystemProperties.getBoolean( - "persist.env.browser.wap2estore", false); - if ((wap2estore && isEstoreTypeUrl(text)) - || isRtspTypeUrl(text)) { + Object[] params = {new String("persist.env.browser.wap2estore"), + Boolean.valueOf(false)}; + Class[] type = new Class[] {String.class, boolean.class}; + Boolean wap2estore = (Boolean) ReflectHelper.invokeStaticMethod( + "android.os.SystemProperties", "getBoolean", type, params); + if ((wap2estore && isEstoreTypeUrl(text)) || isRtspTypeUrl(text)) { url = text; } else { url = UrlUtils.smartUrlFilter(text, false); @@ -209,8 +213,8 @@ public class NavigationBarBase extends LinearLayout implements } if (source != null) { Bundle appData = new Bundle(); - appData.putString(com.android.common.Search.SOURCE, source); - i.putExtra(SearchManager.APP_DATA, appData); + appData.putString("source", source); + i.putExtra("source", appData); } mUiController.handleNewIntent(i); setDisplayTitle(text); @@ -242,17 +246,17 @@ public class NavigationBarBase extends LinearLayout implements finalUrl = url; } if (finalUrl.replaceFirst("estore:", "").length() > 256) { - Toast.makeText(mContext, R.string.estore_url_warning, Toast.LENGTH_LONG).show(); + Toast.makeText(getContext(), R.string.estore_url_warning, Toast.LENGTH_LONG).show(); return; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(finalUrl)); try { - mContext.startActivity(intent); + getContext().startActivity(intent); } catch (ActivityNotFoundException ex) { - String downloadUrl = mContext.getResources().getString(R.string.estore_homepage); + String downloadUrl = getContext().getResources().getString(R.string.estore_homepage); mUiController.loadUrl(mBaseUi.getActiveTab(), downloadUrl); - Toast.makeText(mContext, R.string.download_estore_app, Toast.LENGTH_LONG).show(); + Toast.makeText(getContext(), R.string.download_estore_app, Toast.LENGTH_LONG).show(); } } @@ -280,7 +284,7 @@ public class NavigationBarBase extends LinearLayout implements } try { - mContext.startActivity(intent); + getContext().startActivity(intent); } catch (ActivityNotFoundException ex) { Log.w("Browser", "No resolveActivity " + url); return false; diff --git a/src/com/android/swe/browser/NavigationBarPhone.java b/src/com/android/swe/browser/NavigationBarPhone.java index 23176589..a559e9f2 100644 --- a/src/com/android/swe/browser/NavigationBarPhone.java +++ b/src/com/android/swe/browser/NavigationBarPhone.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.Context; @@ -24,13 +24,14 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewConfiguration; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.PopupMenu.OnDismissListener; import android.widget.PopupMenu.OnMenuItemClickListener; -import com.android.browser.UrlInputView.StateListener; +import com.android.swe.browser.R; +import com.android.swe.browser.UrlInputView.StateListener; public class NavigationBarPhone extends NavigationBarBase implements StateListener, OnMenuItemClickListener, OnDismissListener { @@ -154,6 +155,10 @@ public class NavigationBarPhone extends NavigationBarBase implements WebView web = mBaseUi.getWebView(); if (web != null) { stopEditingUrl(); + Tab currentTab = mUiController.getTabControl().getCurrentTab(); + if (currentTab.hasCrashed) { + currentTab.replaceCrashView(web, currentTab.getViewContainer()); + } web.reload(); } } @@ -180,7 +185,7 @@ public class NavigationBarPhone extends NavigationBarBase implements void showMenu(View anchor) { Activity activity = mUiController.getActivity(); if (mPopupMenu == null) { - mPopupMenu = new PopupMenu(mContext, anchor); + mPopupMenu = new PopupMenu(getContext(), anchor); mPopupMenu.setOnMenuItemClickListener(this); mPopupMenu.setOnDismissListener(this); if (!activity.onCreateOptionsMenu(mPopupMenu.getMenu())) { diff --git a/src/com/android/swe/browser/NavigationBarTablet.java b/src/com/android/swe/browser/NavigationBarTablet.java index adfd5e79..30376c96 100644 --- a/src/com/android/swe/browser/NavigationBarTablet.java +++ b/src/com/android/swe/browser/NavigationBarTablet.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -31,8 +31,9 @@ import android.view.View; import android.widget.ImageButton; import android.widget.ImageView; -import com.android.browser.UI.ComboViews; -import com.android.browser.UrlInputView.StateListener; +import com.android.swe.browser.R; +import com.android.swe.browser.UI.ComboViews; +import com.android.swe.browser.UrlInputView.StateListener; public class NavigationBarTablet extends NavigationBarBase implements StateListener { @@ -115,7 +116,7 @@ public class NavigationBarTablet extends NavigationBarBase implements StateListe public void onConfigurationChanged(Configuration config) { super.onConfigurationChanged(config); - Resources res = mContext.getResources(); + Resources res = getContext().getResources(); mHideNavButtons = res.getBoolean(R.bool.hide_nav_buttons); if (mUrlInput.hasFocus()) { if (mHideNavButtons && (mNavButtons.getVisibility() == View.VISIBLE)) { @@ -245,6 +246,11 @@ public class NavigationBarTablet extends NavigationBarBase implements StateListe mUiController.stopLoading(); } else { if (mUiController.getCurrentTopWebView() != null) { + Tab currTab = mUiController.getTabControl().getCurrentTab(); + if (currTab.hasCrashed) { + currTab.replaceCrashView(mUiController.getCurrentTopWebView(), + currTab.getViewContainer()); + } mUiController.getCurrentTopWebView().reload(); } } diff --git a/src/com/android/swe/browser/NetworkStateHandler.java b/src/com/android/swe/browser/NetworkStateHandler.java index 9201f0f2..81a718b4 100644 --- a/src/com/android/swe/browser/NetworkStateHandler.java +++ b/src/com/android/swe/browser/NetworkStateHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.BroadcastReceiver; @@ -23,10 +23,9 @@ import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import android.webkit.WebView; -import android.webkit.WebViewClassic; +import org.codeaurora.swe.WebView; -import com.android.browser.BrowserSettings; +import com.android.swe.browser.BrowserSettings; /** * Handle network state changes @@ -114,8 +113,8 @@ public class NetworkStateHandler { private void sendNetworkType(String type, String subtype) { WebView w = mController.getCurrentWebView(); - if (w != null && BrowserWebView.isClassic()) { - WebViewClassic.fromWebView(w).setNetworkType(type, subtype); + if (w != null ) { + w.setNetworkType(type, subtype); } } } diff --git a/src/com/android/swe/browser/NfcHandler.java b/src/com/android/swe/browser/NfcHandler.java index 0dd85769..e1709b30 100644 --- a/src/com/android/swe/browser/NfcHandler.java +++ b/src/com/android/swe/browser/NfcHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.nfc.NdefMessage; diff --git a/src/com/android/swe/browser/OpenDownloadReceiver.java b/src/com/android/swe/browser/OpenDownloadReceiver.java index 4277ff49..84354058 100644 --- a/src/com/android/swe/browser/OpenDownloadReceiver.java +++ b/src/com/android/swe/browser/OpenDownloadReceiver.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.DownloadManager; import android.content.ActivityNotFoundException; diff --git a/src/com/android/swe/browser/OptionsMenuHandler.java b/src/com/android/swe/browser/OptionsMenuHandler.java index d602c7d3..13512213 100644 --- a/src/com/android/swe/browser/OptionsMenuHandler.java +++ b/src/com/android/swe/browser/OptionsMenuHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.view.Menu; import android.view.MenuItem; diff --git a/src/com/android/swe/browser/PageDialogsHandler.java b/src/com/android/swe/browser/PageDialogsHandler.java index dba52893..6ac52653 100644 --- a/src/com/android/swe/browser/PageDialogsHandler.java +++ b/src/com/android/swe/browser/PageDialogsHandler.java @@ -14,19 +14,25 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; + +import java.lang.reflect.Method; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.res.Configuration; +import android.content.res.Resources; import android.net.http.SslCertificate; import android.net.http.SslError; import android.view.LayoutInflater; import android.view.View; -import android.webkit.HttpAuthHandler; -import android.webkit.SslErrorHandler; -import android.webkit.WebView; +import org.codeaurora.swe.HttpAuthHandler; +import org.codeaurora.swe.SslErrorHandler; +import org.codeaurora.swe.WebView; + +import com.android.swe.browser.R; + import android.widget.LinearLayout; import android.widget.TextView; @@ -332,6 +338,28 @@ public class PageDialogsHandler { .show(); } + private static View inflateCertificateView(SslCertificate certificate, Context ctx) { + Class certClass; + try { + certClass = Class.forName("android.net.http.SslCertificate"); + + Class argTypes[] = new Class[1]; + argTypes[0] = Context.class; + + Method m = certClass.getDeclaredMethod("inflateCertificateView", argTypes); + m.setAccessible(true); + + Object args[] = new Object[1]; + args[0] = ctx; + return (View) m.invoke(certificate, args); + + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + /* * Creates an AlertDialog to display the given certificate. If error is * null, text is added to state that the certificae is valid and the icon @@ -341,9 +369,11 @@ public class PageDialogsHandler { */ private AlertDialog.Builder createSslCertificateDialog(SslCertificate certificate, SslError error) { - View certificateView = certificate.inflateCertificateView(mContext); + View certificateView = inflateCertificateView(certificate, mContext); + Resources res = Resources.getSystem(); + int placeholder_id = res.getIdentifier("placeholder", "id", "android"); final LinearLayout placeholder = - (LinearLayout)certificateView.findViewById(com.android.internal.R.id.placeholder); + (LinearLayout)certificateView.findViewById(placeholder_id); LayoutInflater factory = LayoutInflater.from(mContext); int iconId; @@ -352,7 +382,7 @@ public class PageDialogsHandler { iconId = R.drawable.ic_dialog_browser_certificate_secure; LinearLayout table = (LinearLayout)factory.inflate(R.layout.ssl_success, placeholder); TextView successString = (TextView)table.findViewById(R.id.success); - successString.setText(com.android.internal.R.string.ssl_certificate_is_valid); + successString.setText(R.string.ssl_certificate_is_valid); } else { iconId = R.drawable.ic_dialog_browser_certificate_partially_secure; if (error.hasError(SslError.SSL_UNTRUSTED)) { @@ -384,7 +414,7 @@ public class PageDialogsHandler { } return new AlertDialog.Builder(mContext) - .setTitle(com.android.internal.R.string.ssl_certificate) + .setTitle(R.string.ssl_certificate) .setIcon(iconId) .setView(certificateView); } diff --git a/src/com/android/swe/browser/PageProgressView.java b/src/com/android/swe/browser/PageProgressView.java index f512cefa..c63d60e5 100644 --- a/src/com/android/swe/browser/PageProgressView.java +++ b/src/com/android/swe/browser/PageProgressView.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.graphics.Canvas; diff --git a/src/com/android/swe/browser/Performance.java b/src/com/android/swe/browser/Performance.java index e9ddfa26..3e1577c5 100644 --- a/src/com/android/swe/browser/Performance.java +++ b/src/com/android/swe/browser/Performance.java @@ -14,11 +14,12 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; + +import com.android.swe.browser.platformsupport.Process; +import com.android.swe.browser.platformsupport.WebAddress; -import android.net.WebAddress; import android.os.Debug; -import android.os.Process; import android.os.SystemClock; import android.util.Log; @@ -30,7 +31,7 @@ public class Performance { private static final String LOGTAG = "browser"; private final static boolean LOGD_ENABLED = - com.android.browser.Browser.LOGD_ENABLED; + com.android.swe.browser.Browser.LOGD_ENABLED; private static boolean mInTrace; diff --git a/src/com/android/swe/browser/PhoneUi.java b/src/com/android/swe/browser/PhoneUi.java index 89eae708..471e8004 100644 --- a/src/com/android/swe/browser/PhoneUi.java +++ b/src/com/android/swe/browser/PhoneUi.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -35,10 +35,11 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.accessibility.AccessibilityEvent; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; import android.widget.ImageView; -import com.android.browser.UrlInputView.StateListener; +import com.android.swe.browser.R; +import com.android.swe.browser.UrlInputView.StateListener; /** * Ui for regular phone screen sizes @@ -66,7 +67,7 @@ public class PhoneUi extends BaseUi { mNavigationBar = (NavigationBarPhone) mTitleBar.getNavigationBar(); TypedValue heightValue = new TypedValue(); browser.getTheme().resolveAttribute( - com.android.internal.R.attr.actionBarSize, heightValue, true); + android.R.attr.actionBarSize, heightValue, true); mActionBarHeight = TypedValue.complexToDimensionPixelSize(heightValue.data, browser.getResources().getDisplayMetrics()); } @@ -292,7 +293,8 @@ public class PhoneUi extends BaseUi { int fromLeft = 0; int fromTop = getTitleBar().getHeight(); int fromRight = mContentView.getWidth(); - int fromBottom = mContentView.getHeight(); + int fixedTbarHeight = mTitleBar.isFixed() ? mTitleBar.calculateEmbeddedHeight() : 0; + int fromBottom = mContentView.getHeight() + fixedTbarHeight; int width = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_width); int height = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_height); int ntth = mActivity.getResources().getDimensionPixelSize(R.dimen.nav_tab_titleheight); @@ -301,7 +303,9 @@ public class PhoneUi extends BaseUi { int toRight = toLeft + width; int toBottom = toTop + height; float scaleFactor = width / (float) mContentView.getWidth(); - detachTab(mActiveTab); + // SWE: Detaching the active tab results flashing screen with SWE. + // Not detaching the tab doesn't seem to have any issues. + //detachTab(mActiveTab); mContentView.setVisibility(View.GONE); AnimatorSet set1 = new AnimatorSet(); AnimatorSet inanim = new AnimatorSet(); @@ -378,12 +382,18 @@ public class PhoneUi extends BaseUi { if (mAnimScreen.mMain.getParent() == null) { mCustomViewContainer.addView(mAnimScreen.mMain, COVER_SCREEN_PARAMS); } + int fixedTbarHeight = mTitleBar.isFixed() ? mTitleBar.calculateEmbeddedHeight() : 0; mAnimScreen.mMain.layout(0, 0, mContentView.getWidth(), - mContentView.getHeight()); + mContentView.getHeight() + fixedTbarHeight); mNavScreen.mScroller.finishScroller(); ImageView target = tabview.mImage; int toLeft = 0; - int toTop = (tab.getWebView() != null) ? tab.getWebView().getVisibleTitleHeight() : 0; + int toTop = 0; + if (mTitleBar.isFixed()) { + toTop = fixedTbarHeight; + } else { + toTop = (tab.getWebView() != null) ? tab.getWebView().getVisibleTitleHeight() : 0; + } int toRight = mContentView.getWidth(); int width = target.getDrawable().getIntrinsicWidth(); int height = target.getDrawable().getIntrinsicHeight(); @@ -480,12 +490,14 @@ public class PhoneUi extends BaseUi { if (tbar == null || web == null) { return; } - if (tbar.getWidth() > 0 && tbar.getEmbeddedHeight() > 0) { + int embTbarHeight = tbar.getEmbeddedHeight(); + int tbarHeight = tbar.isFixed() ? tbar.calculateEmbeddedHeight() : embTbarHeight; + if (tbar.getWidth() > 0 && tbarHeight > 0) { if (mTitleBarBitmap == null || mTitleBarBitmap.getWidth() != tbar.getWidth() - || mTitleBarBitmap.getHeight() != tbar.getEmbeddedHeight()) { + || mTitleBarBitmap.getHeight() != tbarHeight) { mTitleBarBitmap = safeCreateBitmap(tbar.getWidth(), - tbar.getEmbeddedHeight()); + tbarHeight); } if (mTitleBarBitmap != null) { Canvas c = new Canvas(mTitleBarBitmap); @@ -497,19 +509,23 @@ public class PhoneUi extends BaseUi { } mTitle.setImageBitmap(mTitleBarBitmap); mTitle.setVisibility(View.VISIBLE); - int h = web.getHeight() - tbar.getEmbeddedHeight(); - if (mContentBitmap == null - || mContentBitmap.getWidth() != web.getWidth() - || mContentBitmap.getHeight() != h) { - mContentBitmap = safeCreateBitmap(web.getWidth(), h); - } - if (mContentBitmap != null) { - Canvas c = new Canvas(mContentBitmap); - int tx = web.getScrollX(); - int ty = web.getScrollY(); - c.translate(-tx, -ty - tbar.getEmbeddedHeight()); - web.draw(c); - c.setBitmap(null); + // SWE: WebView.draw() wouldn't draw anything if SurfaceView is enabled. + mContentBitmap = web.getViewportBitmap(); + if (mContentBitmap == null) { + int h = web.getHeight() - embTbarHeight; + if (mContentBitmap == null + || mContentBitmap.getWidth() != web.getWidth() + || mContentBitmap.getHeight() != h) { + mContentBitmap = safeCreateBitmap(web.getWidth(), h); + } + if (mContentBitmap != null) { + Canvas c = new Canvas(mContentBitmap); + int tx = web.getScrollX(); + int ty = web.getScrollY(); + c.translate(-tx, -ty - embTbarHeight); + web.draw(c); + c.setBitmap(null); + } } mContent.setImageBitmap(mContentBitmap); } diff --git a/src/com/android/swe/browser/PieControl.java b/src/com/android/swe/browser/PieControl.java index a33f8c66..83653f52 100644 --- a/src/com/android/swe/browser/PieControl.java +++ b/src/com/android/swe/browser/PieControl.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.Context; @@ -24,19 +24,20 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; import android.widget.BaseAdapter; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ImageView.ScaleType; import android.widget.TextView; -import com.android.browser.UI.ComboViews; -import com.android.browser.view.PieItem; -import com.android.browser.view.PieMenu; -import com.android.browser.view.PieMenu.PieView.OnLayoutListener; -import com.android.browser.view.PieStackView; -import com.android.browser.view.PieStackView.OnCurrentListener; +import com.android.swe.browser.R; +import com.android.swe.browser.UI.ComboViews; +import com.android.swe.browser.view.PieItem; +import com.android.swe.browser.view.PieMenu; +import com.android.swe.browser.view.PieStackView; +import com.android.swe.browser.view.PieMenu.PieView.OnLayoutListener; +import com.android.swe.browser.view.PieStackView.OnCurrentListener; import java.util.ArrayList; import java.util.List; diff --git a/src/com/android/swe/browser/PreferenceKeys.java b/src/com/android/swe/browser/PreferenceKeys.java index ffbb39ab..36d02ca3 100644 --- a/src/com/android/swe/browser/PreferenceKeys.java +++ b/src/com/android/swe/browser/PreferenceKeys.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; public interface PreferenceKeys { @@ -40,6 +40,7 @@ public interface PreferenceKeys { static final String PREF_DEFAULT_TEXT_ENCODING = "default_text_encoding"; static final String PREF_DEFAULT_ZOOM = "default_zoom"; static final String PREF_ENABLE_JAVASCRIPT = "enable_javascript"; + static final String PREF_ENABLE_MEMORY_MONITOR = "enable_memory_monitor"; static final String PREF_LOAD_PAGE = "load_page"; static final String PREF_OPEN_IN_BACKGROUND = "open_in_background"; static final String PREF_PLUGIN_STATE = "plugin_state"; diff --git a/src/com/android/swe/browser/PreloadController.java b/src/com/android/swe/browser/PreloadController.java index 881f19ed..e2d43c1a 100644 --- a/src/com/android/swe/browser/PreloadController.java +++ b/src/com/android/swe/browser/PreloadController.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.Context; @@ -25,11 +25,11 @@ import android.os.Message; import android.util.Log; import android.view.KeyEvent; import android.view.View; -import android.webkit.HttpAuthHandler; -import android.webkit.SslErrorHandler; +import org.codeaurora.swe.HttpAuthHandler; +import org.codeaurora.swe.SslErrorHandler; import android.webkit.ValueCallback; import android.webkit.WebChromeClient.CustomViewCallback; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; public class PreloadController implements WebViewController { diff --git a/src/com/android/swe/browser/PreloadRequestReceiver.java b/src/com/android/swe/browser/PreloadRequestReceiver.java index c654037a..058f9ee7 100644 --- a/src/com/android/swe/browser/PreloadRequestReceiver.java +++ b/src/com/android/swe/browser/PreloadRequestReceiver.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.BroadcastReceiver; import android.content.Context; @@ -34,7 +34,7 @@ import java.util.Map; public class PreloadRequestReceiver extends BroadcastReceiver { private final static String LOGTAG = "browser.preloader"; - private final static boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED; + private final static boolean LOGD_ENABLED = com.android.swe.browser.Browser.LOGD_ENABLED; private static final String ACTION_PRELOAD = "android.intent.action.PRELOAD"; static final String EXTRA_PRELOAD_ID = "preload_id"; diff --git a/src/com/android/swe/browser/PreloadedTabControl.java b/src/com/android/swe/browser/PreloadedTabControl.java index 21dafa9d..88e6c9c6 100644 --- a/src/com/android/swe/browser/PreloadedTabControl.java +++ b/src/com/android/swe/browser/PreloadedTabControl.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.net.Uri; import android.text.TextUtils; @@ -26,7 +26,7 @@ import java.util.regex.Pattern; * Class to manage the controlling of preloaded tab. */ public class PreloadedTabControl { - private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED; + private static final boolean LOGD_ENABLED = com.android.swe.browser.Browser.LOGD_ENABLED; private static final String LOGTAG = "PreloadedTabControl"; final Tab mTab; diff --git a/src/com/android/swe/browser/Preloader.java b/src/com/android/swe/browser/Preloader.java index 3273a8c8..e2125756 100644 --- a/src/com/android/swe/browser/Preloader.java +++ b/src/com/android/swe/browser/Preloader.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.os.Handler; import android.os.Looper; import android.util.Log; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; import java.util.Map; @@ -29,7 +29,7 @@ import java.util.Map; public class Preloader { private final static String LOGTAG = "browser.preloader"; - private final static boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED; + private final static boolean LOGD_ENABLED = com.android.swe.browser.Browser.LOGD_ENABLED; private static final int PRERENDER_TIMEOUT_MILLIS = 30 * 1000; // 30s diff --git a/src/com/android/swe/browser/ShortcutActivity.java b/src/com/android/swe/browser/ShortcutActivity.java index 56e9c30b..e8f66901 100644 --- a/src/com/android/swe/browser/ShortcutActivity.java +++ b/src/com/android/swe/browser/ShortcutActivity.java @@ -14,7 +14,9 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; + +import com.android.swe.browser.R; import android.app.Activity; import android.content.Intent; diff --git a/src/com/android/swe/browser/SnapshotBar.java b/src/com/android/swe/browser/SnapshotBar.java index 51e1226c..3fef6f4b 100644 --- a/src/com/android/swe/browser/SnapshotBar.java +++ b/src/com/android/swe/browser/SnapshotBar.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.graphics.Bitmap; @@ -31,7 +31,8 @@ import android.widget.LinearLayout; import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.TextView; -import com.android.browser.UI.ComboViews; +import com.android.swe.browser.R; +import com.android.swe.browser.UI.ComboViews; import java.text.DateFormat; import java.util.Date; diff --git a/src/com/android/swe/browser/SnapshotTab.java b/src/com/android/swe/browser/SnapshotTab.java index e14f0959..91494250 100644 --- a/src/com/android/swe/browser/SnapshotTab.java +++ b/src/com/android/swe/browser/SnapshotTab.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.ContentResolver; import android.content.ContentUris; @@ -26,10 +26,9 @@ import android.os.AsyncTask; import android.os.Bundle; import android.text.TextUtils; import android.util.Log; -import android.webkit.WebView; -import android.webkit.WebViewClassic; +import org.codeaurora.swe.WebView; -import com.android.browser.provider.SnapshotProvider.Snapshots; +import com.android.swe.browser.provider.SnapshotProvider.Snapshots; import java.io.ByteArrayInputStream; import java.io.FileNotFoundException; @@ -48,6 +47,7 @@ public class SnapshotTab extends Tab { private int mBackgroundColor; private long mDateCreated; private boolean mIsLive; + private String mLiveUrl; public SnapshotTab(WebViewController wvcontroller, long snapshotId) { super(wvcontroller, null, null); @@ -122,11 +122,15 @@ public class SnapshotTab extends Tab { return mDateCreated; } + public String getLiveUrl() { + return mLiveUrl; + } + @Override public void loadUrl(String url, Map headers) { if (!mIsLive) { mIsLive = true; - getWebViewClassic().clearViewState(); + getWebView().clearViewState(); } super.loadUrl(url, headers); } @@ -191,10 +195,6 @@ public class SnapshotTab extends Tab { } private InputStream getInputStream(Cursor c) throws FileNotFoundException { - String path = c.getString(SNAPSHOT_VIEWSTATE_PATH); - if (!TextUtils.isEmpty(path)) { - return mContext.openFileInput(path); - } byte[] data = c.getBlob(SNAPSHOT_VIEWSTATE); ByteArrayInputStream bis = new ByteArrayInputStream(data); return bis; @@ -206,16 +206,22 @@ public class SnapshotTab extends Tab { if (result.moveToFirst()) { mTab.mCurrentState.mTitle = result.getString(SNAPSHOT_TITLE); mTab.mCurrentState.mUrl = result.getString(SNAPSHOT_URL); + mTab.mLiveUrl = result.getString(SNAPSHOT_URL); byte[] favicon = result.getBlob(SNAPSHOT_FAVICON); if (favicon != null) { mTab.mCurrentState.mFavicon = BitmapFactory .decodeByteArray(favicon, 0, favicon.length); } - WebViewClassic web = mTab.getWebViewClassic(); + WebView web = mTab.getWebView(); if (web != null) { - InputStream ins = getInputStream(result); - GZIPInputStream stream = new GZIPInputStream(ins); - web.loadViewState(stream); + String path = result.getString(SNAPSHOT_VIEWSTATE_PATH); + if (!TextUtils.isEmpty(path)) { + web.loadViewState(path); + } else { + InputStream ins = getInputStream(result); + GZIPInputStream stream = new GZIPInputStream(ins); + web.loadViewState(stream); + } } mTab.mBackgroundColor = result.getInt(SNAPSHOT_BACKGROUND); mTab.mDateCreated = result.getLong(SNAPSHOT_DATE_CREATED); diff --git a/src/com/android/swe/browser/SuggestionsAdapter.java b/src/com/android/swe/browser/SuggestionsAdapter.java index 9f66e3c4..ecb375be 100644 --- a/src/com/android/swe/browser/SuggestionsAdapter.java +++ b/src/com/android/swe/browser/SuggestionsAdapter.java @@ -14,14 +14,16 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.SearchManager; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; -import android.provider.BrowserContract; + +import com.android.swe.browser.R; + import android.text.Html; import android.text.TextUtils; import android.view.LayoutInflater; @@ -34,8 +36,9 @@ import android.widget.Filterable; import android.widget.ImageView; import android.widget.TextView; -import com.android.browser.provider.BrowserProvider2.OmniboxSuggestions; -import com.android.browser.search.SearchEngine; +import com.android.swe.browser.platformsupport.BrowserContract; +import com.android.swe.browser.provider.BrowserProvider2.OmniboxSuggestions; +import com.android.swe.browser.search.SearchEngine; import java.util.ArrayList; import java.util.List; diff --git a/src/com/android/swe/browser/SystemAllowGeolocationOrigins.java b/src/com/android/swe/browser/SystemAllowGeolocationOrigins.java index e0759ade..54ee79c3 100644 --- a/src/com/android/swe/browser/SystemAllowGeolocationOrigins.java +++ b/src/com/android/swe/browser/SystemAllowGeolocationOrigins.java @@ -14,23 +14,22 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.content.SharedPreferences; import android.database.ContentObserver; import android.net.Uri; -import android.os.AsyncTask; import android.os.Handler; -import android.preference.PreferenceManager; import android.provider.Settings; import android.text.TextUtils; -import android.webkit.GeolocationPermissions; import android.webkit.ValueCallback; import java.util.HashSet; import java.util.Set; +import org.codeaurora.swe.GeolocationPermissions; + /** * Manages the interaction between the secure system setting for default geolocation * permissions and the browser. diff --git a/src/com/android/swe/browser/Tab.java b/src/com/android/swe/browser/Tab.java index e33a56bd..91cb2d2e 100644 --- a/src/com/android/swe/browser/Tab.java +++ b/src/com/android/swe/browser/Tab.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.app.AlertDialog; @@ -23,6 +23,7 @@ import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; +import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; @@ -46,45 +47,50 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewStub; -import android.webkit.BrowserDownloadListener; -import android.webkit.ClientCertRequestHandler; +import android.view.View.OnClickListener; import android.webkit.ConsoleMessage; import android.webkit.GeolocationPermissions; -import android.webkit.HttpAuthHandler; -import android.webkit.SslErrorHandler; import android.webkit.URLUtil; -import android.webkit.ValueCallback; -import android.webkit.WebBackForwardList; -import android.webkit.WebBackForwardListClient; -import android.webkit.WebChromeClient; -import android.webkit.WebHistoryItem; import android.webkit.WebResourceResponse; import android.webkit.WebStorage; -import android.webkit.WebView; -import android.webkit.WebView.PictureListener; -import android.webkit.WebViewClassic; -import android.webkit.WebViewClient; -import android.webkit.WebViewClientClassicExt; +import android.webkit.WebChromeClient.CustomViewCallback; +import android.webkit.ValueCallback; import android.widget.CheckBox; import android.widget.Toast; - -import com.android.browser.TabControl.OnThumbnailUpdatedListener; -import com.android.browser.homepages.HomeProvider; -import com.android.browser.mynavigation.MyNavigationUtil; -import com.android.browser.provider.MyNavigationProvider; -import com.android.browser.provider.SnapshotProvider.Snapshots; +import android.widget.FrameLayout; +import android.widget.Button; + +import com.android.swe.browser.R; + +import org.codeaurora.swe.BrowserDownloadListener; +import org.codeaurora.swe.ClientCertRequestHandler; +import org.codeaurora.swe.HttpAuthHandler; +import org.codeaurora.swe.SslErrorHandler; +import org.codeaurora.swe.WebBackForwardList; +import org.codeaurora.swe.WebBackForwardListClient; +import org.codeaurora.swe.WebChromeClient; +import org.codeaurora.swe.WebHistoryItem; +import org.codeaurora.swe.WebView; +import org.codeaurora.swe.WebView.PictureListener; +import org.codeaurora.swe.WebViewClient; + +import com.android.swe.browser.TabControl.OnThumbnailUpdatedListener; +import com.android.swe.browser.homepages.HomeProvider; +import com.android.swe.browser.mynavigation.MyNavigationUtil; +import com.android.swe.browser.provider.MyNavigationProvider; +import com.android.swe.browser.provider.SnapshotProvider.Snapshots; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.IOException; -import java.io.OutputStream; +import java.io.InputStream; import java.nio.ByteBuffer; import java.util.LinkedList; import java.util.Map; import java.util.UUID; import java.util.Vector; import java.util.regex.Pattern; -import java.util.zip.GZIPOutputStream; +import java.sql.Timestamp; +import java.util.Date; /** * Class for maintaining Tabs with a main WebView and a subwindow. @@ -93,17 +99,18 @@ class Tab implements PictureListener { // Log Tag private static final String LOGTAG = "Tab"; - private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED; + private static final boolean LOGD_ENABLED = com.android.swe.browser.Browser.LOGD_ENABLED; // Special case the logtag for messages for the Console to make it easier to // filter them and match the logtag used for these messages in older versions // of the browser. private static final String CONSOLE_LOGTAG = "browser"; private static final int MSG_CAPTURE = 42; - private static final int CAPTURE_DELAY = 100; + private static final int CAPTURE_DELAY = 1000; private static final int INITIAL_PROGRESS = 5; private static Bitmap sDefaultFavicon; + protected boolean hasCrashed = false; private static Paint sAlphaPaint = new Paint(); static { @@ -190,6 +197,7 @@ class Tab implements PictureListener { private Bitmap mCapture; private Handler mHandler; private boolean mUpdateThumbnail; + private Timestamp timestamp; /** * See {@link #clearBackStackWhenItemAdded(String)}. @@ -322,11 +330,41 @@ class Tab implements PictureListener { } } + protected void replaceCrashView(View view, View container) { + if (hasCrashed && (view == mMainView)) { + final FrameLayout wrapper = (FrameLayout) container.findViewById(R.id.webview_wrapper); + wrapper.removeAllViewsInLayout(); + wrapper.addView(view); + hasCrashed = false; + } + } + + protected void showCrashView() { + if (hasCrashed) { + LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( + Context.LAYOUT_INFLATER_SERVICE); + final View crashLayout = inflater.inflate(R.layout.browser_tab_crash, null); + final FrameLayout wrapper = + (FrameLayout) mContainer.findViewById(R.id.webview_wrapper); + wrapper.removeAllViewsInLayout(); + wrapper.addView(crashLayout); + mContainer.requestFocus(); + Button reloadBtn = (Button) crashLayout.findViewById(R.id.browser_crash_reload_btn); + reloadBtn.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View arg0) { + replaceCrashView(mMainView, mContainer); + mMainView.reload(); + } + }); + } + } + // ------------------------------------------------------------------------- // WebViewClient implementation for the main WebView // ------------------------------------------------------------------------- - private final WebViewClientClassicExt mWebViewClient = new WebViewClientClassicExt() { + private final WebViewClient mWebViewClient = new WebViewClient() { private Message mDontResend; private Message mResend; @@ -611,6 +649,13 @@ class Tab implements PictureListener { }, null, null, host, port, null); } + @Override + public void onRendererCrash(WebView view, boolean crashedWhileOomProtected) { + Log.e(LOGTAG, "Tab Crashed"); + hasCrashed = true; + showCrashView(); + } + /** * Handles an HTTP authentication request. * @@ -628,6 +673,13 @@ class Tab implements PictureListener { @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { + //intercept if opening a new incognito tab - show the incognito welcome page + if (url.startsWith("browser:incognito")) { + Resources resourceHandle = mContext.getResources(); + InputStream inStream = resourceHandle.openRawResource( + com.android.swe.browser.R.raw.incognito_mode_start_page); + return new WebResourceResponse("text/html", "utf8", inStream); + } WebResourceResponse res; if (MyNavigationUtil.MY_NAVIGATION.equals(url)) { res = MyNavigationProvider.shouldInterceptRequest(mContext, url); @@ -741,7 +793,7 @@ class Tab implements PictureListener { } // Short-circuit if this was a user gesture. - if (userGesture) { + if (userGesture || !mSettings.blockPopupWindows()) { createWindow(dialog, resultMsg); return true; } @@ -800,6 +852,7 @@ class Tab implements PictureListener { public void onProgressChanged(WebView view, int newProgress) { mPageLoadProgress = newProgress; if (newProgress == 100) { + Log.i(CONSOLE_LOGTAG, "SWE Pageload Progress = 100"); mInPageLoad = false; } mWebViewController.onProgressChanged(Tab.this); @@ -840,7 +893,7 @@ class Tab implements PictureListener { @Override public void onShowCustomView(View view, - WebChromeClient.CustomViewCallback callback) { + CustomViewCallback callback) { Activity activity = mWebViewController.getActivity(); if (activity != null) { onShowCustomView(view, activity.getRequestedOrientation(), callback); @@ -849,7 +902,7 @@ class Tab implements PictureListener { @Override public void onShowCustomView(View view, int requestedOrientation, - WebChromeClient.CustomViewCallback callback) { + CustomViewCallback callback) { if (mInForeground) mWebViewController.showCustomView(Tab.this, view, requestedOrientation, callback); } @@ -1054,12 +1107,12 @@ class Tab implements PictureListener { // Subclass of WebViewClient used in subwindows to notify the main // WebViewClient of certain WebView activities. - private static class SubWindowClient extends WebViewClientClassicExt { + private static class SubWindowClient extends WebViewClient { // The main WebViewClient. - private final WebViewClientClassicExt mClient; + private final WebViewClient mClient; private final WebViewController mController; - SubWindowClient(WebViewClientClassicExt client, WebViewController controller) { + SubWindowClient(WebViewClient client, WebViewController controller) { mClient = client; mController = controller; } @@ -1263,6 +1316,20 @@ class Tab implements PictureListener { setWebView(w, true); } + public boolean isNativeActive(){ + if (mMainView == null) + return false; + return true; + } + + public void setTimeStamp(){ + Date d = new Date(); + timestamp = (new Timestamp(d.getTime())); + } + + public Timestamp getTimestamp() { + return timestamp; + } /** * Sets the WebView for this tab, correctly removing the old WebView from * the container view. @@ -1299,11 +1366,9 @@ class Tab implements PictureListener { // does a redirect after a period of time. The user could have // switched to another tab while waiting for the download to start. mMainView.setDownloadListener(mDownloadListener); - if (BrowserWebView.isClassic()) { - getWebViewClassic().setWebBackForwardListClient(mWebBackForwardListClient); - } + getWebView().setWebBackForwardListClient(mWebBackForwardListClient); TabControl tc = mWebViewController.getTabControl(); - if (tc != null && tc.getOnThumbnailUpdatedListener() != null) { + if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) { mMainView.setPictureListener(this); } if (restore && (mSavedState != null)) { @@ -1537,18 +1602,6 @@ class Tab implements PictureListener { return mMainView; } - /** - * Return the underlying WebViewClassic implementation. As with getWebView, - * this maybe null for background tabs. - * @return The main WebView of this tab. - */ - WebViewClassic getWebViewClassic() { - if (!BrowserWebView.isClassic()) { - return null; - } - return WebViewClassic.fromWebView(mMainView); - } - void setViewContainer(View container) { mContainer = container; } @@ -1813,24 +1866,29 @@ class Tab implements PictureListener { return false; } - private static class SaveCallback implements ValueCallback { - boolean mResult; + private static class SaveCallback implements ValueCallback { + boolean onReceiveValueCalled = false; + private String mPath; @Override - public void onReceiveValue(Boolean value) { - mResult = value; + public void onReceiveValue(String path) { + this.onReceiveValueCalled = true; + this.mPath = path; synchronized (this) { notifyAll(); } } + public String getPath() { + return mPath; + } } /** * Must be called on the UI thread */ public ContentValues createSnapshotValues() { - WebViewClassic web = getWebViewClassic(); + WebView web = getWebView(); if (web == null) return null; ContentValues values = new ContentValues(); values.put(Snapshots.TITLE, mCurrentState.mTitle); @@ -1838,9 +1896,7 @@ class Tab implements PictureListener { values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor()); values.put(Snapshots.DATE_CREATED, System.currentTimeMillis()); values.put(Snapshots.FAVICON, compressBitmap(getFavicon())); - Bitmap screenshot = Controller.createScreenshot(mMainView, - Controller.getDesiredThumbnailWidth(mContext), - Controller.getDesiredThumbnailHeight(mContext)); + Bitmap screenshot = web.getViewportBitmap(); values.put(Snapshots.THUMBNAIL, compressBitmap(screenshot)); return values; } @@ -1849,45 +1905,33 @@ class Tab implements PictureListener { * Probably want to call this on a background thread */ public boolean saveViewState(ContentValues values) { - WebViewClassic web = getWebViewClassic(); + WebView web = getWebView(); if (web == null) return false; - String path = UUID.randomUUID().toString(); + String filename = UUID.randomUUID().toString(); SaveCallback callback = new SaveCallback(); - OutputStream outs = null; try { - outs = mContext.openFileOutput(path, Context.MODE_PRIVATE); - GZIPOutputStream stream = new GZIPOutputStream(outs); synchronized (callback) { - web.saveViewState(stream, callback); - callback.wait(); + web.saveViewState(filename, callback); + callback.wait(); } - stream.flush(); - stream.close(); } catch (Exception e) { Log.w(LOGTAG, "Failed to save view state", e); - if (outs != null) { - try { - outs.close(); - } catch (IOException ignore) {} - } - File file = mContext.getFileStreamPath(path); - if (file.exists() && !file.delete()) { - file.deleteOnExit(); + String path = callback.getPath(); + if (path != null) { + File file = mContext.getFileStreamPath(path); + if (file.exists() && !file.delete()) { + file.deleteOnExit(); + } } return false; } - File savedFile = mContext.getFileStreamPath(path); - if (!callback.mResult) { - if (!savedFile.delete()) { - savedFile.deleteOnExit(); - } - return false; + String path = callback.getPath(); + File savedFile = new File(path); + if (!savedFile.exists()) { + return false; } - long size = savedFile.length(); - if (values == null) - return false; - values.put(Snapshots.VIEWSTATE_PATH, path); - values.put(Snapshots.VIEWSTATE_SIZE, size); + values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1)); + values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length()); return true; } @@ -1920,16 +1964,24 @@ class Tab implements PictureListener { return; } Canvas c = new Canvas(mCapture); - final int left = mMainView.getScrollX(); - final int top = mMainView.getScrollY() + mMainView.getVisibleTitleHeight(); int state = c.save(); - c.translate(-left, -top); - float scale = mCaptureWidth / (float) mMainView.getWidth(); - c.scale(scale, scale, left, top); - if (mMainView instanceof BrowserWebView) { - ((BrowserWebView)mMainView).drawContent(c); - } else { - mMainView.draw(c); + Bitmap screenShot = mMainView.getViewportBitmap(); + if (screenShot != null) { + mCapture.eraseColor(Color.WHITE); + float scale = (float) mCaptureWidth / screenShot.getWidth(); + c.scale(scale, scale); + c.drawBitmap(screenShot, 0, 0, null); + } else { + final int left = mMainView.getViewScrollX(); + final int top = mMainView.getViewScrollY() + mMainView.getVisibleTitleHeight(); + c.translate(-left, -top); + float scale = mCaptureWidth / (float) mMainView.getWidth(); + c.scale(scale, scale, left, top); + if (mMainView instanceof BrowserWebView) { + ((BrowserWebView)mMainView).drawContent(c); + } else { + mMainView.draw(c); + } } c.restoreToCount(state); // manually anti-alias the edges for the tilt diff --git a/src/com/android/swe/browser/TabBar.java b/src/com/android/swe/browser/TabBar.java index cf82e015..d74dcbe9 100644 --- a/src/com/android/swe/browser/TabBar.java +++ b/src/com/android/swe/browser/TabBar.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.animation.Animator; import android.animation.Animator.AnimatorListener; @@ -45,6 +45,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.android.swe.browser.R; + /** * tabbed title bar for xlarge screen browser */ diff --git a/src/com/android/swe/browser/TabControl.java b/src/com/android/swe/browser/TabControl.java index 10de8a10..7030c10f 100644 --- a/src/com/android/swe/browser/TabControl.java +++ b/src/com/android/swe/browser/TabControl.java @@ -14,12 +14,14 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.os.Bundle; -import android.os.SystemProperties; import android.util.Log; -import android.webkit.WebView; + +import com.android.swe.browser.reflect.ReflectHelper; + +import org.codeaurora.swe.WebView; import java.util.ArrayList; import java.util.HashMap; @@ -304,7 +306,8 @@ class TabControl { int i = 0; for (Tab tab : mTabs) { Bundle tabState = tab.saveState(); - if (tabState != null) { + if (tabState != null && tab.getWebView() != null + && tab.getWebView().isPrivateBrowsingEnabled() == false) { ids[i++] = tab.getId(); String key = Long.toString(tab.getId()); if (outState.containsKey(key)) { @@ -414,8 +417,12 @@ class TabControl { // If the webview restore successfully, add javascript interface again. WebView view = t.getWebView(); if (view != null) { - String browserRes = SystemProperties.get("persist.env.c.browser.resource", - "default"); + Object[] params = { new String("persist.env.c.browser.resource"), + new String("default")}; + Class[] type = new Class[] {String.class, String.class}; + String browserRes = (String)ReflectHelper.invokeStaticMethod( + "android.os.SystemProperties","get", + type, params); if ("ct".equals(browserRes)) { view.getSettings().setJavaScriptEnabled(true); if (mController.getActivity() instanceof BrowserActivity) { diff --git a/src/com/android/swe/browser/TabScrollView.java b/src/com/android/swe/browser/TabScrollView.java index 52dd6af0..14caac49 100644 --- a/src/com/android/swe/browser/TabScrollView.java +++ b/src/com/android/swe/browser/TabScrollView.java @@ -14,9 +14,10 @@ * the License. */ -package com.android.browser; +package com.android.swe.browser; -import com.android.browser.TabBar.TabView; +import com.android.swe.browser.R; +import com.android.swe.browser.TabBar.TabView; import android.animation.ObjectAnimator; import android.content.Context; diff --git a/src/com/android/swe/browser/TitleBar.java b/src/com/android/swe/browser/TitleBar.java index a0cc857d..89c175e0 100644 --- a/src/com/android/swe/browser/TitleBar.java +++ b/src/com/android/swe/browser/TitleBar.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.animation.Animator; import android.animation.Animator.AnimatorListener; @@ -31,7 +31,10 @@ import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.view.animation.DecelerateInterpolator; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; + +import com.android.swe.browser.R; + import android.widget.FrameLayout; import android.widget.RelativeLayout; @@ -120,9 +123,8 @@ public class TitleBar extends RelativeLayout { private void setFixedTitleBar() { boolean isFixed = !mUseQuickControls - && !mContext.getResources().getBoolean(R.bool.hide_title); + && !getContext().getResources().getBoolean(R.bool.hide_title); isFixed |= mAccessibilityManager.isEnabled(); - isFixed |= !BrowserWebView.isClassic(); // If getParent() returns null, we are initializing ViewGroup parent = (ViewGroup)getParent(); if (mIsFixedTitleBar == isFixed && parent != null) return; @@ -172,7 +174,7 @@ public class TitleBar extends RelativeLayout { } void setupTitleBarAnimator(Animator animator) { - Resources res = mContext.getResources(); + Resources res = getContext().getResources(); int duration = res.getInteger(R.integer.titlebar_animation_duration); animator.setInterpolator(new DecelerateInterpolator( ANIM_TITLEBAR_DECELERATE)); @@ -300,7 +302,11 @@ public class TitleBar extends RelativeLayout { return calculateEmbeddedHeight(); } - private int calculateEmbeddedHeight() { + public boolean isFixed() { + return mIsFixedTitleBar; + } + + int calculateEmbeddedHeight() { int height = mNavBar.getHeight(); if (mAutoLogin != null && mAutoLogin.getVisibility() == View.VISIBLE) { height += mAutoLogin.getHeight(); diff --git a/src/com/android/swe/browser/UI.java b/src/com/android/swe/browser/UI.java index 677c3d3b..18f189fb 100644 --- a/src/com/android/swe/browser/UI.java +++ b/src/com/android/swe/browser/UI.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.res.Configuration; import android.graphics.Bitmap; @@ -25,7 +25,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.WebChromeClient.CustomViewCallback; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; import java.util.List; diff --git a/src/com/android/swe/browser/UiController.java b/src/com/android/swe/browser/UiController.java index 683e4732..563f4687 100644 --- a/src/com/android/swe/browser/UiController.java +++ b/src/com/android/swe/browser/UiController.java @@ -14,15 +14,15 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.MenuItem; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; -import com.android.browser.UI.ComboViews; +import com.android.swe.browser.UI.ComboViews; import java.util.List; diff --git a/src/com/android/swe/browser/UploadHandler.java b/src/com/android/swe/browser/UploadHandler.java index 544419b6..ee744b91 100644 --- a/src/com/android/swe/browser/UploadHandler.java +++ b/src/com/android/swe/browser/UploadHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.ActivityNotFoundException; @@ -22,11 +22,13 @@ import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Environment; -import android.os.SystemProperties; import android.provider.MediaStore; import android.webkit.ValueCallback; import android.widget.Toast; +import com.android.swe.browser.R; +import com.android.swe.browser.reflect.ReflectHelper; + import java.io.File; import java.util.Vector; @@ -120,7 +122,11 @@ public class UploadHandler { } // add unsupport uploading drm file feature for carrier. - boolean drmUpload = SystemProperties.getBoolean("persist.env.browser.drmupload", false); + Object[] params = {new String("persist.env.browser.drmupload"), + Boolean.valueOf(false)}; + Class[] type = new Class[] {String.class, boolean.class}; + Boolean drmUpload = (Boolean) ReflectHelper.invokeStaticMethod( + "android.os.SystemProperties", "getBoolean", type, params); if (drmUpload && isDrmFileUpload(result)) { mUploadMessage.onReceiveValue(null); } else { diff --git a/src/com/android/swe/browser/UrlBarAutoShowManager.java b/src/com/android/swe/browser/UrlBarAutoShowManager.java index 9f7827b2..c5c23b9f 100644 --- a/src/com/android/swe/browser/UrlBarAutoShowManager.java +++ b/src/com/android/swe/browser/UrlBarAutoShowManager.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.os.SystemClock; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewConfiguration; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; -import com.android.browser.BrowserWebView.OnScrollChangedListener; +import com.android.swe.browser.BrowserWebView.OnScrollChangedListener; /** * Helper class to manage when to show the URL bar based off of touch diff --git a/src/com/android/swe/browser/UrlHandler.java b/src/com/android/swe/browser/UrlHandler.java index ac8442ac..1e320d1a 100755 --- a/src/com/android/swe/browser/UrlHandler.java +++ b/src/com/android/swe/browser/UrlHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.ActivityNotFoundException; @@ -22,28 +22,24 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.database.Cursor; import android.net.Uri; -import android.os.AsyncTask; -import android.os.SystemProperties; import android.provider.Browser; import android.util.Log; -import android.webkit.WebView; import android.widget.Toast; +import com.android.swe.browser.R; +import com.android.swe.browser.reflect.ReflectHelper; + import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.util.List; import java.util.regex.Matcher; -/** - * - */ +import org.codeaurora.swe.WebView; + public class UrlHandler { private final static String TAG = "UrlHandler"; - static final String RLZ_PROVIDER = "com.google.android.partnersetup.rlzappprovider"; - static final Uri RLZ_PROVIDER_URI = Uri.parse("content://" + RLZ_PROVIDER + "/"); // Use in overrideUrlLoading /* package */ final static String SCHEME_WTAI = "wtai://wp/"; @@ -54,9 +50,6 @@ public class UrlHandler { Controller mController; Activity mActivity; - private Boolean mIsProviderPresent = null; - private Uri mRlzUri = null; - public UrlHandler(Controller controller) { mController = controller; mActivity = mController.getActivity(); @@ -109,23 +102,13 @@ public class UrlHandler { mController.startAddMyNavigation(url); return true; } - // If this is a Google search, attempt to add an RLZ string - // (if one isn't already present). - if (rlzProviderPresent()) { - Uri siteUri = Uri.parse(url); - if (needsRlzString(siteUri)) { - // Need to look up the RLZ info from a database, so do it in an - // AsyncTask. Although we are not overriding the URL load synchronously, - // we guarantee that we will handle this URL load after the task executes, - // so it's safe to just return true to WebCore now to stop its own loading. - new RLZTask(tab, siteUri, view).execute(); - return true; - } - } // add for carrier wap2estore feature - boolean wap2estore = SystemProperties.getBoolean( - "persist.env.browser.wap2estore", false); + Object[] params = {new String("persist.env.browser.wap2estore"), + Boolean.valueOf(false)}; + Class[] type = new Class[] {String.class, boolean.class}; + Boolean wap2estore = (Boolean)ReflectHelper.invokeStaticMethod( + "android.os.SystemProperties", "getBoolean", type, params); if (wap2estore && isEstoreTypeUrl(url)) { handleEstoreTypeUrl(url); return true; @@ -289,112 +272,4 @@ public class UrlHandler { return false; } - // TODO: Move this class into Tab, where it can be properly stopped upon - // closure of the tab - private class RLZTask extends AsyncTask { - private Tab mTab; - private Uri mSiteUri; - private WebView mWebView; - - public RLZTask(Tab tab, Uri uri, WebView webView) { - mTab = tab; - mSiteUri = uri; - mWebView = webView; - } - - protected String doInBackground(Void... unused) { - String result = mSiteUri.toString(); - Cursor cur = null; - try { - cur = mActivity.getContentResolver() - .query(getRlzUri(), null, null, null, null); - if (cur != null && cur.moveToFirst() && !cur.isNull(0)) { - result = mSiteUri.buildUpon() - .appendQueryParameter("rlz", cur.getString(0)) - .build().toString(); - } - } finally { - if (cur != null) { - cur.close(); - } - } - return result; - } - - protected void onPostExecute(String result) { - // abort if we left browser already - if (mController.isActivityPaused()) return; - // Make sure the Tab was not closed while handling the task - if (mController.getTabControl().getTabPosition(mTab) != -1) { - // If the Activity Manager is not invoked, load the URL directly - if (!startActivityForUrl(mTab, result)) { - if (!handleMenuClick(mTab, result)) { - mController.loadUrl(mTab, result); - } - } - } - } - } - - // Determine whether the RLZ provider is present on the system. - private boolean rlzProviderPresent() { - if (mIsProviderPresent == null) { - PackageManager pm = mActivity.getPackageManager(); - mIsProviderPresent = pm.resolveContentProvider(RLZ_PROVIDER, 0) != null; - } - return mIsProviderPresent; - } - - // Retrieve the RLZ access point string and cache the URI used to - // retrieve RLZ values. - private Uri getRlzUri() { - if (mRlzUri == null) { - String ap = mActivity.getResources() - .getString(R.string.rlz_access_point); - mRlzUri = Uri.withAppendedPath(RLZ_PROVIDER_URI, ap); - } - return mRlzUri; - } - - // Determine if this URI appears to be for a Google search - // and does not have an RLZ parameter. - // Taken largely from Chrome source, src/chrome/browser/google_url_tracker.cc - private static boolean needsRlzString(Uri uri) { - String scheme = uri.getScheme(); - if (("http".equals(scheme) || "https".equals(scheme)) && - (uri.getQueryParameter("q") != null) && - (uri.getQueryParameter("rlz") == null)) { - String host = uri.getHost(); - if (host == null) { - return false; - } - String[] hostComponents = host.split("\\."); - - if (hostComponents.length < 2) { - return false; - } - int googleComponent = hostComponents.length - 2; - String component = hostComponents[googleComponent]; - if (!"google".equals(component)) { - if (hostComponents.length < 3 || - (!"co".equals(component) && !"com".equals(component))) { - return false; - } - googleComponent = hostComponents.length - 3; - if (!"google".equals(hostComponents[googleComponent])) { - return false; - } - } - - // Google corp network handling. - if (googleComponent > 0 && "corp".equals( - hostComponents[googleComponent - 1])) { - return false; - } - - return true; - } - return false; - } - } diff --git a/src/com/android/swe/browser/UrlInputView.java b/src/com/android/swe/browser/UrlInputView.java index 02bba3cb..e8b45128 100644 --- a/src/com/android/swe/browser/UrlInputView.java +++ b/src/com/android/swe/browser/UrlInputView.java @@ -14,11 +14,10 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.content.Context; import android.content.res.Configuration; -import android.content.res.TypedArray; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.text.Editable; @@ -36,14 +35,13 @@ import android.widget.AutoCompleteTextView; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; -import com.android.browser.SuggestionsAdapter.CompletionListener; -import com.android.browser.SuggestionsAdapter.SuggestItem; -import com.android.browser.search.SearchEngine; -import com.android.browser.search.SearchEngineInfo; -import com.android.browser.search.SearchEngines; -import com.android.internal.R; +import com.android.swe.browser.SuggestionsAdapter.CompletionListener; +import com.android.swe.browser.SuggestionsAdapter.SuggestItem; +import com.android.swe.browser.reflect.ReflectHelper; +import com.android.swe.browser.search.SearchEngine; +import com.android.swe.browser.search.SearchEngineInfo; +import com.android.swe.browser.search.SearchEngines; -import java.util.List; /** * url/search input view @@ -80,19 +78,24 @@ public class UrlInputView extends AutoCompleteTextView public UrlInputView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + // SWE_TODO : HARDCODED a random background - clean up + /* TypedArray a = context.obtainStyledAttributes( - attrs, com.android.internal.R.styleable.PopupWindow, + attrs, R.styleable.PopupWindow, R.attr.autoCompleteTextViewStyle, 0); Drawable popupbg = a.getDrawable(R.styleable.PopupWindow_popupBackground); - a.recycle(); + a.recycle(); */ + Drawable popupbg = context.getResources().getDrawable(android.R.drawable.editbox_background); mPopupPadding = new Rect(); popupbg.getPadding(mPopupPadding); init(context); } public UrlInputView(Context context, AttributeSet attrs) { - this(context, attrs, R.attr.autoCompleteTextViewStyle); + // SWE_TODO : Needs Fix + //this(context, attrs, R.attr.autoCompleteTextViewStyle); + this(context, attrs, 0); } public UrlInputView(Context context) { @@ -246,7 +249,10 @@ public class UrlInputView extends AutoCompleteTextView } void showIME() { - mInputManager.focusIn(this); + //mInputManager.focusIn(this); + Object[] params = {this}; + Class[] type = new Class[] {View.class}; + ReflectHelper.invokeMethod(mInputManager, "focusIn", type, params); mInputManager.showSoftInput(this, 0); } @@ -264,7 +270,7 @@ public class UrlInputView extends AutoCompleteTextView .getSearchEngine(); if (searchEngine == null) return; SearchEngineInfo engineInfo = SearchEngines - .getSearchEngineInfo(mContext, searchEngine.getName()); + .getSearchEngineInfo(getContext(), searchEngine.getName()); if (engineInfo == null) return; url = engineInfo.getSearchUriForQuery(url); // mLister.onAction can take it from here without logging diff --git a/src/com/android/swe/browser/UrlSelectionActionMode.java b/src/com/android/swe/browser/UrlSelectionActionMode.java index 56363884..646ad511 100644 --- a/src/com/android/swe/browser/UrlSelectionActionMode.java +++ b/src/com/android/swe/browser/UrlSelectionActionMode.java @@ -14,7 +14,9 @@ * the License. */ -package com.android.browser; +package com.android.swe.browser; + +import com.android.swe.browser.R; import android.view.ActionMode; import android.view.Menu; diff --git a/src/com/android/swe/browser/UrlUtils.java b/src/com/android/swe/browser/UrlUtils.java index ff786474..ee5cef0f 100755 --- a/src/com/android/swe/browser/UrlUtils.java +++ b/src/com/android/swe/browser/UrlUtils.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.net.Uri; import android.util.Patterns; diff --git a/src/com/android/swe/browser/WallpaperHandler.java b/src/com/android/swe/browser/WallpaperHandler.java index 0c60664e..94564abc 100644 --- a/src/com/android/swe/browser/WallpaperHandler.java +++ b/src/com/android/swe/browser/WallpaperHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.ProgressDialog; import android.app.WallpaperManager; @@ -34,6 +34,8 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import com.android.swe.browser.R; + /** * Handle setWallpaper requests * diff --git a/src/com/android/swe/browser/WebStorageSizeManager.java b/src/com/android/swe/browser/WebStorageSizeManager.java index 73a3bfbe..4cc71b5b 100644 --- a/src/com/android/swe/browser/WebStorageSizeManager.java +++ b/src/com/android/swe/browser/WebStorageSizeManager.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; -import com.android.browser.preferences.WebsiteSettingsFragment; +import com.android.swe.browser.R; +import com.android.swe.browser.preferences.WebsiteSettingsFragment; import android.app.Notification; import android.app.NotificationManager; @@ -86,8 +87,8 @@ import java.io.File; */ public class WebStorageSizeManager { // Logging flags. - private final static boolean LOGV_ENABLED = com.android.browser.Browser.LOGV_ENABLED; - private final static boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED; + private final static boolean LOGV_ENABLED = com.android.swe.browser.Browser.LOGV_ENABLED; + private final static boolean LOGD_ENABLED = com.android.swe.browser.Browser.LOGD_ENABLED; private final static String LOGTAG = "browser"; // The default quota value for an origin. public final static long ORIGIN_DEFAULT_QUOTA = 3 * 1024 * 1024; // 3MB diff --git a/src/com/android/swe/browser/WebViewController.java b/src/com/android/swe/browser/WebViewController.java index e814ff9e..1c9e537f 100644 --- a/src/com/android/swe/browser/WebViewController.java +++ b/src/com/android/swe/browser/WebViewController.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.Context; @@ -24,11 +24,12 @@ import android.net.http.SslError; import android.os.Message; import android.view.KeyEvent; import android.view.View; -import android.webkit.HttpAuthHandler; -import android.webkit.SslErrorHandler; +import org.codeaurora.swe.HttpAuthHandler; +import org.codeaurora.swe.SslErrorHandler; import android.webkit.ValueCallback; -import android.webkit.WebChromeClient; -import android.webkit.WebView; +import android.webkit.WebChromeClient.CustomViewCallback; +import org.codeaurora.swe.WebChromeClient; +import org.codeaurora.swe.WebView; import java.util.List; @@ -76,7 +77,7 @@ public interface WebViewController { String mimeType, String referer, long contentLength); void showCustomView(Tab tab, View view, int requestedOrientation, - WebChromeClient.CustomViewCallback callback); + CustomViewCallback callback); void hideCustomView(); diff --git a/src/com/android/swe/browser/WebViewFactory.java b/src/com/android/swe/browser/WebViewFactory.java index 1186e65b..a835b108 100644 --- a/src/com/android/swe/browser/WebViewFactory.java +++ b/src/com/android/swe/browser/WebViewFactory.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; /** * Factory for WebViews diff --git a/src/com/android/swe/browser/WebViewProperties.java b/src/com/android/swe/browser/WebViewProperties.java index c6629579..b7d4b03b 100644 --- a/src/com/android/swe/browser/WebViewProperties.java +++ b/src/com/android/swe/browser/WebViewProperties.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; public interface WebViewProperties { static final String gfxInvertedScreen = "inverted"; diff --git a/src/com/android/swe/browser/WebViewTimersControl.java b/src/com/android/swe/browser/WebViewTimersControl.java index d6d17263..8e16ff2a 100644 --- a/src/com/android/swe/browser/WebViewTimersControl.java +++ b/src/com/android/swe/browser/WebViewTimersControl.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.os.Looper; import android.util.Log; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; /** * Centralised point for controlling WebView timers pausing and resuming. @@ -26,7 +26,7 @@ import android.webkit.WebView; */ public class WebViewTimersControl { - private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED; + private static final boolean LOGD_ENABLED = com.android.swe.browser.Browser.LOGD_ENABLED; private static final String LOGTAG = "WebViewTimersControl"; private static WebViewTimersControl sInstance; diff --git a/src/com/android/swe/browser/XLargeUi.java b/src/com/android/swe/browser/XLargeUi.java index df7a586e..9a5d3166 100644 --- a/src/com/android/swe/browser/XLargeUi.java +++ b/src/com/android/swe/browser/XLargeUi.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.ActionBar; import android.app.Activity; @@ -31,8 +31,9 @@ import android.view.ActionMode; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; -import android.webkit.WebView; -import android.webkit.WebViewClassic; +import org.codeaurora.swe.WebView; + +import com.android.swe.browser.R; import java.util.List; @@ -117,8 +118,8 @@ public class XLargeUi extends BaseUi { void stopWebViewScrolling() { BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView(); - if (web != null && BrowserWebView.isClassic()) { - WebViewClassic.fromWebView(web).stopScroll(); + if (web != null) { + web.stopScroll(); } } diff --git a/src/com/android/swe/browser/addbookmark/FolderSpinner.java b/src/com/android/swe/browser/addbookmark/FolderSpinner.java index dd85cda3..4dfaea36 100644 --- a/src/com/android/swe/browser/addbookmark/FolderSpinner.java +++ b/src/com/android/swe/browser/addbookmark/FolderSpinner.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser.addbookmark; +package com.android.swe.browser.addbookmark; import android.content.Context; import android.view.View; diff --git a/src/com/android/swe/browser/addbookmark/FolderSpinnerAdapter.java b/src/com/android/swe/browser/addbookmark/FolderSpinnerAdapter.java index f86c9c6e..82dc5978 100644 --- a/src/com/android/swe/browser/addbookmark/FolderSpinnerAdapter.java +++ b/src/com/android/swe/browser/addbookmark/FolderSpinnerAdapter.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.android.browser.addbookmark; +package com.android.swe.browser.addbookmark; -import com.android.browser.R; +import com.android.swe.browser.R; import android.content.Context; import android.graphics.drawable.Drawable; diff --git a/src/com/android/swe/browser/homepages/HomeProvider.java b/src/com/android/swe/browser/homepages/HomeProvider.java index 6ccc94a2..a710a6fa 100644 --- a/src/com/android/swe/browser/homepages/HomeProvider.java +++ b/src/com/android/swe/browser/homepages/HomeProvider.java @@ -1,124 +1,124 @@ - -/* - * Copyright (C) 2011 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. - */ -package com.android.browser.homepages; - -import android.content.ContentProvider; -import android.content.ContentValues; -import android.content.Context; -import android.content.res.AssetFileDescriptor; -import android.database.Cursor; -import android.net.Uri; -import android.os.ParcelFileDescriptor; -import android.util.Log; -import android.webkit.WebResourceResponse; - -import com.android.browser.BrowserSettings; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; - -public class HomeProvider extends ContentProvider { - - private static final String TAG = "HomeProvider"; - public static final String AUTHORITY = "com.android.browser.home"; - public static final String MOST_VISITED = "content://" + AUTHORITY + "/index"; - - @Override - public int delete(Uri uri, String selection, String[] selectionArgs) { - return 0; - } - - @Override - public String getType(Uri uri) { - return null; - } - - @Override - public Uri insert(Uri uri, ContentValues values) { - return null; - } - - @Override - public boolean onCreate() { - return false; - } - - @Override - public Cursor query(Uri uri, String[] projection, String selection, - String[] selectionArgs, String sortOrder) { - return null; - } - - @Override - public int update(Uri uri, ContentValues values, String selection, - String[] selectionArgs) { - return 0; - } - - @Override - public ParcelFileDescriptor openFile(Uri uri, String mode) { - try { - ParcelFileDescriptor[] pipes = ParcelFileDescriptor.createPipe(); - final ParcelFileDescriptor write = pipes[1]; - AssetFileDescriptor afd = new AssetFileDescriptor(write, 0, -1); - new RequestHandler(getContext(), uri, afd.createOutputStream()).start(); - return pipes[0]; - } catch (IOException e) { - Log.e(TAG, "Failed to handle request: " + uri, e); - return null; - } - } - - public static WebResourceResponse shouldInterceptRequest(Context context, - String url) { - try { - boolean useMostVisited = BrowserSettings.getInstance().useMostVisitedHomepage(); - if (useMostVisited && url.startsWith("content://")) { - Uri uri = Uri.parse(url); - if (AUTHORITY.equals(uri.getAuthority())) { - InputStream ins = context.getContentResolver() - .openInputStream(uri); - return new WebResourceResponse("text/html", "utf-8", ins); - } - } - boolean listFiles = BrowserSettings.getInstance().isDebugEnabled(); - if (listFiles && interceptFile(url)) { - PipedInputStream ins = new PipedInputStream(); - PipedOutputStream outs = new PipedOutputStream(ins); - new RequestHandler(context, Uri.parse(url), outs).start(); - return new WebResourceResponse("text/html", "utf-8", ins); - } - } catch (Exception e) {} - return null; - } - - private static boolean interceptFile(String url) { - if (!url.startsWith("file:///")) { - return false; - } - String fpath = url.substring(7); - File f = new File(fpath); - if (!f.isDirectory()) { - return false; - } - return true; - } - -} + +/* + * Copyright (C) 2011 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. + */ +package com.android.swe.browser.homepages; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.database.Cursor; +import android.net.Uri; +import android.os.ParcelFileDescriptor; +import android.util.Log; +import android.webkit.WebResourceResponse; + +import com.android.swe.browser.BrowserSettings; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; + +public class HomeProvider extends ContentProvider { + + private static final String TAG = "HomeProvider"; + public static final String AUTHORITY = "com.android.swe.browser.home"; + public static final String MOST_VISITED = "content://" + AUTHORITY + "/index"; + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + return 0; + } + + @Override + public String getType(Uri uri) { + return null; + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + return null; + } + + @Override + public boolean onCreate() { + return false; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, + String[] selectionArgs, String sortOrder) { + return null; + } + + @Override + public int update(Uri uri, ContentValues values, String selection, + String[] selectionArgs) { + return 0; + } + + @Override + public ParcelFileDescriptor openFile(Uri uri, String mode) { + try { + ParcelFileDescriptor[] pipes = ParcelFileDescriptor.createPipe(); + final ParcelFileDescriptor write = pipes[1]; + AssetFileDescriptor afd = new AssetFileDescriptor(write, 0, -1); + new RequestHandler(getContext(), uri, afd.createOutputStream()).start(); + return pipes[0]; + } catch (IOException e) { + Log.e(TAG, "Failed to handle request: " + uri, e); + return null; + } + } + + public static WebResourceResponse shouldInterceptRequest(Context context, + String url) { + try { + boolean useMostVisited = BrowserSettings.getInstance().useMostVisitedHomepage(); + if (useMostVisited && url.startsWith("content://")) { + Uri uri = Uri.parse(url); + if (AUTHORITY.equals(uri.getAuthority())) { + InputStream ins = context.getContentResolver() + .openInputStream(uri); + return new WebResourceResponse("text/html", "utf-8", ins); + } + } + boolean listFiles = BrowserSettings.getInstance().isDebugEnabled(); + if (listFiles && interceptFile(url)) { + PipedInputStream ins = new PipedInputStream(); + PipedOutputStream outs = new PipedOutputStream(ins); + new RequestHandler(context, Uri.parse(url), outs).start(); + return new WebResourceResponse("text/html", "utf-8", ins); + } + } catch (Exception e) {} + return null; + } + + private static boolean interceptFile(String url) { + if (!url.startsWith("file:///")) { + return false; + } + String fpath = url.substring(7); + File f = new File(fpath); + if (!f.isDirectory()) { + return false; + } + return true; + } + +} \ No newline at end of file diff --git a/src/com/android/swe/browser/homepages/RequestHandler.java b/src/com/android/swe/browser/homepages/RequestHandler.java index c75ffcba..c01db4e8 100644 --- a/src/com/android/swe/browser/homepages/RequestHandler.java +++ b/src/com/android/swe/browser/homepages/RequestHandler.java @@ -1,264 +1,264 @@ - -/* - * Copyright (C) 2011 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. - */ -package com.android.browser.homepages; - -import android.content.Context; -import android.content.UriMatcher; -import android.content.res.Resources; -import android.database.Cursor; -import android.database.MergeCursor; -import android.net.Uri; -import android.provider.BrowserContract.Bookmarks; -import android.provider.BrowserContract.History; -import android.text.TextUtils; -import android.util.Base64; -import android.util.Log; - -import com.android.browser.R; -import com.android.browser.homepages.Template.ListEntityIterator; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.DateFormat; -import java.text.DecimalFormat; -import java.util.Arrays; -import java.util.Comparator; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class RequestHandler extends Thread { - - private static final String TAG = "RequestHandler"; - private static final int INDEX = 1; - private static final int RESOURCE = 2; - private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); - - Uri mUri; - Context mContext; - OutputStream mOutput; - - static { - sUriMatcher.addURI(HomeProvider.AUTHORITY, "index", INDEX); - sUriMatcher.addURI(HomeProvider.AUTHORITY, "res/*/*", RESOURCE); - } - - public RequestHandler(Context context, Uri uri, OutputStream out) { - mUri = uri; - mContext = context.getApplicationContext(); - mOutput = out; - } - - @Override - public void run() { - super.run(); - try { - doHandleRequest(); - } catch (Exception e) { - Log.e(TAG, "Failed to handle request: " + mUri, e); - } finally { - cleanup(); - } - } - - void doHandleRequest() throws IOException { - if ("file".equals(mUri.getScheme())) { - writeFolderIndex(); - return; - } - int match = sUriMatcher.match(mUri); - switch (match) { - case INDEX: - writeTemplatedIndex(); - break; - case RESOURCE: - writeResource(getUriResourcePath()); - break; - } - } - - byte[] htmlEncode(String s) { - return TextUtils.htmlEncode(s).getBytes(); - } - - // We can reuse this for both History and Bookmarks queries because the - // columns defined actually belong to the CommonColumn and ImageColumn - // interfaces that both History and Bookmarks implement - private static final String[] PROJECTION = new String[] { - History.URL, - History.TITLE, - History.THUMBNAIL - }; - private static final String SELECTION = History.URL - + " NOT LIKE 'content:%' AND " + History.THUMBNAIL + " IS NOT NULL"; - void writeTemplatedIndex() throws IOException { - Template t = Template.getCachedTemplate(mContext, R.raw.most_visited); - Cursor historyResults = mContext.getContentResolver().query( - History.CONTENT_URI, PROJECTION, SELECTION, - null, History.VISITS + " DESC LIMIT 12"); - Cursor cursor = historyResults; - try { - if (cursor.getCount() < 12) { - Cursor bookmarkResults = mContext.getContentResolver().query( - Bookmarks.CONTENT_URI, PROJECTION, SELECTION, - null, Bookmarks.DATE_CREATED + " DESC LIMIT 12"); - cursor = new MergeCursor(new Cursor[] { historyResults, bookmarkResults }) { - @Override - public int getCount() { - return Math.min(12, super.getCount()); - } - }; - } - t.assignLoop("most_visited", new Template.CursorListEntityWrapper(cursor) { - @Override - public void writeValue(OutputStream stream, String key) throws IOException { - Cursor cursor = getCursor(); - if (key.equals("url")) { - stream.write(htmlEncode(cursor.getString(0))); - } else if (key.equals("title")) { - stream.write(htmlEncode(cursor.getString(1))); - } else if (key.equals("thumbnail")) { - stream.write("data:image/png;base64,".getBytes()); - byte[] thumb = cursor.getBlob(2); - stream.write(Base64.encode(thumb, Base64.DEFAULT)); - } - } - }); - t.write(mOutput); - } finally { - cursor.close(); - } - } - - private static final Comparator sFileComparator = new Comparator() { - @Override - public int compare(File lhs, File rhs) { - if (lhs.isDirectory() != rhs.isDirectory()) { - return lhs.isDirectory() ? -1 : 1; - } - return lhs.getName().compareTo(rhs.getName()); - } - }; - - void writeFolderIndex() throws IOException { - File f = new File(mUri.getPath()); - final File[] files = f.listFiles(); - Arrays.sort(files, sFileComparator); - Template t = Template.getCachedTemplate(mContext, R.raw.folder_view); - t.assign("path", mUri.getPath()); - t.assign("parent_url", f.getParent() != null ? f.getParent() : f.getPath()); - t.assignLoop("files", new ListEntityIterator() { - int index = -1; - - @Override - public void writeValue(OutputStream stream, String key) throws IOException { - File f = files[index]; - if ("name".equals(key)) { - stream.write(f.getName().getBytes()); - } - if ("url".equals(key)) { - stream.write(("file://" + f.getAbsolutePath()).getBytes()); - } - if ("type".equals(key)) { - stream.write((f.isDirectory() ? "dir" : "file").getBytes()); - } - if ("size".equals(key)) { - if (f.isFile()) { - stream.write(readableFileSize(f.length()).getBytes()); - } - } - if ("last_modified".equals(key)) { - String date = DateFormat.getDateTimeInstance( - DateFormat.SHORT, DateFormat.SHORT) - .format(f.lastModified()); - stream.write(date.getBytes()); - } - if ("alt".equals(key)) { - if (index % 2 == 0) { - stream.write("alt".getBytes()); - } - } - } - - @Override - public ListEntityIterator getListIterator(String key) { - return null; - } - - @Override - public void reset() { - index = -1; - } - - @Override - public boolean moveToNext() { - return (++index) < files.length; - } - }); - t.write(mOutput); - } - - static String readableFileSize(long size) { - if(size <= 0) return "0"; - final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; - int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); - return new DecimalFormat("#,##0.#").format( - size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; - } - - String getUriResourcePath() { - final Pattern pattern = Pattern.compile("/?res/([\\w/]+)"); - Matcher m = pattern.matcher(mUri.getPath()); - if (m.matches()) { - return m.group(1); - } else { - return mUri.getPath(); - } - } - - void writeResource(String fileName) throws IOException { - Resources res = mContext.getResources(); - String packageName = R.class.getPackage().getName(); - int id = res.getIdentifier(fileName, null, packageName); - if (id != 0) { - InputStream in = res.openRawResource(id); - byte[] buf = new byte[4096]; - int read; - while ((read = in.read(buf)) > 0) { - mOutput.write(buf, 0, read); - } - } - } - - void writeString(String str) throws IOException { - mOutput.write(str.getBytes()); - } - - void writeString(String str, int offset, int count) throws IOException { - mOutput.write(str.getBytes(), offset, count); - } - - void cleanup() { - try { - mOutput.close(); - } catch (Exception e) { - Log.e(TAG, "Failed to close pipe!", e); - } - } - -} + +/* + * Copyright (C) 2011 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. + */ +package com.android.swe.browser.homepages; + +import android.content.Context; +import android.content.UriMatcher; +import android.content.res.Resources; +import android.database.Cursor; +import android.database.MergeCursor; +import android.net.Uri; +import android.text.TextUtils; +import android.util.Base64; +import android.util.Log; + +import com.android.swe.browser.R; +import com.android.swe.browser.homepages.Template.ListEntityIterator; +import com.android.swe.browser.platformsupport.BrowserContract.Bookmarks; +import com.android.swe.browser.platformsupport.BrowserContract.History; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.text.DateFormat; +import java.text.DecimalFormat; +import java.util.Arrays; +import java.util.Comparator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class RequestHandler extends Thread { + + private static final String TAG = "RequestHandler"; + private static final int INDEX = 1; + private static final int RESOURCE = 2; + private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + + Uri mUri; + Context mContext; + OutputStream mOutput; + + static { + sUriMatcher.addURI(HomeProvider.AUTHORITY, "index", INDEX); + sUriMatcher.addURI(HomeProvider.AUTHORITY, "res/*/*", RESOURCE); + } + + public RequestHandler(Context context, Uri uri, OutputStream out) { + mUri = uri; + mContext = context.getApplicationContext(); + mOutput = out; + } + + @Override + public void run() { + super.run(); + try { + doHandleRequest(); + } catch (Exception e) { + Log.e(TAG, "Failed to handle request: " + mUri, e); + } finally { + cleanup(); + } + } + + void doHandleRequest() throws IOException { + if ("file".equals(mUri.getScheme())) { + writeFolderIndex(); + return; + } + int match = sUriMatcher.match(mUri); + switch (match) { + case INDEX: + writeTemplatedIndex(); + break; + case RESOURCE: + writeResource(getUriResourcePath()); + break; + } + } + + byte[] htmlEncode(String s) { + return TextUtils.htmlEncode(s).getBytes(); + } + + // We can reuse this for both History and Bookmarks queries because the + // columns defined actually belong to the CommonColumn and ImageColumn + // interfaces that both History and Bookmarks implement + private static final String[] PROJECTION = new String[] { + History.URL, + History.TITLE, + History.THUMBNAIL + }; + private static final String SELECTION = History.URL + + " NOT LIKE 'content:%' AND " + History.THUMBNAIL + " IS NOT NULL"; + void writeTemplatedIndex() throws IOException { + Template t = Template.getCachedTemplate(mContext, R.raw.most_visited); + Cursor historyResults = mContext.getContentResolver().query( + History.CONTENT_URI, PROJECTION, SELECTION, + null, History.VISITS + " DESC LIMIT 12"); + Cursor cursor = historyResults; + try { + if (cursor.getCount() < 12) { + Cursor bookmarkResults = mContext.getContentResolver().query( + Bookmarks.CONTENT_URI, PROJECTION, SELECTION, + null, Bookmarks.DATE_CREATED + " DESC LIMIT 12"); + cursor = new MergeCursor(new Cursor[] { historyResults, bookmarkResults }) { + @Override + public int getCount() { + return Math.min(12, super.getCount()); + } + }; + } + t.assignLoop("most_visited", new Template.CursorListEntityWrapper(cursor) { + @Override + public void writeValue(OutputStream stream, String key) throws IOException { + Cursor cursor = getCursor(); + if (key.equals("url")) { + stream.write(htmlEncode(cursor.getString(0))); + } else if (key.equals("title")) { + stream.write(htmlEncode(cursor.getString(1))); + } else if (key.equals("thumbnail")) { + stream.write("data:image/png;base64,".getBytes()); + byte[] thumb = cursor.getBlob(2); + stream.write(Base64.encode(thumb, Base64.DEFAULT)); + } + } + }); + t.write(mOutput); + } finally { + cursor.close(); + } + } + + private static final Comparator sFileComparator = new Comparator() { + @Override + public int compare(File lhs, File rhs) { + if (lhs.isDirectory() != rhs.isDirectory()) { + return lhs.isDirectory() ? -1 : 1; + } + return lhs.getName().compareTo(rhs.getName()); + } + }; + + void writeFolderIndex() throws IOException { + File f = new File(mUri.getPath()); + final File[] files = f.listFiles(); + Arrays.sort(files, sFileComparator); + Template t = Template.getCachedTemplate(mContext, R.raw.folder_view); + t.assign("path", mUri.getPath()); + t.assign("parent_url", f.getParent() != null ? f.getParent() : f.getPath()); + t.assignLoop("files", new ListEntityIterator() { + int index = -1; + + @Override + public void writeValue(OutputStream stream, String key) throws IOException { + File f = files[index]; + if ("name".equals(key)) { + stream.write(f.getName().getBytes()); + } + if ("url".equals(key)) { + stream.write(("file://" + f.getAbsolutePath()).getBytes()); + } + if ("type".equals(key)) { + stream.write((f.isDirectory() ? "dir" : "file").getBytes()); + } + if ("size".equals(key)) { + if (f.isFile()) { + stream.write(readableFileSize(f.length()).getBytes()); + } + } + if ("last_modified".equals(key)) { + String date = DateFormat.getDateTimeInstance( + DateFormat.SHORT, DateFormat.SHORT) + .format(f.lastModified()); + stream.write(date.getBytes()); + } + if ("alt".equals(key)) { + if (index % 2 == 0) { + stream.write("alt".getBytes()); + } + } + } + + @Override + public ListEntityIterator getListIterator(String key) { + return null; + } + + @Override + public void reset() { + index = -1; + } + + @Override + public boolean moveToNext() { + return (++index) < files.length; + } + }); + t.write(mOutput); + } + + static String readableFileSize(long size) { + if(size <= 0) return "0"; + final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; + int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); + return new DecimalFormat("#,##0.#").format( + size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; + } + + String getUriResourcePath() { + final Pattern pattern = Pattern.compile("/?res/([\\w/]+)"); + Matcher m = pattern.matcher(mUri.getPath()); + if (m.matches()) { + return m.group(1); + } else { + return mUri.getPath(); + } + } + + void writeResource(String fileName) throws IOException { + Resources res = mContext.getResources(); + String packageName = R.class.getPackage().getName(); + int id = res.getIdentifier(fileName, null, packageName); + if (id != 0) { + InputStream in = res.openRawResource(id); + byte[] buf = new byte[4096]; + int read; + while ((read = in.read(buf)) > 0) { + mOutput.write(buf, 0, read); + } + } + } + + void writeString(String str) throws IOException { + mOutput.write(str.getBytes()); + } + + void writeString(String str, int offset, int count) throws IOException { + mOutput.write(str.getBytes(), offset, count); + } + + void cleanup() { + try { + mOutput.close(); + } catch (Exception e) { + Log.e(TAG, "Failed to close pipe!", e); + } + } + +} \ No newline at end of file diff --git a/src/com/android/swe/browser/homepages/Template.java b/src/com/android/swe/browser/homepages/Template.java index e918b07d..847cfcb0 100644 --- a/src/com/android/swe/browser/homepages/Template.java +++ b/src/com/android/swe/browser/homepages/Template.java @@ -1,281 +1,281 @@ - -/* - * Copyright (C) 2011 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. - */ -package com.android.browser.homepages; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import android.content.Context; -import android.content.res.Resources; -import android.database.Cursor; -import android.util.TypedValue; - -import com.android.browser.R; - -public class Template { - - private static HashMap sCachedTemplates = new HashMap(); - - public static Template getCachedTemplate(Context context, int id) { - synchronized (sCachedTemplates) { - Template template = sCachedTemplates.get(id); - if (template == null) { - template = new Template(context, id); - sCachedTemplates.put(id, template); - } - // Return a copy so that we don't share data - return template.copy(); - } - } - - interface Entity { - void write(OutputStream stream, EntityData params) throws IOException; - } - - interface EntityData { - void writeValue(OutputStream stream, String key) throws IOException; - ListEntityIterator getListIterator(String key); - } - - interface ListEntityIterator extends EntityData { - void reset(); - boolean moveToNext(); - } - - static class StringEntity implements Entity { - - byte[] mValue; - - public StringEntity(String value) { - mValue = value.getBytes(); - } - - @Override - public void write(OutputStream stream, EntityData params) throws IOException { - stream.write(mValue); - } - - } - - static class SimpleEntity implements Entity { - - String mKey; - - public SimpleEntity(String key) { - mKey = key; - } - - @Override - public void write(OutputStream stream, EntityData params) throws IOException { - params.writeValue(stream, mKey); - } - - } - - static class ListEntity implements Entity { - - String mKey; - Template mSubTemplate; - - public ListEntity(Context context, String key, String subTemplate) { - mKey = key; - mSubTemplate = new Template(context, subTemplate); - } - - @Override - public void write(OutputStream stream, EntityData params) throws IOException { - ListEntityIterator iter = params.getListIterator(mKey); - iter.reset(); - while (iter.moveToNext()) { - mSubTemplate.write(stream, iter); - } - } - - } - - public abstract static class CursorListEntityWrapper implements ListEntityIterator { - - private Cursor mCursor; - - public CursorListEntityWrapper(Cursor cursor) { - mCursor = cursor; - } - - @Override - public boolean moveToNext() { - return mCursor.moveToNext(); - } - - @Override - public void reset() { - mCursor.moveToPosition(-1); - } - - @Override - public ListEntityIterator getListIterator(String key) { - return null; - } - - public Cursor getCursor() { - return mCursor; - } - - } - - static class HashMapEntityData implements EntityData { - - HashMap mData; - - public HashMapEntityData(HashMap map) { - mData = map; - } - - @Override - public ListEntityIterator getListIterator(String key) { - return (ListEntityIterator) mData.get(key); - } - - @Override - public void writeValue(OutputStream stream, String key) throws IOException { - stream.write((byte[]) mData.get(key)); - } - - } - - private List mTemplate; - private HashMap mData = new HashMap(); - private Template(Context context, int tid) { - this(context, readRaw(context, tid)); - } - - private Template(Context context, String template) { - mTemplate = new ArrayList(); - template = replaceConsts(context, template); - parseTemplate(context, template); - } - - private Template(Template copy) { - mTemplate = copy.mTemplate; - } - - Template copy() { - return new Template(this); - } - - void parseTemplate(Context context, String template) { - final Pattern pattern = Pattern.compile("<%([=\\{])\\s*(\\w+)\\s*%>"); - Matcher m = pattern.matcher(template); - int start = 0; - while (m.find()) { - String static_part = template.substring(start, m.start()); - if (static_part.length() > 0) { - mTemplate.add(new StringEntity(static_part)); - } - String type = m.group(1); - String name = m.group(2); - if (type.equals("=")) { - mTemplate.add(new SimpleEntity(name)); - } else if (type.equals("{")) { - Pattern p = Pattern.compile("<%\\}\\s*" + Pattern.quote(name) + "\\s*%>"); - Matcher end_m = p.matcher(template); - if (end_m.find(m.end())) { - start = m.end(); - m.region(end_m.end(), template.length()); - String subTemplate = template.substring(start, end_m.start()); - mTemplate.add(new ListEntity(context, name, subTemplate)); - start = end_m.end(); - continue; - } - } - start = m.end(); - } - String static_part = template.substring(start, template.length()); - if (static_part.length() > 0) { - mTemplate.add(new StringEntity(static_part)); - } - } - - public void assign(String name, String value) { - mData.put(name, value.getBytes()); - } - - public void assignLoop(String name, ListEntityIterator iter) { - mData.put(name, iter); - } - - public void write(OutputStream stream) throws IOException { - write(stream, new HashMapEntityData(mData)); - } - - public void write(OutputStream stream, EntityData data) throws IOException { - for (Entity ent : mTemplate) { - ent.write(stream, data); - } - } - - private static String replaceConsts(Context context, String template) { - final Pattern pattern = Pattern.compile("<%@\\s*(\\w+/\\w+)\\s*%>"); - final Resources res = context.getResources(); - final String packageName = R.class.getPackage().getName(); - Matcher m = pattern.matcher(template); - StringBuffer sb = new StringBuffer(); - while (m.find()) { - String name = m.group(1); - if (name.startsWith("drawable/")) { - m.appendReplacement(sb, "res/" + name); - } else { - int id = res.getIdentifier(name, null, packageName); - if (id != 0) { - TypedValue value = new TypedValue(); - res.getValue(id, value, true); - String replacement; - if (value.type == TypedValue.TYPE_DIMENSION) { - float dimen = res.getDimension(id); - int dimeni = (int) dimen; - if (dimeni == dimen) - replacement = Integer.toString(dimeni); - else - replacement = Float.toString(dimen); - } else { - replacement = value.coerceToString().toString(); - } - m.appendReplacement(sb, replacement); - } - } - } - m.appendTail(sb); - return sb.toString(); - } - - private static String readRaw(Context context, int id) { - InputStream ins = context.getResources().openRawResource(id); - try { - byte[] buf = new byte[ins.available()]; - ins.read(buf); - return new String(buf, "utf-8"); - } catch (IOException ex) { - return "Error"; - } - } - -} + +/* + * Copyright (C) 2011 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. + */ +package com.android.swe.browser.homepages; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import android.content.Context; +import android.content.res.Resources; +import android.database.Cursor; +import android.util.TypedValue; + +import com.android.swe.browser.R; + +public class Template { + + private static HashMap sCachedTemplates = new HashMap(); + + public static Template getCachedTemplate(Context context, int id) { + synchronized (sCachedTemplates) { + Template template = sCachedTemplates.get(id); + if (template == null) { + template = new Template(context, id); + sCachedTemplates.put(id, template); + } + // Return a copy so that we don't share data + return template.copy(); + } + } + + interface Entity { + void write(OutputStream stream, EntityData params) throws IOException; + } + + interface EntityData { + void writeValue(OutputStream stream, String key) throws IOException; + ListEntityIterator getListIterator(String key); + } + + interface ListEntityIterator extends EntityData { + void reset(); + boolean moveToNext(); + } + + static class StringEntity implements Entity { + + byte[] mValue; + + public StringEntity(String value) { + mValue = value.getBytes(); + } + + @Override + public void write(OutputStream stream, EntityData params) throws IOException { + stream.write(mValue); + } + + } + + static class SimpleEntity implements Entity { + + String mKey; + + public SimpleEntity(String key) { + mKey = key; + } + + @Override + public void write(OutputStream stream, EntityData params) throws IOException { + params.writeValue(stream, mKey); + } + + } + + static class ListEntity implements Entity { + + String mKey; + Template mSubTemplate; + + public ListEntity(Context context, String key, String subTemplate) { + mKey = key; + mSubTemplate = new Template(context, subTemplate); + } + + @Override + public void write(OutputStream stream, EntityData params) throws IOException { + ListEntityIterator iter = params.getListIterator(mKey); + iter.reset(); + while (iter.moveToNext()) { + mSubTemplate.write(stream, iter); + } + } + + } + + public abstract static class CursorListEntityWrapper implements ListEntityIterator { + + private Cursor mCursor; + + public CursorListEntityWrapper(Cursor cursor) { + mCursor = cursor; + } + + @Override + public boolean moveToNext() { + return mCursor.moveToNext(); + } + + @Override + public void reset() { + mCursor.moveToPosition(-1); + } + + @Override + public ListEntityIterator getListIterator(String key) { + return null; + } + + public Cursor getCursor() { + return mCursor; + } + + } + + static class HashMapEntityData implements EntityData { + + HashMap mData; + + public HashMapEntityData(HashMap map) { + mData = map; + } + + @Override + public ListEntityIterator getListIterator(String key) { + return (ListEntityIterator) mData.get(key); + } + + @Override + public void writeValue(OutputStream stream, String key) throws IOException { + stream.write((byte[]) mData.get(key)); + } + + } + + private List mTemplate; + private HashMap mData = new HashMap(); + private Template(Context context, int tid) { + this(context, readRaw(context, tid)); + } + + private Template(Context context, String template) { + mTemplate = new ArrayList(); + template = replaceConsts(context, template); + parseTemplate(context, template); + } + + private Template(Template copy) { + mTemplate = copy.mTemplate; + } + + Template copy() { + return new Template(this); + } + + void parseTemplate(Context context, String template) { + final Pattern pattern = Pattern.compile("<%([=\\{])\\s*(\\w+)\\s*%>"); + Matcher m = pattern.matcher(template); + int start = 0; + while (m.find()) { + String static_part = template.substring(start, m.start()); + if (static_part.length() > 0) { + mTemplate.add(new StringEntity(static_part)); + } + String type = m.group(1); + String name = m.group(2); + if (type.equals("=")) { + mTemplate.add(new SimpleEntity(name)); + } else if (type.equals("{")) { + Pattern p = Pattern.compile("<%\\}\\s*" + Pattern.quote(name) + "\\s*%>"); + Matcher end_m = p.matcher(template); + if (end_m.find(m.end())) { + start = m.end(); + m.region(end_m.end(), template.length()); + String subTemplate = template.substring(start, end_m.start()); + mTemplate.add(new ListEntity(context, name, subTemplate)); + start = end_m.end(); + continue; + } + } + start = m.end(); + } + String static_part = template.substring(start, template.length()); + if (static_part.length() > 0) { + mTemplate.add(new StringEntity(static_part)); + } + } + + public void assign(String name, String value) { + mData.put(name, value.getBytes()); + } + + public void assignLoop(String name, ListEntityIterator iter) { + mData.put(name, iter); + } + + public void write(OutputStream stream) throws IOException { + write(stream, new HashMapEntityData(mData)); + } + + public void write(OutputStream stream, EntityData data) throws IOException { + for (Entity ent : mTemplate) { + ent.write(stream, data); + } + } + + private static String replaceConsts(Context context, String template) { + final Pattern pattern = Pattern.compile("<%@\\s*(\\w+/\\w+)\\s*%>"); + final Resources res = context.getResources(); + final String packageName = R.class.getPackage().getName(); + Matcher m = pattern.matcher(template); + StringBuffer sb = new StringBuffer(); + while (m.find()) { + String name = m.group(1); + if (name.startsWith("drawable/")) { + m.appendReplacement(sb, "res/" + name); + } else { + int id = res.getIdentifier(name, null, packageName); + if (id != 0) { + TypedValue value = new TypedValue(); + res.getValue(id, value, true); + String replacement; + if (value.type == TypedValue.TYPE_DIMENSION) { + float dimen = res.getDimension(id); + int dimeni = (int) dimen; + if (dimeni == dimen) + replacement = Integer.toString(dimeni); + else + replacement = Float.toString(dimen); + } else { + replacement = value.coerceToString().toString(); + } + m.appendReplacement(sb, replacement); + } + } + } + m.appendTail(sb); + return sb.toString(); + } + + private static String readRaw(Context context, int id) { + InputStream ins = context.getResources().openRawResource(id); + try { + byte[] buf = new byte[ins.available()]; + ins.read(buf); + return new String(buf, "utf-8"); + } catch (IOException ex) { + return "Error"; + } + } + +} \ No newline at end of file diff --git a/src/com/android/swe/browser/mynavigation/AddMyNavigationPage.java b/src/com/android/swe/browser/mynavigation/AddMyNavigationPage.java index 1db9fa51..4eca3961 100755 --- a/src/com/android/swe/browser/mynavigation/AddMyNavigationPage.java +++ b/src/com/android/swe/browser/mynavigation/AddMyNavigationPage.java @@ -27,7 +27,7 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.android.browser.mynavigation; +package com.android.swe.browser.mynavigation; import android.app.Activity; import android.content.Context; @@ -41,7 +41,6 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.ParseException; import android.net.Uri; -import android.net.WebAddress; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -52,9 +51,10 @@ import android.widget.EditText; import android.widget.TextView; import android.util.Log; -import com.android.browser.BrowserUtils; -import com.android.browser.R; -import com.android.browser.UrlUtils; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserUtils; +import com.android.swe.browser.UrlUtils; +import com.android.swe.browser.platformsupport.WebAddress; import java.io.ByteArrayOutputStream; import java.net.URI; diff --git a/src/com/android/swe/browser/mynavigation/MyNavigationRequestHandler.java b/src/com/android/swe/browser/mynavigation/MyNavigationRequestHandler.java index e1f9ebee..1d18974d 100755 --- a/src/com/android/swe/browser/mynavigation/MyNavigationRequestHandler.java +++ b/src/com/android/swe/browser/mynavigation/MyNavigationRequestHandler.java @@ -27,7 +27,7 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.android.browser.mynavigation; +package com.android.swe.browser.mynavigation; import android.content.Context; import android.content.UriMatcher; @@ -42,7 +42,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.android.browser.R; +import com.android.swe.browser.R; public class MyNavigationRequestHandler extends Thread { @@ -96,7 +96,7 @@ public class MyNavigationRequestHandler extends Thread { MyNavigationTemplate t = MyNavigationTemplate.getCachedTemplate(mContext, R.raw.my_navigation); Cursor cursor = mContext.getContentResolver().query( - Uri.parse("content://com.android.browser.mynavigation/websites"), + Uri.parse("content://com.android.swe.browser.mynavigation/websites"), new String[] { "url", "title", "thumbnail" }, diff --git a/src/com/android/swe/browser/mynavigation/MyNavigationTemplate.java b/src/com/android/swe/browser/mynavigation/MyNavigationTemplate.java index 85d1baf5..d7d83ccd 100755 --- a/src/com/android/swe/browser/mynavigation/MyNavigationTemplate.java +++ b/src/com/android/swe/browser/mynavigation/MyNavigationTemplate.java @@ -27,7 +27,7 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.android.browser.mynavigation; +package com.android.swe.browser.mynavigation; import android.content.Context; import android.content.res.Resources; @@ -35,7 +35,7 @@ import android.database.Cursor; import android.util.TypedValue; import android.util.Log; -import com.android.browser.R; +import com.android.swe.browser.R; import java.io.InputStream; import java.io.IOException; diff --git a/src/com/android/swe/browser/mynavigation/MyNavigationUtil.java b/src/com/android/swe/browser/mynavigation/MyNavigationUtil.java index 3b1836d1..c76e350f 100755 --- a/src/com/android/swe/browser/mynavigation/MyNavigationUtil.java +++ b/src/com/android/swe/browser/mynavigation/MyNavigationUtil.java @@ -27,7 +27,7 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.android.browser.mynavigation; +package com.android.swe.browser.mynavigation; import android.content.ContentValues; import android.content.Context; @@ -48,10 +48,10 @@ public class MyNavigationUtil { public static final String THUMBNAIL = "thumbnail"; public static final int WEBSITE_NUMBER = 12; - public static final String AUTHORITY = "com.android.browser.mynavigation"; + public static final String AUTHORITY = "com.android.swe.browser.mynavigation"; public static final String MY_NAVIGATION = "content://" + AUTHORITY + "/" + "websites"; public static final Uri MY_NAVIGATION_URI = Uri - .parse("content://com.android.browser.mynavigation/websites"); + .parse("content://com.android.swe.browser.mynavigation/websites"); public static final String DEFAULT_THUMB = "default_thumb"; public static final String LOGTAG = "MyNavigationUtil"; diff --git a/src/com/android/swe/browser/platformsupport/SeekBarPreference.java b/src/com/android/swe/browser/platformsupport/SeekBarPreference.java index 9801c0a5..5af5312a 100644 --- a/src/com/android/swe/browser/platformsupport/SeekBarPreference.java +++ b/src/com/android/swe/browser/platformsupport/SeekBarPreference.java @@ -22,17 +22,19 @@ public class SeekBarPreference extends Preference Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - int[] attrs2 = new int[] { android.R.attr.indeterminateDrawable /* index 0 */}; - TypedArray a = context.obtainStyledAttributes(android.R.style.Widget_ProgressBar, attrs2); + int[] attributes = new int[] { android.R.attr.indeterminateDrawable}; + TypedArray a = context.obtainStyledAttributes( + android.R.style.Widget_ProgressBar, attributes); + //SWE_TODO: Modify setMax to attain max from XML setMax(100); a.recycle(); setLayoutResource(com.android.swe.browser.R.layout.preference_widget_seekbar); - /*SWE_TODO: Fix w Reflection + /*SWE_TODO : Refactor to use Reflection & replace corresponding above TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ProgressBar, defStyle, 0); - setMax(a.getInt(com.android.internal.R.styleable.ProgressBar_max, mMax)); - a.recycle(); - setLayoutResource(com.android.internal.R.layout.preference_widget_seekbar); + setMax(a.getInt(com.android.internal.R.styleable.ProgressBar_max, mMax)); + a.recycle(); + setLayoutResource(com.android.internal.R.layout.preference_widget_seekbar); */ } @@ -72,8 +74,7 @@ public class SeekBarPreference extends Preference } //@Override - //TODO : Verify the interface and Uncommend the override - public boolean onKey(View v, int keyCode, KeyEvent event) { + public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_UP) { if (keyCode == KeyEvent.KEYCODE_PLUS || keyCode == KeyEvent.KEYCODE_EQUALS) { @@ -236,3 +237,4 @@ public class SeekBarPreference extends Preference }; } } + diff --git a/src/com/android/swe/browser/preferences/AccessibilityPreferencesFragment.java b/src/com/android/swe/browser/preferences/AccessibilityPreferencesFragment.java index 364d3378..cd41ad06 100644 --- a/src/com/android/swe/browser/preferences/AccessibilityPreferencesFragment.java +++ b/src/com/android/swe/browser/preferences/AccessibilityPreferencesFragment.java @@ -14,18 +14,17 @@ * limitations under the License */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; import android.content.Context; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; -import android.webkit.WebView; - -import com.android.browser.BrowserSettings; -import com.android.browser.PreferenceKeys; -import com.android.browser.R; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserSettings; +import com.android.swe.browser.PreferenceKeys; +import org.codeaurora.swe.WebView; import java.text.NumberFormat; public class AccessibilityPreferencesFragment extends PreferenceFragment @@ -52,9 +51,13 @@ public class AccessibilityPreferencesFragment extends PreferenceFragment e = findPreference(PreferenceKeys.PREF_DOUBLE_TAP_ZOOM); e.setOnPreferenceChangeListener(this); updateDoubleTapZoomSummary(e, settings.getDoubleTapZoom()); + /* + * SWE_TODO: Commented out functionality for inverted rendering + * (as well as corresponding sections below) e = findPreference(PreferenceKeys.PREF_INVERTED_CONTRAST); e.setOnPreferenceChangeListener(this); updateInvertedContrastSummary(e, (int) (settings.getInvertedContrast() * 100)); + */ } @Override @@ -89,9 +92,11 @@ public class AccessibilityPreferencesFragment extends PreferenceFragment pref.setSummary(mFormat.format(doubleTapZoom / 100.0)); } + /* void updateInvertedContrastSummary(Preference pref, int contrast) { pref.setSummary(mFormat.format(contrast / 100.0)); } + */ @Override public boolean onPreferenceChange(Preference pref, Object objValue) { @@ -115,10 +120,13 @@ public class AccessibilityPreferencesFragment extends PreferenceFragment updateDoubleTapZoomSummary(pref, settings .getAdjustedDoubleTapZoom((Integer) objValue)); } + /* if (PreferenceKeys.PREF_INVERTED_CONTRAST.equals(pref.getKey())) { updateInvertedContrastSummary(pref, (int) ((10 + (Integer) objValue) * 10)); } + */ + return true; } diff --git a/src/com/android/swe/browser/preferences/AdvancedPreferencesFragment.java b/src/com/android/swe/browser/preferences/AdvancedPreferencesFragment.java index acc26ce2..be045297 100644 --- a/src/com/android/swe/browser/preferences/AdvancedPreferencesFragment.java +++ b/src/com/android/swe/browser/preferences/AdvancedPreferencesFragment.java @@ -14,13 +14,7 @@ * limitations under the License */ -package com.android.browser.preferences; - -import com.android.browser.BrowserActivity; -import com.android.browser.BrowserSettings; -import com.android.browser.DownloadHandler; -import com.android.browser.PreferenceKeys; -import com.android.browser.R; +package com.android.swe.browser.preferences; import android.app.Activity; import android.content.Intent; @@ -33,13 +27,19 @@ import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import android.util.Log; -import android.webkit.GeolocationPermissions; import android.webkit.ValueCallback; -import android.webkit.WebStorage; import android.widget.Toast; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserActivity; +import com.android.swe.browser.BrowserSettings; +import com.android.swe.browser.DownloadHandler; +import com.android.swe.browser.PreferenceKeys; + import java.util.Map; import java.util.Set; +import org.codeaurora.swe.GeolocationPermissions; +import org.codeaurora.swe.WebStorage; public class AdvancedPreferencesFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener { diff --git a/src/com/android/swe/browser/preferences/BandwidthPreferencesFragment.java b/src/com/android/swe/browser/preferences/BandwidthPreferencesFragment.java index 0cb064ab..1e9837ee 100644 --- a/src/com/android/swe/browser/preferences/BandwidthPreferencesFragment.java +++ b/src/com/android/swe/browser/preferences/BandwidthPreferencesFragment.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; import android.content.SharedPreferences; import android.os.Bundle; @@ -22,9 +22,9 @@ import android.preference.ListPreference; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; -import com.android.browser.BrowserSettings; -import com.android.browser.PreferenceKeys; -import com.android.browser.R; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserSettings; +import com.android.swe.browser.PreferenceKeys; public class BandwidthPreferencesFragment extends PreferenceFragment { diff --git a/src/com/android/swe/browser/preferences/DebugPreferencesFragment.java b/src/com/android/swe/browser/preferences/DebugPreferencesFragment.java index 24821d16..b5c469de 100644 --- a/src/com/android/swe/browser/preferences/DebugPreferencesFragment.java +++ b/src/com/android/swe/browser/preferences/DebugPreferencesFragment.java @@ -14,17 +14,17 @@ * limitations under the License */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; import android.os.Bundle; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceFragment; -import com.android.browser.BrowserSettings; -import com.android.browser.GoogleAccountLogin; -import com.android.browser.PreferenceKeys; -import com.android.browser.R; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserSettings; +import com.android.swe.browser.GoogleAccountLogin; +import com.android.swe.browser.PreferenceKeys; public class DebugPreferencesFragment extends PreferenceFragment implements OnPreferenceClickListener { diff --git a/src/com/android/swe/browser/preferences/FontSizePreview.java b/src/com/android/swe/browser/preferences/FontSizePreview.java index 8825f3d8..a1566e3e 100644 --- a/src/com/android/swe/browser/preferences/FontSizePreview.java +++ b/src/com/android/swe/browser/preferences/FontSizePreview.java @@ -14,17 +14,17 @@ * limitations under the License. */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; import android.content.Context; import android.content.res.Resources; import android.util.AttributeSet; import android.view.View; -import android.webkit.WebSettings; -import android.webkit.WebView; +import org.codeaurora.swe.WebSettings; +import org.codeaurora.swe.WebView; -import com.android.browser.BrowserSettings; -import com.android.browser.R; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserSettings; public class FontSizePreview extends WebViewPreview { diff --git a/src/com/android/swe/browser/preferences/GeneralPreferencesFragment.java b/src/com/android/swe/browser/preferences/GeneralPreferencesFragment.java index 2453f462..6cf4e97c 100644 --- a/src/com/android/swe/browser/preferences/GeneralPreferencesFragment.java +++ b/src/com/android/swe/browser/preferences/GeneralPreferencesFragment.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; import android.app.AlertDialog; import android.app.Dialog; @@ -38,12 +38,12 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; -import com.android.browser.BrowserPreferencesPage; -import com.android.browser.BrowserSettings; -import com.android.browser.PreferenceKeys; -import com.android.browser.R; -import com.android.browser.UrlUtils; -import com.android.browser.homepages.HomeProvider; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserPreferencesPage; +import com.android.swe.browser.BrowserSettings; +import com.android.swe.browser.PreferenceKeys; +import com.android.swe.browser.UrlUtils; +import com.android.swe.browser.homepages.HomeProvider; public class GeneralPreferencesFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener { diff --git a/src/com/android/swe/browser/preferences/InvertedContrastPreview.java b/src/com/android/swe/browser/preferences/InvertedContrastPreview.java index 2b8ad473..5602fc78 100644 --- a/src/com/android/swe/browser/preferences/InvertedContrastPreview.java +++ b/src/com/android/swe/browser/preferences/InvertedContrastPreview.java @@ -14,21 +14,21 @@ * limitations under the License. */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; import android.content.Context; import android.text.TextUtils; import android.util.AttributeSet; -import android.webkit.WebSettingsClassic; -import android.webkit.WebViewClassic; +import org.codeaurora.swe.WebSettings; +import org.codeaurora.swe.WebView; -import com.android.browser.BrowserSettings; -import com.android.browser.BrowserWebView; -import com.android.browser.WebViewProperties; +import com.android.swe.browser.BrowserSettings; +import com.android.swe.browser.BrowserWebView; +import com.android.swe.browser.WebViewProperties; public class InvertedContrastPreview extends WebViewPreview { - static final String IMG_ROOT = "content://com.android.browser.home/res/raw/"; + static final String IMG_ROOT = "content://com.android.swe.browser.home/res/raw/"; static final String[] THUMBS = new String[] { "thumb_google", "thumb_amazon", @@ -76,9 +76,9 @@ public class InvertedContrastPreview extends WebViewPreview { @Override protected void updatePreview(boolean forceReload) { - if (mWebView == null || !BrowserWebView.isClassic()) return; + if (mWebView == null) return; - WebSettingsClassic ws = WebViewClassic.fromWebView(mWebView).getSettings(); + WebSettings ws = mWebView.getSettings(); BrowserSettings bs = BrowserSettings.getInstance(); ws.setProperty(WebViewProperties.gfxInvertedScreen, bs.useInvertedRendering() ? "true" : "false"); diff --git a/src/com/android/swe/browser/preferences/LabPreferencesFragment.java b/src/com/android/swe/browser/preferences/LabPreferencesFragment.java index 222b5fa4..fd68fb0f 100644 --- a/src/com/android/swe/browser/preferences/LabPreferencesFragment.java +++ b/src/com/android/swe/browser/preferences/LabPreferencesFragment.java @@ -14,16 +14,16 @@ * limitations under the License */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; -import com.android.browser.BrowserSettings; -import com.android.browser.PreferenceKeys; -import com.android.browser.R; -import com.android.browser.search.SearchEngine; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserSettings; +import com.android.swe.browser.PreferenceKeys; +import com.android.swe.browser.search.SearchEngine; public class LabPreferencesFragment extends PreferenceFragment { diff --git a/src/com/android/swe/browser/preferences/NonformattingListPreference.java b/src/com/android/swe/browser/preferences/NonformattingListPreference.java index 51b3231e..85dba741 100644 --- a/src/com/android/swe/browser/preferences/NonformattingListPreference.java +++ b/src/com/android/swe/browser/preferences/NonformattingListPreference.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; import android.content.Context; import android.preference.ListPreference; diff --git a/src/com/android/swe/browser/preferences/PrivacySecurityPreferencesFragment.java b/src/com/android/swe/browser/preferences/PrivacySecurityPreferencesFragment.java index 35e6e432..9a57c1f6 100644 --- a/src/com/android/swe/browser/preferences/PrivacySecurityPreferencesFragment.java +++ b/src/com/android/swe/browser/preferences/PrivacySecurityPreferencesFragment.java @@ -14,10 +14,10 @@ * limitations under the License */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; -import com.android.browser.PreferenceKeys; -import com.android.browser.R; +import com.android.swe.browser.R; +import com.android.swe.browser.PreferenceKeys; import android.app.Activity; import android.content.Intent; diff --git a/src/com/android/swe/browser/preferences/SeekBarSummaryPreference.java b/src/com/android/swe/browser/preferences/SeekBarSummaryPreference.java index 481fbc72..7db4349c 100644 --- a/src/com/android/swe/browser/preferences/SeekBarSummaryPreference.java +++ b/src/com/android/swe/browser/preferences/SeekBarSummaryPreference.java @@ -14,17 +14,16 @@ * limitations under the License. */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; import android.content.Context; -import android.preference.SeekBarPreference; +import com.android.swe.browser.platformsupport.SeekBarPreference; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.SeekBar; import android.widget.TextView; -import com.android.browser.R; public class SeekBarSummaryPreference extends SeekBarPreference { @@ -48,7 +47,7 @@ public class SeekBarSummaryPreference extends SeekBarPreference { } void init() { - setWidgetLayoutResource(R.layout.font_size_widget); + setWidgetLayoutResource(com.android.swe.browser.R.layout.font_size_widget); } @Override @@ -67,7 +66,7 @@ public class SeekBarSummaryPreference extends SeekBarPreference { @Override protected void onBindView(View view) { super.onBindView(view); - mSummaryView = (TextView) view.findViewById(R.id.text); + mSummaryView = (TextView) view.findViewById(com.android.swe.browser.R.id.text); if (TextUtils.isEmpty(mSummary)) { mSummaryView.setVisibility(View.GONE); } else { diff --git a/src/com/android/swe/browser/preferences/WebViewPreview.java b/src/com/android/swe/browser/preferences/WebViewPreview.java index 1f938f05..c017609e 100644 --- a/src/com/android/swe/browser/preferences/WebViewPreview.java +++ b/src/com/android/swe/browser/preferences/WebViewPreview.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; import android.content.Context; import android.content.SharedPreferences; @@ -24,9 +24,9 @@ import android.preference.PreferenceManager; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; -import com.android.browser.R; +import com.android.swe.browser.R; public abstract class WebViewPreview extends Preference implements OnSharedPreferenceChangeListener { diff --git a/src/com/android/swe/browser/preferences/WebsiteSettingsFragment.java b/src/com/android/swe/browser/preferences/WebsiteSettingsFragment.java index c84c6693..88d1c7c4 100644 --- a/src/com/android/swe/browser/preferences/WebsiteSettingsFragment.java +++ b/src/com/android/swe/browser/preferences/WebsiteSettingsFragment.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser.preferences; +package com.android.swe.browser.preferences; import android.app.AlertDialog; import android.app.ListFragment; @@ -29,22 +29,20 @@ import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.preference.PreferenceActivity; -import android.provider.BrowserContract.Bookmarks; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.webkit.GeolocationPermissions; import android.webkit.ValueCallback; -import android.webkit.WebStorage; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; -import com.android.browser.R; -import com.android.browser.WebStorageSizeManager; +import com.android.swe.browser.R; +import com.android.swe.browser.WebStorageSizeManager; +import com.android.swe.browser.platformsupport.BrowserContract.Bookmarks; import java.util.HashMap; import java.util.HashSet; @@ -52,6 +50,9 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import org.codeaurora.swe.GeolocationPermissions; +import org.codeaurora.swe.WebStorage; + /** * Manage the settings for an origin. * We use it to keep track of the 'HTML5' settings, i.e. database (webstorage) diff --git a/src/com/android/swe/browser/provider/BrowserProvider.java b/src/com/android/swe/browser/provider/BrowserProvider.java index 744032c9..11f903ff 100644 --- a/src/com/android/swe/browser/provider/BrowserProvider.java +++ b/src/com/android/swe/browser/provider/BrowserProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser.provider; +package com.android.swe.browser.provider; import android.app.SearchManager; import android.app.backup.BackupManager; @@ -42,9 +42,9 @@ import android.text.TextUtils; import android.util.Log; import android.util.Patterns; -import com.android.browser.BrowserSettings; -import com.android.browser.R; -import com.android.browser.search.SearchEngine; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserSettings; +import com.android.swe.browser.search.SearchEngine; import java.io.File; import java.io.FilenameFilter; diff --git a/src/com/android/swe/browser/provider/BrowserProvider2.java b/src/com/android/swe/browser/provider/BrowserProvider2.java index 95b34e7f..362e7ad7 100644 --- a/src/com/android/swe/browser/provider/BrowserProvider2.java +++ b/src/com/android/swe/browser/provider/BrowserProvider2.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.browser.provider; +package com.android.swe.browser.provider; import android.accounts.Account; import android.accounts.AccountManager; @@ -36,30 +36,30 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteQueryBuilder; import android.net.Uri; -import android.os.SystemProperties; import android.provider.BaseColumns; import android.provider.Browser; -import android.provider.Browser.BookmarkColumns; -import android.provider.BrowserContract; -import android.provider.BrowserContract.Accounts; -import android.provider.BrowserContract.Bookmarks; -import android.provider.BrowserContract.ChromeSyncColumns; -import android.provider.BrowserContract.Combined; -import android.provider.BrowserContract.History; -import android.provider.BrowserContract.Images; -import android.provider.BrowserContract.Searches; -import android.provider.BrowserContract.Settings; -import android.provider.BrowserContract.SyncState; import android.provider.ContactsContract.RawContacts; import android.provider.SyncStateContract; import android.text.TextUtils; import android.util.Log; -import com.android.browser.BrowserSettings; -import com.android.browser.R; -import com.android.browser.UrlUtils; -import com.android.browser.widget.BookmarkThumbnailWidgetProvider; -import com.android.common.content.SyncStateContentProviderHelper; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserSettings; +import com.android.swe.browser.UrlUtils; +import com.android.swe.browser.platformsupport.BookmarkColumns; +import com.android.swe.browser.platformsupport.BrowserContract; +import com.android.swe.browser.platformsupport.SyncStateContentProviderHelper; +import com.android.swe.browser.platformsupport.BrowserContract.Accounts; +import com.android.swe.browser.platformsupport.BrowserContract.Bookmarks; +import com.android.swe.browser.platformsupport.BrowserContract.ChromeSyncColumns; +import com.android.swe.browser.platformsupport.BrowserContract.Combined; +import com.android.swe.browser.platformsupport.BrowserContract.History; +import com.android.swe.browser.platformsupport.BrowserContract.Images; +import com.android.swe.browser.platformsupport.BrowserContract.Searches; +import com.android.swe.browser.platformsupport.BrowserContract.Settings; +import com.android.swe.browser.platformsupport.BrowserContract.SyncState; +import com.android.swe.browser.reflect.ReflectHelper; +import com.android.swe.browser.widget.BookmarkThumbnailWidgetProvider; import com.google.common.annotations.VisibleForTesting; import java.io.ByteArrayOutputStream; @@ -76,7 +76,7 @@ public class BrowserProvider2 extends SQLiteContentProvider { public static final String PARAM_GROUP_BY = "groupBy"; public static final String PARAM_ALLOW_EMPTY_ACCOUNTS = "allowEmptyAccounts"; - public static final String LEGACY_AUTHORITY = "browser"; + public static final String LEGACY_AUTHORITY = "swebrowser"; static final Uri LEGACY_AUTHORITY_URI = new Uri.Builder() .authority(LEGACY_AUTHORITY).scheme("content").build(); @@ -658,7 +658,12 @@ public class BrowserProvider2 extends SQLiteContentProvider { db.insertOrThrow(TABLE_BOOKMARKS, null, values); // add for carrier bookmark feature - String browserRes = SystemProperties.get("persist.env.c.browser.resource", "default"); + Object[] params = { new String("persist.env.c.browser.resource"), + new String("default")}; + Class[] type = new Class[] {String.class, String.class}; + String browserRes = (String)ReflectHelper.invokeStaticMethod( + "android.os.SystemProperties", "get", + type, params); //don't add default bookmarks for cmcc if (!"cmcc".equals(browserRes)) { @@ -731,7 +736,7 @@ public class BrowserProvider2 extends SQLiteContentProvider { Context mResPackageCtx = null; try { mResPackageCtx = getContext().createPackageContext( - "com.android.browser.res", + "com.android.swe.browser.res", Context.CONTEXT_IGNORE_SECURITY); } catch (Exception e) { Log.e(TAG, "Create Res Apk Failed"); @@ -742,9 +747,11 @@ public class BrowserProvider2 extends SQLiteContentProvider { CharSequence[] bookmarks = null; TypedArray preloads = null; Resources res = mResPackageCtx.getResources(); - int resBookmarksID = res.getIdentifier("bookmarks", "array", "com.android.browser.res"); + int resBookmarksID = res.getIdentifier("bookmarks", + "array", + "com.android.swe.browser.res"); int resPreloadsID = res.getIdentifier("bookmark_preloads", "array", - "com.android.browser.res"); + "com.android.swe.browser.res"); if (resBookmarksID != 0 && resPreloadsID != 0) { bookmarks = res.getTextArray(resBookmarksID); preloads = res.obtainTypedArray(resPreloadsID); @@ -851,7 +858,7 @@ public class BrowserProvider2 extends SQLiteContentProvider { return ret; } - private CharSequence replaceSystemPropertyInString(Context context, CharSequence srcString) { + private CharSequence replaceSystemPropertyInString(Context context, CharSequence srcString){ StringBuffer sb = new StringBuffer(); int lastCharLoc = 0; @@ -1001,7 +1008,7 @@ public class BrowserProvider2 extends SQLiteContentProvider { case BOOKMARKS_ID: case BOOKMARKS: { // Only show deleted bookmarks if requested to do so - if (!uri.getBooleanQueryParameter(Bookmarks.QUERY_PARAMETER_SHOW_DELETED, false)) { + if (!uri.getBooleanQueryParameter(Bookmarks.QUERY_PARAMETER_SHOW_DELETED, false)){ selection = DatabaseUtils.concatenateWhere( Bookmarks.IS_DELETED + "=0", selection); } diff --git a/src/com/android/swe/browser/provider/MyNavigationProvider.java b/src/com/android/swe/browser/provider/MyNavigationProvider.java index 3dc2954b..c075e381 100755 --- a/src/com/android/swe/browser/provider/MyNavigationProvider.java +++ b/src/com/android/swe/browser/provider/MyNavigationProvider.java @@ -27,7 +27,7 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.android.browser.provider; +package com.android.swe.browser.provider; import android.content.Context; import android.content.ContentProvider; @@ -48,11 +48,6 @@ import android.text.TextUtils; import android.util.Log; import android.webkit.WebResourceResponse; -import com.android.browser.BrowserSettings; -import com.android.browser.homepages.RequestHandler; -import com.android.browser.mynavigation.MyNavigationUtil; -import com.android.browser.mynavigation.MyNavigationRequestHandler; -import com.android.browser.provider.BrowserProvider2; import java.io.ByteArrayOutputStream; import java.io.File; @@ -60,7 +55,12 @@ import java.io.IOException; import java.io.InputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; -import com.android.browser.R; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserSettings; +import com.android.swe.browser.homepages.RequestHandler; +import com.android.swe.browser.mynavigation.MyNavigationRequestHandler; +import com.android.swe.browser.mynavigation.MyNavigationUtil; +import com.android.swe.browser.provider.BrowserProvider2; public class MyNavigationProvider extends ContentProvider { diff --git a/src/com/android/swe/browser/provider/SQLiteContentProvider.java b/src/com/android/swe/browser/provider/SQLiteContentProvider.java index 75e298e5..056017e4 100644 --- a/src/com/android/swe/browser/provider/SQLiteContentProvider.java +++ b/src/com/android/swe/browser/provider/SQLiteContentProvider.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.browser.provider; +package com.android.swe.browser.provider; import android.content.ContentProvider; import android.content.ContentProviderOperation; diff --git a/src/com/android/swe/browser/provider/SnapshotProvider.java b/src/com/android/swe/browser/provider/SnapshotProvider.java index e005c367..f484ce72 100644 --- a/src/com/android/swe/browser/provider/SnapshotProvider.java +++ b/src/com/android/swe/browser/provider/SnapshotProvider.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser.provider; +package com.android.swe.browser.provider; import android.content.ContentProvider; import android.content.ContentUris; @@ -26,11 +26,15 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteQueryBuilder; import android.net.Uri; -import android.os.FileUtils; -import android.provider.BrowserContract; + +import com.android.swe.browser.platformsupport.BrowserContract; + import android.text.TextUtils; import java.io.File; +import java.io.IOException; +import java.io.FileOutputStream; +import java.io.FileInputStream; public class SnapshotProvider extends ContentProvider { @@ -51,7 +55,7 @@ public class SnapshotProvider extends ContentProvider { public static final String VIEWSTATE_SIZE = "viewstate_size"; } - public static final String AUTHORITY = "com.android.browser.snapshots"; + public static final String AUTHORITY = "com.android.swe.browser.snapshots"; public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY); static final String TABLE_SNAPSHOTS = "snapshots"; @@ -117,6 +121,36 @@ public class SnapshotProvider extends ContentProvider { return new File(dir, SnapshotDatabaseHelper.DATABASE_NAME); } + private static boolean copyFile(File srcFile, File destFile) { + try { + if (destFile.exists()) { + destFile.delete(); + } + + FileInputStream in = new FileInputStream(srcFile); + FileOutputStream out = new FileOutputStream(destFile); + + try { + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = in.read(buffer)) >= 0) { + out.write(buffer, 0, bytesRead); + } + } finally { + out.flush(); + try { + out.getFD().sync(); + } catch (IOException e) { + } + in.close(); + out.close(); + } + return true; + } catch (IOException e) { + return false; + } + } + private void migrateToDataFolder() { File dbPath = getContext().getDatabasePath(SnapshotDatabaseHelper.DATABASE_NAME); if (dbPath.exists()) return; @@ -125,7 +159,7 @@ public class SnapshotProvider extends ContentProvider { // Try to move if (!oldPath.renameTo(dbPath)) { // Failed, do a copy - FileUtils.copyFile(oldPath, dbPath); + copyFile(oldPath, dbPath); } // Cleanup oldPath.delete(); diff --git a/src/com/android/swe/browser/reflect/ReflectHelper.java b/src/com/android/swe/browser/reflect/ReflectHelper.java new file mode 100644 index 00000000..ffae7d39 --- /dev/null +++ b/src/com/android/swe/browser/reflect/ReflectHelper.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +package com.android.swe.browser.reflect; + +import android.util.Log; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Field; + +public class ReflectHelper { + + private final static String LOGTAG = "ReflectHelper"; + + public static Object newObject(String className) { + Object obj = null; + try { + Class clazz = Class.forName(className); + obj = clazz.newInstance(); + } catch (Exception e) { + Log.e(LOGTAG, "An exception occured : " + e.getMessage()); + } + return obj; + } + + public static Object newObject(String className, Class[] argTypes, Object[] args) { + if (args == null || args.length == 0) { + return newObject(className); + } + Object obj = null; + try { + Class clazz = Class.forName(className); + Constructor ctor = clazz.getDeclaredConstructor(argTypes); + obj = ctor.newInstance(args); + } catch (Exception e) { + Log.e(LOGTAG, "An exception occured : " + e.getMessage() ); + } + return obj; + } + + public static Object invokeMethod(Object obj, String method, Class[] argTypes, Object[] args) { + Object result = null; + boolean modifiedAccessibility = false; + if (obj == null || method == null) { + throw new IllegalArgumentException("Object and Method must be supplied."); + } + try { + Method m = obj.getClass().getDeclaredMethod(method, argTypes); + if(m != null) { + // make it visible + if (!m.isAccessible()) { + modifiedAccessibility = true; + m.setAccessible(true); + } + result = m.invoke(obj, args); + if (modifiedAccessibility) + m.setAccessible(false); + } + } catch (Exception e) { + Log.e(LOGTAG, "An exception occured : " + e.getMessage() ); + } + return result; + } + + public static Object invokeStaticMethod(String className, String method, + Class[] argTypes, Object[] args) { + Object result = null; + boolean modifiedAccessibility = false; + if (className == null || method == null) { + throw new IllegalArgumentException("Object and Method must be supplied."); + } + try { + Class clazz = Class.forName(className); + Method m = clazz.getDeclaredMethod(method, argTypes); + if(m != null) { + // make it visible + if (!m.isAccessible()) { + modifiedAccessibility = true; + m.setAccessible(true); + } + result = m.invoke(null, args); + if (modifiedAccessibility) + m.setAccessible(false); + } + } catch (Exception e) { + Log.e(LOGTAG, "An exception occured : " + e.getMessage() ); + } + return result; + } + + public static Object getStaticVariable(String className, String fieldName) { + Object result = null; + boolean modifiedAccessibility = false; + try { + Class clazz = Class.forName(className); + Field f = clazz.getDeclaredField(fieldName); + if(f != null) { + if (!f.isAccessible()) { + modifiedAccessibility = true; + f.setAccessible(true); + } + f.setAccessible(true); + result = f.get(null); + if (modifiedAccessibility) + f.setAccessible(false); + } + } catch (Exception e) { + Log.e(LOGTAG, "An exception occured : " + e.getMessage() ); + } + return result; + } + + public static Object getVariable(Object obj, String fieldName) { + Object result = null; + boolean modifiedAccessibility = false; + try { + Class clazz = obj.getClass(); + Field f = clazz.getDeclaredField(fieldName); + if(f != null) { + if (!f.isAccessible()) { + modifiedAccessibility = true; + f.setAccessible(true); + } + f.setAccessible(true); + result = f.get(obj); + if (modifiedAccessibility) + f.setAccessible(false); + } + } catch (Exception e) { + Log.e(LOGTAG, "An exception occured : " + e.getMessage() ); + } + return result; + } +} \ No newline at end of file diff --git a/src/com/android/swe/browser/search/DefaultSearchEngine.java b/src/com/android/swe/browser/search/DefaultSearchEngine.java index e4e0e968..f7047cc0 100644 --- a/src/com/android/swe/browser/search/DefaultSearchEngine.java +++ b/src/com/android/swe/browser/search/DefaultSearchEngine.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser.search; +package com.android.swe.browser.search; import android.app.PendingIntent; import android.app.SearchManager; @@ -29,6 +29,7 @@ import android.os.Bundle; import android.provider.Browser; import android.text.TextUtils; import android.util.Log; +import com.android.swe.browser.reflect.ReflectHelper; public class DefaultSearchEngine implements SearchEngine { @@ -46,7 +47,9 @@ public class DefaultSearchEngine implements SearchEngine { public static DefaultSearchEngine create(Context context) { SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); - ComponentName name = searchManager.getWebSearchActivity(); + ComponentName name = (ComponentName) ReflectHelper.invokeMethod( + searchManager, "getWebSearchActivity", null, null); + if (name == null) return null; SearchableInfo searchable = searchManager.getSearchableInfo(name); if (searchable == null) return null; @@ -80,7 +83,8 @@ public class DefaultSearchEngine implements SearchEngine { return mLabel; } - public void startSearch(Context context, String query, Bundle appData, String extraData) { + public void startSearch(Context context, String query, + Bundle appData, String extraData) { try { Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.setComponent(mSearchable.getSearchActivity()); @@ -101,14 +105,19 @@ public class DefaultSearchEngine implements SearchEngine { intent.putExtra(SearchManager.EXTRA_WEB_SEARCH_PENDINGINTENT, pending); context.startActivity(intent); } catch (ActivityNotFoundException ex) { - Log.e(TAG, "Web search activity not found: " + mSearchable.getSearchActivity()); + Log.e(TAG, "Web search activity not found: " + + mSearchable.getSearchActivity()); } } public Cursor getSuggestions(Context context, String query) { SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); - return searchManager.getSuggestions(mSearchable, query); + Object[] params = {mSearchable, query}; + Class[] type = new Class[] {SearchableInfo.class, String.class}; + Cursor cursor = (Cursor) ReflectHelper.invokeMethod( + searchManager, "getSuggestions", type, params); + return cursor; } public boolean supportsSuggestions() { diff --git a/src/com/android/swe/browser/search/OpenSearchSearchEngine.java b/src/com/android/swe/browser/search/OpenSearchSearchEngine.java index e600aa98..986c40ac 100644 --- a/src/com/android/swe/browser/search/OpenSearchSearchEngine.java +++ b/src/com/android/swe/browser/search/OpenSearchSearchEngine.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser.search; +package com.android.swe.browser.search; -import com.android.browser.R; +import com.android.swe.browser.R; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; diff --git a/src/com/android/swe/browser/search/SearchEngine.java b/src/com/android/swe/browser/search/SearchEngine.java index 8f2d58db..83c4503f 100644 --- a/src/com/android/swe/browser/search/SearchEngine.java +++ b/src/com/android/swe/browser/search/SearchEngine.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser.search; +package com.android.swe.browser.search; import android.content.Context; import android.database.Cursor; diff --git a/src/com/android/swe/browser/search/SearchEngineInfo.java b/src/com/android/swe/browser/search/SearchEngineInfo.java index ec304f64..eea11cf5 100644 --- a/src/com/android/swe/browser/search/SearchEngineInfo.java +++ b/src/com/android/swe/browser/search/SearchEngineInfo.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser.search; +package com.android.swe.browser.search; import android.content.Context; import android.content.res.Resources; @@ -21,7 +21,7 @@ import android.content.res.Resources.NotFoundException; import android.text.TextUtils; import android.util.Log; -import com.android.browser.R; +import com.android.swe.browser.R; import java.net.URLEncoder; import java.util.Arrays; diff --git a/src/com/android/swe/browser/search/SearchEnginePreference.java b/src/com/android/swe/browser/search/SearchEnginePreference.java index 62ce97bc..2eb0c2c6 100644 --- a/src/com/android/swe/browser/search/SearchEnginePreference.java +++ b/src/com/android/swe/browser/search/SearchEnginePreference.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser.search; +package com.android.swe.browser.search; -import com.android.browser.R; +import com.android.swe.browser.R; import android.app.SearchManager; import android.content.ComponentName; diff --git a/src/com/android/swe/browser/search/SearchEngines.java b/src/com/android/swe/browser/search/SearchEngines.java index 2484ce01..a2e96192 100644 --- a/src/com/android/swe/browser/search/SearchEngines.java +++ b/src/com/android/swe/browser/search/SearchEngines.java @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser.search; +package com.android.swe.browser.search; -import com.android.browser.R; +import com.android.swe.browser.R; import android.content.Context; import android.content.res.Resources; -import android.os.SystemProperties; import android.text.TextUtils; import android.util.Log; +import com.android.swe.browser.reflect.ReflectHelper; + import java.util.ArrayList; import java.util.List; @@ -38,7 +39,11 @@ public class SearchEngines { ArrayList searchEngineInfos = new ArrayList(); Resources res = context.getResources(); String[] searchEngines = res.getStringArray(R.array.search_engines); - String browserRes = SystemProperties.get("persist.env.c.browser.resource", "default"); + Object[] params = { new String("persist.env.c.browser.resource"), + new String("default")}; + Class[] type = new Class[] {String.class, String.class}; + String browserRes = (String)ReflectHelper.invokeStaticMethod( + "android.os.SystemProperties","get", type, params); for (int i = 0; i < searchEngines.length; i++) { String name = searchEngines[i]; if ("cmcc".equals(browserRes)) { diff --git a/src/com/android/swe/browser/stub/NullController.java b/src/com/android/swe/browser/stub/NullController.java index 149fe4ef..8c53662d 100644 --- a/src/com/android/swe/browser/stub/NullController.java +++ b/src/com/android/swe/browser/stub/NullController.java @@ -1,4 +1,4 @@ -package com.android.browser.stub; +package com.android.swe.browser.stub; import android.content.Intent; import android.content.res.Configuration; @@ -12,7 +12,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ContextMenu.ContextMenuInfo; -import com.android.browser.ActivityController; +import com.android.swe.browser.ActivityController; public class NullController implements ActivityController { diff --git a/src/com/android/swe/browser/util/ThreadedCursorAdapter.java b/src/com/android/swe/browser/util/ThreadedCursorAdapter.java index 72a07eaf..bc3c7d84 100644 --- a/src/com/android/swe/browser/util/ThreadedCursorAdapter.java +++ b/src/com/android/swe/browser/util/ThreadedCursorAdapter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser.util; +package com.android.swe.browser.util; import android.content.Context; import android.database.Cursor; @@ -21,7 +21,6 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.os.Process; -import android.os.SystemProperties; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -29,7 +28,7 @@ import android.widget.Adapter; import android.widget.BaseAdapter; import android.widget.CursorAdapter; -import com.android.browser.R; +import com.android.swe.browser.R; import java.lang.ref.WeakReference; diff --git a/src/com/android/swe/browser/view/BasePieView.java b/src/com/android/swe/browser/view/BasePieView.java index b9178be0..d1997f0f 100644 --- a/src/com/android/swe/browser/view/BasePieView.java +++ b/src/com/android/swe/browser/view/BasePieView.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser.view; +package com.android.swe.browser.view; import android.database.DataSetObserver; import android.graphics.Canvas; diff --git a/src/com/android/swe/browser/view/BookmarkContainer.java b/src/com/android/swe/browser/view/BookmarkContainer.java index 5175589d..edda2c4b 100644 --- a/src/com/android/swe/browser/view/BookmarkContainer.java +++ b/src/com/android/swe/browser/view/BookmarkContainer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser.view; +package com.android.swe.browser.view; import android.content.Context; import android.graphics.drawable.Drawable; diff --git a/src/com/android/swe/browser/view/BookmarkExpandableView.java b/src/com/android/swe/browser/view/BookmarkExpandableView.java index 5c0f0307..6d6990bb 100644 --- a/src/com/android/swe/browser/view/BookmarkExpandableView.java +++ b/src/com/android/swe/browser/view/BookmarkExpandableView.java @@ -14,11 +14,10 @@ * limitations under the License. */ -package com.android.browser.view; +package com.android.swe.browser.view; import android.content.Context; import android.database.DataSetObserver; -import android.provider.BrowserContract; import android.util.AttributeSet; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -32,14 +31,15 @@ import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; -import com.android.browser.BreadCrumbView; -import com.android.browser.BrowserBookmarksAdapter; -import com.android.browser.R; -import com.android.internal.view.menu.MenuBuilder; +import com.android.swe.browser.R; +import com.android.swe.browser.BreadCrumbView; +import com.android.swe.browser.BrowserBookmarksAdapter; +import com.android.swe.browser.platformsupport.BrowserContract; import org.json.JSONException; import org.json.JSONObject; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; @@ -156,6 +156,26 @@ public class BookmarkExpandableView extends ExpandableListView } } + // SWE: com.android.internal.view.menu.MenuBuilder is a hidden class in SDK. + // Since the 'menu' object is of type MenuBuilder, java reflection method + // is the only way to access MenuBuilder.setCurrentMenuInfo(). + static void setCurrentMenuInfo(ContextMenu menu, ContextMenuInfo menuInfo) { + try { + Class proxyClass = Class.forName("com.android.internal.view.menu.MenuBuilder"); + Class argTypes[] = new Class[1]; + argTypes[0] = ContextMenuInfo.class; + Method m = proxyClass.getDeclaredMethod("setCurrentMenuInfo", argTypes); + m.setAccessible(true); + + Object args[] = new Object[1]; + args[0] = menuInfo; + m.invoke(menu, args); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + @Override public void createContextMenu(ContextMenu menu) { // The below is copied from View - we want to bypass the override @@ -165,7 +185,7 @@ public class BookmarkExpandableView extends ExpandableListView // Sets the current menu info so all items added to menu will have // my extra info set. - ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); + setCurrentMenuInfo(menu, menuInfo); onCreateContextMenu(menu); if (mOnCreateContextMenuListener != null) { @@ -174,10 +194,10 @@ public class BookmarkExpandableView extends ExpandableListView // Clear the extra information so subsequent items that aren't mine don't // have my extra info. - ((MenuBuilder)menu).setCurrentMenuInfo(null); + setCurrentMenuInfo(menu, null); - if (mParent != null) { - mParent.createContextMenu(menu); + if (getParent() != null) { + getParent().createContextMenu(menu); } } diff --git a/src/com/android/swe/browser/view/CustomScreenLinearLayout.java b/src/com/android/swe/browser/view/CustomScreenLinearLayout.java index f5341e8d..93cd16ed 100644 --- a/src/com/android/swe/browser/view/CustomScreenLinearLayout.java +++ b/src/com/android/swe/browser/view/CustomScreenLinearLayout.java @@ -15,7 +15,7 @@ */ -package com.android.browser.view; +package com.android.swe.browser.view; import android.content.Context; import android.util.AttributeSet; diff --git a/src/com/android/swe/browser/view/EventRedirectingFrameLayout.java b/src/com/android/swe/browser/view/EventRedirectingFrameLayout.java index 901b0217..1e7d686c 100644 --- a/src/com/android/swe/browser/view/EventRedirectingFrameLayout.java +++ b/src/com/android/swe/browser/view/EventRedirectingFrameLayout.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.browser.view; +package com.android.swe.browser.view; import android.content.Context; import android.util.AttributeSet; diff --git a/src/com/android/swe/browser/view/PieItem.java b/src/com/android/swe/browser/view/PieItem.java index 9e04ecbf..31e3413e 100644 --- a/src/com/android/swe/browser/view/PieItem.java +++ b/src/com/android/swe/browser/view/PieItem.java @@ -14,11 +14,11 @@ * the License. */ -package com.android.browser.view; +package com.android.swe.browser.view; import android.view.View; -import com.android.browser.view.PieMenu.PieView; +import com.android.swe.browser.view.PieMenu.PieView; import java.util.ArrayList; import java.util.List; diff --git a/src/com/android/swe/browser/view/PieListView.java b/src/com/android/swe/browser/view/PieListView.java index 1043fc77..3cd43714 100644 --- a/src/com/android/swe/browser/view/PieListView.java +++ b/src/com/android/swe/browser/view/PieListView.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.android.browser.view; +package com.android.swe.browser.view; -import com.android.browser.R; +import com.android.swe.browser.R; import android.content.Context; import android.graphics.Canvas; diff --git a/src/com/android/swe/browser/view/PieMenu.java b/src/com/android/swe/browser/view/PieMenu.java index 1699c274..a9a9de35 100644 --- a/src/com/android/swe/browser/view/PieMenu.java +++ b/src/com/android/swe/browser/view/PieMenu.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser.view; +package com.android.swe.browser.view; import android.animation.Animator; import android.animation.Animator.AnimatorListener; @@ -37,7 +37,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; -import com.android.browser.R; +import com.android.swe.browser.R; import java.util.ArrayList; import java.util.List; diff --git a/src/com/android/swe/browser/view/PieStackView.java b/src/com/android/swe/browser/view/PieStackView.java index e1f41bd8..a9f3e304 100644 --- a/src/com/android/swe/browser/view/PieStackView.java +++ b/src/com/android/swe/browser/view/PieStackView.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.android.browser.view; +package com.android.swe.browser.view; -import com.android.browser.R; +import com.android.swe.browser.R; import android.content.Context; import android.graphics.Canvas; diff --git a/src/com/android/swe/browser/view/ScrollerView.java b/src/com/android/swe/browser/view/ScrollerView.java index 545dd25f..252c6d57 100644 --- a/src/com/android/swe/browser/view/ScrollerView.java +++ b/src/com/android/swe/browser/view/ScrollerView.java @@ -14,13 +14,11 @@ * limitations under the License. */ -package com.android.browser.view; +package com.android.swe.browser.view; import android.content.Context; -import android.content.res.TypedArray; import android.graphics.PointF; import android.graphics.Rect; -import android.os.StrictMode; import android.util.AttributeSet; import android.view.FocusFinder; import android.view.InputDevice; @@ -40,8 +38,6 @@ import android.widget.LinearLayout; import android.widget.OverScroller; import android.widget.TextView; -import com.android.internal.R; - import java.util.List; /** @@ -127,14 +123,90 @@ public class ScrollerView extends FrameLayout { */ private int mActivePointerId = INVALID_POINTER; + private static class ThreadSpanState { + public Span mActiveHead; // doubly-linked list. + public int mActiveSize; + public Span mFreeListHead; // singly-linked list. only changes at head. + public int mFreeListSize; + } + + public static class Span { + private String mName; + private long mCreateMillis; + private Span mNext; + private Span mPrev; // not used when in freeList, only active + private final ThreadSpanState mContainerState; + + Span(ThreadSpanState threadState) { + mContainerState = threadState; + } + + // Empty constructor for the NO_OP_SPAN + protected Span() { + mContainerState = null; + } + + /** + * To be called when the critical span is complete (i.e. the + * animation is done animating). This can be called on any + * thread (even a different one from where the animation was + * taking place), but that's only a defensive implementation + * measure. It really makes no sense for you to call this on + * thread other than that where you created it. + * + * @hide + */ + public void finish() { + ThreadSpanState state = mContainerState; + synchronized (state) { + if (mName == null) { + // Duplicate finish call. Ignore. + return; + } + + // Remove ourselves from the active list. + if (mPrev != null) { + mPrev.mNext = mNext; + } + if (mNext != null) { + mNext.mPrev = mPrev; + } + if (state.mActiveHead == this) { + state.mActiveHead = mNext; + } + + state.mActiveSize--; + + this.mCreateMillis = -1; + this.mName = null; + this.mPrev = null; + this.mNext = null; + + // Add ourselves to the freeList, if it's not already + // too big. + if (state.mFreeListSize < 5) { + this.mNext = state.mFreeListHead; + state.mFreeListHead = this; + state.mFreeListSize++; + } + } + } + } + + private static final Span NO_OP_SPAN = new Span() { + public void finish() { + // Do nothing. + } + }; + /** * The StrictMode "critical time span" objects to catch animation * stutters. Non-null when a time-sensitive animation is * in-flight. Must call finish() on them when done animating. * These are no-ops on user builds. */ - private StrictMode.Span mScrollStrictSpan = null; // aka "drag" - private StrictMode.Span mFlingStrictSpan = null; + private Span mScrollStrictSpan = null; // aka "drag" + private Span mFlingStrictSpan = null; /** * Sentinel value for no current active pointer. @@ -158,19 +230,19 @@ public class ScrollerView extends FrameLayout { } public ScrollerView(Context context, AttributeSet attrs) { - this(context, attrs, com.android.internal.R.attr.scrollViewStyle); + this(context, attrs, android.R.attr.scrollViewStyle); } public ScrollerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); initScrollView(); - + // SWE_TODO : Fix me + /* TypedArray a = - context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ScrollView, defStyle, 0); - - setFillViewport(a.getBoolean(R.styleable.ScrollView_fillViewport, false)); - - a.recycle(); + context.obtainStyledAttributes(attrs, R.styleable.ScrollView, defStyle, 0); + setFillViewport(a.getBoolean(R.styleable.ScrollView_android_fillViewport, false)); + a.recycle();*/ + setFillViewport(false); } private void initScrollView() { @@ -178,7 +250,7 @@ public class ScrollerView extends FrameLayout { setFocusable(true); setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setWillNotDraw(false); - final ViewConfiguration configuration = ViewConfiguration.get(mContext); + final ViewConfiguration configuration = ViewConfiguration.get(getContext()); mTouchSlop = configuration.getScaledTouchSlop(); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); @@ -204,13 +276,13 @@ public class ScrollerView extends FrameLayout { } if (mHorizontal) { final int length = getHorizontalFadingEdgeLength(); - if (mScrollX < length) { - return mScrollX / (float) length; + if (getScrollX() < length) { + return getScrollX() / (float) length; } } else { final int length = getVerticalFadingEdgeLength(); - if (mScrollY < length) { - return mScrollY / (float) length; + if (getScrollY() < length) { + return getScrollY() / (float) length; } } return 1.0f; @@ -223,15 +295,15 @@ public class ScrollerView extends FrameLayout { } if (mHorizontal) { final int length = getHorizontalFadingEdgeLength(); - final int bottomEdge = getWidth() - mPaddingRight; - final int span = getChildAt(0).getRight() - mScrollX - bottomEdge; + final int bottomEdge = getWidth() - getPaddingRight(); + final int span = getChildAt(0).getRight() - getScrollX() - bottomEdge; if (span < length) { return span / (float) length; } } else { final int length = getVerticalFadingEdgeLength(); - final int bottomEdge = getHeight() - mPaddingBottom; - final int span = getChildAt(0).getBottom() - mScrollY - bottomEdge; + final int bottomEdge = getHeight() - getPaddingBottom(); + final int span = getChildAt(0).getBottom() - getScrollY() - bottomEdge; if (span < length) { return span / (float) length; } @@ -245,7 +317,7 @@ public class ScrollerView extends FrameLayout { */ public int getMaxScrollAmount() { return (int) (MAX_SCROLL_FACTOR * (mHorizontal - ? (mRight - mLeft) : (mBottom - mTop))); + ? (getRight() - getLeft()) : (getBottom() - getTop()))); } @@ -292,9 +364,9 @@ public class ScrollerView extends FrameLayout { View child = getChildAt(0); if (child != null) { if (mHorizontal) { - return getWidth() < child.getWidth() + mPaddingLeft + mPaddingRight; + return getWidth() < child.getWidth() + getPaddingLeft() + getPaddingRight(); } else { - return getHeight() < child.getHeight() + mPaddingTop + mPaddingBottom; + return getHeight() < child.getHeight() + getPaddingTop() + getPaddingBottom(); } } return false; @@ -364,10 +436,10 @@ public class ScrollerView extends FrameLayout { .getLayoutParams(); int childHeightMeasureSpec = getChildMeasureSpec( - heightMeasureSpec, mPaddingTop + mPaddingBottom, + heightMeasureSpec, getPaddingTop() + getPaddingBottom(), lp.height); - width -= mPaddingLeft; - width -= mPaddingRight; + width -= getPaddingLeft(); + width -= getPaddingRight(); int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec( width, MeasureSpec.EXACTLY); @@ -380,10 +452,10 @@ public class ScrollerView extends FrameLayout { .getLayoutParams(); int childWidthMeasureSpec = getChildMeasureSpec( - widthMeasureSpec, mPaddingLeft + mPaddingRight, + widthMeasureSpec, getPaddingLeft() + getPaddingRight(), lp.width); - height -= mPaddingTop; - height -= mPaddingBottom; + height -= getPaddingTop(); + height -= getPaddingBottom(); int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec( height, MeasureSpec.EXACTLY); @@ -451,7 +523,7 @@ public class ScrollerView extends FrameLayout { private boolean inChild(int x, int y) { if (getChildCount() > 0) { - final int scrollY = mScrollY; + final int scrollY = getScrollY(); final View child = getChildAt(0); return !(y < child.getTop() - scrollY || y >= child.getBottom() - scrollY @@ -538,8 +610,9 @@ public class ScrollerView extends FrameLayout { initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); if (mScrollStrictSpan == null) { - mScrollStrictSpan = StrictMode - .enterCriticalSpan("ScrollView-scroll"); + /*mScrollStrictSpan = StrictMode + .enterCriticalSpan("ScrollView-scroll");*/ + mScrollStrictSpan = NO_OP_SPAN; } } else { final float ocoord = mHorizontal ? ev.getY(pointerIndex) : ev @@ -580,8 +653,9 @@ public class ScrollerView extends FrameLayout { */ mIsBeingDragged = !mScroller.isFinished(); if (mIsBeingDragged && mScrollStrictSpan == null) { - mScrollStrictSpan = StrictMode - .enterCriticalSpan("ScrollView-scroll"); + /*mScrollStrictSpan = StrictMode + .enterCriticalSpan("ScrollView-scroll");*/ + mScrollStrictSpan = NO_OP_SPAN; } mIsOrthoDragged = false; final float ocoord = mHorizontal ? ev.getY() : ev.getX(); @@ -597,7 +671,7 @@ public class ScrollerView extends FrameLayout { mIsOrthoDragged = false; mActivePointerId = INVALID_POINTER; recycleVelocityTracker(); - if (mScroller.springBack(mScrollX, mScrollY, 0, 0, 0, + if (mScroller.springBack(getScrollX(), getScrollY(), 0, 0, 0, getScrollRange())) { invalidate(); } @@ -663,23 +737,23 @@ public class ScrollerView extends FrameLayout { final int deltaY = (int) (mLastMotionY - y); mLastMotionY = y; - final int oldX = mScrollX; - final int oldY = mScrollY; + final int oldX = getScrollX(); + final int oldY = getScrollY(); final int range = getScrollRange(); if (mHorizontal) { - if (overScrollBy(deltaY, 0, mScrollX, 0, range, 0, + if (overScrollBy(deltaY, 0, getScrollX(), 0, range, 0, mOverscrollDistance, 0, true)) { // Break our velocity if we hit a scroll barrier. mVelocityTracker.clear(); } } else { - if (overScrollBy(0, deltaY, 0, mScrollY, 0, range, + if (overScrollBy(0, deltaY, 0, getScrollY(), 0, range, 0, mOverscrollDistance, true)) { // Break our velocity if we hit a scroll barrier. mVelocityTracker.clear(); } } - onScrollChanged(mScrollX, mScrollY, oldX, oldY); + onScrollChanged(getScrollX(), getScrollY(), oldX, oldY); final int overscrollMode = getOverScrollMode(); if (overscrollMode == OVER_SCROLL_ALWAYS || @@ -723,11 +797,13 @@ public class ScrollerView extends FrameLayout { } else { final int bottom = getScrollRange(); if (mHorizontal) { - if (mScroller.springBack(mScrollX, mScrollY, 0, bottom, 0, 0)) { + if (mScroller.springBack(getScrollX(), getScrollY(), 0, + bottom, 0, 0)) { invalidate(); } } else { - if (mScroller.springBack(mScrollX, mScrollY, 0, 0, 0, bottom)) { + if (mScroller.springBack(getScrollX(), getScrollY(), 0, + 0, 0, bottom)) { invalidate(); } } @@ -746,11 +822,13 @@ public class ScrollerView extends FrameLayout { endDrag(); } else if (mIsBeingDragged && getChildCount() > 0) { if (mHorizontal) { - if (mScroller.springBack(mScrollX, mScrollY, 0, getScrollRange(), 0, 0)) { + if (mScroller.springBack(getScrollX(), getScrollY(), 0, + getScrollRange(), 0, 0)) { invalidate(); } } else { - if (mScroller.springBack(mScrollX, mScrollY, 0, 0, 0, getScrollRange())) { + if (mScroller.springBack(getScrollX(), getScrollY(), 0, 0, 0, + getScrollRange())) { invalidate(); } } @@ -813,9 +891,10 @@ public class ScrollerView extends FrameLayout { final float hscroll = event .getAxisValue(MotionEvent.AXIS_HSCROLL); if (hscroll != 0) { - final int delta = (int) (hscroll * getHorizontalScrollFactor()); + /* SWE_TODO : - disruptive getHorizontalScrollFactor()*/ + final int delta = (int) (hscroll * 10); final int range = getScrollRange(); - int oldScrollX = mScrollX; + int oldScrollX = getScrollX(); int newScrollX = oldScrollX - delta; if (newScrollX < 0) { newScrollX = 0; @@ -823,7 +902,7 @@ public class ScrollerView extends FrameLayout { newScrollX = range; } if (newScrollX != oldScrollX) { - super.scrollTo(newScrollX, mScrollY); + super.scrollTo(newScrollX, getScrollY()); return true; } } @@ -831,9 +910,10 @@ public class ScrollerView extends FrameLayout { final float vscroll = event .getAxisValue(MotionEvent.AXIS_VSCROLL); if (vscroll != 0) { - final int delta = (int) (vscroll * getVerticalScrollFactor()); + /* SWE_TODO : - disruptive getVerticalScrollFactor()*/ + final int delta = (int) (vscroll * 10); final int range = getScrollRange(); - int oldScrollY = mScrollY; + int oldScrollY = getScrollY(); int newScrollY = oldScrollY - delta; if (newScrollY < 0) { newScrollY = 0; @@ -841,7 +921,7 @@ public class ScrollerView extends FrameLayout { newScrollY = range; } if (newScrollY != oldScrollY) { - super.scrollTo(mScrollX, newScrollY); + super.scrollTo(getScrollX(), newScrollY); return true; } } @@ -867,13 +947,15 @@ public class ScrollerView extends FrameLayout { boolean clampedX, boolean clampedY) { // Treat animating scrolls differently; see #computeScroll() for why. if (!mScroller.isFinished()) { - mScrollX = scrollX; - mScrollY = scrollY; - invalidateParentIfNeeded(); + setScrollX(scrollX); + setScrollY(scrollY); + if (isHardwareAccelerated() && getParent() instanceof View) { + ((View) getParent()).invalidate(); + } if (mHorizontal && clampedX) { - mScroller.springBack(mScrollX, mScrollY, 0, getScrollRange(), 0, 0); + mScroller.springBack(getScrollX(), getScrollY(), 0, getScrollRange(), 0, 0); } else if (!mHorizontal && clampedY) { - mScroller.springBack(mScrollX, mScrollY, 0, 0, 0, getScrollRange()); + mScroller.springBack(getScrollX(), getScrollY(), 0, 0, 0, getScrollRange()); } } else { super.scrollTo(scrollX, scrollY); @@ -909,10 +991,10 @@ public class ScrollerView extends FrameLayout { View child = getChildAt(0); if (mHorizontal) { scrollRange = Math.max(0, - child.getWidth() - (getWidth() - mPaddingRight - mPaddingLeft)); + child.getWidth() - (getWidth() - getPaddingRight() - getPaddingLeft())); } else { scrollRange = Math.max(0, - child.getHeight() - (getHeight() - mPaddingBottom - mPaddingTop)); + child.getHeight() - (getHeight() - getPaddingBottom() - getPaddingTop())); } } return scrollRange; @@ -1102,7 +1184,7 @@ public class ScrollerView extends FrameLayout { int count = getChildCount(); if (count > 0) { View view = getChildAt(count - 1); - mTempRect.bottom = view.getBottom() + mPaddingBottom; + mTempRect.bottom = view.getBottom() + getPaddingBottom(); mTempRect.top = mTempRect.bottom - height; } } @@ -1178,7 +1260,7 @@ public class ScrollerView extends FrameLayout { } else if (direction == View.FOCUS_DOWN) { if (getChildCount() > 0) { int daBottom = getChildAt(0).getBottom(); - int screenBottom = getScrollY() + getHeight() - mPaddingBottom; + int screenBottom = getScrollY() + getHeight() - getPaddingBottom(); if (daBottom - screenBottom < maxJump) { scrollDelta = daBottom - screenBottom; } @@ -1275,19 +1357,19 @@ public class ScrollerView extends FrameLayout { long duration = AnimationUtils.currentAnimationTimeMillis() - mLastScroll; if (duration > ANIMATED_SCROLL_GAP) { if (mHorizontal) { - final int width = getWidth() - mPaddingRight - mPaddingLeft; + final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); - final int scrollX = mScrollX; + final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; - mScroller.startScroll(scrollX, mScrollY, dx, 0); + mScroller.startScroll(scrollX, getScrollY(), dx, 0); } else { - final int height = getHeight() - mPaddingBottom - mPaddingTop; + final int height = getHeight() - getPaddingBottom() - getPaddingTop(); final int bottom = getChildAt(0).getHeight(); final int maxY = Math.max(0, bottom - height); - final int scrollY = mScrollY; + final int scrollY = getScrollY(); dy = Math.max(0, Math.min(scrollY + dy, maxY)) - scrollY; - mScroller.startScroll(mScrollX, scrollY, 0, dy); + mScroller.startScroll(getScrollX(), scrollY, 0, dy); } invalidate(); } else { @@ -1310,7 +1392,7 @@ public class ScrollerView extends FrameLayout { * @param y the position where to scroll on the Y axis */ public final void smoothScrollTo(int x, int y) { - smoothScrollBy(x - mScrollX, y - mScrollY); + smoothScrollBy(x - getScrollX(), y - getScrollY()); } /** @@ -1325,13 +1407,13 @@ public class ScrollerView extends FrameLayout { return super.computeVerticalScrollRange(); } final int count = getChildCount(); - final int contentHeight = getHeight() - mPaddingBottom - mPaddingTop; + final int contentHeight = getHeight() - getPaddingBottom() - getPaddingTop(); if (count == 0) { return contentHeight; } int scrollRange = getChildAt(0).getBottom(); - final int scrollY = mScrollY; + final int scrollY = getScrollY(); final int overscrollBottom = Math.max(0, scrollRange - contentHeight); if (scrollY < 0) { scrollRange -= scrollY; @@ -1354,13 +1436,13 @@ public class ScrollerView extends FrameLayout { return super.computeHorizontalScrollRange(); } final int count = getChildCount(); - final int contentWidth = getWidth() - mPaddingRight - mPaddingLeft; + final int contentWidth = getWidth() - getPaddingRight() - getPaddingLeft(); if (count == 0) { return contentWidth; } int scrollRange = getChildAt(0).getRight(); - final int scrollX = mScrollX; + final int scrollX = getScrollX(); final int overscrollBottom = Math.max(0, scrollRange - contentWidth); if (scrollX < 0) { scrollRange -= scrollX; @@ -1389,13 +1471,13 @@ public class ScrollerView extends FrameLayout { int childHeightMeasureSpec; if (mHorizontal) { - childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, mPaddingTop - + mPaddingBottom, lp.height); + childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, getPaddingTop() + + getPaddingBottom(), lp.height); childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } else { - childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, mPaddingLeft - + mPaddingRight, lp.width); + childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, getPaddingLeft() + + getPaddingRight(), lp.width); childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } @@ -1412,13 +1494,13 @@ public class ScrollerView extends FrameLayout { int childHeightMeasureSpec; if (mHorizontal) { childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, - mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin + getPaddingTop() + getPaddingBottom() + lp.topMargin + lp.bottomMargin + heightUsed, lp.height); childWidthMeasureSpec = MeasureSpec.makeMeasureSpec( lp.leftMargin + lp.rightMargin, MeasureSpec.UNSPECIFIED); } else { childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, - mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin + getPaddingLeft() + getPaddingRight() + lp.leftMargin + lp.rightMargin + widthUsed, lp.width); childHeightMeasureSpec = MeasureSpec.makeMeasureSpec( lp.topMargin + lp.bottomMargin, MeasureSpec.UNSPECIFIED); @@ -1442,11 +1524,11 @@ public class ScrollerView extends FrameLayout { // // I agree. The alternative, which I think would be worse, is to post // something and tell the subclasses later. This is bad because there - // will be a window where mScrollX/Y is different from what the app + // will be a window where getScrollX()/Y is different from what the app // thinks it is. // - int oldX = mScrollX; - int oldY = mScrollY; + int oldX = getScrollX(); + int oldY = getScrollY(); int x = mScroller.getCurrX(); int y = mScroller.getCurrY(); @@ -1458,7 +1540,7 @@ public class ScrollerView extends FrameLayout { overScrollBy(x - oldX, y - oldY, oldX, oldY, 0, getScrollRange(), 0, mOverflingDistance, false); } - onScrollChanged(mScrollX, mScrollY, oldX, oldY); + onScrollChanged(getScrollX(), getScrollY(), oldX, oldY); } awakenScrollBars(); @@ -1743,7 +1825,7 @@ public class ScrollerView extends FrameLayout { mChildToScrollTo = null; // Calling this with the present values causes it to re-clam them - scrollTo(mScrollX, mScrollY); + scrollTo(getScrollX(), getScrollY()); } @Override @@ -1787,20 +1869,21 @@ public class ScrollerView extends FrameLayout { public void fling(int velocityY) { if (getChildCount() > 0) { if (mHorizontal) { - int width = getWidth() - mPaddingRight - mPaddingLeft; + int width = getWidth() - getPaddingRight() - getPaddingLeft(); int right = getChildAt(0).getWidth(); - mScroller.fling(mScrollX, mScrollY, velocityY, 0, + mScroller.fling(getScrollX(), getScrollY(), velocityY, 0, 0, Math.max(0, right - width), 0, 0, width/2, 0); } else { - int height = getHeight() - mPaddingBottom - mPaddingTop; + int height = getHeight() - getPaddingBottom() - getPaddingTop(); int bottom = getChildAt(0).getHeight(); - mScroller.fling(mScrollX, mScrollY, 0, velocityY, 0, 0, 0, + mScroller.fling(getScrollX(), getScrollY(), 0, velocityY, 0, 0, 0, Math.max(0, bottom - height), 0, height/2); } if (mFlingStrictSpan == null) { - mFlingStrictSpan = StrictMode.enterCriticalSpan("ScrollView-fling"); + //mFlingStrictSpan = StrictMode.enterCriticalSpan("ScrollView-fling"); + mFlingStrictSpan = NO_OP_SPAN; } invalidate(); @@ -1828,9 +1911,9 @@ public class ScrollerView extends FrameLayout { // we rely on the fact the View.scrollBy calls scrollTo. if (getChildCount() > 0) { View child = getChildAt(0); - x = clamp(x, getWidth() - mPaddingRight - mPaddingLeft, child.getWidth()); - y = clamp(y, getHeight() - mPaddingBottom - mPaddingTop, child.getHeight()); - if (x != mScrollX || y != mScrollY) { + x = clamp(x, getWidth() - getPaddingRight() - getPaddingLeft(), child.getWidth()); + y = clamp(y, getHeight() - getPaddingBottom() - getPaddingTop(), child.getHeight()); + if (x != getScrollX() || y != getScrollY()) { super.scrollTo(x, y); } } @@ -1851,7 +1934,7 @@ public class ScrollerView extends FrameLayout { * n < 0 is this case: * |------ me ------| * |-------- child --------| - * |-- mScrollX --| + * |-- getScrollX() --| */ return 0; } @@ -1859,7 +1942,7 @@ public class ScrollerView extends FrameLayout { /* this case: * |------ me ------| * |------ child ------| - * |-- mScrollX --| + * |-- getScrollX() --| */ return child-my; } diff --git a/src/com/android/swe/browser/view/SnapshotGridView.java b/src/com/android/swe/browser/view/SnapshotGridView.java index ab12060b..4c87e02d 100644 --- a/src/com/android/swe/browser/view/SnapshotGridView.java +++ b/src/com/android/swe/browser/view/SnapshotGridView.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser.view; +package com.android.swe.browser.view; import android.content.Context; import android.util.AttributeSet; diff --git a/src/com/android/swe/browser/view/StopProgressView.java b/src/com/android/swe/browser/view/StopProgressView.java index 64fa5d03..cd479d53 100644 --- a/src/com/android/swe/browser/view/StopProgressView.java +++ b/src/com/android/swe/browser/view/StopProgressView.java @@ -1,7 +1,7 @@ -package com.android.browser.view; +package com.android.swe.browser.view; -import com.android.browser.R; +import com.android.swe.browser.R; import android.content.Context; import android.graphics.Canvas; @@ -24,7 +24,7 @@ public class StopProgressView extends ProgressBar { * @param styleRes */ public StopProgressView(Context context, AttributeSet attrs, int defStyle, int styleRes) { - super(context, attrs, defStyle, styleRes); + super(context, attrs, defStyle); init(attrs); } @@ -57,7 +57,7 @@ public class StopProgressView extends ProgressBar { private void init(AttributeSet attrs) { mProgressDrawable = getIndeterminateDrawable(); - setImageDrawable(mContext.getResources() + setImageDrawable(getContext().getResources() .getDrawable(R.drawable.ic_stop_holo_dark)); } diff --git a/src/com/android/swe/browser/widget/BookmarkThumbnailWidgetProvider.java b/src/com/android/swe/browser/widget/BookmarkThumbnailWidgetProvider.java index f3d26759..5184a221 100644 --- a/src/com/android/swe/browser/widget/BookmarkThumbnailWidgetProvider.java +++ b/src/com/android/swe/browser/widget/BookmarkThumbnailWidgetProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser.widget; +package com.android.swe.browser.widget; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; @@ -25,15 +25,15 @@ import android.content.Intent; import android.net.Uri; import android.widget.RemoteViews; -import com.android.browser.BrowserActivity; -import com.android.browser.R; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserActivity; /** * Widget that shows a preview of the user's bookmarks. */ public class BookmarkThumbnailWidgetProvider extends AppWidgetProvider { public static final String ACTION_BOOKMARK_APPWIDGET_UPDATE = - "com.android.browser.BOOKMARK_APPWIDGET_UPDATE"; + "com.android.swe.browser.BOOKMARK_APPWIDGET_UPDATE"; @Override public void onReceive(Context context, Intent intent) { diff --git a/src/com/android/swe/browser/widget/BookmarkThumbnailWidgetService.java b/src/com/android/swe/browser/widget/BookmarkThumbnailWidgetService.java index 209faadf..c264f40c 100644 --- a/src/com/android/swe/browser/widget/BookmarkThumbnailWidgetService.java +++ b/src/com/android/swe/browser/widget/BookmarkThumbnailWidgetService.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser.widget; +package com.android.swe.browser.widget; import android.appwidget.AppWidgetManager; import android.content.ContentUris; @@ -29,16 +29,16 @@ import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; import android.net.Uri; import android.os.Binder; -import android.provider.BrowserContract; -import android.provider.BrowserContract.Bookmarks; import android.text.TextUtils; import android.util.Log; import android.widget.RemoteViews; import android.widget.RemoteViewsService; -import com.android.browser.BrowserActivity; -import com.android.browser.R; -import com.android.browser.provider.BrowserProvider2; +import com.android.swe.browser.R; +import com.android.swe.browser.BrowserActivity; +import com.android.swe.browser.platformsupport.BrowserContract; +import com.android.swe.browser.platformsupport.BrowserContract.Bookmarks; +import com.android.swe.browser.provider.BrowserProvider2; import java.io.File; import java.io.FilenameFilter; @@ -50,7 +50,7 @@ public class BookmarkThumbnailWidgetService extends RemoteViewsService { static final String TAG = "BookmarkThumbnailWidgetService"; static final String ACTION_CHANGE_FOLDER - = "com.android.browser.widget.CHANGE_FOLDER"; + = "com.android.swe.browser.widget.CHANGE_FOLDER"; static final String STATE_CURRENT_FOLDER = "current_folder"; static final String STATE_ROOT_FOLDER = "root_folder"; @@ -88,8 +88,26 @@ public class BookmarkThumbnailWidgetService extends RemoteViewsService { Context.MODE_PRIVATE); } + static private File mPreferencesDir; + static File getPreferencesDir(Context context) { + if (mPreferencesDir == null) { + mPreferencesDir = new File(context.getApplicationInfo().dataDir, "shared_prefs"); + } + return mPreferencesDir; + } + static File makeFilename(File base, String name) { + if (name.indexOf(File.separatorChar) < 0) { + return new File(base, name); + } + throw new IllegalArgumentException( + "File " + name + " contains a path separator"); + } + static File getSharedPrefsFile(Context context, String name) { + return makeFilename(getPreferencesDir(context), name + ".xml"); + } + static void deleteWidgetState(Context context, int widgetId) { - File file = context.getSharedPrefsFile( + File file = getSharedPrefsFile(context, String.format("widgetState-%d", widgetId)); if (file.exists()) { if (!file.delete()) { @@ -121,7 +139,7 @@ public class BookmarkThumbnailWidgetService extends RemoteViewsService { * Checks for any state files that may have not received onDeleted */ static void removeOrphanedStates(Context context, int[] widgetIds) { - File prefsDirectory = context.getSharedPrefsFile("null").getParentFile(); + File prefsDirectory = getSharedPrefsFile(context, "null").getParentFile(); File[] widgetStates = prefsDirectory.listFiles(new StateFilter(widgetIds)); if (widgetStates != null) { for (File f : widgetStates) { @@ -242,19 +260,24 @@ public class BookmarkThumbnailWidgetService extends RemoteViewsService { if (isFolder) { if (id == mCurrentFolder) { id = mBookmarks.getLong(BOOKMARK_INDEX_PARENT_ID); - views.setImageViewResource(R.id.thumb, R.drawable.thumb_bookmark_widget_folder_back_holo); + views.setImageViewResource(R.id.thumb, + R.drawable.thumb_bookmark_widget_folder_back_holo); } else { - views.setImageViewResource(R.id.thumb, R.drawable.thumb_bookmark_widget_folder_holo); + views.setImageViewResource(R.id.thumb, + R.drawable.thumb_bookmark_widget_folder_holo); } - views.setImageViewResource(R.id.favicon, R.drawable.ic_bookmark_widget_bookmark_holo_dark); - views.setDrawableParameters(R.id.thumb, true, 0, -1, null, -1); + views.setImageViewResource(R.id.favicon, + R.drawable.ic_bookmark_widget_bookmark_holo_dark); + // SWE_TODO : Fix Me + //views.setDrawableParameters(R.id.thumb, true, 0, -1, null, -1); } else { // RemoteViews require a valid bitmap config Options options = new Options(); options.inPreferredConfig = Config.ARGB_8888; Bitmap thumbnail = null, favicon = null; byte[] blob = mBookmarks.getBlob(BOOKMARK_INDEX_THUMBNAIL); - views.setDrawableParameters(R.id.thumb, true, 255, -1, null, -1); + // SWE_TODO : Fix Me + //views.setDrawableParameters(R.id.thumb, true, 255, -1, null, -1); if (blob != null && blob.length > 0) { thumbnail = BitmapFactory.decodeByteArray( blob, 0, blob.length, options); diff --git a/src/com/android/swe/browser/widget/BookmarkWidgetConfigure.java b/src/com/android/swe/browser/widget/BookmarkWidgetConfigure.java index a74bed9c..c51dea54 100644 --- a/src/com/android/swe/browser/widget/BookmarkWidgetConfigure.java +++ b/src/com/android/swe/browser/widget/BookmarkWidgetConfigure.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser.widget; +package com.android.swe.browser.widget; import android.app.ListActivity; import android.app.LoaderManager.LoaderCallbacks; @@ -25,15 +25,15 @@ import android.content.Intent; import android.content.Loader; import android.database.Cursor; import android.os.Bundle; -import android.provider.BrowserContract.Accounts; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; -import com.android.browser.AddBookmarkPage.BookmarkAccount; -import com.android.browser.R; -import com.android.browser.provider.BrowserProvider2; +import com.android.swe.browser.R; +import com.android.swe.browser.AddBookmarkPage.BookmarkAccount; +import com.android.swe.browser.platformsupport.BrowserContract.Accounts; +import com.android.swe.browser.provider.BrowserProvider2; public class BookmarkWidgetConfigure extends ListActivity implements OnClickListener, LoaderCallbacks { diff --git a/src/com/android/swe/browser/widget/BookmarkWidgetProxy.java b/src/com/android/swe/browser/widget/BookmarkWidgetProxy.java index 8ab57fc3..0667686a 100644 --- a/src/com/android/swe/browser/widget/BookmarkWidgetProxy.java +++ b/src/com/android/swe/browser/widget/BookmarkWidgetProxy.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.android.browser.widget; +package com.android.swe.browser.widget; -import com.android.browser.BrowserActivity; +import com.android.swe.browser.BrowserActivity; import android.content.BroadcastReceiver; import android.content.Context; diff --git a/swe_android_browser.gypi b/swe_android_browser.gypi index a200a288..6873fc3e 100644 --- a/swe_android_browser.gypi +++ b/swe_android_browser.gypi @@ -17,9 +17,7 @@ 'resource_dir': '../../swe/browser/res', 'native_lib_target': 'libswewebviewchromium', 'additional_input_paths': ['<(PRODUCT_DIR)/android_webview_apk/assets/webviewchromium.pak'], - 'additional_native_libs': ['<@(libnetxt_native_libs)', - '<@(libsweadrenoext_native_libs)', - '<(SHARED_LIB_DIR)/libswewebviewchromium/libswenetxt_plugin_proxy.so',] + 'additional_native_libs': ['<@(libnetxt_native_libs)'] }, 'copies': [ { diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml index cb1ffc77..68144e24 100644 --- a/tests/AndroidManifest.xml +++ b/tests/AndroidManifest.xml @@ -16,7 +16,7 @@ + package="com.android.swe.browser.tests"> - diff --git a/tests/src/com/android/browser/BrowserLaunchPerformance.java b/tests/src/com/android/browser/BrowserLaunchPerformance.java index c5d4279f..b2d05747 100644 --- a/tests/src/com/android/browser/BrowserLaunchPerformance.java +++ b/tests/src/com/android/browser/BrowserLaunchPerformance.java @@ -1,4 +1,4 @@ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.os.Bundle; @@ -10,7 +10,7 @@ public class BrowserLaunchPerformance extends LaunchPerformanceBase { public void onCreate(Bundle arguments) { super.onCreate(arguments); - mIntent.setClassName(getTargetContext(), "com.android.browser.BrowserActivity"); + mIntent.setClassName(getTargetContext(), "com.android.swe.browser.BrowserActivity"); start(); } diff --git a/tests/src/com/android/browser/BrowserProviderTests.java b/tests/src/com/android/browser/BrowserProviderTests.java index c63cad17..00b7031a 100644 --- a/tests/src/com/android/browser/BrowserProviderTests.java +++ b/tests/src/com/android/browser/BrowserProviderTests.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; -import com.android.browser.provider.BrowserProvider; -import com.android.browser.provider.BrowserProvider2; -import com.android.browser.tests.utils.ProviderTestCase3; +import com.android.swe.browser.provider.BrowserProvider; +import com.android.swe.browser.provider.BrowserProvider2; +import com.android.swe.browser.tests.utils.ProviderTestCase3; import android.app.SearchManager; import android.content.ContentValues; diff --git a/tests/src/com/android/browser/IntentHandlerTests.java b/tests/src/com/android/browser/IntentHandlerTests.java index 2bdadaeb..f870363d 100644 --- a/tests/src/com/android/browser/IntentHandlerTests.java +++ b/tests/src/com/android/browser/IntentHandlerTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Activity; import android.content.Intent; @@ -21,7 +21,7 @@ import android.net.Uri; import android.provider.Browser; import android.test.ActivityInstrumentationTestCase2; import android.text.TextUtils; -import android.webkit.WebView; +import org.codeaurora.swe.WebView; public class IntentHandlerTests extends ActivityInstrumentationTestCase2 { diff --git a/tests/src/com/android/browser/PopularUrlsTest.java b/tests/src/com/android/browser/PopularUrlsTest.java index 566d74b8..8e46f5d0 100644 --- a/tests/src/com/android/browser/PopularUrlsTest.java +++ b/tests/src/com/android/browser/PopularUrlsTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.browser; +package com.android.swe.browser; import android.app.Instrumentation; import android.content.Intent; @@ -31,8 +31,7 @@ import android.webkit.HttpAuthHandler; import android.webkit.JsPromptResult; import android.webkit.JsResult; import android.webkit.SslErrorHandler; -import android.webkit.WebView; -import android.webkit.WebViewClassic; +import android.webkit.WebViewClassic import java.io.BufferedReader; import java.io.File; @@ -47,6 +46,7 @@ import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.codeaurora.swe.WebView; /** * * Iterates over a list of URLs from a file and outputs the time to load each. @@ -248,9 +248,6 @@ public class PopularUrlsTest extends ActivityInstrumentationTestCase2 extends Andro * Sets up the environment for the test fixture. *

* Creates a new - * {@link com.android.browser.tests.utils.MockContentResolver2}, a new IsolatedContext + * {@link com.android.swe.browser.tests.utils.MockContentResolver2}, a new IsolatedContext * that isolates the provider's file operations, and a new instance of * the provider under test within the isolated environment. *

-- cgit v1.2.3