blob: 3956c4847b4d8aa1a8bac728a1bd68f8811fe535 [file] [log] [blame]
[email protected]fb5c4742014-05-01 09:05:271// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]b6e7b542013-03-08 01:57:522// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]fb5c4742014-05-01 09:05:275#ifndef EXTENSIONS_RENDERER_DOM_ACTIVITY_LOGGER_H_
6#define EXTENSIONS_RENDERER_DOM_ACTIVITY_LOGGER_H_
[email protected]b6e7b542013-03-08 01:57:527
mostynbea64f7c2016-04-03 16:03:448#include <memory>
[email protected]b6e7b542013-03-08 01:57:529#include <string>
10
[email protected]fb5c4742014-05-01 09:05:2711#include "base/macros.h"
[email protected]370c6bed2014-05-01 18:06:0812#include "extensions/common/dom_action_types.h"
[email protected]2255a9332013-06-17 05:12:3113#include "third_party/WebKit/public/web/WebDOMActivityLogger.h"
[email protected]370c6bed2014-05-01 18:06:0814#include "v8/include/v8.h"
15
16namespace base {
17class ListValue;
18}
19
20namespace blink {
21class WebString;
22class WebURL;
23}
[email protected]b6e7b542013-03-08 01:57:5224
[email protected]fd46e7a2014-04-16 17:59:4725namespace content {
26class V8ValueConverter;
27}
28
[email protected]040a7342014-04-15 21:33:1329namespace extensions {
30
[email protected]fd46e7a2014-04-16 17:59:4731// Used to log DOM API calls from within WebKit. The events are sent via IPC to
32// extensions::ActivityLog for recording and display.
[email protected]a1221aea2013-11-07 01:31:3033class DOMActivityLogger: public blink::WebDOMActivityLogger {
[email protected]b6e7b542013-03-08 01:57:5234 public:
35 static const int kMainWorldId = 0;
[email protected]9f07b0422013-09-24 21:58:2336 explicit DOMActivityLogger(const std::string& extension_id);
aviaae26ee2015-09-25 05:05:2337 ~DOMActivityLogger() override;
[email protected]b6e7b542013-03-08 01:57:5238
[email protected]a20c8112013-09-05 00:40:4339 // Check (using the WebKit API) if there is no logger attached to the world
40 // corresponding to world_id, and if so, construct a new logger and attach it.
[email protected]9f07b0422013-09-24 21:58:2341 // world_id = 0 indicates the main world.
[email protected]b6e7b542013-03-08 01:57:5242 static void AttachToWorld(int world_id,
[email protected]9f07b0422013-09-24 21:58:2343 const std::string& extension_id);
[email protected]b6e7b542013-03-08 01:57:5244
45 private:
[email protected]370c6bed2014-05-01 18:06:0846 // blink::WebDOMActivityLogger implementation.
47 // Marshals the arguments into an ExtensionHostMsg_DOMAction_Params and sends
48 // it over to the browser (via IPC) for appending it to the extension activity
49 // log.
mostynb0eac4e1b2014-10-03 16:32:1950 // These methods don't have the override keyword due to the complexities it
[email protected]370c6bed2014-05-01 18:06:0851 // introduces when changes blink apis.
aviaae26ee2015-09-25 05:05:2352 void logGetter(const blink::WebString& api_name,
53 const blink::WebURL& url,
54 const blink::WebString& title) override;
55 void logSetter(const blink::WebString& api_name,
56 const v8::Local<v8::Value>& new_value,
57 const blink::WebURL& url,
58 const blink::WebString& title) override;
[email protected]370c6bed2014-05-01 18:06:0859 virtual void logSetter(const blink::WebString& api_name,
tfarinaf85316f2015-04-29 17:03:4060 const v8::Local<v8::Value>& new_value,
61 const v8::Local<v8::Value>& old_value,
[email protected]370c6bed2014-05-01 18:06:0862 const blink::WebURL& url,
63 const blink::WebString& title);
aviaae26ee2015-09-25 05:05:2364 void logMethod(const blink::WebString& api_name,
65 int argc,
66 const v8::Local<v8::Value>* argv,
67 const blink::WebURL& url,
68 const blink::WebString& title) override;
69 void logEvent(const blink::WebString& event_name,
70 int argc,
71 const blink::WebString* argv,
72 const blink::WebURL& url,
73 const blink::WebString& title) override;
[email protected]370c6bed2014-05-01 18:06:0874
75 // Helper function to actually send the message across IPC.
76 void SendDomActionMessage(const std::string& api_call,
77 const GURL& url,
78 const base::string16& url_title,
79 DomActionType::Type call_type,
mostynbea64f7c2016-04-03 16:03:4480 std::unique_ptr<base::ListValue> args);
[email protected]370c6bed2014-05-01 18:06:0881
82 // The id of the extension with which this logger is associated.
[email protected]b6e7b542013-03-08 01:57:5283 std::string extension_id_;
[email protected]b6e7b542013-03-08 01:57:5284
85 DISALLOW_COPY_AND_ASSIGN(DOMActivityLogger);
86};
87
88} // namespace extensions
89
[email protected]fb5c4742014-05-01 09:05:2790#endif // EXTENSIONS_RENDERER_DOM_ACTIVITY_LOGGER_H_
[email protected]b6e7b542013-03-08 01:57:5291