| 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 DistillerJsRenderFrameObserver::~DistillerJsRenderFrameObserver() {} | |
| 25 | |
| 26 void DistillerJsRenderFrameObserver::DidStartProvisionalLoad() { | |
| 27 RegisterMojoService(); | |
| 28 } | |
| 29 | |
| 30 void DistillerJsRenderFrameObserver::DidFinishLoad() { | |
| 31 // If no message about the distilled page was received at this point, there | |
| 32 // will not be one; remove the DistillerPageNotifierService from the registry. | |
| 33 render_frame() | |
| 34 ->GetServiceRegistry() | |
| 35 ->RemoveService<DistillerPageNotifierService>(); | |
| 36 } | |
| 37 | |
| 38 void DistillerJsRenderFrameObserver::DidCreateScriptContext( | |
| 39 v8::Local<v8::Context> context, | |
| 40 int extension_group, | |
| 41 int world_id) { | |
| 42 if (world_id != distiller_isolated_world_id_ || !is_distiller_page_) { | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 native_javascript_handle_.reset( | |
| 47 new DistillerNativeJavaScript(render_frame())); | |
| 48 native_javascript_handle_->AddJavaScriptObjectToFrame(context); | |
| 49 } | |
| 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 // This is strongly bound to and owned by the pipe. | |
| 60 new DistillerPageNotifierServiceImpl(this, request.Pass()); | |
| 61 } | |
| 62 | |
| 63 void DistillerJsRenderFrameObserver::SetIsDistillerPage() { | |
| 64 is_distiller_page_ = true; | |
| 65 } | |
| 66 | |
| 67 } // namespace dom_distiller | |
| OLD | NEW |