| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/contextual_search/renderer/overlay_js_render_frame_observer
.h" | 5 #include "components/contextual_search/renderer/overlay_js_render_frame_observer
.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "components/contextual_search/renderer/contextual_search_wrapper.h" | 10 #include "components/contextual_search/renderer/contextual_search_wrapper.h" |
| 11 #include "components/contextual_search/renderer/overlay_page_notifier_service_im
pl.h" | 11 #include "components/contextual_search/renderer/overlay_page_notifier_service_im
pl.h" |
| 12 #include "content/public/common/service_registry.h" | |
| 13 #include "content/public/renderer/render_frame.h" | 12 #include "content/public/renderer/render_frame.h" |
| 13 #include "services/shell/public/cpp/interface_registry.h" |
| 14 #include "v8/include/v8.h" | 14 #include "v8/include/v8.h" |
| 15 | 15 |
| 16 namespace contextual_search { | 16 namespace contextual_search { |
| 17 | 17 |
| 18 OverlayJsRenderFrameObserver::OverlayJsRenderFrameObserver( | 18 OverlayJsRenderFrameObserver::OverlayJsRenderFrameObserver( |
| 19 content::RenderFrame* render_frame) | 19 content::RenderFrame* render_frame) |
| 20 : RenderFrameObserver(render_frame), | 20 : RenderFrameObserver(render_frame), |
| 21 is_contextual_search_overlay_(false), | 21 is_contextual_search_overlay_(false), |
| 22 weak_factory_(this) {} | 22 weak_factory_(this) {} |
| 23 | 23 |
| 24 OverlayJsRenderFrameObserver::~OverlayJsRenderFrameObserver() {} | 24 OverlayJsRenderFrameObserver::~OverlayJsRenderFrameObserver() {} |
| 25 | 25 |
| 26 void OverlayJsRenderFrameObserver::DidStartProvisionalLoad() { | 26 void OverlayJsRenderFrameObserver::DidStartProvisionalLoad() { |
| 27 RegisterMojoService(); | 27 RegisterMojoInterface(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void OverlayJsRenderFrameObserver::RegisterMojoService() { | 30 void OverlayJsRenderFrameObserver::RegisterMojoInterface() { |
| 31 render_frame()->GetServiceRegistry()->AddService(base::Bind( | 31 render_frame()->GetInterfaceRegistry()->AddInterface(base::Bind( |
| 32 &OverlayJsRenderFrameObserver::CreateOverlayPageNotifierService, | 32 &OverlayJsRenderFrameObserver::CreateOverlayPageNotifierService, |
| 33 weak_factory_.GetWeakPtr())); | 33 weak_factory_.GetWeakPtr())); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void OverlayJsRenderFrameObserver::CreateOverlayPageNotifierService( | 36 void OverlayJsRenderFrameObserver::CreateOverlayPageNotifierService( |
| 37 mojo::InterfaceRequest<mojom::OverlayPageNotifierService> request) { | 37 mojo::InterfaceRequest<mojom::OverlayPageNotifierService> request) { |
| 38 // This is strongly bound to and owned by the pipe. | 38 // This is strongly bound to and owned by the pipe. |
| 39 new OverlayPageNotifierServiceImpl(this, std::move(request)); | 39 new OverlayPageNotifierServiceImpl(this, std::move(request)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void OverlayJsRenderFrameObserver::SetIsContextualSearchOverlay() { | 42 void OverlayJsRenderFrameObserver::SetIsContextualSearchOverlay() { |
| 43 is_contextual_search_overlay_ = true; | 43 is_contextual_search_overlay_ = true; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void OverlayJsRenderFrameObserver::DidClearWindowObject() { | 46 void OverlayJsRenderFrameObserver::DidClearWindowObject() { |
| 47 if (is_contextual_search_overlay_) { | 47 if (is_contextual_search_overlay_) { |
| 48 contextual_search::ContextualSearchWrapper::Install(render_frame()); | 48 contextual_search::ContextualSearchWrapper::Install(render_frame()); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 void OverlayJsRenderFrameObserver::DidFinishLoad() { | 52 void OverlayJsRenderFrameObserver::DidFinishLoad() { |
| 53 // If no message about the Contextual Search overlay was received at this | 53 // If no message about the Contextual Search overlay was received at this |
| 54 // point, there will not be one; remove the OverlayPageNotifierService | 54 // point, there will not be one; remove the OverlayPageNotifierService |
| 55 // from the registry. | 55 // from the registry. |
| 56 render_frame() | 56 render_frame() |
| 57 ->GetServiceRegistry() | 57 ->GetInterfaceRegistry() |
| 58 ->RemoveService<mojom::OverlayPageNotifierService>(); | 58 ->RemoveInterface<mojom::OverlayPageNotifierService>(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void OverlayJsRenderFrameObserver::OnDestruct() { | 61 void OverlayJsRenderFrameObserver::OnDestruct() { |
| 62 delete this; | 62 delete this; |
| 63 } | 63 } |
| 64 | 64 |
| 65 } // namespace contextual_search | 65 } // namespace contextual_search |
| OLD | NEW |