<commit_before>/****************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Contact: <NAME> <<EMAIL>>
**
****************************************************************************/

/* 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/. */

import QtQuick 2.1
import Sailfish.Browser 1.0
import "WebViewTabCache.js" as TabCache

TabModel {
    property Component webViewComponent
    property Item contentItem
    property Item webViewContainer

    // Load goes so that we first use engine load to resolve url
    // and then save that resolved url to the history. This way
    // urls that resolve to download urls won't get saved to the
    // history (as those won't trigger url change). By doing this way
    // a redirected url will be saved with the redirected url not with
    // the input url.
    property var _newTabData

    function newTab(url, title) {
        // Url is not need in model._newTabData as we let engine to resolve
        // the url and use the resolved url.
        _newTabData = { "url": url, "title": title, "previousView": webViewContainer.contentItem }
        webViewContainer.load(url, title)
    }

    // TODO: Check could this be merged with activateTab(tabId)
    // TabModel could keep also TabCache internally.
    function activateView(tabId) {
        if (!TabCache.initialized) {
            TabCache.init({"tab": currentTab, "container": webViewContainer},
                          webViewComponent, webViewContainer)
        }

        if (tabId > 0 || !webViewContainer.contentItem || webViewContainer.contentItem.tabId !== tabId) {
            webViewContainer.contentItem = TabCache.getView(tabId)
            return true
        }
        return false
    }

    function releaseView(tabId) {
        TabCache.releaseView(tabId)
        if (count == 0) {
            webViewContainer.contentItem = null
        }
    }

    // arguments of the signal handler: int tabId
    onActiveTabChanged: {
        if (_newTabData) {
            webViewContainer.currentTabChanged()
            return
        }

        activateView(tabId)

        // When all tabs are closed, we're in invalid state.
        if (currentTab.valid && webViewContainer._readyToLoad &&
                (contentItem.tabId !== tabId || currentTab.url != contentItem.url)) {
            webViewContainer.load(currentTab.url, currentTab.title)
        }<commit_msg>Guard loading of active tab so that we have always a view<commit_after>/****************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Contact: <NAME> <<EMAIL>>
**
****************************************************************************/

/* 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/. */

import QtQuick 2.1
import Sailfish.Browser 1.0
import "WebViewTabCache.js" as TabCache

TabModel {
    property Component webViewComponent
    property Item contentItem
    property Item webViewContainer

    // Load goes so that we first use engine load to resolve url
    // and then save that resolved url to the history. This way
    // urls that resolve to download urls won't get saved to the
    // history (as those won't trigger url change). By doing this way
    // a redirected url will be saved with the redirected url not with
    // the input url.
    property var _newTabData

    function newTab(url, title) {
        // Url is not need in model._newTabData as we let engine to resolve
        // the url and use the resolved url.
        _newTabData = { "url": url, "title": title, "previousView": webViewContainer.contentItem }
        webViewContainer.load(url, title)
    }

    // TODO: Check could this be merged with activateTab(tabId)
    // TabModel could keep also TabCache internally.
    function activateView(tabId) {
        if (!TabCache.initialized) {
            TabCache.init({"tab": currentTab, "container": webViewContainer},
                          webViewComponent, webViewContainer)
        }

        if (tabId > 0 || !webViewContainer.contentItem || webViewContainer.contentItem.tabId !== tabId) {
            webViewContainer.contentItem = TabCache.getView(tabId)
            return true
        }
        return false
    }

    function releaseView(tabId) {
        TabCache.releaseView(tabId)
        if (count == 0) {
            webViewContainer.contentItem = null
        }
    }

    // arguments of the signal handler: int tabId
    onActiveTabChanged: {
        if (_newTabData) {
            webViewContainer.currentTabChanged()
            return
        }

        console.log("active tab changed: ", tabId)
        // When all tabs are closed tabId is invalid and view will not get activated.
        if (activateView(tabId) && currentTab.valid && webViewContainer._readyToLoad &&
                (contentItem.tabId !== tabId || currentTab.url != contentItem.url)) {
            webViewContainer.load(currentTab.url, currentTab.title)
        }
{'fraction_non_alphanumeric': 0.13964474678760394, 'fraction_numerical': 0.005291005291005291, 'mean_word_length': 2.622861054072553, 'pattern_counts': {'":': 10, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7370963', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1343, 'n_words': 484}