| Index: components/dom_distiller/content/renderer/distiller_js_render_frame_observer.cc
|
| diff --git a/components/dom_distiller/content/renderer/distiller_js_render_frame_observer.cc b/components/dom_distiller/content/renderer/distiller_js_render_frame_observer.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1d2cb754ddc6028f7b455d329e132af239a9d200
|
| --- /dev/null
|
| +++ b/components/dom_distiller/content/renderer/distiller_js_render_frame_observer.cc
|
| @@ -0,0 +1,52 @@
|
| +// 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/dom_distiller/content/renderer/distiller_js_render_frame_observer.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "components/dom_distiller/content/common/distiller_page_notifier_service.mojom.h"
|
| +#include "components/dom_distiller/content/renderer/distiller_page_notifier_service_impl.h"
|
| +#include "content/public/common/service_registry.h"
|
| +#include "content/public/renderer/render_frame.h"
|
| +
|
| +namespace dom_distiller {
|
| +
|
| +DistillerJsRenderFrameObserver::DistillerJsRenderFrameObserver(
|
| + content::RenderFrame* render_frame)
|
| + : RenderFrameObserver(render_frame),
|
| + is_distiller_page_(false),
|
| + weak_factory_(this) {}
|
| +
|
| +void DistillerJsRenderFrameObserver::DidStartProvisionalLoad() {
|
| + RegisterMojoService();
|
| +}
|
| +
|
| +void DistillerJsRenderFrameObserver::DidClearWindowObject() {
|
| + // This is needed for testing because the window is cleared before
|
| + // a test is run.
|
| + if (is_distiller_page_)
|
| + SetupMojoForJavaScript();
|
| +}
|
| +
|
| +DistillerJsRenderFrameObserver::~DistillerJsRenderFrameObserver() {}
|
| +
|
| +void DistillerJsRenderFrameObserver::RegisterMojoService() {
|
| + render_frame()->GetServiceRegistry()->AddService(base::Bind(
|
| + &DistillerJsRenderFrameObserver::createDistillerPageNotifierService,
|
| + weak_factory_.GetWeakPtr()));
|
| +}
|
| +
|
| +void DistillerJsRenderFrameObserver::createDistillerPageNotifierService(
|
| + mojo::InterfaceRequest<DistillerPageNotifierService> request) {
|
| + BindToRequest(new DistillerPageNotifierServiceImpl(this), &request);
|
| +}
|
| +
|
| +void DistillerJsRenderFrameObserver::SetupMojoForJavaScript() {
|
| + native_javascript_handle_.reset(
|
| + new DistillerNativeJavaScript(render_frame()));
|
| + native_javascript_handle_->AddJavaScriptObjectToFrame();
|
| + is_distiller_page_ = true;
|
| +}
|
| +
|
| +} // namespace dom_distiller
|
|
|