<commit_before>/*global fetch, Promise, Clipboard*/
'use strict';

class TimelineUrl {
	constructor(win) {

		this.input = win['timeline-url'];
		this.result = win.result;
		this.generateBtn = win.generateBtn;
		this.confirmation = win.confirmation;
		this.resultsDiv = win.results;

		this.inputUrl = undefined;
		this.outputUrl = undefined;

		this.isUrlCORS = false;
		this.revInfo = {};

		this.generateUrl();
	}

	getRevs() {
		var chromeVersion = navigator.appVersion.replace(/.+Chrome\/(.+) .+/, '$1');

		var revInfo = {};
		var revUrls = ['https://omahaproxy.appspot.com/revision.json?version=',
			'https://omahaproxy.appspot.com/webkit.json?version='];

		// take our two URLs, fetch them in parallel, parse to JSON, and merge.
		return revUrls.map(function (url) {
			return fetch(url + chromeVersion);
		}).reduce(function handleJSON(chain, revPromise) {
			return revPromise.then(function (payload) {
				return payload.json();
			}).then(function (json) {
				return Object.assign(revInfo, json);
			});
		}, Promise.resolve()).then(function(revInfo){
			// {"chromium_base_position":"338390","blink_position":"198714", …
			this.revInfo = revInfo;
		}.bind(this));

	}

	getUrl(url) {

		var chromeRev = this.revInfo.chromium_base_position;
		var blinkRev = this.revInfo.blink_position;

		return [
			this.isUrlCORS ? 'https://frontend.chrome-dev.tools/serve_rev/@' :
				'chrome-devtools://devtools/remote/serve_rev/@',

			blinkRev, // e.g. 198714

			// Devtools previously used devtools.html : codereview.chromium.org/1144393004/
			chromeRev < 332419 ? '/devtools.html' : '/inspector.html',

			'?loadTimelineFromURL=', url
		].join('');
	}

	checkForCORS() {

		// if the URL is CORS-y we can do a clickable URL
		return window.fetch(this.inputUrl, {
			mode: 'cors',
			method: 'HEAD'
		}).then(function (resp) {
			this.isUrlCORS = true;
		}.bind(this))
		.catch(function (err) {
			return 'chill';  // this.isUrlCORS remains false<commit_msg>Fix bug because of blink/chromium merge<commit_after>/*global fetch, Promise, Clipboard*/
'use strict';

class TimelineUrl {
	constructor(win) {

		this.input = win['timeline-url'];
		this.result = win.result;
		this.generateBtn = win.generateBtn;
		this.confirmation = win.confirmation;
		this.resultsDiv = win.results;

		this.inputUrl = undefined;
		this.outputUrl = undefined;

		this.isUrlCORS = false;
		this.revs = {};

		this.generateUrl();
	}

	getRevs() {
		var chromeVersion = navigator.appVersion.replace(/.+Chrome\/(.+) .+/, '$1');
		var url = 'https://omahaproxy.appspot.com/revision.json?version=' + chromeVersion;

		return fetch(url).then(function (payload) {
			return payload.json();
		}).then(function (revs) {
			this.revs = revs;
		}.bind(this));
	}

	getUrl(url) {
		var position = this.revs.chromium_base_position;
		var commit = this.revs.chromium_base_commit;

		return [
			this.isUrlCORS ? 'https://frontend.chrome-dev.tools/serve_rev/@' :
				'chrome-devtools://devtools/remote/serve_rev/@',

			commit, // e.g. 198714

			// Devtools previously used devtools.html : codereview.chromium.org/1144393004/
			position < 332419 ? '/devtools.html' : '/inspector.html',

			'?loadTimelineFromURL=', url
		].join('');
	}

	checkForCORS() {

		// if the URL is CORS-y we can do a clickable URL
		return window.fetch(this.inputUrl, {
			mode: 'cors',
			method: 'HEAD'
		}).then(function (resp) {
			this.isUrlCORS = true;
		}.bind(this))
		.catch(function (err) {
			return 'chill';  // this.isUrlCORS remains false
{'fraction_non_alphanumeric': 0.16095890410958905, 'fraction_numerical': 0.016552511415525113, 'mean_word_length': 3.6179183135704873, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 5, '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': '3070240', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1221, 'n_words': 238}