[email protected] | fb5c474 | 2014-05-01 09:05:27 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | b6e7b54 | 2013-03-08 01:57:52 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | fb5c474 | 2014-05-01 09:05:27 | [diff] [blame] | 5 | #ifndef EXTENSIONS_RENDERER_DOM_ACTIVITY_LOGGER_H_ |
| 6 | #define EXTENSIONS_RENDERER_DOM_ACTIVITY_LOGGER_H_ |
[email protected] | b6e7b54 | 2013-03-08 01:57:52 | [diff] [blame] | 7 | |
mostynb | ea64f7c | 2016-04-03 16:03:44 | [diff] [blame] | 8 | #include <memory> |
[email protected] | b6e7b54 | 2013-03-08 01:57:52 | [diff] [blame] | 9 | #include <string> |
| 10 | |
[email protected] | fb5c474 | 2014-05-01 09:05:27 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 370c6bed | 2014-05-01 18:06:08 | [diff] [blame] | 12 | #include "extensions/common/dom_action_types.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 13 | #include "third_party/WebKit/public/web/WebDOMActivityLogger.h" |
[email protected] | 370c6bed | 2014-05-01 18:06:08 | [diff] [blame] | 14 | #include "v8/include/v8.h" |
| 15 | |
| 16 | namespace base { |
| 17 | class ListValue; |
| 18 | } |
| 19 | |
| 20 | namespace blink { |
| 21 | class WebString; |
| 22 | class WebURL; |
| 23 | } |
[email protected] | b6e7b54 | 2013-03-08 01:57:52 | [diff] [blame] | 24 | |
[email protected] | fd46e7a | 2014-04-16 17:59:47 | [diff] [blame] | 25 | namespace content { |
| 26 | class V8ValueConverter; |
| 27 | } |
| 28 | |
[email protected] | 040a734 | 2014-04-15 21:33:13 | [diff] [blame] | 29 | namespace extensions { |
| 30 | |
[email protected] | fd46e7a | 2014-04-16 17:59:47 | [diff] [blame] | 31 | // 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] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 33 | class DOMActivityLogger: public blink::WebDOMActivityLogger { |
[email protected] | b6e7b54 | 2013-03-08 01:57:52 | [diff] [blame] | 34 | public: |
| 35 | static const int kMainWorldId = 0; |
[email protected] | 9f07b042 | 2013-09-24 21:58:23 | [diff] [blame] | 36 | explicit DOMActivityLogger(const std::string& extension_id); |
avi | aae26ee | 2015-09-25 05:05:23 | [diff] [blame] | 37 | ~DOMActivityLogger() override; |
[email protected] | b6e7b54 | 2013-03-08 01:57:52 | [diff] [blame] | 38 | |
[email protected] | a20c811 | 2013-09-05 00:40:43 | [diff] [blame] | 39 | // 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] | 9f07b042 | 2013-09-24 21:58:23 | [diff] [blame] | 41 | // world_id = 0 indicates the main world. |
[email protected] | b6e7b54 | 2013-03-08 01:57:52 | [diff] [blame] | 42 | static void AttachToWorld(int world_id, |
[email protected] | 9f07b042 | 2013-09-24 21:58:23 | [diff] [blame] | 43 | const std::string& extension_id); |
[email protected] | b6e7b54 | 2013-03-08 01:57:52 | [diff] [blame] | 44 | |
| 45 | private: |
[email protected] | 370c6bed | 2014-05-01 18:06:08 | [diff] [blame] | 46 | // 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. |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 50 | // These methods don't have the override keyword due to the complexities it |
[email protected] | 370c6bed | 2014-05-01 18:06:08 | [diff] [blame] | 51 | // introduces when changes blink apis. |
avi | aae26ee | 2015-09-25 05:05:23 | [diff] [blame] | 52 | 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] | 370c6bed | 2014-05-01 18:06:08 | [diff] [blame] | 59 | virtual void logSetter(const blink::WebString& api_name, |
tfarina | f85316f | 2015-04-29 17:03:40 | [diff] [blame] | 60 | const v8::Local<v8::Value>& new_value, |
| 61 | const v8::Local<v8::Value>& old_value, |
[email protected] | 370c6bed | 2014-05-01 18:06:08 | [diff] [blame] | 62 | const blink::WebURL& url, |
| 63 | const blink::WebString& title); |
avi | aae26ee | 2015-09-25 05:05:23 | [diff] [blame] | 64 | 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] | 370c6bed | 2014-05-01 18:06:08 | [diff] [blame] | 74 | |
| 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, |
mostynb | ea64f7c | 2016-04-03 16:03:44 | [diff] [blame] | 80 | std::unique_ptr<base::ListValue> args); |
[email protected] | 370c6bed | 2014-05-01 18:06:08 | [diff] [blame] | 81 | |
| 82 | // The id of the extension with which this logger is associated. |
[email protected] | b6e7b54 | 2013-03-08 01:57:52 | [diff] [blame] | 83 | std::string extension_id_; |
[email protected] | b6e7b54 | 2013-03-08 01:57:52 | [diff] [blame] | 84 | |
| 85 | DISALLOW_COPY_AND_ASSIGN(DOMActivityLogger); |
| 86 | }; |
| 87 | |
| 88 | } // namespace extensions |
| 89 | |
[email protected] | fb5c474 | 2014-05-01 09:05:27 | [diff] [blame] | 90 | #endif // EXTENSIONS_RENDERER_DOM_ACTIVITY_LOGGER_H_ |
[email protected] | b6e7b54 | 2013-03-08 01:57:52 | [diff] [blame] | 91 | |