Index: content/renderer/renderer_webcolorchooser_impl.cc |
diff --git a/content/renderer/renderer_webcolorchooser_impl.cc b/content/renderer/renderer_webcolorchooser_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d0d7ab769de3e7da1d620513d6284a0939cb8e60 |
--- /dev/null |
+++ b/content/renderer/renderer_webcolorchooser_impl.cc |
@@ -0,0 +1,79 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/renderer/renderer_webcolorchooser_impl.h" |
+ |
+#include "content/common/view_messages.h" |
+#include "content/renderer/render_view_impl.h" |
+ |
+static unsigned generateColorChooserIdentifier() { |
jam
2012/02/22 02:55:20
nit: GenerateColorChooserIdentifier
keishi
2012/02/24 14:38:54
Done.
|
+ static unsigned next = 0; |
jam
2012/02/22 02:55:20
nit: 2 space indents per chrome C++ style guide
keishi
2012/02/24 14:38:54
Done.
|
+ return ++next; |
+} |
+ |
+RendererWebColorChooserImpl::RendererWebColorChooserImpl( |
+ RenderViewImpl* render_view, WebKit::WebColorChooserClient* client) |
+ : content::RenderViewObserver(render_view), |
+ identifier_(generateColorChooserIdentifier()), |
+ client_(client) { |
+} |
+ |
+RendererWebColorChooserImpl::~RendererWebColorChooserImpl() { |
+} |
+ |
+bool RendererWebColorChooserImpl::OnMessageReceived( |
+ const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(RendererWebColorChooserImpl, message) |
+ IPC_MESSAGE_HANDLER(ViewMsg_DidChooseColorResponse, |
+ OnDidChooseColorResponse) |
+ IPC_MESSAGE_HANDLER(ViewMsg_DidEndColorChooser, |
+ OnDidEndColorChooser) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void RendererWebColorChooserImpl::FrameWillClose(WebKit::WebFrame* frame) { |
+ endChooser(); |
+} |
+ |
+void RendererWebColorChooserImpl::setSelectedColor(WebKit::WebColor color) { |
+ Send(new ViewHostMsg_SetSelectedColorInColorChooser(routing_id(), identifier_, |
+ static_cast<SkColor>(color))); |
+} |
+ |
+void RendererWebColorChooserImpl::endChooser() { |
+ Send(new ViewHostMsg_EndColorChooser(routing_id(), identifier_)); |
+ if (client_.get()) |
+ client_->didEndChooser(); |
jam
2012/02/22 02:55:20
I don't see the webkit side giving NULL pointers,
keishi
2012/02/24 14:38:54
OK. Removed all checks.
|
+} |
+ |
+void RendererWebColorChooserImpl::Open(SkColor initial_color) { |
+ Send(new ViewHostMsg_OpenColorChooser(routing_id(), identifier_, |
+ initial_color)); |
+ if (client_.get()) |
+ client_->didEndChooser(); |
+} |
+ |
+void RendererWebColorChooserImpl::OnDidChooseColorResponse( |
+ int color_chooser_id, |
+ const SkColor& color) { |
+ if (identifier_ != color_chooser_id) |
jam
2012/02/22 02:55:20
is this a race condition that you sent the picture
keishi
2012/02/24 14:38:54
No, it's for another race condition. But this race
jam
2012/02/24 21:41:17
Are you sure that's a race condition that can occu
|
+ return; |
+ if (client_.get()) |
+ client_->didChooseColor(static_cast<WebKit::WebColor>(color)); |
+} |
+ |
+void RendererWebColorChooserImpl::OnDidEndColorChooser( |
+ int color_chooser_id) { |
+ if (identifier_ != color_chooser_id) |
+ return; |
+ if (client_.get()) |
+ client_->didEndChooser(); |
+} |
+ |
+WebKit::WebColorChooserClient* RendererWebColorChooserImpl::client() { |
+ return client_.get(); |
+} |