South Africa were 351 for five at the close, an overall lead of 432 on a ground where no team has successfully chased more than 271 in the fourth innings.
In contrast to the first two days, when seam bowlers held sway, South Africa scored freely against a lacklustre bowling attack on a pitch which seemed to have flattened out.
Cook made 117 to lead a powerful batting performance by the hosts.
He shared century partnerships with Dean Elgar (52) and Hashim Amla (48). Cook and Elgar put on 116 for the first wicket, their second three-figure opening stand of the match. Then Cook and Amla added 105 for the second wicket off only 118 balls as the Sri Lankan bowlers and fielders wilted.
After two interruptions for rain, the playing hours were changed and South Africa scored 182 runs off 40 overs in an extended post-lunch period. They added another 131 off 29 overs before the close.
Cook, who made his third century in only seven Tests, survived a chance to gully off Suranga Lakmal when he was on 62, but played with more freedom than in previous appearances. He reached his fifty off 81 balls and his hundred off 152 deliveries.
He was out soon after tea when he edged an attempted cut against Dushmantha Chameera to be caught behind. His Test-best 117 was scored off 178 balls with 11 fours.
With Sri Lanka setting defensive fields, the South African batsmen were able to score plenty of singles and keep the score moving. They lost two more wickets, both to off-spinner Dhananjaya de Silva, before captain Faf du Plessis and Quinton de Kock added an unbeaten 74 off 92 balls before the close.
An indication of the lack of control exerted by the Sri Lankan bowlers was that they only bowled three maiden overs during the innings, two of them by Lakmal, who added the wicket of Elgar to the five he collected in the first innings. But Lakmal, who bowled 27 overs in the first innings, seldom threatened on Wednesday.
Sri Lanka were bowled out early in the day for 205, with Vernon Philander finishing with five for 45, losing their remaining three wickets for 24 runs.
Philander struck twice in the first over of the day after Sri Lanka resumed at 181 for seven. His first ball was a perfect out-swinger which De Silva edged to wicketkeeper De Kock. De Silva had batted impressively to make 43 on Tuesday but Philander made the ball deviate just enough to catch the edge as De Silva played back defensively.
Lakmal hit a boundary but then chipped the final ball of the over to Kyle Abbott at mid-on.
Chameera and Nuwan Pradeep added 20 for the last wicket before Chameera edged Abbott to Amla at first slip after making a Test-best 19. Abbott finished with three for 63.