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

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: Clean up Created 5 years, 4 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 #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() {}
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698