OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "extensions/browser/api_activity_monitor.h" |
| 6 |
| 7 #include "base/values.h" |
| 8 |
| 9 namespace extensions { |
| 10 namespace activity_monitor { |
| 11 |
| 12 namespace { |
| 13 |
| 14 Monitor g_event_monitor = nullptr; |
| 15 Monitor g_function_monitor = nullptr; |
| 16 WebRequestMonitor g_web_request_monitor = nullptr; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 Monitor GetApiEventMonitor() { |
| 21 return g_event_monitor; |
| 22 } |
| 23 |
| 24 Monitor GetApiFunctionMonitor() { |
| 25 return g_function_monitor; |
| 26 } |
| 27 |
| 28 WebRequestMonitor GetWebRequestMonitor() { |
| 29 return g_web_request_monitor; |
| 30 } |
| 31 |
| 32 void SetApiEventMonitor(Monitor event_monitor) { |
| 33 g_event_monitor = event_monitor; |
| 34 } |
| 35 |
| 36 void SetApiFunctionMonitor(Monitor function_monitor) { |
| 37 g_function_monitor = function_monitor; |
| 38 } |
| 39 |
| 40 void SetWebRequestMonitor(WebRequestMonitor web_request_monitor) { |
| 41 g_web_request_monitor = web_request_monitor; |
| 42 } |
| 43 |
| 44 void OnApiEventDispatched(content::BrowserContext* browser_context, |
| 45 const std::string& extension_id, |
| 46 const std::string& event_name, |
| 47 const base::ListValue& event_args) { |
| 48 if (g_event_monitor) |
| 49 g_event_monitor(browser_context, extension_id, event_name, event_args); |
| 50 } |
| 51 |
| 52 // Called when an extension calls an API function. |
| 53 void OnApiFunctionCalled(content::BrowserContext* browser_context, |
| 54 const std::string& extension_id, |
| 55 const std::string& api_name, |
| 56 const base::ListValue& args) { |
| 57 if (g_function_monitor) |
| 58 g_function_monitor(browser_context, extension_id, api_name, args); |
| 59 } |
| 60 |
| 61 void OnWebRequestApiUsed(content::BrowserContext* browser_context, |
| 62 const std::string& extension_id, |
| 63 const GURL& url, |
| 64 bool is_incognito, |
| 65 const std::string& api_call, |
| 66 std::unique_ptr<base::DictionaryValue> details) { |
| 67 if (g_web_request_monitor) { |
| 68 g_web_request_monitor(browser_context, extension_id, url, is_incognito, |
| 69 api_call, std::move(details)); |
| 70 } |
| 71 } |
| 72 |
| 73 } // namespace activity_monitor |
| 74 } // namespace extensions |
OLD | NEW |