MWContext* XP_FindSomeContext() { MWContext* cx = XP_FindContextOfType(NULL, MWContextBrowser); if (!cx) cx = XP_FindContextOfType(NULL, MWContextMail); if (!cx) cx = XP_FindContextOfType(NULL, MWContextNews); if (!cx) cx = XP_FindContextOfType(NULL, MWContextPane); #if 0 /* dp says don't do this */ if (!cx) cx = fe_all_MWContexts->context; #endif return cx; }
/* arguments: 0. url 1. component name 2. version no. to compare 3. flags return: true if update triggered and no errors */ JSBool PR_CALLBACK asd_conditional_update (JSContext *cx, JSObject *obj, uint argc, jsval *argv, jsval *rval) { REGERR status = 0; if (argc >= 4 && JSVAL_IS_STRING(argv[0]) && JSVAL_IS_STRING(argv[1]) && JSVAL_IS_OBJECT(argv[2]) && JSVAL_IS_INT(argv[3])) { VERSION curr_vers; char* component_path = JS_GetStringBytes(JSVAL_TO_STRING(argv[1])); status = VR_GetVersion(component_path, &curr_vers); if (status == REGERR_OK) { JSObject* versObj = JSVAL_TO_OBJECT(argv[2]); VERSION req_vers; asd_objToVers(cx, versObj, &req_vers); if ( asd_compareVersion(&req_vers, &curr_vers) > 0 ) { char* url = JS_GetStringBytes(JSVAL_TO_STRING(argv[0])); MWContext* cx = XP_FindContextOfType(NULL, MWContextBookmarks); XP_Bool result = SU_StartSoftwareUpdate( cx, url, NULL, NULL, NULL, JSVAL_TO_INT(argv[3]) ); *rval = BOOLEAN_TO_JSVAL(result); return JS_TRUE; } } } *rval = BOOLEAN_TO_JSVAL(JS_FALSE); /*INT_TO_JSVAL(status);*/ return JS_TRUE; }
/* arguments: 0. url 1. flags return: true if no errors */ JSBool PR_CALLBACK asd_start_update (JSContext *cx, JSObject *obj, uint argc, jsval *argv, jsval *rval) { if (argc >= 2 && JSVAL_IS_STRING(argv[0]) && JSVAL_IS_INT(argv[1])) { char* url = JS_GetStringBytes(JSVAL_TO_STRING(argv[0])); /* Bookmarks is a hack, you should really get some SmartUpdate context */ MWContext* cx = XP_FindContextOfType(NULL, MWContextBookmarks); XP_Bool result = SU_StartSoftwareUpdate( cx, url, NULL, NULL, NULL, JSVAL_TO_INT(argv[1]) ); *rval = BOOLEAN_TO_JSVAL(result); return JS_TRUE; } *rval = BOOLEAN_TO_JSVAL(JS_FALSE); return JS_TRUE; }
static char * fe_server_handle_command (Display *dpy, Window window, XEvent *event, char *command) { char *name = 0; char **av = 0; int ac = 0; int avsize = 0; Boolean raise_p = True; int i; char *buf; char *buf2; int32 buf2_size; char *head, *tail; XtActionProc action = 0; Widget widget = XtWindowToWidget (dpy, window); MWContext *context = fe_WidgetToMWContext (widget); XP_Bool mail_or_news_required = FALSE; MWContextType required_type = (MWContextType) (~0); XP_Bool make_context_if_necessary = FALSE; MWContext *target_context = context; XP_ASSERT(context); buf = fe_StringTrim (strdup (command)); buf2_size = strlen (buf) + 200; buf2 = (char *) malloc (buf2_size); head = buf; tail = buf; if (! widget) { PR_snprintf (buf2, buf2_size, XP_GetString(XFE_REMOTE_S_509_INTERNAL_ERROR), (unsigned int) window); free (buf); return buf2; } /* extract the name (everything before the first '(', trimmed.) */ while (1) if (*tail == '(' || isspace (*tail) || !*tail) { *tail = 0; tail++; name = fe_StringTrim (head); break; } else tail++; if (!name || !*name) { PR_snprintf (buf2, buf2_size, XP_GetString(XFE_REMOTE_S_500_UNPARSABLE_COMMAND), command); free (buf); return buf2; } /* look for it in the old remote actions. */ for (i = 0; i < fe_CommandActionsSize; i++) if (!XP_STRCASECMP(name, fe_CommandActions [i].string)) { name = fe_CommandActions [i].string; action = fe_CommandActions [i].proc; break; } if (!av) { avsize = 20; av = (char **) calloc (avsize, sizeof (char *)); /* if it's not an old action, we need to know the name of the command, so we stick it on the front. This will be dealt with in xfeDoRemoteCommand. */ if (!action) av[ ac++ ] = name; while (*tail == '(' || isspace (*tail)) tail++; head = tail; while (1) { if (*tail == ')' || *tail == ',' || *tail == 0) { char delim = *tail; if (ac >= (avsize - 2)) { avsize += 20; av = (char **) realloc (av, avsize * sizeof (char *)); } *tail = 0; av [ac++] = fe_StringTrim (head); if (delim != ',' && !*av[ac-1]) ac--; else if (!strcasecomp (av [ac-1], "noraise")) { raise_p = False; ac--; } else if (!strcasecomp (av [ac-1], "raise")) { raise_p = True; ac--; } head = tail+1; if (delim != ',') break; } tail++; } av [ac++] = "<remote>"; } /* If this is GetURL or something like it, make sure the context we pick matches the URL. */ if (strstr(name, "URL")) { const char *url = av[0]; mail_or_news_required = FALSE; required_type = (MWContextType) (~0); #ifdef MOZ_MAIL_NEWS if (MSG_RequiresMailWindow (url)) required_type = MWContextMail; else if (MSG_RequiresNewsWindow (url)) required_type = MWContextNews; else if (MSG_RequiresBrowserWindow (url)) #endif required_type = MWContextBrowser; /* Nothing to do for MSG_RequiresComposeWindow compose. */ if (required_type != (MWContextType) (~0)) { make_context_if_necessary = TRUE; } } else if (!strcasecomp(name, "openfile")) { required_type = MWContextBrowser; make_context_if_necessary = TRUE; } if (raise_p) XMapRaised (dpy, window); if (required_type != (MWContextType) (~0)) target_context = XP_FindContextOfType(context, required_type); if (make_context_if_necessary && !target_context) target_context = FE_MakeNewWindow(context, NULL, NULL, NULL); if (target_context) { Cardinal ac2 = ac; /* why is this passed as a pointer??? */ if (name && action) { (*action) (CONTEXT_WIDGET(target_context), event, av, &ac2); } else /* now we call our new xfe2 interface to the command mechanism */ { xfeDoRemoteCommand (CONTEXT_WIDGET(target_context), event, av, &ac2); } } PR_snprintf (buf2, buf2_size, XP_GetString(XFE_REMOTE_S_200_EXECUTED_COMMAND), name); for (i = 0; i < ac-1; i++) { strcat (buf2, av [i]); if (i < ac-2) strcat (buf2, ", "); } strcat (buf2, ")"); free (av); free (buf); return buf2; }