As has been mentioned, this is a movie invention and doesn't appear in the book. Nonetheless, it does seem interesting to consider in the context of Tolkien's other works.
Tolkien's primary dragon, the one we know most about, is not Smaug but Glaurung, the Father of Dragons from the First Age who is extensively detailed in the Silmarillion. And yes, Glaurung does display a similar ability to have knowledge beyond that which would be expected of him.
He knows substantial details of Túrin's past:
Thankless fosterling, outlaw, slayer of thy friend, thief of love, usurper of Nargothrond, captain foolhardy, and deserter of thy kin.
He knows about Túrin's family:
If thou wilt be slain, I will slay thee gladly. But small help will that be to Morwen and Nienor.
He knows about Túrin's love interest in Nargothrond:
And if thou tarry for Finduilas, then never shalt thou see Morwen again, and never at all shalt thou see Nienor thy sister; and they will curse thee.
He not only knows that Nienor is pregnant, but also who got her pregnant:
And now thou shalt know him: a stabber in the dark, treacherous to foes, faithless to friends, and a curse unto his kin, Túrin son of Húrin! But the worst of all his deeds thou shalt feel in thyself.
And it's plain that this was not all news brought to him by Orcs, because after the sack of Nargothrond he drove all the Orcs away, and Mablung the Elf was subsequently able to explore it in safety while Glaurung was out for a short while.
A possible explanation for all of this is given at the point where Glaurung utters his first words in the Silmarillion:
Then suddenly he spoke, by the evil spirit that was in him, saying: "Hail, son of Húrin. Well met!"
So dragons are therefore creatures of Morgoth inhabited by evil spirits, and the Silmarillion mentions two possible sources for these spirits. The first (not explicitly evil, but if Maiar can be corrupted then surely so can these):
When the Children awake, then the thought of Yavanna will awake also, and it will summon spirits from afar, and they will go among the kelvar and the olvar, and some will dwell therein, and be held in reverence, and their just anger shall be feared.
The second (in relation to the wolf Carcharoth but one can easily imagine a similar origin for dragons):
...he chose one from among the whelps of the race of Draugluin; and he fed him with his own hand upon living flesh, and put his power upon him. Swiftly the wolf grew, until he could creep into no den, but lay huge and hungry before the feet of Morgoth. There the fire and anguish of hell entered into him, and he became filled with a devouring spirit, tormented, terrible, and strong.
Either way it's an evil spirit, and it shouldn't be too much a stretch to imagine such an evil spirit having the ability to divine information beyond that immediately available to it.