Where did the phrase 'bought the farm' originate and what does it mean?

some say that it originated in the 30's or 40's and meant that when someone passed away, their life insurance policy was large enough that they could pay off their mortgages and "buy the farm".
A WWII pilot said that it originated from bombers in England during the war that had engine problems after takeoff and would pull a lever that dropped all their bombs at once often onto farms which the government would have to pay for and hence the pilot was said to have bought the farm.
I believe the phrase originated during WWI. If a soldier was killed the death benefit was sufficient for the surviving family members to purchase a farm. Hence, a soldier who was killed,"bought the farm."

It also might refer to the play and movie "Of Mice and Men". At the end of the story when George has to kill Lenny, George assures Lenny that he (George) has indeed bought the farm where they will both live hapily together.