Solution (source code)

= Solution

The uniform prior is the <Beta distribution> $\operatorname{Beta}(1,1)$. By <Beta-binomial conjugacy>, after observing $X$ heads the posterior is
$$
\theta\mid X\sim\operatorname{Beta}(X+1,n-X+1).
$$
The <Bayes estimator under squared error loss> is the posterior mean, hence
$$
\boxed{\widehat\theta_B=\frac{X+1}{n+2}}.
$$