summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/activity_log_converter_strategy.h
blob: fd7a1d2babf87cf2f0355f8ff34d1123c022aa18 (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 2014 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 EXTENSIONS_RENDERER_ACTIVITY_LOG_CONVERTER_STRATEGY_H_
#define EXTENSIONS_RENDERER_ACTIVITY_LOG_CONVERTER_STRATEGY_H_

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "content/public/child/v8_value_converter.h"
#include "v8/include/v8.h"

namespace extensions {

// This class is used by activity logger and extends behavior of
// V8ValueConverter. It overwrites conversion of V8 arrays and objects.  When
// converting arrays and objects, we must not invoke any JS code which may
// result in triggering activity logger. In such case, the log entries will be
// generated due to V8 object conversion rather than extension activity.
class ActivityLogConverterStrategy
    : public content::V8ValueConverter::Strategy {
 public:
  typedef content::V8ValueConverter::Strategy::FromV8ValueCallback
      FromV8ValueCallback;

  ActivityLogConverterStrategy();
  ~ActivityLogConverterStrategy() override;

  // content::V8ValueConverter::Strategy implementation.
  bool FromV8Object(v8::Local<v8::Object> value,
                    base::Value** out,
                    v8::Isolate* isolate,
                    const FromV8ValueCallback& callback) const override;
  bool FromV8Array(v8::Local<v8::Array> value,
                   base::Value** out,
                   v8::Isolate* isolate,
                   const FromV8ValueCallback& callback) const override;

 private:
  bool FromV8Internal(v8::Local<v8::Object> value,
                      base::Value** out,
                      v8::Isolate* isolate,
                      const FromV8ValueCallback& callback) const;

  DISALLOW_COPY_AND_ASSIGN(ActivityLogConverterStrategy);
};

}  // namespace extensions

#endif  // EXTENSIONS_RENDERER_ACTIVITY_LOG_CONVERTER_STRATEGY_H_