<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.focus.activity

import android.os.Bundle
import mozilla.components.browser.session.Session
import mozilla.components.support.utils.SafeIntent
import org.mozilla.focus.ext.components
import org.mozilla.focus.session.removeAndCloseSession

/**
 * The main entry point for "custom tabs" opened by third-party apps.
 */
class CustomTabActivity : MainActivity() {
    private lateinit var customTabId: String

    private val customTabSession: Session by lazy {
        components.sessionManager.findSessionById(customTabId)
            ?: throw IllegalAccessError("No session wiht id $customTabId")
    }

    override val currentSessionForActivity: Session by lazy { customTabSession }

    override val isCustomTabMode: Boolean = true

    override fun onCreate(savedInstanceState: Bundle?) {
        val intent = SafeIntent(intent)
        customTabId = intent.getStringExtra(CUSTOM_TAB_ID)
            ?: throw IllegalAccessError("No custom tab id in intent")

        // The session for this ID, no longer exists. This usually happens because we were gc-d
        // and since we do not save custom tab sessions, the activity is re-created and we no longer
        // have a session with us to restore. It's safer to finish the activity instead.
        if (components.sessionManager.findSessionById(customTabId) == null) {
            finish()
        }

        super.onCreate(savedInstanceState)
    }

    override fun onPause() {
        super.onPause()

        if (isFinishing && customTabSession.isCustomTabSession()) {
            // This may not be a custom tab session anymore ("open in firefox focus"). So only remove it if this
            // activity is finishing and this is still a custom tab session.
            components.sessionManager.removeAndCloseSession(customTabSession)
        }
    }
    companion object {
        const val CUSTOM_TAB_ID = "custom_tab_id"
    }
}<commit_msg>Closes #4597: Early return after finishing CustomTabActivity<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.focus.activity

import android.os.Bundle
import mozilla.components.browser.session.Session
import mozilla.components.support.utils.SafeIntent
import org.mozilla.focus.ext.components
import org.mozilla.focus.session.removeAndCloseSession

/**
 * The main entry point for "custom tabs" opened by third-party apps.
 */
class CustomTabActivity : MainActivity() {
    private lateinit var customTabId: String

    private val customTabSession: Session by lazy {
        components.sessionManager.findSessionById(customTabId)
            ?: throw IllegalAccessError("No session wiht id $customTabId")
    }

    override val currentSessionForActivity: Session by lazy { customTabSession }

    override val isCustomTabMode: Boolean = true

    override fun onCreate(savedInstanceState: Bundle?) {
        val intent = SafeIntent(intent)
        customTabId = intent.getStringExtra(CUSTOM_TAB_ID)
            ?: throw IllegalAccessError("No custom tab id in intent")

        // The session for this ID, no longer exists. This usually happens because we were gc-d
        // and since we do not save custom tab sessions, the activity is re-created and we no longer
        // have a session with us to restore. It's safer to finish the activity instead.
        if (components.sessionManager.findSessionById(customTabId) == null) {
            finish()
            return
        }

        super.onCreate(savedInstanceState)
    }

    override fun onPause() {
        super.onPause()

        if (isFinishing && customTabSession.isCustomTabSession()) {
            // This may not be a custom tab session anymore ("open in firefox focus"). So only remove it if this
            // activity is finishing and this is still a custom tab session.
            components.sessionManager.removeAndCloseSession(customTabSession)
        }
    }
    companion object {
        const val CUSTOM_TAB_ID = "custom_tab_id"
    }
}
{'fraction_non_alphanumeric': 0.07480495640201927, 'fraction_numerical': 0.0027535566773749425, 'mean_word_length': 2.9844606946983547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '374594', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1102, 'n_words': 411}