Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/dom_distiller/content/renderer/distiller_js_render_frame_ob server.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "components/dom_distiller/content/common/distiller_page_notifier_servic e.mojom.h" | |
| 9 #include "components/dom_distiller/content/renderer/distiller_page_notifier_serv ice_impl.h" | |
| 10 #include "content/public/common/service_registry.h" | |
| 11 #include "content/public/renderer/render_frame.h" | |
| 12 #include "v8/include/v8.h" | |
| 13 | |
| 14 namespace dom_distiller { | |
| 15 | |
| 16 DistillerJsRenderFrameObserver::DistillerJsRenderFrameObserver( | |
| 17 content::RenderFrame* render_frame, | |
| 18 const int distiller_isolated_world_id) | |
| 19 : RenderFrameObserver(render_frame), | |
| 20 distiller_isolated_world_id_(distiller_isolated_world_id), | |
| 21 is_distiller_page_(false), | |
| 22 weak_factory_(this) {} | |
| 23 | |
| 24 void DistillerJsRenderFrameObserver::DidStartProvisionalLoad() { | |
| 25 RegisterMojoService(); | |
| 26 } | |
| 27 | |
| 28 void DistillerJsRenderFrameObserver::DidFinishLoad() { | |
| 29 // If no message about the distilled page was received at this point, there | |
| 30 // will not be one; remove the DistillerPageNotifierService from the registry. | |
| 31 render_frame() | |
| 32 ->GetServiceRegistry() | |
| 33 ->RemoveService<DistillerPageNotifierService>(); | |
| 34 } | |
| 35 | |
| 36 void DistillerJsRenderFrameObserver::DidCreateScriptContext( | |
| 37 v8::Local<v8::Context> context, | |
| 38 int extension_group, | |
| 39 int world_id) { | |
| 40 if (world_id != distiller_isolated_world_id_ || !is_distiller_page_) { | |
| 41 return; | |
| 42 } | |
| 43 | |
| 44 native_javascript_handle_.reset( | |
| 45 new DistillerNativeJavaScript(render_frame())); | |
| 46 native_javascript_handle_->AddJavaScriptObjectToFrame(context); | |
| 47 } | |
| 48 | |
| 49 DistillerJsRenderFrameObserver::~DistillerJsRenderFrameObserver() {} | |
|
nyquist
2015/08/19 10:59:54
Could this also live with the constructor?
mdjones
2015/08/19 20:25:19
Done.
| |
| 50 | |
| 51 void DistillerJsRenderFrameObserver::RegisterMojoService() { | |
| 52 render_frame()->GetServiceRegistry()->AddService(base::Bind( | |
| 53 &DistillerJsRenderFrameObserver::CreateDistillerPageNotifierService, | |
| 54 weak_factory_.GetWeakPtr())); | |
| 55 } | |
| 56 | |
| 57 void DistillerJsRenderFrameObserver::CreateDistillerPageNotifierService( | |
| 58 mojo::InterfaceRequest<DistillerPageNotifierService> request) { | |
| 59 BindToRequest(new DistillerPageNotifierServiceImpl(this), &request); | |
| 60 } | |
| 61 | |
| 62 void DistillerJsRenderFrameObserver::SetIsDistillerPage() { | |
| 63 is_distiller_page_ = true; | |
| 64 } | |
| 65 | |
| 66 } // namespace dom_distiller | |
| OLD | NEW |