1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
// 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/renderer/overlay_js_render_frame_observer.h"
#include <utility>
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "components/contextual_search/renderer/contextual_search_wrapper.h"
#include "components/contextual_search/renderer/overlay_page_notifier_service_impl.h"
#include "content/public/renderer/render_frame.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/service_manager/public/cpp/interface_registry.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() {
RegisterMojoInterface();
}
void OverlayJsRenderFrameObserver::RegisterMojoInterface() {
render_frame()->GetInterfaceRegistry()->AddInterface(base::Bind(
&OverlayJsRenderFrameObserver::CreateOverlayPageNotifierService,
weak_factory_.GetWeakPtr()));
}
void OverlayJsRenderFrameObserver::CreateOverlayPageNotifierService(
mojo::InterfaceRequest<mojom::OverlayPageNotifierService> request) {
mojo::MakeStrongBinding(
base::MakeUnique<OverlayPageNotifierServiceImpl>(
weak_factory_.GetWeakPtr()),
std::move(request));
}
void OverlayJsRenderFrameObserver::SetIsContextualSearchOverlay() {
is_contextual_search_overlay_ = true;
}
void OverlayJsRenderFrameObserver::DidClearWindowObject() {
if (is_contextual_search_overlay_) {
contextual_search::ContextualSearchWrapper::Install(render_frame());
}
}
void OverlayJsRenderFrameObserver::DidFinishLoad() {
// If no message about the Contextual Search overlay was received at this
// point, there will not be one; remove the OverlayPageNotifierService
// from the registry.
DestroyOverlayPageNotifierService();
}
void OverlayJsRenderFrameObserver::DestroyOverlayPageNotifierService() {
if (render_frame()) {
render_frame()
->GetInterfaceRegistry()
->RemoveInterface<mojom::OverlayPageNotifierService>();
}
}
void OverlayJsRenderFrameObserver::OnDestruct() {
DestroyOverlayPageNotifierService();
delete this;
}
} // namespace contextual_search
|