Commit 9e47ab57 authored by ajith.v's avatar ajith.v Committed by Commit bot

Optimizing DateTimeAndroid and ColorChooserAndroid initializations.

Some of the functions are direct wrapper to WebContents methods. In this
patch, taken care of removing those dependencies and added extra validation to prevent run time crashes.

BUG=398263

Review URL: https://codereview.chromium.org/639703004

Cr-Commit-Position: refs/heads/master@{#302146}
parent d3574dfb
......@@ -4,14 +4,15 @@
package org.chromium.components.web_contents_delegate_android;
import android.app.Activity;
import android.content.Context;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.ui.ColorPickerDialog;
import org.chromium.ui.ColorSuggestion;
import org.chromium.ui.OnColorChangedListener;
import org.chromium.ui.base.WindowAndroid;
/**
* ColorChooserAndroid communicates with the java ColorPickerDialog and the
......@@ -48,11 +49,13 @@ public class ColorChooserAndroid {
@CalledByNative
public static ColorChooserAndroid createColorChooserAndroid(
long nativeColorChooserAndroid,
ContentViewCore contentViewCore,
WindowAndroid windowAndroid,
int initialColor,
ColorSuggestion[] suggestions) {
Activity windowAndroidActivity = windowAndroid.getActivity().get();
if (windowAndroidActivity == null) return null;
ColorChooserAndroid chooser = new ColorChooserAndroid(nativeColorChooserAndroid,
contentViewCore.getContext(), initialColor, suggestions);
windowAndroidActivity, initialColor, suggestions);
chooser.openColorChooser();
return chooser;
}
......
......@@ -6,10 +6,10 @@
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "content/public/browser/android/content_view_core.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/color_suggestion.h"
#include "jni/ColorChooserAndroid_jni.h"
#include "ui/base/android/window_android.h"
using base::android::ConvertUTF16ToJavaString;
......@@ -21,10 +21,6 @@ ColorChooserAndroid::ColorChooserAndroid(
const std::vector<content::ColorSuggestion>& suggestions)
: web_contents_(web_contents) {
JNIEnv* env = AttachCurrentThread();
content::ContentViewCore* content_view_core =
content::ContentViewCore::FromWebContents(web_contents);
DCHECK(content_view_core);
ScopedJavaLocalRef<jobjectArray> suggestions_array;
if (suggestions.size() > 0) {
......@@ -46,9 +42,11 @@ ColorChooserAndroid::ColorChooserAndroid(
j_color_chooser_.Reset(Java_ColorChooserAndroid_createColorChooserAndroid(
env,
reinterpret_cast<intptr_t>(this),
content_view_core->GetJavaObject().obj(),
web_contents->GetTopLevelNativeWindow()->GetJavaObject().obj(),
initial_color,
suggestions_array.obj()));
if (j_color_chooser_.is_null())
OnColorChosen(env, j_color_chooser_.obj(), initial_color);
}
ColorChooserAndroid::~ColorChooserAndroid() {
......
......@@ -9,11 +9,11 @@
#include "base/i18n/char_iterator.h"
#include "content/common/date_time_suggestion.h"
#include "content/common/view_messages.h"
#include "content/public/browser/android/content_view_core.h"
#include "content/public/browser/render_view_host.h"
#include "jni/DateTimeChooserAndroid_jni.h"
#include "third_party/icu/source/common/unicode/uchar.h"
#include "third_party/icu/source/common/unicode/unistr.h"
#include "ui/base/android/window_android.h"
using base::android::AttachCurrentThread;
using base::android::ConvertJavaStringToUTF16;
......@@ -73,7 +73,7 @@ void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) {
}
void DateTimeChooserAndroid::ShowDialog(
ContentViewCore* content,
gfx::NativeWindow native_window,
RenderViewHost* host,
ui::TextInputType dialog_type,
double dialog_value,
......@@ -104,7 +104,7 @@ void DateTimeChooserAndroid::ShowDialog(
j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser(
env,
content->GetJavaObject().obj(),
native_window->GetJavaObject().obj(),
reinterpret_cast<intptr_t>(this),
dialog_type,
dialog_value,
......@@ -112,6 +112,8 @@ void DateTimeChooserAndroid::ShowDialog(
max,
step,
suggestions_array.obj()));
if (j_date_time_chooser_.is_null())
ReplaceDateTime(env, j_date_time_chooser_.obj(), dialog_value);
}
// ----------------------------------------------------------------------------
......
......@@ -11,6 +11,7 @@
#include "base/android/jni_weak_ref.h"
#include "base/memory/scoped_ptr.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/gfx/native_widget_types.h"
namespace content {
......@@ -27,7 +28,7 @@ class DateTimeChooserAndroid {
// DateTimeChooser implementation:
// Shows the dialog. |dialog_value| is the date/time value converted to a
// number as defined in HTML. (See blink::InputType::parseToNumber())
void ShowDialog(ContentViewCore* content,
void ShowDialog(gfx::NativeWindow native_window,
RenderViewHost* host,
ui::TextInputType dialog_type,
double dialog_value,
......
......@@ -105,11 +105,9 @@
#include "ui/gl/gl_switches.h"
#if defined(OS_ANDROID)
#include "content/browser/android/content_view_core_impl.h"
#include "content/browser/android/date_time_chooser_android.h"
#include "content/browser/media/android/browser_media_player_manager.h"
#include "content/browser/web_contents/web_contents_android.h"
#include "content/public/browser/android/content_view_core.h"
#endif
#if defined(OS_MACOSX)
......@@ -2878,7 +2876,7 @@ void WebContentsImpl::OnFindMatchRectsReply(
void WebContentsImpl::OnOpenDateTimeDialog(
const ViewHostMsg_DateTimeDialogValue_Params& value) {
date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
GetRenderViewHost(),
value.dialog_type,
value.dialog_value,
......
......@@ -4,11 +4,12 @@
package org.chromium.content.browser.input;
import android.app.Activity;
import android.content.Context;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.picker.DateTimeSuggestion;
import org.chromium.ui.picker.InputDialogContainer;
......@@ -47,15 +48,15 @@ class DateTimeChooserAndroid {
@CalledByNative
private static DateTimeChooserAndroid createDateTimeChooser(
ContentViewCore contentViewCore,
WindowAndroid windowAndroid,
long nativeDateTimeChooserAndroid,
int dialogType, double dialogValue,
double min, double max, double step,
DateTimeSuggestion[] suggestions) {
Activity windowAndroidActivity = windowAndroid.getActivity().get();
if (windowAndroidActivity == null) return null;
DateTimeChooserAndroid chooser =
new DateTimeChooserAndroid(
contentViewCore.getContext(),
nativeDateTimeChooserAndroid);
new DateTimeChooserAndroid(windowAndroidActivity, nativeDateTimeChooserAndroid);
chooser.showDialog(dialogType, dialogValue, min, max, step, suggestions);
return chooser;
}
......
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