Skip to content

Commit 7d85c20

Browse files
committed
Merge branch 'hotfix/4.0.9'
2 parents 79a8c23 + 4b38391 commit 7d85c20

File tree

6 files changed

+63
-38
lines changed

6 files changed

+63
-38
lines changed

app/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ apply plugin: 'kotlin-kapt'
66
apply from: '../versioning.gradle'
77

88
ext {
9-
VERSION_NAME = "4.0.8"
9+
VERSION_NAME = "4.0.9"
1010
}
1111

1212
android {
@@ -79,6 +79,9 @@ ext {
7979

8080

8181
dependencies {
82+
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4'
83+
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
84+
8285
implementation fileTree(dir: 'libs', include: ['*.jar'])
8386
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
8487
implementation "com.android.support:appcompat-v7:$supportLibrary"

app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ import android.arch.lifecycle.ViewModelProviders
2424
import android.content.Context
2525
import android.content.Intent
2626
import android.net.Uri
27+
import android.os.Build
2728
import android.os.Bundle
2829
import android.support.v7.widget.LinearLayoutManager
2930
import android.text.Editable
3031
import android.view.KeyEvent.KEYCODE_ENTER
3132
import android.view.Menu
3233
import android.view.MenuItem
3334
import android.view.View
35+
import android.view.View.FOCUSABLE
3436
import android.view.inputmethod.EditorInfo.IME_ACTION_DONE
3537
import android.webkit.CookieManager
3638
import android.webkit.WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE
39+
import android.webkit.WebView
3740
import android.widget.TextView
3841
import android.widget.Toast
3942
import com.duckduckgo.app.bookmarks.ui.BookmarksActivity
@@ -79,11 +82,43 @@ class BrowserActivity : DuckDuckGoActivity() {
7982
private val fireMenu: MenuItem?
8083
get() = toolbar.menu.findItem(R.id.fire_menu_item)
8184

85+
private lateinit var webView: WebView
86+
8287
override fun onCreate(savedInstanceState: Bundle?) {
8388
super.onCreate(savedInstanceState)
89+
8490
setContentView(R.layout.activity_browser)
91+
92+
createWebView()
93+
createPopupMenu()
94+
configureObservers()
95+
configureToolbar()
96+
configureWebView()
97+
configureOmnibarTextInput()
98+
configureDummyViewTouchHandler()
99+
configureAutoComplete()
100+
101+
if (savedInstanceState == null) {
102+
consumeSharedTextExtra()
103+
}
104+
}
105+
106+
private fun createPopupMenu() {
85107
popupMenu = BrowserPopupMenu(layoutInflater)
108+
}
86109

110+
// inspired by https://stackoverflow.com/a/8011027/73479
111+
private fun createWebView() {
112+
webView = NestedWebView(this.applicationContext)
113+
webView.gone()
114+
webView.isFocusableInTouchMode = true
115+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
116+
webView.focusable = FOCUSABLE
117+
}
118+
webViewContainer.addView(webView)
119+
}
120+
121+
private fun configureObservers() {
87122
viewModel.viewState.observe(this, Observer<BrowserViewModel.ViewState> {
88123
it?.let { render(it) }
89124
})
@@ -122,16 +157,6 @@ class BrowserActivity : DuckDuckGoActivity() {
122157
}
123158
}
124159
})
125-
126-
configureToolbar()
127-
configureWebView()
128-
configureOmnibarTextInput()
129-
configureDummyViewTouchHandler()
130-
configureAutoComplete()
131-
132-
if (savedInstanceState == null) {
133-
consumeSharedTextExtra()
134-
}
135160
}
136161

