Skip to content

Commit

Permalink
Fixes mozilla-mobile#3564 - Send Search Privately Intent to IntentRec…
Browse files Browse the repository at this point in the history
…eiverActivity
  • Loading branch information
ekager committed Oct 9, 2018
1 parent 308093e commit 2f34456
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ open class MainActivity : LocaleAwareAppCompatActivity() {
const val ACTION_ERASE = "erase"
const val ACTION_OPEN = "open"

const val EXTRA_TEXT_SELECTION = "text_selection"
const val EXTRA_NOTIFICATION = "notification"

private const val EXTRA_SHORTCUT = "shortcut"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ class TextActionActivity : Activity() {
} else {
""
}

val searchUrl = UrlUtils.createSearchUrl(this, searchText)

val searchIntent = Intent(this, MainActivity::class.java)
val searchIntent = Intent(this, IntentReceiverActivity::class.java)
searchIntent.action = Intent.ACTION_VIEW
searchIntent.putExtra(MainActivity.EXTRA_TEXT_SELECTION, true)
searchIntent.putExtra(EXTRA_TEXT_SELECTION, true)
searchIntent.data = Uri.parse(searchUrl)

startActivity(searchIntent)

finish()
}

companion object {
const val EXTRA_TEXT_SELECTION = "text_selection"
}
}
36 changes: 25 additions & 11 deletions app/src/main/java/org/mozilla/focus/session/IntentProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.tab.CustomTabConfig
import mozilla.components.support.utils.SafeIntent
import mozilla.components.support.utils.WebURLFinder
import org.mozilla.focus.activity.TextActionActivity
import org.mozilla.focus.ext.shouldRequestDesktopSite
import org.mozilla.focus.shortcut.HomeScreen
import org.mozilla.focus.utils.UrlUtils
Expand Down Expand Up @@ -63,18 +64,31 @@ class IntentProcessor(
return null
}

return if (intent.hasExtra(HomeScreen.ADD_TO_HOMESCREEN_TAG)) {
val blockingEnabled = intent.getBooleanExtra(HomeScreen.BLOCKING_ENABLED, true)
val requestDesktop = intent.getBooleanExtra(HomeScreen.REQUEST_DESKTOP, false)

createSession(
Session.Source.HOME_SCREEN,
return when {
intent.hasExtra(HomeScreen.ADD_TO_HOMESCREEN_TAG) -> {
val blockingEnabled =
intent.getBooleanExtra(HomeScreen.BLOCKING_ENABLED, true)
val requestDesktop =
intent.getBooleanExtra(HomeScreen.REQUEST_DESKTOP, false)

createSession(
Session.Source.HOME_SCREEN,
intent,
intent.dataString ?: "",
blockingEnabled,
requestDesktop
)
}
intent.hasExtra(TextActionActivity.EXTRA_TEXT_SELECTION) -> createSession(
Session.Source.TEXT_SELECTION,
intent,
intent.dataString ?: "",
blockingEnabled,
requestDesktop)
} else {
createSession(Session.Source.ACTION_VIEW, intent, intent.dataString ?: "")
intent.dataString ?: ""
)
else -> createSession(
Session.Source.ACTION_VIEW,
intent,
intent.dataString ?: ""
)
}
}

Expand Down

0 comments on commit 2f34456

Please sign in to comment.