Finland was a province and then a grand duchy under Sweden from the 12th to the 19th centuries , and an autonomous grand duchy of Russia after 1809 .