137162
private fun configureAutoComplete() {
@@ -435,6 +460,9 @@ class BrowserActivity : DuckDuckGoActivity() {
435460
}
436461

437462
override fun onDestroy() {
463+
webViewContainer.removeAllViews()
464+
webView.destroy()
465+
438466
popupMenu.dismiss()
439467
super.onDestroy()
440468
}

app/src/main/java/com/duckduckgo/app/browser/BrowserWebViewClient.kt

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class BrowserWebViewClient @Inject constructor(
4242
) : WebViewClient() {
4343

4444
var webViewClientListener: WebViewClientListener? = null
45-
45+
var currentUrl: String? = null
4646

4747
/**
4848
* This is the new method of url overriding available from API 24 onwards
@@ -84,6 +84,7 @@ class BrowserWebViewClient @Inject constructor(
8484
}
8585

8686
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
87+
currentUrl = url
8788
webViewClientListener?.loadingStarted()
8889
webViewClientListener?.urlChanged(url)
8990
}
@@ -94,15 +95,15 @@ class BrowserWebViewClient @Inject constructor(
9495

9596
@WorkerThread
9697
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
97-
Timber.v("Intercepting resource ${request.url} on page ${view.urlFromAnyThread()}}")
98+
Timber.v("Intercepting resource ${request.url} on page ${currentUrl}}")
9899

99100
if (shouldUpgrade(request)) {
100101
val newUri = httpsUpgrader.upgrade(request.url)
101102
view.post { view.loadUrl(newUri.toString()) }
102103
return WebResourceResponse(null, null, null)
103104
}
104105

105-
val documentUrl = view.urlFromAnyThread() ?: return null
106+
val documentUrl = currentUrl ?: return null
106107

107108
if (TrustedSites.isTrusted(documentUrl)) {
108109
return null
@@ -138,26 +139,9 @@ class BrowserWebViewClient @Inject constructor(
138139
* Utility to function to execute a function, and then return true
139140
*
140141
* Useful to reduce clutter in repeatedly including `return true` after doing the real work.
141-
*/
142+
*/
142143
private inline fun consume(function: () -> Unit): Boolean {
143144
function()
144145
return true
145146
}
146-
147-
/**
148-
* Access WebView.url from any thread. If you are on the main thread it is more efficient to use
149-
* WebView.url directly.
150-
*/
151-
@AnyThread
152-
private fun WebView.urlFromAnyThread(): String? {
153-
val latch = CountDownLatch(1)
154-
var safeUrl: String? = null
155-
post {
156-
safeUrl = url
157-
latch.countDown()
158-
}
159-
latch.await()
160-
return safeUrl
161-
}
162-
163147
}

app/src/main/java/com/duckduckgo/app/browser/NestedWebView.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.duckduckgo.app.browser
1818

19+
import android.annotation.SuppressLint
1920
import android.content.Context
2021
import android.support.v4.view.NestedScrollingChild
2122
import android.support.v4.view.NestedScrollingChildHelper
@@ -44,6 +45,7 @@ class NestedWebView : WebView, NestedScrollingChild {
4445
isNestedScrollingEnabled = true
4546
}
4647

48+
@SuppressLint("ClickableViewAccessibility")
4749
override fun onTouchEvent(ev: MotionEvent): Boolean {
4850
var returnValue = false
4951

app/src/main/java/com/duckduckgo/app/global/DuckDuckGoApplication.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.duckduckgo.app.di.DaggerAppComponent
2424
import com.duckduckgo.app.job.AppConfigurationSyncer
2525
import com.duckduckgo.app.migration.LegacyMigration
2626
import com.duckduckgo.app.trackerdetection.TrackerDataLoader
27+
import com.squareup.leakcanary.LeakCanary
2728
import dagger.android.AndroidInjector
2829
import dagger.android.DispatchingAndroidInjector
2930
import dagger.android.HasActivityInjector
@@ -56,6 +57,8 @@ class DuckDuckGoApplication : HasActivityInjector, HasServiceInjector, Applicati
5657
override fun onCreate() {
5758
super.onCreate()
5859

60+
if (!installLeakCanary()) return
61+
5962
configureDependencyInjection()
6063
configureLogging()
6164
configureCrashReporting()
@@ -66,6 +69,14 @@ class DuckDuckGoApplication : HasActivityInjector, HasServiceInjector, Applicati
6669
migrateLegacyDb()
6770
}
6871

72+
private fun installLeakCanary(): Boolean {
73+
if (LeakCanary.isInAnalyzerProcess(this)) {
74+
return false;
75+
}
76+
LeakCanary.install(this);
77+
return true
78+
}
79+
6980
private fun migrateLegacyDb() {
7081
doAsync {
7182
migration.start { favourites, searches ->

app/src/main/res/layout/activity_browser.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,12 @@
140140
android:layout_height="match_parent"
141141
android:focusableInTouchMode="true" />
142142

143-
<com.duckduckgo.app.browser.NestedWebView
144-
android:id="@+id/webView"
143+
<FrameLayout
144+
android:id="@+id/webViewContainer"
145145
android:layout_width="match_parent"
146146
android:layout_height="match_parent"
147-
android:focusable="true"
148-
android:focusableInTouchMode="true"
149-
android:visibility="gone"
150147
app:layout_behavior="@string/appbar_scrolling_view_behavior"
151-
tools:visibility="visible" />
148+
/>
152149

153150
<android.support.v7.widget.RecyclerView
154151
android:id="@+id/autoCompleteSuggestionsList"

0 commit comments

Comments
 (0)