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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/dom_distiller/content/renderer/distiller_js_render_frame_observer.cc
diff --git a/components/dom_distiller/content/renderer/distiller_js_render_frame_observer.cc b/components/dom_distiller/content/renderer/distiller_js_render_frame_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1d2cb754ddc6028f7b455d329e132af239a9d200
--- /dev/null
+++ b/components/dom_distiller/content/renderer/distiller_js_render_frame_observer.cc
@@ -0,0 +1,52 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/dom_distiller/content/renderer/distiller_js_render_frame_observer.h"
+
+#include "base/bind.h"
+#include "components/dom_distiller/content/common/distiller_page_notifier_service.mojom.h"
+#include "components/dom_distiller/content/renderer/distiller_page_notifier_service_impl.h"
+#include "content/public/common/service_registry.h"
+#include "content/public/renderer/render_frame.h"
+
+namespace dom_distiller {
+
+DistillerJsRenderFrameObserver::DistillerJsRenderFrameObserver(
+ content::RenderFrame* render_frame)
+ : RenderFrameObserver(render_frame),
+ is_distiller_page_(false),
+ weak_factory_(this) {}
+
+void DistillerJsRenderFrameObserver::DidStartProvisionalLoad() {
+ RegisterMojoService();
+}
+
+void DistillerJsRenderFrameObserver::DidClearWindowObject() {
+ // This is needed for testing because the window is cleared before
+ // a test is run.
+ if (is_distiller_page_)
+ SetupMojoForJavaScript();
+}
+
+DistillerJsRenderFrameObserver::~DistillerJsRenderFrameObserver() {}
+
+void DistillerJsRenderFrameObserver::RegisterMojoService() {
+ render_frame()->GetServiceRegistry()->AddService(base::Bind(
+ &DistillerJsRenderFrameObserver::createDistillerPageNotifierService,
+ weak_factory_.GetWeakPtr()));
+}
+
+void DistillerJsRenderFrameObserver::createDistillerPageNotifierService(
+ mojo::InterfaceRequest<DistillerPageNotifierService> request) {
+ BindToRequest(new DistillerPageNotifierServiceImpl(this), &request);
+}
+
+void DistillerJsRenderFrameObserver::SetupMojoForJavaScript() {
+ native_javascript_handle_.reset(
+ new DistillerNativeJavaScript(render_frame()));
+ native_javascript_handle_->AddJavaScriptObjectToFrame();
+ is_distiller_page_ = true;
+}
+
+} // namespace dom_distiller

Powered by Google App Engine
This is Rietveld 408576698