Refactor management of overview window copy lifetime into a separate class.
[chromium-blink-merge.git] / content / renderer / renderer_webcolorchooser_impl.cc
blob337ec7e6212d71f5622153ad4306c01b359cc86b
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/renderer_webcolorchooser_impl.h"
7 #include "content/common/view_messages.h"
8 #include "content/renderer/render_view_impl.h"
10 namespace content {
12 static int GenerateColorChooserIdentifier() {
13 static int next = 0;
14 return ++next;
17 RendererWebColorChooserImpl::RendererWebColorChooserImpl(
18 RenderViewImpl* render_view,
19 WebKit::WebColorChooserClient* client)
20 : RenderViewObserver(render_view),
21 identifier_(GenerateColorChooserIdentifier()),
22 client_(client) {
25 RendererWebColorChooserImpl::~RendererWebColorChooserImpl() {
28 bool RendererWebColorChooserImpl::OnMessageReceived(
29 const IPC::Message& message) {
30 bool handled = true;
31 IPC_BEGIN_MESSAGE_MAP(RendererWebColorChooserImpl, message)
32 IPC_MESSAGE_HANDLER(ViewMsg_DidChooseColorResponse,
33 OnDidChooseColorResponse)
34 IPC_MESSAGE_HANDLER(ViewMsg_DidEndColorChooser,
35 OnDidEndColorChooser)
36 IPC_MESSAGE_UNHANDLED(handled = false)
37 IPC_END_MESSAGE_MAP()
38 return handled;
41 void RendererWebColorChooserImpl::setSelectedColor(WebKit::WebColor color) {
42 Send(new ViewHostMsg_SetSelectedColorInColorChooser(routing_id(), identifier_,
43 static_cast<SkColor>(color)));
46 void RendererWebColorChooserImpl::endChooser() {
47 Send(new ViewHostMsg_EndColorChooser(routing_id(), identifier_));
50 void RendererWebColorChooserImpl::Open(SkColor initial_color) {
51 Send(new ViewHostMsg_OpenColorChooser(routing_id(), identifier_,
52 initial_color));
55 void RendererWebColorChooserImpl::OnDidChooseColorResponse(int color_chooser_id,
56 SkColor color) {
57 DCHECK(identifier_ == color_chooser_id);
59 client_->didChooseColor(static_cast<WebKit::WebColor>(color));
62 void RendererWebColorChooserImpl::OnDidEndColorChooser(int color_chooser_id) {
63 if (identifier_ != color_chooser_id)
64 return;
65 client_->didEndChooser();
68 } // namespace content