struct PP_Var ppb_url_util_dev_resolve_relative_to_url(struct PP_Var base_url, struct PP_Var relative_string, struct PP_URLComponents_Dev *components) { reset_components(components); struct PP_Var var = PP_MakeNull(); if (base_url.type != PP_VARTYPE_STRING) { trace_warning("%s, base_url is not a string\n", __func__); return PP_MakeNull(); } if (relative_string.type != PP_VARTYPE_STRING) { trace_warning("%s, relative_string is not a string\n", __func__); return PP_MakeNull(); } const char *s_base_url = ppb_var_var_to_utf8(base_url, NULL); const char *s_relative_string = ppb_var_var_to_utf8(relative_string, NULL); UriParserStateA ups; UriUriA uri_base, uri_rel, uri_result; ups.uri = &uri_base; if (uriParseUriA(&ups, s_base_url) != URI_SUCCESS) { trace_warning("%s, can't parse s_base_url\n", __func__); goto err_1; } ups.uri = &uri_rel; if (uriParseUriA(&ups, s_relative_string) != URI_SUCCESS) { trace_warning("%s, can't parse s_relative_string\n", __func__); goto err_2; } if (uriAddBaseUriA(&uri_result, &uri_rel, &uri_base) != URI_SUCCESS) { trace_warning("%s, can't merge base and rel\n", __func__); goto err_3; } int len; uriToStringCharsRequiredA(&uri_result, &len); len++; char *str = malloc(len); uriToStringA(str, &uri_result, len, NULL); var = ppb_var_var_from_utf8_z(str); free(str); if (components) parse_url_string(str, components); err_3: uriFreeUriMembersA(&uri_result); err_2: uriFreeUriMembersA(&uri_rel); err_1: uriFreeUriMembersA(&uri_base); return var; }
struct PP_Var ppb_url_util_dev_get_plugin_instance_url(PP_Instance instance, struct PP_URLComponents_Dev *components) { struct pp_instance_s *pp_i = tables_get_pp_instance(instance); struct PP_Var var = PP_MakeString(pp_i->instance_url); if (components) parse_url_string(ppb_var_var_to_utf8(var, NULL), components); return var; }
struct PP_Var ppb_url_util_dev_get_document_url(PP_Instance instance, struct PP_URLComponents_Dev *components) { struct pp_instance_s *pp_i = tables_get_pp_instance(instance); struct PP_Var result = PP_MakeString(""); NPIdentifier location_id = npn.getstringidentifier("location"); NPIdentifier href_id = npn.getstringidentifier("href"); NPObject *np_window_obj, *np_location_obj; NPVariant location_var, href_var; if (npn.getvalue(pp_i->npp, NPNVWindowNPObject, &np_window_obj) != NPERR_NO_ERROR) goto err_1; if (!npn.getproperty(pp_i->npp, np_window_obj, location_id, &location_var)) goto err_2; if (location_var.type != NPVariantType_Object) goto err_3; np_location_obj = location_var.value.objectValue; if (!npn.getproperty(pp_i->npp, np_location_obj, href_id, &href_var)) goto err_3; struct PP_Var var = np_variant_to_pp_var(href_var); if (var.type != PP_VARTYPE_STRING) { ppb_var_release(var); goto err_4; } ppb_var_release(result); result = var; if (components) parse_url_string(ppb_var_var_to_utf8(result, NULL), components); err_4: npn.releasevariantvalue(&href_var); err_3: npn.releasevariantvalue(&location_var); err_2: npn.releaseobject(np_window_obj); err_1: return result; }
struct PP_Var ppb_url_util_dev_get_plugin_instance_url(PP_Instance instance, struct PP_URLComponents_Dev *components) { reset_components(components); struct pp_instance_s *pp_i = tables_get_pp_instance(instance); if (!pp_i) { trace_error("%s, bad instance\n", __func__); return PP_MakeUndefined(); } struct PP_Var var = ppb_var_var_from_utf8_z(pp_i->instance_url); if (components) parse_url_string(ppb_var_var_to_utf8(var, NULL), components); return var; }
struct PP_Var ppb_url_util_dev_get_document_url(PP_Instance instance, struct PP_URLComponents_Dev *components) { reset_components(components); struct pp_instance_s *pp_i = tables_get_pp_instance(instance); if (!pp_i) { trace_error("%s, bad instance\n", __func__); return PP_MakeUndefined(); } struct get_document_url_param_s p; p.npp = pp_i->npp; p.m_loop = ppb_message_loop_get_current(); p.depth = ppb_message_loop_get_depth(p.m_loop) + 1; p.np_window_obj = pp_i->np_window_obj; ppb_message_loop_post_work(p.m_loop, PP_MakeCompletionCallback(_get_document_url_comt, &p), 0); ppb_message_loop_run_int(p.m_loop, 1); if (components) parse_url_string(ppb_var_var_to_utf8(p.result, NULL), components); return p.result; }