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 "components/web_contents_delegate_android/color_chooser_android.h"
7 #include "content/public/browser/android/content_view_core.h"
8 #include "content/public/browser/web_contents.h"
9 #include "content/public/browser/web_contents_view.h"
10 #include "jni/ColorChooserAndroid_jni.h"
12 namespace web_contents_delegate_android {
14 ColorChooserAndroid::ColorChooserAndroid(content::WebContents* web_contents,
15 SkColor initial_color)
16 : web_contents_(web_contents) {
17 JNIEnv* env = AttachCurrentThread();
18 content::ContentViewCore* content_view_core =
19 content::ContentViewCore::FromWebContents(web_contents);
20 DCHECK(content_view_core);
22 j_color_chooser_.Reset(Java_ColorChooserAndroid_createColorChooserAndroid(
24 reinterpret_cast<intptr_t>(this),
25 content_view_core->GetJavaObject().obj(),
29 ColorChooserAndroid::~ColorChooserAndroid() {
32 void ColorChooserAndroid::End() {
33 if (!j_color_chooser_.is_null()) {
34 JNIEnv* env = AttachCurrentThread();
35 Java_ColorChooserAndroid_closeColorChooser(env, j_color_chooser_.obj());
39 void ColorChooserAndroid::SetSelectedColor(SkColor color) {
40 // Not implemented since the color is set on the java side only, in theory
41 // it can be set from JS which would override the user selection but
42 // we don't support that for now.
45 void ColorChooserAndroid::OnColorChosen(JNIEnv* env, jobject obj, jint color) {
46 web_contents_->DidChooseColorInColorChooser(color);
47 web_contents_->DidEndColorChooser();
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
53 bool RegisterColorChooserAndroid(JNIEnv* env) {
54 return RegisterNativesImpl(env);
57 } // namespace web_contents_delegate_android