Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4118)

Unified Diff: chrome/browser/android/contextualsearch/contextual_search_manager.cc

Issue 1532743002: [Contextual Search] Use Mojo API for Quick Answers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated a comment. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+}

Powered by Google App Engine
This is Rietveld 408576698