예제 #1
0
 public GadgetSpec getGadgetSpec(GadgetContext context)
 {
     String rawxml = context.getParameter(RAW_GADGETSPEC_XML_PARAM_NAME);
     if (rawxml != null)
     {
         // Set URI to a fixed, safe value (localhost), preventing a gadget rendered
         // via raw XML (eg. via POST) to be rendered on a locked domain of any other
         // gadget whose spec is hosted non-locally.
         return new GadgetSpec(RAW_GADGET_URI, rawxml);
     }
     return getGadgetSpec(context.getUrl(), context.getIgnoreCache());
 }
        public GadgetSpec getGadgetSpec(GadgetContext context)
        {
            String rawxml = context.getParameter(RAW_GADGETSPEC_XML_PARAM_NAME);

            if (rawxml != null)
            {
                // Set URI to a fixed, safe value (localhost), preventing a gadget rendered
                // via raw XML (eg. via POST) to be rendered on a locked domain of any other
                // gadget whose spec is hosted non-locally.
                return(new GadgetSpec(RAW_GADGET_URI, rawxml));
            }
            return(getGadgetSpec(context.getUrl(), context.getIgnoreCache()));
        }
예제 #3
0
        /**
         * TODO: This is in need of a rewrite most likely. It doesn't even take locked domain into
         * consideration!
         */
        public String getIframeUrl(Gadget gadget)
        {
            GadgetContext context = gadget.getContext();
            GadgetSpec    spec    = gadget.getSpec();
            String        url     = context.getUrl().ToString();
            View          view    = gadget.getCurrentView();

            View.ContentType type = view == null ? View.ContentType.HTML : view.getType();

            UriBuilder uri;

            if (type == View.ContentType.URL)
            {
                uri = view == null ? new UriBuilder() : new UriBuilder(view.getHref());
            }
            else
            {
                // TODO: Locked domain support.
                Uri iframeBaseUri;
                uri = iframeBaseUris.TryGetValue(context.getContainer(), out iframeBaseUri) ? new UriBuilder(iframeBaseUri) : new UriBuilder();
                String host = lockedDomainService.getLockedDomainForGadget(spec, context.getContainer());
                if (host != null)
                {
                    uri.setAuthority(host);
                }
            }

            uri.addQueryParameter("container", context.getContainer());
            if (!string.IsNullOrEmpty(context.getModuleId()))
            {
                uri.addQueryParameter("mid", context.getModuleId());
            }
            if (context.getIgnoreCache())
            {
                uri.addQueryParameter("nocache", "1");
            }
            else
            {
                uri.addQueryParameter("v", spec.getChecksum());
            }

            uri.addQueryParameter("lang", context.getLocale().getLanguage());
            uri.addQueryParameter("country", context.getLocale().getCountry());
            uri.addQueryParameter("view", context.getView());

            UserPrefs prefs = context.getUserPrefs();

            foreach (UserPref pref in gadget.getSpec().getUserPrefs())
            {
                String name  = pref.getName();
                String value = prefs.getPref(name);
                if (value == null)
                {
                    value = pref.getDefaultValue();
                }
                uri.addQueryParameter("up_" + pref.getName(), value);
            }
            // add url last to work around browser bugs
            if (!type.Equals(View.ContentType.URL))
            {
                uri.addQueryParameter("url", url);
            }

            return(uri.ToString());
        }