Commit 621ae172 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

[WebLayer] Hook up color picker for inputs with type="color"

Change-Id: I8e0c93abdbaf040347448a51c0280cbfe524abc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1877307
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709064}
parent b30e87e2
...@@ -164,6 +164,7 @@ jumbo_static_library("weblayer_lib") { ...@@ -164,6 +164,7 @@ jumbo_static_library("weblayer_lib") {
if (is_android) { if (is_android) {
deps += [ deps += [
"//components/embedder_support/android:web_contents_delegate",
"//components/version_info", "//components/version_info",
"//ui/android", "//ui/android",
"//weblayer/browser/java:jni", "//weblayer/browser/java:jni",
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "base/android/callback_android.h" #include "base/android/callback_android.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "components/embedder_support/android/delegate/color_chooser_android.h"
#include "weblayer/browser/isolated_world_ids.h" #include "weblayer/browser/isolated_world_ids.h"
#include "weblayer/browser/java/jni/BrowserControllerImpl_jni.h" #include "weblayer/browser/java/jni/BrowserControllerImpl_jni.h"
#include "weblayer/browser/top_controls_container_view.h" #include "weblayer/browser/top_controls_container_view.h"
...@@ -181,6 +182,18 @@ void BrowserControllerImpl::DidNavigateMainFramePostCommit( ...@@ -181,6 +182,18 @@ void BrowserControllerImpl::DidNavigateMainFramePostCommit(
observer.DisplayedUrlChanged(web_contents->GetVisibleURL()); observer.DisplayedUrlChanged(web_contents->GetVisibleURL());
} }
content::ColorChooser* BrowserControllerImpl::OpenColorChooser(
content::WebContents* web_contents,
SkColor color,
const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions) {
#if defined(OS_ANDROID)
return new web_contents_delegate_android::ColorChooserAndroid(
web_contents, color, suggestions);
#else
return nullptr;
#endif
}
void BrowserControllerImpl::RunFileChooser( void BrowserControllerImpl::RunFileChooser(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
std::unique_ptr<content::FileSelectListener> listener, std::unique_ptr<content::FileSelectListener> listener,
......
...@@ -76,6 +76,11 @@ class BrowserControllerImpl : public BrowserController, ...@@ -76,6 +76,11 @@ class BrowserControllerImpl : public BrowserController,
// content::WebContentsDelegate: // content::WebContentsDelegate:
void DidNavigateMainFramePostCommit( void DidNavigateMainFramePostCommit(
content::WebContents* web_contents) override; content::WebContents* web_contents) override;
content::ColorChooser* OpenColorChooser(
content::WebContents* web_contents,
SkColor color,
const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions)
override;
void RunFileChooser(content::RenderFrameHost* render_frame_host, void RunFileChooser(content::RenderFrameHost* render_frame_host,
std::unique_ptr<content::FileSelectListener> listener, std::unique_ptr<content::FileSelectListener> listener,
const blink::mojom::FileChooserParams& params) override; const blink::mojom::FileChooserParams& params) override;
......
...@@ -42,6 +42,7 @@ android_library("java") { ...@@ -42,6 +42,7 @@ android_library("java") {
"//base:base_java", "//base:base_java",
"//base:jni_java", "//base:jni_java",
"//components/embedder_support/android:application_java", "//components/embedder_support/android:application_java",
"//components/embedder_support/android:web_contents_delegate_java",
"//content/public/android:content_java", "//content/public/android:content_java",
"//third_party/android_deps:com_android_support_support_compat_java", "//third_party/android_deps:com_android_support_support_compat_java",
"//ui/android:ui_java", "//ui/android:ui_java",
......
...@@ -9,6 +9,7 @@ import android.content.Intent; ...@@ -9,6 +9,7 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import org.chromium.components.embedder_support.application.ClassLoaderContextWrapperFactory;
import org.chromium.weblayer_private.aidl.BrowserFragmentArgs; import org.chromium.weblayer_private.aidl.BrowserFragmentArgs;
import org.chromium.weblayer_private.aidl.IBrowserFragment; import org.chromium.weblayer_private.aidl.IBrowserFragment;
import org.chromium.weblayer_private.aidl.IBrowserFragmentController; import org.chromium.weblayer_private.aidl.IBrowserFragmentController;
...@@ -32,9 +33,9 @@ public class BrowserFragmentImpl extends RemoteFragmentImpl { ...@@ -32,9 +33,9 @@ public class BrowserFragmentImpl extends RemoteFragmentImpl {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
mContext = context; mContext = ClassLoaderContextWrapperFactory.get(context);
if (mController != null) { // On first creation, onAttach is called before onCreate if (mController != null) { // On first creation, onAttach is called before onCreate
mController.onFragmentAttached(context, new FragmentWindowAndroid(context, this)); mController.onFragmentAttached(mContext, new FragmentWindowAndroid(mContext, this));
} }
} }
......
...@@ -267,7 +267,7 @@ instrumentation_test_apk("weblayer_instrumentation_test_apk") { ...@@ -267,7 +267,7 @@ instrumentation_test_apk("weblayer_instrumentation_test_apk") {
"javatests/src/org/chromium/weblayer/test/RenderingTest.java", "javatests/src/org/chromium/weblayer/test/RenderingTest.java",
"javatests/src/org/chromium/weblayer/test/WebLayerShellActivityTestRule.java", "javatests/src/org/chromium/weblayer/test/WebLayerShellActivityTestRule.java",
"javatests/src/org/chromium/weblayer/test/FragmentRestoreTest.java", "javatests/src/org/chromium/weblayer/test/FragmentRestoreTest.java",
"javatests/src/org/chromium/weblayer/test/FileInputTest.java", "javatests/src/org/chromium/weblayer/test/InputTypesTest.java",
"shell_apk/src/org/chromium/weblayer/shell/WebLayerShellActivity.java", "shell_apk/src/org/chromium/weblayer/shell/WebLayerShellActivity.java",
] ]
additional_apks = [ additional_apks = [
......
...@@ -34,7 +34,7 @@ import java.io.File; ...@@ -34,7 +34,7 @@ import java.io.File;
* Tests that file inputs work as expected. * Tests that file inputs work as expected.
*/ */
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class FileInputTest { public class InputTypesTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule();
...@@ -83,7 +83,7 @@ public class FileInputTest { ...@@ -83,7 +83,7 @@ public class FileInputTest {
Assert.assertTrue(mTestServer.start(0)); Assert.assertTrue(mTestServer.start(0));
WebLayerShellActivity activity = WebLayerShellActivity activity =
mActivityTestRule.launchShellWithUrl(mTestServer.getURL("/file_input.html")); mActivityTestRule.launchShellWithUrl(mTestServer.getURL("/input_types.html"));
mTempFile = File.createTempFile("file", null); mTempFile = File.createTempFile("file", null);
activity.setIntentInterceptor(mIntentInterceptor); activity.setIntentInterceptor(mIntentInterceptor);
...@@ -102,7 +102,7 @@ public class FileInputTest { ...@@ -102,7 +102,7 @@ public class FileInputTest {
public void testFileInputBasic() { public void testFileInputBasic() {
String id = "input_file"; String id = "input_file";
openInputWithId(id); openFileInputWithId(id);
Assert.assertFalse(getContentIntent().hasCategory(Intent.CATEGORY_OPENABLE)); Assert.assertFalse(getContentIntent().hasCategory(Intent.CATEGORY_OPENABLE));
...@@ -115,12 +115,12 @@ public class FileInputTest { ...@@ -115,12 +115,12 @@ public class FileInputTest {
String id = "input_file"; String id = "input_file";
// First add a file. // First add a file.
openInputWithId(id); openFileInputWithId(id);
waitForNumFiles(id, 1); waitForNumFiles(id, 1);
// Now cancel the intent. // Now cancel the intent.
mIntentInterceptor.setResponse(Activity.RESULT_CANCELED, null); mIntentInterceptor.setResponse(Activity.RESULT_CANCELED, null);
openInputWithId(id); openFileInputWithId(id);
waitForNumFiles(id, 0); waitForNumFiles(id, 0);
} }
...@@ -129,7 +129,7 @@ public class FileInputTest { ...@@ -129,7 +129,7 @@ public class FileInputTest {
public void testFileInputText() { public void testFileInputText() {
String id = "input_text"; String id = "input_text";
openInputWithId(id); openFileInputWithId(id);
Assert.assertTrue(getContentIntent().hasCategory(Intent.CATEGORY_OPENABLE)); Assert.assertTrue(getContentIntent().hasCategory(Intent.CATEGORY_OPENABLE));
...@@ -141,7 +141,7 @@ public class FileInputTest { ...@@ -141,7 +141,7 @@ public class FileInputTest {
public void testFileInputAny() { public void testFileInputAny() {
String id = "input_any"; String id = "input_any";
openInputWithId(id); openFileInputWithId(id);
Assert.assertFalse(getContentIntent().hasCategory(Intent.CATEGORY_OPENABLE)); Assert.assertFalse(getContentIntent().hasCategory(Intent.CATEGORY_OPENABLE));
...@@ -160,7 +160,7 @@ public class FileInputTest { ...@@ -160,7 +160,7 @@ public class FileInputTest {
mIntentInterceptor.setResponse(Activity.RESULT_OK, response); mIntentInterceptor.setResponse(Activity.RESULT_OK, response);
String id = "input_file_multiple"; String id = "input_file_multiple";
openInputWithId(id); openFileInputWithId(id);
Intent contentIntent = getContentIntent(); Intent contentIntent = getContentIntent();
Assert.assertFalse(contentIntent.hasCategory(Intent.CATEGORY_OPENABLE)); Assert.assertFalse(contentIntent.hasCategory(Intent.CATEGORY_OPENABLE));
...@@ -175,7 +175,7 @@ public class FileInputTest { ...@@ -175,7 +175,7 @@ public class FileInputTest {
public void testFileInputImage() { public void testFileInputImage() {
String id = "input_image"; String id = "input_image";
openInputWithId(id); openFileInputWithId(id);
Assert.assertEquals( Assert.assertEquals(
MediaStore.ACTION_IMAGE_CAPTURE, mIntentInterceptor.mLastIntent.getAction()); MediaStore.ACTION_IMAGE_CAPTURE, mIntentInterceptor.mLastIntent.getAction());
...@@ -188,7 +188,7 @@ public class FileInputTest { ...@@ -188,7 +188,7 @@ public class FileInputTest {
public void testFileInputAudio() { public void testFileInputAudio() {
String id = "input_audio"; String id = "input_audio";
openInputWithId(id); openFileInputWithId(id);
Assert.assertEquals(MediaStore.Audio.Media.RECORD_SOUND_ACTION, Assert.assertEquals(MediaStore.Audio.Media.RECORD_SOUND_ACTION,
mIntentInterceptor.mLastIntent.getAction()); mIntentInterceptor.mLastIntent.getAction());
...@@ -196,7 +196,19 @@ public class FileInputTest { ...@@ -196,7 +196,19 @@ public class FileInputTest {
waitForNumFiles(id, 1); waitForNumFiles(id, 1);
} }
private void openInputWithId(String id) { @Test
@SmallTest
public void testColorInput() {
// Just make sure we don't crash when opening the color picker.
mActivityTestRule.executeScriptSync("var done = false; document.onclick = function() {"
+ "document.getElementById('input_color').click(); done = true;}");
EventUtils.simulateTouchCenterOfView(
mActivityTestRule.getActivity().getWindow().getDecorView());
CriteriaHelper.pollInstrumentationThread(
() -> { return mActivityTestRule.executeScriptAndExtractBoolean("done"); });
}
private void openFileInputWithId(String id) {
// We need to click the input after user input, otherwise it won't open due to security // We need to click the input after user input, otherwise it won't open due to security
// policy. // policy.
mActivityTestRule.executeScriptSync( mActivityTestRule.executeScriptSync(
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<input id="input_file_multiple" type="file" multiple /> <input id="input_file_multiple" type="file" multiple />
<input id="input_image" type="file" accept="image/*" capture /> <input id="input_image" type="file" accept="image/*" capture />
<input id="input_audio" type="file" accept="audio/*" capture /> <input id="input_audio" type="file" accept="audio/*" capture />
<input id="input_color" type="color" />
</form> </form>
</body> </body>
</html> </html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment