Index: components/contextual_search/overlay_js_render_frame_observer.cc |
diff --git a/components/contextual_search/overlay_js_render_frame_observer.cc b/components/contextual_search/overlay_js_render_frame_observer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..520691eb21927bf2e35930148ace14f78b0eb65d |
--- /dev/null |
+++ b/components/contextual_search/overlay_js_render_frame_observer.cc |
@@ -0,0 +1,62 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/contextual_search/overlay_js_render_frame_observer.h" |
+ |
+#include "base/bind.h" |
+#include "components/contextual_search/contextual_search_wrapper.h" |
+#include "components/contextual_search/overlay_page_notifier_service_impl.h" |
+#include "content/public/common/service_registry.h" |
+#include "content/public/renderer/render_frame.h" |
+#include "v8/include/v8.h" |
+ |
+namespace contextual_search { |
+ |
+OverlayJsRenderFrameObserver::OverlayJsRenderFrameObserver( |
+ content::RenderFrame* render_frame) |
+ : RenderFrameObserver(render_frame), |
+ is_contextual_search_overlay_(false), |
+ weak_factory_(this) {} |
+ |
+OverlayJsRenderFrameObserver::~OverlayJsRenderFrameObserver() {} |
+ |
+void OverlayJsRenderFrameObserver::DidStartProvisionalLoad() { |
+ RegisterMojoService(); |
+} |
+ |
+void OverlayJsRenderFrameObserver::RegisterMojoService() { |
+ render_frame()->GetServiceRegistry()->AddService(base::Bind( |
+ &OverlayJsRenderFrameObserver::CreateOverlayPageNotifierService, |
+ weak_factory_.GetWeakPtr())); |
+} |
+ |
+void OverlayJsRenderFrameObserver::CreateOverlayPageNotifierService( |
+ mojo::InterfaceRequest<OverlayPageNotifierService> request) { |
+ // This is strongly bound to and owned by the pipe. |
+ new OverlayPageNotifierServiceImpl(this, request.Pass()); |
+} |
+ |
+void OverlayJsRenderFrameObserver::SetIsContextualSearchOverlay() { |
+ is_contextual_search_overlay_ = true; |
+} |
+ |
+void OverlayJsRenderFrameObserver::DidCreateNewDocument() { |
+ DVLOG(0) << "ctxs OverlayJsRenderFrameObserver::DidCreateNewDocument for " |
jochen (gone - plz use gerrit)
2015/11/17 14:58:12
0 is too noisy, please use at least 1. or consider
Donn Denman
2015/11/19 01:11:29
Done - removed.
|
+ << render_frame(); |
+ if (is_contextual_search_overlay_) { |
+ DVLOG(0) << "ctxs installing CS... "; |
+ contextual_search::ContextualSearchWrapper::Install(render_frame()); |
+ DVLOG(0) << "ctxs installing CS... DONE!"; |
+ } |
+} |
+ |
+void OverlayJsRenderFrameObserver::DidFinishLoad() { |
+ // If no message about the distilled page was received at this point, there |
+ // will not be one; remove the OverlayPageNotifierService from the registry. |
+ render_frame() |
+ ->GetServiceRegistry() |
+ ->RemoveService<OverlayPageNotifierService>(); |
+} |
+ |
+} // namespace contextual_search |