Ejemplo n.º 1
0
        // Multiple calls of this method are wrapped in
        // GetSequencesForWindowBegin and GetSequencesForWindowEnd
        private static List <string> GetSequencesForWindow(PwEntry pwe,
                                                           IntPtr hWnd, string strWindow, PwDatabase pdContext, int iEventID)
        {
            List <string> l = new List <string>();

            if (pwe == null)
            {
                Debug.Assert(false); return(l);
            }
            if (strWindow == null)
            {
                Debug.Assert(false); return(l);
            }                                                                    // May be empty

            if (!pwe.GetAutoTypeEnabled())
            {
                return(l);
            }

            SprContext sprCtx = new SprContext(pwe, pdContext,
                                               SprCompileFlags.NonActive);

            RaiseSequenceQueryEvent(AutoType.SequenceQueryPre, iEventID,
                                    hWnd, strWindow, pwe, pdContext, l);

            // Specifically defined sequences must match before the title,
            // in order to allow selecting the first item as default one
            foreach (AutoTypeAssociation a in pwe.AutoType.Associations)
            {
                string strFilter = SprEngine.Compile(a.WindowName, sprCtx);
                if (IsMatchWindow(strWindow, strFilter))
                {
                    string strSeq = a.Sequence;
                    if (string.IsNullOrEmpty(strSeq))
                    {
                        strSeq = pwe.GetAutoTypeSequence();
                    }
                    AddSequence(l, strSeq);
                }
            }

            RaiseSequenceQueryEvent(AutoType.SequenceQuery, iEventID,
                                    hWnd, strWindow, pwe, pdContext, l);

            if (Program.Config.Integration.AutoTypeMatchByTitle)
            {
                string strTitle = SprEngine.Compile(pwe.Strings.ReadSafe(
                                                        PwDefs.TitleField), sprCtx);
                if (IsMatchSub(strWindow, strTitle))
                {
                    AddSequence(l, pwe.GetAutoTypeSequence());
                }
            }

            string strCmpUrl = null;             // To cache the compiled URL

            if (Program.Config.Integration.AutoTypeMatchByUrlInTitle)
            {
                strCmpUrl = SprEngine.Compile(pwe.Strings.ReadSafe(
                                                  PwDefs.UrlField), sprCtx);
                if (IsMatchSub(strWindow, strCmpUrl))
                {
                    AddSequence(l, pwe.GetAutoTypeSequence());
                }
            }

            if (Program.Config.Integration.AutoTypeMatchByUrlHostInTitle)
            {
                if (strCmpUrl == null)
                {
                    strCmpUrl = SprEngine.Compile(pwe.Strings.ReadSafe(
                                                      PwDefs.UrlField), sprCtx);
                }

                string strCleanUrl = StrUtil.RemovePlaceholders(strCmpUrl).Trim();
                string strHost     = UrlUtil.GetHost(strCleanUrl);

                if (strHost.StartsWith("www.", StrUtil.CaseIgnoreCmp) &&
                    (strCleanUrl.StartsWith("http:", StrUtil.CaseIgnoreCmp) ||
                     strCleanUrl.StartsWith("https:", StrUtil.CaseIgnoreCmp)))
                {
                    strHost = strHost.Substring(4);
                }

                if (IsMatchSub(strWindow, strHost))
                {
                    AddSequence(l, pwe.GetAutoTypeSequence());
                }
            }

            if (Program.Config.Integration.AutoTypeMatchByTagInTitle)
            {
                foreach (string strTag in pwe.GetTagsInherited())
                {
                    if (IsMatchSub(strWindow, strTag))
                    {
                        AddSequence(l, pwe.GetAutoTypeSequence());
                        break;
                    }
                }
            }

            RaiseSequenceQueryEvent(AutoType.SequenceQueryPost, iEventID,
                                    hWnd, strWindow, pwe, pdContext, l);

            return(l);
        }