Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: issue-reporter.js

Issue 29583568: Issue 5880 - Basic issue reporter implementation (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome
Left Patch Set: Created Oct. 19, 2017, 12:28 p.m.
Right Patch Set: Do not offer issue reporter for local pages Created Oct. 19, 2017, 2:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « issue-reporter.html ('k') | polyfill.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 uuidString += component; 335 uuidString += component;
336 if (i >= 1 && i<= 4) 336 if (i >= 1 && i<= 4)
337 uuidString += "-"; 337 uuidString += "-";
338 } 338 }
339 339
340 let params = new URLSearchParams({ 340 let params = new URLSearchParams({
341 version: 1, 341 version: 1,
342 guid: uuidString, 342 guid: uuidString,
343 lang: reportData.getElementsByTagName("adblock-plus")[0].getAttribute("local e") 343 lang: reportData.getElementsByTagName("adblock-plus")[0].getAttribute("local e")
344 }); 344 });
345 let url = "https://reports.adblockplus.org/submitReport?" + params; 345 let url = "https://reports.adblockplus.org/submitReport?" + params;
Felix Dahlke 2017/10/19 16:48:04 Why not make this a pref?
Wladimir Palant 2017/10/19 17:54:25 Why make it a pref? It used to be a pref in the le
Felix Dahlke 2017/10/19 18:21:31 Two reasons: 1. Feels wrong to hard code URLs in
346 346
347 let reportSent = event => 347 let reportSent = event =>
348 { 348 {
349 let success; 349 let success = false;
350 let errorMessage; 350 let errorMessage = browser.i18n.getMessage("filters_subscription_lastDownloa d_connectionError");
351 try 351 try
352 { 352 {
353 success = request.status == 200; 353 success = request.status == 200;
354 errorMessage = request.status + " " + request.statusText; 354 if (request.status != 0)
355 errorMessage = request.status + " " + request.statusText;
355 } 356 }
356 catch (e) 357 catch (e)
357 { 358 {
358 // No request status, connection wasn't established. 359 // Getting request status might throw if no connection was established
359 success = false;
360 errorMessage = browser.i18n.getMessage("filters_subscription_lastDownload_ connectionError");
361 } 360 }
362 361
363 let result; 362 let result;
364 try 363 try
365 { 364 {
366 result = request.responseText; 365 result = request.responseText;
367 } 366 }
368 catch (e) 367 catch (e)
369 { 368 {
370 result = ""; 369 result = "";
370 }
371
372 if (!success)
373 {
374 let errorElement = document.getElementById("error");
375 let template = browser.i18n.getMessage("issueReporter_errorMessage").repla ce(/[\r\n\s]+/g, " ");
376
377 let [, beforeLink, linkText, afterLink] = /(.*)\[link\](.*)\[\/link\](.*)/ .exec(template) || [null, "", template, ""];
378 beforeLink = beforeLink.replace(/\?1\?/g, errorMessage);
379 afterLink = afterLink.replace(/\?1\?/g, errorMessage);
380
381 while (errorElement.firstChild)
382 errorElement.removeChild(errorElement.firstChild);
383
384 let link = document.createElement("a");
385 link.textContent = linkText;
386 browser.runtime.sendMessage({
387 type: "app.get",
388 what: "doclink",
389 link: "reporter_connect_issue"
390 }).then(url =>
391 {
392 link.href = url;
393 });
394
395
396 errorElement.appendChild(document.createTextNode(beforeLink));
397 errorElement.appendChild(link);
398 errorElement.appendChild(document.createTextNode(afterLink));
399
400 errorElement.hidden = false;
371 } 401 }
372 402
373 result = result.replace(/%CONFIRMATION%/g, encodeHTML(browser.i18n.getMessag e("issueReporter_confirmationMessage"))); 403 result = result.replace(/%CONFIRMATION%/g, encodeHTML(browser.i18n.getMessag e("issueReporter_confirmationMessage")));
374 result = result.replace(/%KNOWNISSUE%/g, encodeHTML(browser.i18n.getMessage( "issueReporter_knownIssueMessage"))); 404 result = result.replace(/%KNOWNISSUE%/g, encodeHTML(browser.i18n.getMessage( "issueReporter_knownIssueMessage")));
375 result = result.replace(/(<html)\b/, '$1 dir="' + encodeHTML(window.getCompu tedStyle(document.documentElement, "").direction + '"')); 405 result = result.replace(/(<html)\b/, '$1 dir="' + encodeHTML(window.getCompu tedStyle(document.documentElement, "").direction + '"'));
376 406
407 document.getElementById("sendReportMessage").hidden = true;
377 document.getElementById("sendingProgressContainer").hidden = true; 408 document.getElementById("sendingProgressContainer").hidden = true;
378 409
379 let resultFrame = document.getElementById("result"); 410 let resultFrame = document.getElementById("result");
380 resultFrame.setAttribute("src", "data:text/html;charset=utf-8," + encodeURIC omponent(result)); 411 resultFrame.setAttribute("src", "data:text/html;charset=utf-8," + encodeURIC omponent(result));
381 resultFrame.hidden = false; 412 resultFrame.hidden = false;
382 413
383 document.getElementById("continue").disabled = false; 414 document.getElementById("continue").disabled = false;
384 }; 415 };
385 416
386 let request = new XMLHttpRequest(); 417 let request = new XMLHttpRequest();
(...skipping 15 matching lines...) Expand all
402 progress.value = event.loaded; 433 progress.value = event.loaded;
403 } 434 }
404 }); 435 });
405 request.send(serializeReportData()); 436 request.send(serializeReportData());
406 } 437 }
407 438
408 function leaveSendPage() 439 function leaveSendPage()
409 { 440 {
410 window.close(); 441 window.close();
411 } 442 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld