Skip to content

Commit

Permalink
Merge branch 'hotfix/4.0.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
subsymbolic committed Jan 23, 2018
2 parents 79a8c23 + 4b38391 commit 7d85c20
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 38 deletions.
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'kotlin-kapt'
apply from: '../versioning.gradle'

ext {
VERSION_NAME = "4.0.8"
VERSION_NAME = "4.0.9"
}

android {
Expand Down Expand Up @@ -79,6 +79,9 @@ ext {


dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "com.android.support:appcompat-v7:$supportLibrary"
Expand Down
48 changes: 38 additions & 10 deletions app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ import android.arch.lifecycle.ViewModelProviders
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.text.Editable
import android.view.KeyEvent.KEYCODE_ENTER
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.View.FOCUSABLE
import android.view.inputmethod.EditorInfo.IME_ACTION_DONE
import android.webkit.CookieManager
import android.webkit.WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE
import android.webkit.WebView
import android.widget.TextView
import android.widget.Toast
import com.duckduckgo.app.bookmarks.ui.BookmarksActivity
Expand Down Expand Up @@ -79,11 +82,43 @@ class BrowserActivity : DuckDuckGoActivity() {
private val fireMenu: MenuItem?
get() = toolbar.menu.findItem(R.id.fire_menu_item)

private lateinit var webView: WebView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_browser)

createWebView()
createPopupMenu()
configureObservers()
configureToolbar()
configureWebView()
configureOmnibarTextInput()
configureDummyViewTouchHandler()
configureAutoComplete()

if (savedInstanceState == null) {
consumeSharedTextExtra()
}
}

private fun createPopupMenu() {
popupMenu = BrowserPopupMenu(layoutInflater)
}

// inspired by https://stackoverflow.com/a/8011027/73479
private fun createWebView() {
webView = NestedWebView(this.applicationContext)
webView.gone()
webView.isFocusableInTouchMode = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
webView.focusable = FOCUSABLE
}
webViewContainer.addView(webView)
}

private fun configureObservers() {
viewModel.viewState.observe(this, Observer<BrowserViewModel.ViewState> {
it?.let { render(it) }
})
Expand Down Expand Up @@ -122,16 +157,6 @@ class BrowserActivity : DuckDuckGoActivity() {
}
}
})

configureToolbar()
configureWebView()
configureOmnibarTextInput()
configureDummyViewTouchHandler()
configureAutoComplete()

if (savedInstanceState == null) {
consumeSharedTextExtra()
}
}

private fun configureAutoComplete() {
Expand Down Expand Up @@ -435,6 +460,9 @@ class BrowserActivity : DuckDuckGoActivity() {
}

override fun onDestroy() {
webViewContainer.removeAllViews()
webView.destroy()

popupMenu.dismiss()
super.onDestroy()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BrowserWebViewClient @Inject constructor(
) : WebViewClient() {

var webViewClientListener: WebViewClientListener? = null

var currentUrl: String? = null

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

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

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

if (shouldUpgrade(request)) {
val newUri = httpsUpgrader.upgrade(request.url)
view.post { view.loadUrl(newUri.toString()) }
return WebResourceResponse(null, null, null)
}

val documentUrl = view.urlFromAnyThread() ?: return null
val documentUrl = currentUrl ?: return null

if (TrustedSites.isTrusted(documentUrl)) {
return null
Expand Down Expand Up @@ -138,26 +139,9 @@ class BrowserWebViewClient @Inject constructor(
* Utility to function to execute a function, and then return true
*
* Useful to reduce clutter in repeatedly including `return true` after doing the real work.
*/
*/
private inline fun consume(function: () -> Unit): Boolean {
function()
return true
}

/**
* Access WebView.url from any thread. If you are on the main thread it is more efficient to use
* WebView.url directly.
*/
@AnyThread
private fun WebView.urlFromAnyThread(): String? {
val latch = CountDownLatch(1)
var safeUrl: String? = null
post {
safeUrl = url
latch.countDown()
}
latch.await()
return safeUrl
}

}
2 changes: 2 additions & 0 deletions app/src/main/java/com/duckduckgo/app/browser/NestedWebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.duckduckgo.app.browser

import android.annotation.SuppressLint
import android.content.Context
import android.support.v4.view.NestedScrollingChild
import android.support.v4.view.NestedScrollingChildHelper
Expand Down Expand Up @@ -44,6 +45,7 @@ class NestedWebView : WebView, NestedScrollingChild {
isNestedScrollingEnabled = true
}

@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(ev: MotionEvent): Boolean {
var returnValue = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.duckduckgo.app.di.DaggerAppComponent
import com.duckduckgo.app.job.AppConfigurationSyncer
import com.duckduckgo.app.migration.LegacyMigration
import com.duckduckgo.app.trackerdetection.TrackerDataLoader
import com.squareup.leakcanary.LeakCanary
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasActivityInjector
Expand Down Expand Up @@ -56,6 +57,8 @@ class DuckDuckGoApplication : HasActivityInjector, HasServiceInjector, Applicati
override fun onCreate() {
super.onCreate()

if (!installLeakCanary()) return

configureDependencyInjection()
configureLogging()
configureCrashReporting()
Expand All @@ -66,6 +69,14 @@ class DuckDuckGoApplication : HasActivityInjector, HasServiceInjector, Applicati
migrateLegacyDb()
}

private fun installLeakCanary(): Boolean {
if (LeakCanary.isInAnalyzerProcess(this)) {
return false;
}
LeakCanary.install(this);
return true
}

private fun migrateLegacyDb() {
doAsync {
migration.start { favourites, searches ->
Expand Down
9 changes: 3 additions & 6 deletions app/src/main/res/layout/activity_browser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,12 @@
android:layout_height="match_parent"
android:focusableInTouchMode="true" />

<com.duckduckgo.app.browser.NestedWebView
android:id="@+id/webView"
<FrameLayout
android:id="@+id/webViewContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:visibility="visible" />
/>

<android.support.v7.widget.RecyclerView
android:id="@+id/autoCompleteSuggestionsList"
Expand Down

0 comments on commit 7d85c20

Please sign in to comment.