Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .build_exclusions
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ chrome-resources/update-from-chrome-svn.sh
webextension/chrome-resources/update-from-chrome-svn.sh
.eslintrc.json
webextension/.eslintrc.json
chromium/.eslintignore
1 change: 1 addition & 0 deletions chromium/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
external/*

@Hainish Hainish Nov 15, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to add chromium/.eslintignore to the top-level .build_exclusions as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

40 changes: 21 additions & 19 deletions chromium/debugging-rulesets.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
.section-header{
margin-bottom: 10px;
.cm-s-main{
width: 100%;
height: 500px;
}

.cm-s-saved{
border: 1px solid black;
}

.cm-s-unsaved{
border: 1px solid red;
}

.section-explainer{
margin-bottom: 5px;
}

.section-header{
margin-bottom: 10px;
}

.section-header-span{
border-bottom: 1px solid #ccc;
font-size: 15px;
}

#debugging-rulesets{
width: 100%;
height: 500px;
#saved-text{
display: none;
border: 1px solid black;
}

#debugging-rulesets.unsaved{
border: 1px solid red;
color: green;
font-weight: bold;
margin: 30px;
}

#changed{
#unsaved-text{
font-weight: bold;
margin: 10px 0px;
color: #F00;
color: red;
visibility: hidden;
text-align: center;
}

#saved{
display: none;
color: green;
font-weight: bold;
margin: 30px;
}
25 changes: 13 additions & 12 deletions chromium/debugging-rulesets.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
<meta charset="utf-8">
<title></title>
<link href="debugging-rulesets.css" rel="stylesheet">
<script src="external/codemirror/codemirror-5.31.0.min.js"></script>
<link href="external/codemirror/codemirror-5.31.0.min.css" rel="stylesheet">
<script src="external/codemirror/codemirror-5.31.0.xml.min.js"></script>
</head>
<body>
<form id="debugging-rulesets-form">
<div class="section-header"><span class="section-header-span">Debugging Rulesets</span></div>
<div class="section-explainer">
Enter ruleset XML below and click save when ready. These rulesets will be immediately activated upon saving, and will persist across restarts.<br>
<i>Warning</i>: This should only be used for debugging rulesets. This feature is not guaranteed to work reliably for regular usage.<br>
<i>Note</i>: Due to a bug in Chromium, it may be necessary to close the options ui before saving.
</div>
<div id="changed">There are unsaved changes! Be sure to save them for them to take effect.</div>
<textarea id="debugging-rulesets" spellcheck="false"></textarea>
<button type="submit" id="save">Save</button>
</form>
<div id='saved'>Saved!</div>
<div class="section-header"><span class="section-header-span">Debugging Rulesets</span></div>
<div class="section-explainer">
Enter ruleset XML below and click save when ready. These rulesets will be immediately activated upon saving, and will persist across restarts.<br>
<i>Warning</i>: This should only be used for debugging rulesets. This feature is not guaranteed to work reliably for regular usage.<br>
<i>Note</i>: Due to a bug in Chromium, it may be necessary to close the options ui before saving.
</div>
<div id="unsaved-text">There are unsaved changes! Be sure to save them for them to take effect.</div>
<textarea id="codemirror-textarea"></textarea>
<button type="button" id="save-button">Save</button>
<div id="saved-text">Saved!</div>
<script src="send-message.js"></script>
<script src="debugging-rulesets.js"></script>
</body>
Expand Down
59 changes: 33 additions & 26 deletions chromium/debugging-rulesets.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
/* global sendMessage */
/* global sendMessage, CodeMirror */

"use strict";

const debugging_rulesets_textarea = document.getElementById("debugging-rulesets");
const changed = document.getElementById("changed");
const default_title = "Debugging Rulesets";
const unsaved_title = "* Debugging Rulesets";
const savedTextElement = document.getElementById("saved-text");
const unsavedTextElement = document.getElementById("unsaved-text");
const savedTitle = "Debugging Rulesets";
const unsavedTitle = "* Debugging Rulesets";

debugging_rulesets_textarea.addEventListener("input", debugging_rulesets_changed);
document.getElementById("debugging-rulesets-form").addEventListener("submit", save_debugging_rulesets);
document.title = savedTitle;

document.title = default_title;
const cm = CodeMirror.fromTextArea(
document.getElementById("codemirror-textarea"),
{
mode: "xml",
theme: "default main saved"
}
);

