Permalink
Browse files

Ignore same external URI in quick succession

Each external URI is ignored for 300 ms.

Issue: #425
  • Loading branch information...
fenryxo committed Apr 25, 2018
1 parent c62d892 commit edfb93ddae29b733a1eee309988f5d94367e3610
Showing with 46 additions and 4 deletions.
  1. +16 −1 src/nuvolakit-runner/cef/CefEngine.vala
  2. +20 −3 web_apps/test/home.html
  3. +10 −0 web_apps/test/home.js
@@ -47,6 +47,7 @@ public class CefEngine : WebEngine {
private Config config;
private Drt.KeyValueStorage session;
private HashTable<string, Variant> worker_data;
private GenericSet<string> recent_external_uris;
private static string[] allowed_url_prefixes;
static construct {
@@ -66,6 +67,7 @@ public class CefEngine : WebEngine {
this.runner_app = runner_app;
this.config = config;
this.web_worker = new RemoteWebWorker(ipc_bus);
this.recent_external_uris = new GenericSet<string>(str_hash, str_equal);
this.worker_data = worker_data;
worker_data["NUVOLA_API_ROUTER_TOKEN"] = ipc_bus.router.hex_token;
worker_data["WEBKITGTK_MAJOR"] = WebKit.get_major_version();
@@ -602,12 +604,25 @@ public class CefEngine : WebEngine {
}
}
} else {
runner_app.show_uri(uri);
open_external_uri(uri);
request.cancel();
}
}
}
private void open_external_uri(string uri) {
if (!(uri in recent_external_uris)) {
runner_app.show_uri(uri);
recent_external_uris.add(uri);
Timeout.add(300, () => {
recent_external_uris.remove(uri);
return false;
});
} else {
debug("External URI '%s' ignored because it was opened recently.", uri);
}
}
private bool navigation_request(string url, ref bool new_window) {
var builder = new VariantBuilder(new VariantType("a{smv}"));
builder.add("{smv}", "url", new Variant.string(url));
View
@@ -46,9 +46,12 @@ <h1>Test</h1>
<tbody id="playlist"></tbody>
</table>
<p>
Google.com:
</p>
<table>
<tr>
<th>Google.com</th><th>Tiliado</th>
</tr>
<tr>
<td>
<ul>
<li><a href="http://google.com" >Current window</a></li>
<li><a href="http://google.com" target="_blank">New window</a></li>
@@ -58,6 +61,20 @@ <h1>Test</h1>
<li><a href="#" onclick="window.open('http://google.com', '_blank', 'left=0,top=0,width=100,height=100'); return false;">Pop-up window 0,0+100×100</a></li>
<li><a href="#" onclick="window.open('http://google.com', '_blank', 'left=200,top=100,width=400,height=200'); return false;">Pop-up window 200,100+400×200</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="http://tiliado.eu" >Current window</a> (<a href="http://tiliado.eu" onclick="_openURI(this.href); return false;">window.location</a>)</li>
<li><a href="http://tiliado.eu" target="_blank">New window</a></li>
<li><a href="#" onclick="window.open('http://tiliado.eu', '_blank'); return false;">Pop-up window</a></li>
<li><a href="#" onclick="window.open('http://tiliado.eu', '_blank', 'fullscreen=yes'); return false;">Pop-up window full-screen</a></li>
<li><a href="#" onclick="window.open('http://tiliado.eu', '_blank', 'width=100,height=100'); return false;">Pop-up window 100×100</a></li>
<li><a href="#" onclick="window.open('http://tiliado.eu', '_blank', 'left=0,top=0,width=100,height=100'); return false;">Pop-up window 0,0+100×100</a></li>
<li><a href="#" onclick="window.open('http://tiliado.eu', '_blank', 'left=200,top=100,width=400,height=200'); return false;">Pop-up window 200,100+400×200</a></li>
</ul>
</td>
</tr>
</table>
<p>Misc</p>
<ul>
View
@@ -280,3 +280,13 @@ Player.prototype._onProgressBarClicked = function (button, event) {
}
window.player = new Player()
window._openURI = function (uri, step) {
step = step || 0
if (step < 5) {
setTimeout(() => {
window.location = uri
window._openURI(uri, step + 1)
}, 50)
}
}

0 comments on commit edfb93d

Please sign in to comment.