Chromium Code Reviews| 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..34db6b802cf5e2fb137f15e58048dfd0a779b3d7 |
| --- /dev/null |
| +++ b/components/dom_distiller/content/renderer/distiller_js_render_frame_observer.cc |
| @@ -0,0 +1,66 @@ |
| +// 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" |
| +#include "v8/include/v8.h" |
| + |
| +namespace dom_distiller { |
| + |
| +DistillerJsRenderFrameObserver::DistillerJsRenderFrameObserver( |
| + content::RenderFrame* render_frame, |
| + const int distiller_isolated_world_id) |
| + : RenderFrameObserver(render_frame), |
| + distiller_isolated_world_id_(distiller_isolated_world_id), |
| + is_distiller_page_(false), |
| + weak_factory_(this) {} |
| + |
| +void DistillerJsRenderFrameObserver::DidStartProvisionalLoad() { |
| + RegisterMojoService(); |
| +} |
| + |
| +void DistillerJsRenderFrameObserver::DidFinishLoad() { |
| + // If no message about the distilled page was received at this point, there |
| + // will not be one; remove the DistillerPageNotifierService from the registry. |
| + render_frame() |
| + ->GetServiceRegistry() |
| + ->RemoveService<DistillerPageNotifierService>(); |
| +} |
| + |
| +void DistillerJsRenderFrameObserver::DidCreateScriptContext( |
| + v8::Local<v8::Context> context, |
| + int extension_group, |
| + int world_id) { |
| + if (world_id != distiller_isolated_world_id_ || !is_distiller_page_) { |
| + return; |
| + } |
| + |
| + native_javascript_handle_.reset( |
| + new DistillerNativeJavaScript(render_frame())); |
| + native_javascript_handle_->AddJavaScriptObjectToFrame(context); |
| +} |
| + |
| +DistillerJsRenderFrameObserver::~DistillerJsRenderFrameObserver() {} |
|
nyquist
2015/08/19 10:59:54
Could this also live with the constructor?
mdjones
2015/08/19 20:25:19
Done.
|
| + |
| +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::SetIsDistillerPage() { |
| + is_distiller_page_ = true; |
| +} |
| + |
| +} // namespace dom_distiller |