Commit 0b63433f authored by Oksana Zhuravlova's avatar Oksana Zhuravlova Committed by Commit Bot

Convert DateTimeChooser client to use BrowserInterfaceBroker

This change converts DateTimeChooser mojom interface client in
blink to use BrowserInterfaceBroker. Since DateTimeChooserAndroid is a
WebContentsObserver, a static helper function is used to register its
binder.

Bug: 936482,1006361
Change-Id: I3742b3c1c0ab2812308a9956ee69691b35c6848b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863853Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKeishi Hattori <keishi@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710079}
parent 4a7a3817
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/i18n/char_iterator.h" #include "base/i18n/char_iterator.h"
#include "base/i18n/unicodestring.h" #include "base/i18n/unicodestring.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/android/content_jni_headers/DateTimeChooserAndroid_jni.h" #include "content/public/android/content_jni_headers/DateTimeChooserAndroid_jni.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
...@@ -45,13 +44,9 @@ base::string16 SanitizeSuggestionString(const base::string16& string) { ...@@ -45,13 +44,9 @@ base::string16 SanitizeSuggestionString(const base::string16& string) {
namespace content { namespace content {
// DateTimeChooserAndroid implementation // DateTimeChooserAndroid implementation
DateTimeChooserAndroid::DateTimeChooserAndroid(WebContentsImpl* web_contents) DateTimeChooserAndroid::DateTimeChooserAndroid(WebContents* web_contents)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
date_time_chooser_receiver_(this) { date_time_chooser_receiver_(this) {}
binders_.Add(
base::BindRepeating(&DateTimeChooserAndroid::OnDateTimeChooserReceiver,
base::Unretained(this)));
}
DateTimeChooserAndroid::~DateTimeChooserAndroid() { DateTimeChooserAndroid::~DateTimeChooserAndroid() {
} }
...@@ -116,11 +111,6 @@ void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, ...@@ -116,11 +111,6 @@ void DateTimeChooserAndroid::CancelDialog(JNIEnv* env,
std::move(open_date_time_response_callback_).Run(false, 0.0); std::move(open_date_time_response_callback_).Run(false, 0.0);
} }
void DateTimeChooserAndroid::OnInterfaceRequestFromFrame( WEB_CONTENTS_USER_DATA_KEY_IMPL(DateTimeChooserAndroid)
content::RenderFrameHost* render_frame_host,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
binders_.TryBind(interface_name, interface_pipe);
}
} // namespace content } // namespace content
...@@ -12,22 +12,21 @@ ...@@ -12,22 +12,21 @@
#include "base/android/jni_weak_ref.h" #include "base/android/jni_weak_ref.h"
#include "base/macros.h" #include "base/macros.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "services/service_manager/public/cpp/binder_map.h"
#include "third_party/blink/public/mojom/choosers/date_time_chooser.mojom.h" #include "third_party/blink/public/mojom/choosers/date_time_chooser.mojom.h"
#include "ui/base/ime/text_input_type.h" #include "ui/base/ime/text_input_type.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
namespace content { namespace content {
class WebContentsImpl;
class RenderFrameHost;
// Android implementation for DateTimeChooser dialogs. // Android implementation for DateTimeChooser dialogs.
class DateTimeChooserAndroid : public blink::mojom::DateTimeChooser, class DateTimeChooserAndroid
public WebContentsObserver { : public blink::mojom::DateTimeChooser,
public WebContentsObserver,
public WebContentsUserData<DateTimeChooserAndroid> {
public: public:
explicit DateTimeChooserAndroid(WebContentsImpl* web_contents); explicit DateTimeChooserAndroid(WebContents* web_contents);
~DateTimeChooserAndroid() override; ~DateTimeChooserAndroid() override;
void OnDateTimeChooserReceiver( void OnDateTimeChooserReceiver(
...@@ -47,20 +46,15 @@ class DateTimeChooserAndroid : public blink::mojom::DateTimeChooser, ...@@ -47,20 +46,15 @@ class DateTimeChooserAndroid : public blink::mojom::DateTimeChooser,
// Closes the dialog without propagating any changes. // Closes the dialog without propagating any changes.
void CancelDialog(JNIEnv* env, const base::android::JavaRef<jobject>&); void CancelDialog(JNIEnv* env, const base::android::JavaRef<jobject>&);
// WebContentsObserver overrides:
void OnInterfaceRequestFromFrame(
content::RenderFrameHost* render_frame_host,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) override;
private: private:
friend class content::WebContentsUserData<DateTimeChooserAndroid>;
OpenDateTimeDialogCallback open_date_time_response_callback_; OpenDateTimeDialogCallback open_date_time_response_callback_;
base::android::ScopedJavaGlobalRef<jobject> j_date_time_chooser_; base::android::ScopedJavaGlobalRef<jobject> j_date_time_chooser_;
mojo::Receiver<blink::mojom::DateTimeChooser> date_time_chooser_receiver_; mojo::Receiver<blink::mojom::DateTimeChooser> date_time_chooser_receiver_;
service_manager::BinderMap binders_; WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(DateTimeChooserAndroid); DISALLOW_COPY_AND_ASSIGN(DateTimeChooserAndroid);
}; };
......
...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
#endif #endif
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "content/browser/android/date_time_chooser_android.h"
#include "services/device/public/mojom/nfc.mojom.h" #include "services/device/public/mojom/nfc.mojom.h"
#include "third_party/blink/public/mojom/hid/hid.mojom.h" #include "third_party/blink/public/mojom/hid/hid.mojom.h"
#endif #endif
...@@ -141,6 +142,16 @@ void BindTextDetection( ...@@ -141,6 +142,16 @@ void BindTextDetection(
GetShapeDetectionService()->BindTextDetection(std::move(receiver)); GetShapeDetectionService()->BindTextDetection(std::move(receiver));
} }
#if defined(OS_ANDROID)
void BindDateTimeChooserForFrame(
content::RenderFrameHost* host,
mojo::PendingReceiver<blink::mojom::DateTimeChooser> receiver) {
auto* date_time_chooser = DateTimeChooserAndroid::FromWebContents(
WebContents::FromRenderFrameHost(host));
date_time_chooser->OnDateTimeChooserReceiver(std::move(receiver));
}
#endif
} // namespace } // namespace
// Documents/frames // Documents/frames
...@@ -300,6 +311,10 @@ void PopulateBinderMapWithContext( ...@@ -300,6 +311,10 @@ void PopulateBinderMapWithContext(
base::BindRepeating(&WakeLockServiceImpl::Create)); base::BindRepeating(&WakeLockServiceImpl::Create));
map->Add<device::mojom::VRService>( map->Add<device::mojom::VRService>(
base::BindRepeating(&WebvrServiceProvider::BindWebvrService)); base::BindRepeating(&WebvrServiceProvider::BindWebvrService));
#if defined(OS_ANDROID)
map->Add<blink::mojom::DateTimeChooser>(
base::BindRepeating(&BindDateTimeChooserForFrame));
#endif // defined(OS_ANDROID)
GetContentClient()->browser()->RegisterBrowserInterfaceBindersForFrame(map); GetContentClient()->browser()->RegisterBrowserInterfaceBindersForFrame(map);
} }
......
...@@ -2154,7 +2154,7 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params) { ...@@ -2154,7 +2154,7 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params) {
manifest_manager_host_.reset(new ManifestManagerHost(this)); manifest_manager_host_.reset(new ManifestManagerHost(this));
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
date_time_chooser_.reset(new DateTimeChooserAndroid(this)); DateTimeChooserAndroid::CreateForWebContents(this);
#endif #endif
// BrowserPluginGuest::Init needs to be called after this WebContents has // BrowserPluginGuest::Init needs to be called after this WebContents has
......
...@@ -91,7 +91,6 @@ namespace content { ...@@ -91,7 +91,6 @@ namespace content {
enum class PictureInPictureResult; enum class PictureInPictureResult;
class BrowserPluginEmbedder; class BrowserPluginEmbedder;
class BrowserPluginGuest; class BrowserPluginGuest;
class DateTimeChooserAndroid;
class DisplayCutoutHostImpl; class DisplayCutoutHostImpl;
class FindRequestManager; class FindRequestManager;
class InterstitialPageImpl; class InterstitialPageImpl;
...@@ -1721,12 +1720,6 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, ...@@ -1721,12 +1720,6 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
gfx::Size device_emulation_size_; gfx::Size device_emulation_size_;
gfx::Size view_size_before_emulation_; gfx::Size view_size_before_emulation_;
#if defined(OS_ANDROID)
// Date time chooser opened by this tab.
// Only used in Android since all other platforms use a multi field UI.
std::unique_ptr<DateTimeChooserAndroid> date_time_chooser_;
#endif
// Holds information about a current color chooser dialog, if one is visible. // Holds information about a current color chooser dialog, if one is visible.
class ColorChooser; class ColorChooser;
std::unique_ptr<ColorChooser> color_chooser_; std::unique_ptr<ColorChooser> color_chooser_;
......
...@@ -197,7 +197,6 @@ const service_manager::Manifest& GetContentBrowserManifest() { ...@@ -197,7 +197,6 @@ const service_manager::Manifest& GetContentBrowserManifest() {
"autofill.mojom.PasswordManagerDriver", "autofill.mojom.PasswordManagerDriver",
"blink.mojom.CacheStorage", "blink.mojom.CacheStorage",
"blink.mojom.ColorChooserFactory", "blink.mojom.ColorChooserFactory",
"blink.mojom.DateTimeChooser",
"blink.mojom.DisplayCutoutHost", "blink.mojom.DisplayCutoutHost",
"blink.mojom.DedicatedWorkerHostFactory", "blink.mojom.DedicatedWorkerHostFactory",
"blink.mojom.GeolocationService", "blink.mojom.GeolocationService",
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "third_party/blink/renderer/core/html/forms/external_date_time_chooser.h" #include "third_party/blink/renderer/core/html/forms/external_date_time_chooser.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/forms/date_time_chooser_client.h" #include "third_party/blink/renderer/core/html/forms/date_time_chooser_client.h"
...@@ -109,7 +109,7 @@ bool ExternalDateTimeChooser::IsShowingDateTimeChooserUI() const { ...@@ -109,7 +109,7 @@ bool ExternalDateTimeChooser::IsShowingDateTimeChooserUI() const {
mojom::blink::DateTimeChooser& ExternalDateTimeChooser::GetDateTimeChooser( mojom::blink::DateTimeChooser& ExternalDateTimeChooser::GetDateTimeChooser(
LocalFrame* frame) { LocalFrame* frame) {
if (!date_time_chooser_) { if (!date_time_chooser_) {
frame->GetInterfaceProvider().GetInterface( frame->GetBrowserInterfaceBroker().GetInterface(
date_time_chooser_.BindNewPipeAndPassReceiver()); date_time_chooser_.BindNewPipeAndPassReceiver());
} }
......
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