Everyone's responses are good. I'd encourage you to investigate the situation (where she learned about doing this...), teach her about appropriate behavior in public (excellent idea by the way) and keep it low key. Not that I don't think this is a SERIOUS issue because though she might just "grow out of it" but I'd not count on that, BUT if you make too big a deal, like shaming her, then she'll just take it into secret and possibly become more obsessed with it.
Masturbation IS sexuality, and once those desires are brought to our attention, a curiosity is started and experimentation begins, the question is where does it end?
I'd explain to her that those feelings are ok and natural, but they are something that is meant for when she's a grown up and married. I'd look into some good books for dealing with this topic for her age group, and maybe even seek the advise of a counselor who works with kids. Mostly I'm concerned with how she handles being asked to stop it. This is OBVIOUSLY very precious to her. Its normal to experiment with this, but not to be rebellious about moving on.
As a kid we had a neighborhood friend who used to undress for us. My brother and I knew this was wrong but enjoyed it as well and when she got caught by her dad we were not allowed to play alone with her anymore. My parents had taught us very early on about sex, it was a very open conversation, they had great books with pictures of how our bodies developed and how sex fit into the equation. I certainly knew that this behavior from my friend was not ok, and being "caught" we never wanted that to happen again. My mom also talked with us about masturbation, I don't remember how exactly because we were little, but something about how it feels good, but it is something special that we save for our husbands... Anyway, I would've been mortified to have my mother ask me to stop doing it! Also my parents were not informed about our behavior with the neighbor girl (and you know we weren't about to confess) and didn't find out about it until years later. So you might want to have a chat with your child's friends parents as well.
Best wishes, this is a tough topic, but hurray for looking for answers!