Commit 5b666724 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert ContextualSearchJsApiService to new Mojo types

This CL converts ContextualSearchJsApiServicePtr and
ContextualSearchJsApiServiceRequest to new Mojo types.

It uses Remote and PendingReceiver instead of
ContextualSearchJsApiServicePtr and
ContextualSearchJsApiServiceRequest.

Bug: 955171
Change-Id: I2e7c0c5fc10303a949bf57bb1bc1df02f5fa7763
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1810162Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarDonn Denman <donnd@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#697868}
parent d197de2e
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <utility> #include <utility>
#include "components/contextual_search/content/browser/contextual_search_js_api_handler.h" #include "components/contextual_search/content/browser/contextual_search_js_api_handler.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace contextual_search { namespace contextual_search {
...@@ -39,10 +39,11 @@ void ContextualSearchJsApiServiceImpl::HandleChangeOverlayPosition( ...@@ -39,10 +39,11 @@ void ContextualSearchJsApiServiceImpl::HandleChangeOverlayPosition(
// static // static
void CreateContextualSearchJsApiService( void CreateContextualSearchJsApiService(
ContextualSearchJsApiHandler* contextual_search_js_api_handler, ContextualSearchJsApiHandler* contextual_search_js_api_handler,
mojom::ContextualSearchJsApiServiceRequest request) { mojo::PendingReceiver<mojom::ContextualSearchJsApiService> receiver) {
mojo::MakeStrongBinding(std::make_unique<ContextualSearchJsApiServiceImpl>( mojo::MakeSelfOwnedReceiver(
contextual_search_js_api_handler), std::make_unique<ContextualSearchJsApiServiceImpl>(
std::move(request)); contextual_search_js_api_handler),
std::move(receiver));
} }
} // namespace contextual_search } // namespace contextual_search
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "components/contextual_search/content/browser/contextual_search_js_api_handler.h" #include "components/contextual_search/content/browser/contextual_search_js_api_handler.h"
#include "components/contextual_search/content/common/mojom/contextual_search_js_api_service.mojom.h" #include "components/contextual_search/content/common/mojom/contextual_search_js_api_service.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
namespace contextual_search { namespace contextual_search {
...@@ -48,7 +49,7 @@ class ContextualSearchJsApiServiceImpl ...@@ -48,7 +49,7 @@ class ContextualSearchJsApiServiceImpl
// static // static
void CreateContextualSearchJsApiService( void CreateContextualSearchJsApiService(
ContextualSearchJsApiHandler* contextual_search_js_api_handler, ContextualSearchJsApiHandler* contextual_search_js_api_handler,
mojom::ContextualSearchJsApiServiceRequest request); mojo::PendingReceiver<mojom::ContextualSearchJsApiService> receiver);
} // namespace contextual_search } // namespace contextual_search
......
...@@ -75,10 +75,9 @@ gin::ObjectTemplateBuilder ContextualSearchWrapper::GetObjectTemplateBuilder( ...@@ -75,10 +75,9 @@ gin::ObjectTemplateBuilder ContextualSearchWrapper::GetObjectTemplateBuilder(
} }
bool ContextualSearchWrapper::EnsureServiceConnected() { bool ContextualSearchWrapper::EnsureServiceConnected() {
if (render_frame() && (!contextual_search_js_api_service_ || if (render_frame() && !contextual_search_js_api_service_) {
!contextual_search_js_api_service_.is_bound())) {
render_frame()->GetRemoteInterfaces()->GetInterface( render_frame()->GetRemoteInterfaces()->GetInterface(
&contextual_search_js_api_service_); contextual_search_js_api_service_.BindNewPipeAndPassReceiver());
return true; return true;
} }
return false; return false;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "gin/handle.h" #include "gin/handle.h"
#include "gin/wrappable.h" #include "gin/wrappable.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace blink { namespace blink {
class WebFrame; class WebFrame;
...@@ -56,7 +57,8 @@ class ContextualSearchWrapper : public gin::Wrappable<ContextualSearchWrapper>, ...@@ -56,7 +57,8 @@ class ContextualSearchWrapper : public gin::Wrappable<ContextualSearchWrapper>,
bool EnsureServiceConnected(); bool EnsureServiceConnected();
// The service to notify when API calls are made. // The service to notify when API calls are made.
mojom::ContextualSearchJsApiServicePtr contextual_search_js_api_service_; mojo::Remote<mojom::ContextualSearchJsApiService>
contextual_search_js_api_service_;
DISALLOW_COPY_AND_ASSIGN(ContextualSearchWrapper); DISALLOW_COPY_AND_ASSIGN(ContextualSearchWrapper);
}; };
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "components/contextual_search/content/renderer/contextual_search_wrapper.h" #include "components/contextual_search/content/renderer/contextual_search_wrapper.h"
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/service_manager/public/cpp/binder_registry.h" #include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/platform/web_url.h" #include "third_party/blink/public/platform/web_url.h"
...@@ -47,7 +46,7 @@ void OverlayJsRenderFrameObserver::EnableJsApi(bool should_enable) { ...@@ -47,7 +46,7 @@ void OverlayJsRenderFrameObserver::EnableJsApi(bool should_enable) {
bool OverlayJsRenderFrameObserver::EnsureServiceConnected() { bool OverlayJsRenderFrameObserver::EnsureServiceConnected() {
if (render_frame() && !contextual_search_js_api_service_) { if (render_frame() && !contextual_search_js_api_service_) {
render_frame()->GetRemoteInterfaces()->GetInterface( render_frame()->GetRemoteInterfaces()->GetInterface(
&contextual_search_js_api_service_); contextual_search_js_api_service_.BindNewPipeAndPassReceiver());
return true; return true;
} }
return false; return false;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "components/contextual_search/content/common/mojom/contextual_search_js_api_service.mojom.h" #include "components/contextual_search/content/common/mojom/contextual_search_js_api_service.mojom.h"
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/service_manager/public/cpp/binder_registry.h" #include "services/service_manager/public/cpp/binder_registry.h"
#include "third_party/blink/public/web/web_local_frame.h" #include "third_party/blink/public/web/web_local_frame.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
...@@ -42,7 +43,8 @@ class OverlayJsRenderFrameObserver : public content::RenderFrameObserver { ...@@ -42,7 +43,8 @@ class OverlayJsRenderFrameObserver : public content::RenderFrameObserver {
// The CS service to notify when deciding to enable the API or when API calls // The CS service to notify when deciding to enable the API or when API calls
// are made. // are made.
mojom::ContextualSearchJsApiServicePtr contextual_search_js_api_service_; mojo::Remote<mojom::ContextualSearchJsApiService>
contextual_search_js_api_service_;
// Remembers whether we did start enabling the JS API by making a request // Remembers whether we did start enabling the JS API by making a request
// to the Contextual Search service to ask if we should enable for this // to the Contextual Search service to ask if we should enable for this
......
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