blob: b8b608314f5650b1a82ded869a871b966f63ddc1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// 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.
#ifndef COMPONENTS_DOM_DISTILLER_CONTENT_RENDERER_DISTILLER_NATIVE_JAVASCRIPT_H_
#define COMPONENTS_DOM_DISTILLER_CONTENT_RENDERER_DISTILLER_NATIVE_JAVASCRIPT_H_
#include "components/dom_distiller/content/common/distiller_javascript_service.mojom.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "v8/include/v8.h"
namespace dom_distiller {
// This class is the primary interface for custom JavaScript introduced by the
// dom-distiller. Callbacks for JavaScript functionality and the communication
// channel to the browser process are maintained here.
class DistillerNativeJavaScript {
public:
explicit DistillerNativeJavaScript(content::RenderFrame* render_frame);
~DistillerNativeJavaScript();
// Add the "distiller" JavaScript object and its functions to the current
// |RenderFrame|.
void AddJavaScriptObjectToFrame(v8::Local<v8::Context> context);
private:
// Add a function to the provided object.
template<typename Sig>
void BindFunctionToObject(v8::Local<v8::Object> javascript_object,
const std::string& name,
const base::Callback<Sig> callback);
// Make sure the mojo service is connected.
void EnsureServiceConnected();
// Native code for "distiller.echo" in JavaScript. This simply returns the
// provided string.
std::string DistillerEcho(const std::string& message);
content::RenderFrame* render_frame_;
mojom::DistillerJavaScriptServicePtr distiller_js_service_;
};
// static
v8::Local<v8::Object> GetOrCreateDistillerObject(v8::Isolate* isolate,
v8::Local<v8::Object> global);
} // namespace dom_distiller
#endif // COMPONENTS_DOM_DISTILLER_CONTENT_RENDERER_DISTILLER_NATIVE_JAVASCRIPT_H_
|