| Index: chrome/browser/android/contextualsearch/contextual_search_manager.cc
|
| diff --git a/chrome/browser/android/contextualsearch/contextual_search_manager.cc b/chrome/browser/android/contextualsearch/contextual_search_manager.cc
|
| index 3880e783dfd2bed3b3c321eb2825dfc822ef707d..2ffc7f0b14ec74aeff180ee0b9ab80660e3bec50 100644
|
| --- a/chrome/browser/android/contextualsearch/contextual_search_manager.cc
|
| +++ b/chrome/browser/android/contextualsearch/contextual_search_manager.cc
|
| @@ -15,10 +15,14 @@
|
| #include "chrome/browser/android/tab_android.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/search_engines/template_url_service_factory.h"
|
| -#include "chrome/browser/ui/android/view_android_helper.h"
|
| +#include "components/contextual_search/browser/contextual_search_js_api_service_impl.h"
|
| +#include "components/contextual_search/common/overlay_page_notifier_service.mojom.h"
|
| #include "components/navigation_interception/intercept_navigation_delegate.h"
|
| #include "components/variations/variations_associated_data.h"
|
| #include "content/public/browser/android/content_view_core.h"
|
| +#include "content/public/browser/render_frame_host.h"
|
| +#include "content/public/browser/render_view_host.h"
|
| +#include "content/public/common/service_registry.h"
|
| #include "jni/ContextualSearchManager_jni.h"
|
| #include "net/url_request/url_fetcher_impl.h"
|
|
|
| @@ -162,6 +166,30 @@ void ContextualSearchManager::OnIcingSelectionAvailable(
|
| start_offset, end_offset);
|
| }
|
|
|
| +void ContextualSearchManager::EnableContextualSearchJsApiForOverlay(
|
| + JNIEnv* env,
|
| + jobject obj,
|
| + jobject j_overlay_content_view_core) {
|
| + ContentViewCore* overlay_content_view_core =
|
| + ContentViewCore::GetNativeContentViewCore(env,
|
| + j_overlay_content_view_core);
|
| + // Tell our Overlay Notifier Service that this is currently a CS page.
|
| + content::RenderFrameHost* render_frame_host =
|
| + overlay_content_view_core->GetWebContents()
|
| + ->GetRenderViewHost()
|
| + ->GetMainFrame();
|
| + DCHECK(render_frame_host);
|
| + contextual_search::OverlayPageNotifierServicePtr page_notifier_service;
|
| + render_frame_host->GetServiceRegistry()->ConnectToRemoteService(
|
| + mojo::GetProxy(&page_notifier_service));
|
| + DCHECK(page_notifier_service);
|
| + page_notifier_service->NotifyIsContextualSearchOverlay();
|
| +
|
| + // Also set up the backchannel to call into this class from the JS API.
|
| + render_frame_host->GetServiceRegistry()->AddService(
|
| + base::Bind(&contextual_search::CreateContextualSearchJsApiService, this));
|
| +}
|
| +
|
| bool RegisterContextualSearchManager(JNIEnv* env) {
|
| return RegisterNativesImpl(env);
|
| }
|
| @@ -170,3 +198,12 @@ jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
|
| ContextualSearchManager* manager = new ContextualSearchManager(env, obj);
|
| return reinterpret_cast<intptr_t>(manager);
|
| }
|
| +
|
| +void ContextualSearchManager::SetCaption(std::string caption,
|
| + bool does_answer) {
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + base::android::ScopedJavaLocalRef<jstring> j_caption =
|
| + base::android::ConvertUTF8ToJavaString(env, caption.c_str());
|
| + Java_ContextualSearchManager_onSetCaption(env, java_manager_.obj(),
|
| + j_caption.obj(), does_answer);
|
| +}
|
|
|