Skip to content
Permalink
Browse files

St: avoid blocking IO to resolve relative urls

  • Loading branch information
brownsr authored and mtwebster committed Aug 13, 2017
1 parent b3f00f2 commit 5a9ad973e766db9a0781d1791e31d89ce8d66dcb
Showing with 56 additions and 59 deletions.
  1. +19 −7 src/st/st-theme-node.c
  2. +3 −3 src/st/st-theme-private.h
  3. +34 −49 src/st/st-theme.c
@@ -1863,15 +1863,19 @@ _st_theme_node_ensure_background (StThemeNode *node)
else if (term->type == TERM_URI)
{
CRStyleSheet *base_stylesheet;
GFile *file;

if (decl->parent_statement != NULL)
base_stylesheet = decl->parent_statement->parent_sheet;
else
base_stylesheet = NULL;

node->background_image = _st_theme_resolve_url (node->theme,
base_stylesheet,
term->content.str->stryng->str);
file = _st_theme_resolve_url (node->theme,
base_stylesheet,
term->content.str->stryng->str);

node->background_image = g_file_get_path (file);
g_object_unref (file);
}
}
}
@@ -1968,16 +1972,20 @@ _st_theme_node_ensure_background (StThemeNode *node)
if (decl->value->type == TERM_URI)
{
CRStyleSheet *base_stylesheet;
GFile *file;

if (decl->parent_statement != NULL)
base_stylesheet = decl->parent_statement->parent_sheet;
else
base_stylesheet = NULL;

g_free (node->background_image);
node->background_image = _st_theme_resolve_url (node->theme,
base_stylesheet,
decl->value->content.str->stryng->str);
file = _st_theme_resolve_url (node->theme,
base_stylesheet,
decl->value->content.str->stryng->str);

node->background_image = g_file_get_path (file);
g_object_unref (file);
}
else if (term_is_inherit (decl->value))
{
@@ -2861,6 +2869,7 @@ st_theme_node_get_border_image (StThemeNode *node)
int border_bottom;
int border_left;

GFile *file;
char *filename;

/* Support border-image: none; to suppress a previously specified border image */
@@ -2940,7 +2949,10 @@ st_theme_node_get_border_image (StThemeNode *node)
else
base_stylesheet = NULL;

filename = _st_theme_resolve_url (node->theme, base_stylesheet, url);
file = _st_theme_resolve_url (node->theme, base_stylesheet, url);
filename = g_file_get_path (file);
g_object_unref (file);

if (filename == NULL)
goto next_property;

@@ -33,9 +33,9 @@ GPtrArray *_st_theme_get_matched_properties_fallback (StTheme *theme,
StThemeNode *node);

/* Resolve an URL from the stylesheet to a filename */
char *_st_theme_resolve_url (StTheme *theme,
CRStyleSheet *base_stylesheet,
const char *url);
GFile *_st_theme_resolve_url (StTheme *theme,
CRStyleSheet *base_stylesheet,
const char *url);

CRDeclaration *_st_theme_parse_declaration_list (const char *str);

@@ -898,9 +898,16 @@ add_matched_properties (StTheme *a_this,
char *filename = NULL;

if (import_rule->url->stryng && import_rule->url->stryng->str)
filename = _st_theme_resolve_url (a_this,
a_nodesheet,
import_rule->url->stryng->str);
{
GFile *file;

file = _st_theme_resolve_url (a_this,
a_nodesheet,
import_rule->url->stryng->str);
filename = g_file_get_path (file);

g_object_unref (file);
}

if (filename)
import_rule->sheet = parse_stylesheet (filename, NULL);
@@ -1077,63 +1084,41 @@ _st_theme_get_matched_properties_fallback (StTheme *theme,
* local filename, if possible. The resolution here is distinctly lame and
* will fail on many examples.
*/
char *
GFile *
_st_theme_resolve_url (StTheme *theme,
CRStyleSheet *base_stylesheet,
const char *url)
{
const char *base_filename = NULL;
char *dirname;
char *filename;

/* Handle absolute file:/ URLs */
if (g_str_has_prefix (url, "file:") ||
g_str_has_prefix (url, "File:") ||
g_str_has_prefix (url, "FILE:"))
{
GError *error = NULL;
char *fname;

fname = g_filename_from_uri (url, NULL, &error);
if (fname == NULL)
{
g_warning ("%s", error->message);
g_error_free (error);
}
else
{
g_free (fname);
}
char *scheme;
GFile *stylesheet, *resource;

return NULL;
}

/* Guard against http:/ URLs */

if (g_str_has_prefix (url, "http:") ||
g_str_has_prefix (url, "Http:") ||
g_str_has_prefix (url, "HTTP:"))
if ((scheme = g_uri_parse_scheme (url)))
{
g_warning ("Http URL '%s' in theme stylesheet is not supported", url);
return NULL;
g_free (scheme);
resource = g_file_new_for_uri (url);
}
else if (base_stylesheet != NULL)
{
const char *base_filename = NULL;
char *dirname;

/* Assume anything else is a relative URL, and "resolve" it
*/
if (url[0] == '/')
return g_strdup (url);
base_filename = g_hash_table_lookup (theme->filenames_by_stylesheet, base_stylesheet);

base_filename = g_hash_table_lookup (theme->filenames_by_stylesheet, base_stylesheet);
/* This is an internal function, if we get here with
a bad @base_stylesheet we have a problem. */
g_assert (base_filename);

if (base_filename == NULL)
dirname = g_path_get_dirname (base_filename);
stylesheet = g_file_new_for_path (dirname);
resource = g_file_resolve_relative_path (stylesheet, url);

g_object_unref (stylesheet);
g_free (dirname);
}
else
{
g_warning ("Can't get base to resolve url '%s'", url);
return NULL;
resource = g_file_new_for_path (url);
}

dirname = g_path_get_dirname (base_filename);
filename = g_build_filename (dirname, url, NULL);
g_free (dirname);

return filename;
return resource;
}

0 comments on commit 5a9ad97

Please sign in to comment.
You can’t perform that action at this time.