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

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

Issue 2079943002: Change RenderFrame to use InterfaceRegistry et al. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a2
Patch Set: . Created 4 years, 6 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/dom_distiller/content/renderer/distiller_js_render_frame_ob server.h" 5 #include "components/dom_distiller/content/renderer/distiller_js_render_frame_ob server.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "components/dom_distiller/content/common/distiller_page_notifier_servic e.mojom.h" 10 #include "components/dom_distiller/content/common/distiller_page_notifier_servic e.mojom.h"
11 #include "components/dom_distiller/content/renderer/distiller_page_notifier_serv ice_impl.h" 11 #include "components/dom_distiller/content/renderer/distiller_page_notifier_serv ice_impl.h"
12 #include "content/public/common/service_registry.h"
13 #include "content/public/renderer/render_frame.h" 12 #include "content/public/renderer/render_frame.h"
13 #include "services/shell/public/cpp/interface_registry.h"
14 #include "v8/include/v8.h" 14 #include "v8/include/v8.h"
15 15
16 namespace dom_distiller { 16 namespace dom_distiller {
17 17
18 DistillerJsRenderFrameObserver::DistillerJsRenderFrameObserver( 18 DistillerJsRenderFrameObserver::DistillerJsRenderFrameObserver(
19 content::RenderFrame* render_frame, 19 content::RenderFrame* render_frame,
20 const int distiller_isolated_world_id) 20 const int distiller_isolated_world_id)
21 : RenderFrameObserver(render_frame), 21 : RenderFrameObserver(render_frame),
22 distiller_isolated_world_id_(distiller_isolated_world_id), 22 distiller_isolated_world_id_(distiller_isolated_world_id),
23 is_distiller_page_(false), 23 is_distiller_page_(false),
24 weak_factory_(this) {} 24 weak_factory_(this) {}
25 25
26 DistillerJsRenderFrameObserver::~DistillerJsRenderFrameObserver() {} 26 DistillerJsRenderFrameObserver::~DistillerJsRenderFrameObserver() {}
27 27
28 void DistillerJsRenderFrameObserver::DidStartProvisionalLoad() { 28 void DistillerJsRenderFrameObserver::DidStartProvisionalLoad() {
29 RegisterMojoService(); 29 RegisterMojoInterface();
30 } 30 }
31 31
32 void DistillerJsRenderFrameObserver::DidFinishLoad() { 32 void DistillerJsRenderFrameObserver::DidFinishLoad() {
33 // If no message about the distilled page was received at this point, there 33 // If no message about the distilled page was received at this point, there
34 // will not be one; remove the mojom::DistillerPageNotifierService from the 34 // will not be one; remove the mojom::DistillerPageNotifierService from the
35 // registry. 35 // registry.
36 render_frame() 36 render_frame()
37 ->GetServiceRegistry() 37 ->GetInterfaceRegistry()
38 ->RemoveService<mojom::DistillerPageNotifierService>(); 38 ->RemoveInterface<mojom::DistillerPageNotifierService>();
39 } 39 }
40 40
41 void DistillerJsRenderFrameObserver::DidCreateScriptContext( 41 void DistillerJsRenderFrameObserver::DidCreateScriptContext(
42 v8::Local<v8::Context> context, 42 v8::Local<v8::Context> context,
43 int extension_group, 43 int extension_group,
44 int world_id) { 44 int world_id) {
45 if (world_id != distiller_isolated_world_id_ || !is_distiller_page_) { 45 if (world_id != distiller_isolated_world_id_ || !is_distiller_page_) {
46 return; 46 return;
47 } 47 }
48 48
49 native_javascript_handle_.reset( 49 native_javascript_handle_.reset(
50 new DistillerNativeJavaScript(render_frame())); 50 new DistillerNativeJavaScript(render_frame()));
51 native_javascript_handle_->AddJavaScriptObjectToFrame(context); 51 native_javascript_handle_->AddJavaScriptObjectToFrame(context);
52 } 52 }
53 53
54 void DistillerJsRenderFrameObserver::RegisterMojoService() { 54 void DistillerJsRenderFrameObserver::RegisterMojoInterface() {
55 render_frame()->GetServiceRegistry()->AddService(base::Bind( 55 render_frame()->GetInterfaceRegistry()->AddInterface(base::Bind(
56 &DistillerJsRenderFrameObserver::CreateDistillerPageNotifierService, 56 &DistillerJsRenderFrameObserver::CreateDistillerPageNotifierService,
57 weak_factory_.GetWeakPtr())); 57 weak_factory_.GetWeakPtr()));
58 } 58 }
59 59
60 void DistillerJsRenderFrameObserver::CreateDistillerPageNotifierService( 60 void DistillerJsRenderFrameObserver::CreateDistillerPageNotifierService(
61 mojo::InterfaceRequest<mojom::DistillerPageNotifierService> request) { 61 mojo::InterfaceRequest<mojom::DistillerPageNotifierService> request) {
62 // This is strongly bound to and owned by the pipe. 62 // This is strongly bound to and owned by the pipe.
63 new DistillerPageNotifierServiceImpl(this, std::move(request)); 63 new DistillerPageNotifierServiceImpl(this, std::move(request));
64 } 64 }
65 65
66 void DistillerJsRenderFrameObserver::SetIsDistillerPage() { 66 void DistillerJsRenderFrameObserver::SetIsDistillerPage() {
67 is_distiller_page_ = true; 67 is_distiller_page_ = true;
68 } 68 }
69 69
70 void DistillerJsRenderFrameObserver::OnDestruct() { 70 void DistillerJsRenderFrameObserver::OnDestruct() {
71 delete this; 71 delete this;
72 } 72 }
73 73
74 } // namespace dom_distiller 74 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698