Beispiel #1
0
 private void PopulateUrlDropDown(object state)
 {
     foreach (var browserWindowUrl in WebBrowserUrl.GetTopLevelBrowserWindowUrls())
     {
         mURL.BeginInvoke(new Action(() => mURL.Items.Add(browserWindowUrl)));
     }
 }
Beispiel #2
0
        private void AutoType_SequenceQueriesBegin(object sender, SequenceQueriesEventArgs e)
        {
            if (!BrowserUrlReader.IsWindowHandleSupportedBrowser(e.TargetWindowHandle))
            {
                return;
            }

            bool passwordFieldFocussed = false;

            string sUrl = WebBrowserUrl.GetFocusedBrowserUrl(mChromeAccessibility, e.TargetWindowHandle, out passwordFieldFocussed);

            if (!string.IsNullOrEmpty(sUrl))
            {
                lock (mUrlForAutoTypeEvent)
                {
                    mUrlForAutoTypeEvent[e.EventID]     = sUrl;
                    mSkipUserNameForSequence[e.EventID] = passwordFieldFocussed && AutoSkipUserName;
                }

                // Ensure starting un-found.
                mFoundSequence.Remove(e.EventID);
            }
        }
Beispiel #3
0
        private void CreateEntry()
        {
            if (mCreatingEntry)
            {
                return;
            }
            mCreatingEntry = true;
            try
            {
                // Unlock, if required
                m_host.MainWindow.ProcessAppMessage((IntPtr)Program.AppMessage.Unlock, IntPtr.Zero);

                if (m_host.MainWindow.IsAtLeastOneFileOpen())
                {
                    string selectedText, url, title;
                    WebBrowserUrl.GetFocusedBrowserInfo(mChromeAccessibility, out selectedText, out url, out title);

                    var urlSuggestions = new List <String>();
                    if (!String.IsNullOrEmpty(url))
                    {
                        // Use only the root part of the URL
                        try
                        {
                            var uri = new Uri(url);
                            urlSuggestions.Add(uri.GetLeftPart(UriPartial.Authority) + "/");
                            urlSuggestions.Add(uri.GetLeftPart(UriPartial.Path));
                            urlSuggestions.Add(uri.GetLeftPart(UriPartial.Query));
                        }
                        catch (UriFormatException)
                        {
                        }
                        // Finally, the url exactly as given
                        urlSuggestions.Add(url);
                    }

                    // Logic adapted from EntryTemplates.CreateEntry
                    var database = m_host.Database;
                    var entry    = new PwEntry(true, true);
                    if (!String.IsNullOrEmpty(title))
                    {
                        entry.Strings.Set(PwDefs.TitleField, new ProtectedString(database.MemoryProtection.ProtectTitle, title));
                    }
                    if (urlSuggestions.Any())
                    {
                        entry.Strings.Set(PwDefs.UrlField, new ProtectedString(database.MemoryProtection.ProtectUrl, urlSuggestions[0]));
                    }
                    if (!String.IsNullOrEmpty(selectedText))
                    {
                        entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(database.MemoryProtection.ProtectUserName, selectedText));
                    }

                    // Generate a default password, the same as in MainForm.OnEntryAdd
                    ProtectedString psAutoGen;
                    PwGenerator.Generate(out psAutoGen, Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile, null, Program.PwGeneratorPool);
                    psAutoGen = psAutoGen.WithProtection(database.MemoryProtection.ProtectPassword);
                    entry.Strings.Set(PwDefs.PasswordField, psAutoGen);


                    PwGroup group = database.RootGroup;
                    if (CreateEntryTargetGroup != null)
                    {
                        group = database.RootGroup.FindGroup(CreateEntryTargetGroup, true) ?? database.RootGroup;
                    }

                    // Set parent group temporarily, so that the AutoType tab, and other plugins such as PEDCalc, can obtain it in the PwEntryForm.
                    //entry.ParentGroup = group;
                    var parentGroupProperty = typeof(PwEntry).GetProperty("ParentGroup", BindingFlags.Instance | BindingFlags.Public);
                    if (parentGroupProperty != null)
                    {
                        parentGroupProperty.SetValue(entry, @group);
                    }

                    using (var entryForm = new PwEntryForm())
                    {
                        entryForm.InitEx(entry, PwEditMode.AddNewEntry, database, m_host.MainWindow.ClientIcons, false, true);

                        // Customise entry form to show drop-down for selecting URL
                        var urlBox = entryForm.Controls.Find("m_tbUrl", true).FirstOrDefault();
                        if (urlBox != null)
                        {
                            var urlCombo = new ComboBox
                            {
                                DropDownStyle = ComboBoxStyle.DropDown,
                                TabIndex      = urlBox.TabIndex,
                                Text          = urlBox.Text,
                            };
                            foreach (var urlSuggestion in urlSuggestions.Distinct())
                            {
                                urlCombo.Items.Add(urlSuggestion);
                            }
                            var syncPos = new EventHandler(delegate { urlCombo.SetBounds(urlBox.Left, urlBox.Top, urlBox.Width, urlBox.Height); });
                            urlBox.Resize += syncPos;
                            syncPos(null, EventArgs.Empty);                             // Initial sizing
                            urlBox.Parent.Controls.Add(urlCombo);
                            urlBox.Visible = false;

                            // Sync text
                            urlCombo.TextChanged += delegate { urlBox.Text = urlCombo.Text; };
                            urlBox.TextChanged   += delegate { urlCombo.Text = urlBox.Text; };
                        }

                        if (ShowForegroundDialog(entryForm) == DialogResult.OK)
                        {
                            group.AddEntry(entry, true, true);
                            m_host.MainWindow.UpdateUI(false, null, database.UINeedsIconUpdate, null, true, null, true);
                        }
                        else
                        {
                            m_host.MainWindow.UpdateUI(false, null, database.UINeedsIconUpdate, null, database.UINeedsIconUpdate, null, false);
                        }
                    }
                }
            }
            finally
            {
                mCreatingEntry = false;
            }
        }