When parting Lothlorien, Galadriel gives to Frodo the phial containing the light from Earandil's star. This gift has a crucial impact on the mission to destroy the Ring as it not only stops both Frodo and Sam being killed by Shelob, but also allows them to pass the watchers guarding the Tower of Cirith Ungol. I was wondering if this gift was based on specific visions that Galadriel may have seen in her mirror, or just considered as a potentially useful gift given the destination of the Ring-bearer.
I was wondering if (outside of the Lord of the Rings) any mention is made of a specific motivation behind the preparation of this gift?