blob: f55275af3413a25af904f5f14a01ea54e297889e [file] [log] [blame]
// 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.
#ifndef COMPONENTS_CONTEXTUAL_SEARCH_RENDERER_OVERLAY_JS_RENDER_FRAME_OBSERVER_H_
#define COMPONENTS_CONTEXTUAL_SEARCH_RENDERER_OVERLAY_JS_RENDER_FRAME_OBSERVER_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/contextual_search/common/overlay_page_notifier_service.mojom.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "v8/include/v8.h"
namespace contextual_search {
// OverlayJsRenderFrame observer waits for a page to be loaded and then
// tries to connect to a mojo service hosted in the browser process. The
// service will tell this render process if the current page is presented
// in an overlay panel.
class OverlayJsRenderFrameObserver : public content::RenderFrameObserver {
public:
OverlayJsRenderFrameObserver(content::RenderFrame* render_frame,
service_manager::BinderRegistry* registry);
~OverlayJsRenderFrameObserver() override;
// RenderFrameObserver implementation.
void DidStartProvisionalLoad(
blink::WebDocumentLoader* document_loader) override;
void DidClearWindowObject() override;
void DidFinishLoad() override;
// Flag the current page as a contextual search overlay.
void SetIsContextualSearchOverlay();
private:
// RenderFrameObserver implementation.
void OnDestruct() override;
// Creates the OverlayPageNotifierService connecting the browser to this
// observer.
void CreateOverlayPageNotifierService(
mojom::OverlayPageNotifierServiceRequest request);
// Destroys the OverlayPageNotifierService.
void DestroyOverlayPageNotifierService();
// Track if the current page is presented in the contextual search overlay.
bool is_contextual_search_overlay_;
// Requests for mojom::OverlayPageNotifierService are only bound while
// a load is active.
bool can_bind_requests_ = false;
base::WeakPtrFactory<OverlayJsRenderFrameObserver> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(OverlayJsRenderFrameObserver);
};
} // namespace contextual_search
#endif // COMPONENTS_CONTEXTUAL_SEARCH_RENDERER_OVERLAY_JS_RENDER_FRAME_OBSERVER_H_