Ejemplo n.º 1
0
        public String getBundledJsParam(ICollection <String> features, GadgetContext context)
        {
            StringBuilder buf   = new StringBuilder();
            bool          first = false;

            foreach (String feature in features)
            {
                if (ALLOWED_FEATURE_NAME.Match(feature).Success)
                {
                    if (!first)
                    {
                        first = true;
                    }
                    else
                    {
                        buf.Append("__");
                    }
                    buf.Append(feature);
                }
            }
            if (!first)
            {
                buf.Append("core");
            }
            buf.Append(".js?v=").Append(jsChecksum)
            .Append("&container=").Append(context.getContainer())
            .Append("&debug=").Append(context.getDebug() ? "1" : "0");
            return(buf.ToString());
        }
Ejemplo n.º 2
0
        public String getBundledJsUrl(ICollection<String> features, GadgetContext context) 
        {
            String jsPrefix;
            if (!jsUriTemplates.TryGetValue(context.getContainer(), out jsPrefix)) 
            {
                return "";
            }

            return jsPrefix.Replace("%host%", context.getHost())
                .Replace("%js%", getBundledJsParam(features, context));
        }
Ejemplo n.º 3
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());
 }
Ejemplo n.º 4
0
        public String getBundledJsUrl(ICollection <String> features, GadgetContext context)
        {
            String jsPrefix;

            if (!jsUriTemplates.TryGetValue(context.getContainer(), out jsPrefix))
            {
                return("");
            }

            return(jsPrefix.Replace("%host%", context.getHost())
                   .Replace("%js%", getBundledJsParam(features, context)));
        }
        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()));
        }
Ejemplo n.º 6
0
 /**
  * @param context The request that the gadget is being processed for.
  */
 public Gadget setContext(GadgetContext context)
 {
     this.context = context;
     return this;
 }
Ejemplo n.º 7
0
 public String getBundledJsParam(ICollection<String> features, GadgetContext context) 
 {
     StringBuilder buf = new StringBuilder();
     bool first = false;
     foreach (String feature in features) 
     {
         if (ALLOWED_FEATURE_NAME.Match(feature).Success)
         {
             if (!first) 
             {
                 first = true;
             } 
             else
             {
                 buf.Append("__");
             }
             buf.Append(feature);
         }
     }
     if (!first) 
     {
         buf.Append("core");
     }
     buf.Append(".js?v=").Append(jsChecksum)
         .Append("&container=").Append(context.getContainer())
         .Append("&debug=").Append(context.getDebug() ? "1" : "0");
     return buf.ToString();
 }
Ejemplo n.º 8
0
 /**
  * @param context The request that the gadget is being processed for.
  */
 public Gadget setContext(GadgetContext context)
 {
     this.context = context;
     return(this);
 }
Ejemplo n.º 9
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());
        }