Commit a64aba08 authored by Christian Sadilek's avatar Christian Sadilek
Browse files

Closes #5944: Allow addons to specify how to open options_ui

parent e54597e2
......@@ -94,7 +94,8 @@ data class Addon(
data class InstalledState(
val id: String,
val version: String,
val optionsPageUrl: String,
val optionsPageUrl: String?,
val openOptionsPageInTab: Boolean = false,
val enabled: Boolean = false,
val supported: Boolean = true,
val disabledAsUnsupported: Boolean = false
......
......@@ -279,7 +279,8 @@ private fun WebExtension.toInstalledState() =
Addon.InstalledState(
id = id,
version = getMetadata()?.version ?: "",
optionsPageUrl = getMetadata()?.optionsPageUrl ?: "",
optionsPageUrl = getMetadata()?.optionsPageUrl,
openOptionsPageInTab = getMetadata()?.openOptionsPageInTab ?: false,
enabled = isEnabled(),
disabledAsUnsupported = getMetadata()?.disabledFlags?.contains(DisabledFlags.APP_SUPPORT) == true
)
......@@ -106,6 +106,7 @@ class AddonManagerTest {
whenever(newlySupportedExtension.isEnabled()).thenReturn(false)
whenever(metadata.disabledFlags).thenReturn(DisabledFlags.select(DisabledFlags.APP_SUPPORT))
whenever(metadata.optionsPageUrl).thenReturn("http://options-page.moz")
whenever(metadata.openOptionsPageInTab).thenReturn(true)
whenever(newlySupportedExtension.id).thenReturn("ext3")
whenever(newlySupportedExtension.url).thenReturn("site_url")
whenever(newlySupportedExtension.getMetadata()).thenReturn(metadata)
......@@ -127,6 +128,8 @@ class AddonManagerTest {
assertEquals("ext1", addons[0].installedState!!.id)
assertTrue(addons[0].isEnabled())
assertFalse(addons[0].isDisabledAsUnsupported())
assertNull(addons[0].installedState!!.optionsPageUrl)
assertFalse(addons[0].installedState!!.openOptionsPageInTab)
assertEquals("ext2", addons[1].id)
assertNull(addons[1].installedState)
......@@ -140,6 +143,7 @@ class AddonManagerTest {
assertFalse(addons[2].isEnabled())
assertTrue(addons[2].isDisabledAsUnsupported())
assertEquals("http://options-page.moz", addons[2].installedState!!.optionsPageUrl)
assertTrue(addons[2].installedState!!.openOptionsPageInTab)
// Verify the unsupported add-on was included in addons
assertEquals("unsupported_ext", addons[3].id)
......
......@@ -62,7 +62,9 @@ class AddonSettingsActivity : AppCompatActivity() {
super.onViewCreated(view, savedInstanceState)
addonSettingsEngineView.render(engineSession)
engineSession.loadUrl(addon.installedState!!.optionsPageUrl)
addon.installedState?.optionsPageUrl?.let {
engineSession.loadUrl(it)
}
}
override fun onDestroyView() {
......
......@@ -14,8 +14,9 @@ import androidx.appcompat.app.AppCompatActivity
import mozilla.components.feature.addons.Addon
import mozilla.components.feature.addons.ui.translate
import mozilla.components.feature.addons.ui.translatedName
import org.mozilla.samples.browser.R
import org.mozilla.samples.browser.ext.components
import org.mozilla.samples.browser.BrowserActivity
import org.mozilla.samples.browser.R
/**
* An activity to show the details of a installed add-on.
......@@ -93,13 +94,21 @@ class InstalledAddonDetailsActivity : AppCompatActivity() {
}
}
private fun bindSettings(addOn: Addon) {
private fun bindSettings(addon: Addon) {
val view = findViewById<View>(R.id.settings)
view.isEnabled = addOn.installedState?.optionsPageUrl != null
val optionsPageUrl = addon.installedState?.optionsPageUrl
view.isEnabled = optionsPageUrl != null
view.setOnClickListener {
val intent = Intent(this, AddonSettingsActivity::class.java)
intent.putExtra("add_on", addOn)
this.startActivity(intent)
if (addon.installedState?.openOptionsPageInTab == true) {
components.tabsUseCases.addTab(optionsPageUrl as String)
val intent = Intent(this, BrowserActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
this.startActivity(intent)
} else {
val intent = Intent(this, AddonSettingsActivity::class.java)
intent.putExtra("add_on", addon)
this.startActivity(intent)
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment