<commit_before>// (C) Copyright 2015 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

angular.module('mm.core')

/**
 * Directive to handle external content.
 *
 * @module mm.core
 * @ngdoc directive
 * @name mmExternalContent
 * @description
 * Directive to handle external content.
 *
 * This directive should be used with any element that links to external content
 * which we want to have available when the app is offline. Typically images and links.
 *
 * It uses {@link $mmFilepool} in the background.
 *
 * Attributes accepted:
 *     - siteid: Reference to the site ID if different than the site the user is connected to.
 */
.directive('mmExternalContent', function($log, $mmFilepool, $mmSite, $mmSitesManager, $mmUtil, $q, $mmApp) {
    $log = $log.getInstance('mmExternalContent');

    /**
     * Add a new source with a certain URL.
     *
     * @param {Object} dom Current source element. The new source will be a sibling of this element.
     * @param {String} url URL to use in the source.
     */
    function addSource(dom, url) {
        if (dom.tagName !== 'SOURCE') {
            return;
        }

        var e = document.createElement('source'),
            type = dom.getAttribute('type');
        e.setAttribute('src', url);
        if (type) {
            e.setAttribute('type', type);
        }
        dom.parentNode.insertBefore(e, dom);
    }

    /**
     * Handle external content, setting the right URL.
     *
     * @param  {String} siteId        Site ID.
     * @param  {Object} dom           DOM element.
     * @param  {String} targetAttr    Attribute to modify.
     * @param  {String} url           Original URL to treat.
     * @param  {String} [component]   Component
     * @param  {Number} [componentId] Component ID.
     * @return {Promise}              Promise resolved if the element is successfully treated.
     */
    function handleExternalContent(siteId, dom, targetAttr, url, component, componentId) {

        if (!url || !$mmUtil.isDownloadableUrl(url)) {
            $log.debug('Ignoring non-downloadable URL: ' + url);
            if (dom.tagName === 'SOURCE') {
                // Restoring original src.
                addSource(dom, url);
            }
            return $q.reject();
        }<commit_msg>MOBILE-1888 external-content: Display quicktime video as mp4 on Android<commit_after>// (C) Copyright 2015 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

angular.module('mm.core')

/**
 * Directive to handle external content.
 *
 * @module mm.core
 * @ngdoc directive
 * @name mmExternalContent
 * @description
 * Directive to handle external content.
 *
 * This directive should be used with any element that links to external content
 * which we want to have available when the app is offline. Typically images and links.
 *
 * It uses {@link $mmFilepool} in the background.
 *
 * Attributes accepted:
 *     - siteid: Reference to the site ID if different than the site the user is connected to.
 */
.directive('mmExternalContent', function($log, $mmFilepool, $mmSite, $mmSitesManager, $mmUtil, $q, $mmApp) {
    $log = $log.getInstance('mmExternalContent');

    /**
     * Add a new source with a certain URL.
     *
     * @param {Object} dom Current source element. The new source will be a sibling of this element.
     * @param {String} url URL to use in the source.
     */
    function addSource(dom, url) {
        if (dom.tagName !== 'SOURCE') {
            return;
        }

        var e = document.createElement('source'),
            type = dom.getAttribute('type');
        e.setAttribute('src', url);
        if (type) {
            if (ionic.Platform.isAndroid() && type == 'video/quicktime') {
                // Fix for VideoJS/Chrome bug https://github.com/videojs/video.js/issues/423 .
                e.setAttribute('type', 'video/mp4');
            } else {
                e.setAttribute('type', type);
            }
        }
        dom.parentNode.insertBefore(e, dom);
    }

    /**
     * Handle external content, setting the right URL.
     *
     * @param  {String} siteId        Site ID.
     * @param  {Object} dom           DOM element.
     * @param  {String} targetAttr    Attribute to modify.
     * @param  {String} url           Original URL to treat.
     * @param  {String} [component]   Component
     * @param  {Number} [componentId] Component ID.
     * @return {Promise}              Promise resolved if the element is successfully treated.
     */
    function handleExternalContent(siteId, dom, targetAttr, url, component, componentId) {

        if (!url || !$mmUtil.isDownloadableUrl(url)) {
            $log.debug('Ignoring non-downloadable URL: ' + url);
            if (dom.tagName === 'SOURCE') {
                // Restoring original src.
                addSource(dom, url);
            }
            return $q.reject();
        }
{'fraction_non_alphanumeric': 0.11007462686567164, 'fraction_numerical': 0.004240162822252374, 'mean_word_length': 2.40080738177624, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2636037', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1575, 'n_words': 600}