How can template identify what page it’s being used on?

Idea #1 is correct if your template use body_class() like

<body <?php body_class(); ?>>

In this case the body tag will be something like:

<body class="page page-id-6 page-template-default">

If the id of viewed page is 6 and template used is the default.

See Codex

However, in pages the global $post variable is available even in the header and before calling the_post(). So $post->post_name will contain the slug of your page and you can make use of it as you want.