Exemplo n.º 1
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());
        }