Files
SteamFramelyHomebrew--framely/native/plugin_navigation.h
T

22 lines
911 B
C++

#pragma once
#include <string>
// Other localhost ports are only for embedded pages in plugin windows.
// The main frame remains on the Framely origin.
inline bool allow_plugin_navigation(const std::string& url, const std::string& origin,
bool main_frame, bool plugin_window) {
if (url == "about:blank" || url.rfind(origin + "/", 0) == 0) return true;
if (main_frame || !plugin_window) return false;
const std::string prefix = "http://localhost:";
if (url.rfind(prefix, 0) != 0) return false;
auto end = url.find('/', prefix.size());
if (end == std::string::npos || end == prefix.size()) return false;
unsigned port = 0;
for (auto i = prefix.size(); i < end; ++i) {
if (url[i] < '0' || url[i] > '9') return false;
port = port * 10 + unsigned(url[i] - '0');
if (port > 65535) return false;
}
return port > 0;
}