let valueHasChanged = false;
sendMessage("get_option", { debugging_rulesets: "" }, item => {
debugging_rulesets_textarea.value = item.debugging_rulesets;
debugging_rulesets_textarea.style.display = "block";
cm.setValue(item.debugging_rulesets);
cm.on("change", cm => {
if (!(valueHasChanged)) {
valueHasChanged = true;
document.title = unsavedTitle;
cm.setOption("theme", "default main unsaved");
unsavedTextElement.style.visibility = "visible";
}
});
});

function save_debugging_rulesets(e){
document.getElementById("save-button").addEventListener("click", e => {
e.preventDefault();
sendMessage("set_option", { debugging_rulesets: debugging_rulesets_textarea.value }, () => {
const saved = document.getElementById("saved");
saved.style.display = "block";
setTimeout(() => { saved.style.display = "none" }, 1000);

document.title = default_title;
debugging_rulesets_textarea.className = "";
changed.style.visibility = "hidden";
sendMessage("set_option", { debugging_rulesets: cm.getValue() }, () => {
savedTextElement.style.display = "block";
setTimeout(() => { savedTextElement.style.display = "none" }, 1000);

valueHasChanged = false;
document.title = savedTitle;
cm.setOption("theme", "default main saved");
unsavedTextElement.style.visibility = "hidden";
});
}

function debugging_rulesets_changed(){
debugging_rulesets_textarea.className = "unsaved";
document.title = unsaved_title;
changed.style.visibility = "visible";
}
});
42 changes: 42 additions & 0 deletions chromium/external/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# External dependencies

This directory contains files that are external dependencies for HTTPS Everywhere, with instructions on how to get or remake them.

## CodeMirror 5.31.0

```
$ npm install uglify-js@3.1.9

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not a package dependency and is intended to be run as a command line app, let's add a -g flag for global install as the installation instructions specify: https://github.com/mishoo/UglifyJS2#install

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the drawback of defining all the dependencies in package.json in desired versions and define npm scripts that would execute proper commands?

Global packages should be avoided when possible. Someone may skip those steps as they've already performed them before and not notice they've since installed different versions since some other project required different ones. Using local packages gets rid of that problem.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but the above command will cause uglify-js to be added to the dependencies hash, rather than the devDependencies hash. Thus we should preference running this with the -D flag, and the below reproducibility instructions should be modified to be:
../node_modules/uglify-js/bin/uglifyjs

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to specify those packages directly instead of just having package.json checked into the repo and running npm install?

BTW, if you're referring to the binary by path, it's usually better to use ../node_modules/.bin/uglifyjs as that depends less on the internal package structure. node_modules/.bin contains links to binaries exported by top-level packages.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgol creating a dependency management system is on the table, but I don't want to block merging until we have one in place. See #13560 (comment) and resulting discussion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These instructions are supposed to give someone who is knowledgeable about npm the key information needed to reproduce the files: package names, version numbers, options used. It's not supposed to completely walk a beginner through the process of making these files. The user can decide for themselves whether to install the minifier executables globally or not and how to get the files into whatever directories they want.

$ npm install uglifycss@0.0.27

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ curl -o codemirror.zip https://codemirror.net/codemirror-5.31.0.zip
$ unzip codemirror.zip
```

### codemirror-5.31.0.min.js

```bash
uglifyjs \
--compress \
--mangle \
--comments '/copyright|license/' \
--output codemirror-5.31.0.min.js \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relating to the suggestion above of adding each external dependency to its own unique path, we'll want to change these output paths to external/codemirror/...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codemirror-5.31.0/lib/codemirror.js
```

### codemirror-5.31.0.xml.min.js

```bash
uglifyjs \
--compress \
--mangle \
--comments '/copyright|license/' \
--output codemirror-5.31.0.xml.min.js \
codemirror-5.31.0/mode/xml/xml.js
```

### codemirror-5.31.0.min.css

```bash
uglifycss \
--output codemirror-5.31.0.min.css \
codemirror-5.31.0/lib/codemirror.css
```
1 change: 1 addition & 0 deletions chromium/external/codemirror/codemirror-5.31.0.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions chromium/external/codemirror/codemirror-5.31.0.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions chromium/external/codemirror/codemirror-5.31.0.xml.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions run_travis.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -x
toplevel=$(git rev-parse --show-toplevel)
testdir=${toplevel}/test/selenium
linter=${toplevel}/utils/eslint/node_modules/.bin/eslint
srcdir=${toplevel}/chromium
toplevel="$(git rev-parse --show-toplevel)"
testdir="${toplevel}/test/selenium"
srcdir="${toplevel}/chromium"
linter="${toplevel}/utils/eslint/node_modules/.bin/eslint --ignore-path ${srcdir}/.eslintignore"


function run_lint {
Expand Down