Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: components/dom_distiller/content/renderer/distiller_js_render_frame_observer.cc

Issue 1231083007: Expose distiller functions to JavaScript (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-content
Patch Set: cl format Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
13 namespace dom_distiller {
14
15 DistillerJsRenderFrameObserver::DistillerJsRenderFrameObserver(
16 content::RenderFrame* render_frame)
17 : RenderFrameObserver(render_frame),
18 is_distiller_page_(false),
19 weak_factory_(this) {}
20
21 void DistillerJsRenderFrameObserver::DidStartProvisionalLoad() {
22 RegisterMojoService();
23 }
24
25 void DistillerJsRenderFrameObserver::DidClearWindowObject() {
26 // This is needed for testing because the window is cleared before
27 // a test is run.
28 if (is_distiller_page_)
29 SetupMojoForJavaScript();
30 }
31
32 DistillerJsRenderFrameObserver::~DistillerJsRenderFrameObserver() {}
33
34 void DistillerJsRenderFrameObserver::RegisterMojoService() {
35 render_frame()->GetServiceRegistry()->AddService(base::Bind(
36 &DistillerJsRenderFrameObserver::createDistillerPageNotifierService,
37 weak_factory_.GetWeakPtr()));
38 }
39
40 void DistillerJsRenderFrameObserver::createDistillerPageNotifierService(
41 mojo::InterfaceRequest<DistillerPageNotifierService> request) {
42 BindToRequest(new DistillerPageNotifierServiceImpl(this), &request);
43 }
44
45 void DistillerJsRenderFrameObserver::SetupMojoForJavaScript() {
46 native_javascript_handle_.reset(
47 new DistillerNativeJavaScript(render_frame()));
48 native_javascript_handle_->AddJavaScriptObjectToFrame();
49 is_distiller_page_ = true;
50 }
51
52 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698