OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_DOM_ACTIONS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_DOM_ACTIONS_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_DOM_ACTIONS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_DOM_ACTIONS_H_ |
7 | 7 |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "chrome/browser/extensions/activity_log/activity_actions.h" | 9 #include "chrome/browser/extensions/activity_log/activity_actions.h" |
| 10 #include "chrome/common/extensions/dom_action_types.h" |
10 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
11 | 12 |
12 namespace extensions { | 13 namespace extensions { |
13 | 14 |
14 // This class describes extension actions that pertain to DOM API calls and | 15 // This class describes extension actions that pertain to DOM API calls and |
15 // content script insertions. | 16 // content script insertions. |
16 class DOMAction : public Action { | 17 class DOMAction : public Action { |
17 public: | 18 public: |
18 // These values should not be changed. Append any additional values to the | |
19 // end with sequential numbers. | |
20 enum DOMActionType { | |
21 GETTER = 0, // For Content Script DOM manipulations | |
22 SETTER = 1, // For Content Script DOM manipulations | |
23 METHOD = 2, // For Content Script DOM manipulations | |
24 INSERTED = 3, // For when Content Scripts are added to pages | |
25 XHR = 4, // When an extension core sends an XHR | |
26 WEBREQUEST = 5, // When a page request is modified with the WebRequest API | |
27 MODIFIED = 6, // For legacy, also used as a catch-all | |
28 }; | |
29 | |
30 static const char* kTableName; | 19 static const char* kTableName; |
31 static const char* kTableContentFields[]; | 20 static const char* kTableContentFields[]; |
32 static const char* kTableFieldTypes[]; | 21 static const char* kTableFieldTypes[]; |
33 | 22 |
34 // Create a new database table for storing DOMActions, or update the schema if | 23 // Create a new database table for storing DOMActions, or update the schema if |
35 // it is out of date. Any existing data is preserved. | 24 // it is out of date. Any existing data is preserved. |
36 static bool InitializeTable(sql::Connection* db); | 25 static bool InitializeTable(sql::Connection* db); |
37 | 26 |
38 // Create a new DOMAction to describe a new DOM API call. | 27 // Create a new DOMAction to describe a new DOM API call. |
39 // If the DOMAction is on a background page, the url & url_title may be null. | 28 // If the DOMAction is on a background page, the url & url_title may be null. |
40 // If the DOMAction refers to a content script insertion, api_call may be null | 29 // If the DOMAction refers to a content script insertion, api_call may be null |
41 // but args should be the name of the content script. | 30 // but args should be the name of the content script. |
42 DOMAction(const std::string& extension_id, | 31 DOMAction(const std::string& extension_id, |
43 const base::Time& time, | 32 const base::Time& time, |
44 const DOMActionType verb, // what happened | 33 const DomActionType::Type verb, // what happened |
45 const GURL& url, // the url of the page the | 34 const GURL& url, // the url of the page the |
46 // script is running on | 35 // script is running on |
47 const string16& url_title, // the page title | 36 const string16& url_title, // the page title |
48 const std::string& api_call, // the DOM API call | 37 const std::string& api_call, // the DOM API call |
49 const std::string& args, // the args | 38 const std::string& args, // the args |
50 const std::string& extra); // any extra logging info | 39 const std::string& extra); // any extra logging info |
51 | 40 |
52 // Create a new DOMAction from a database row. | 41 // Create a new DOMAction from a database row. |
53 explicit DOMAction(const sql::Statement& s); | 42 explicit DOMAction(const sql::Statement& s); |
54 | 43 |
55 // Record the action in the database. | 44 // Record the action in the database. |
56 virtual void Record(sql::Connection* db) OVERRIDE; | 45 virtual void Record(sql::Connection* db) OVERRIDE; |
57 | 46 |
58 // Print a DOMAction as a regular string for debugging purposes. | 47 // Print a DOMAction as a regular string for debugging purposes. |
59 virtual std::string PrintForDebug() OVERRIDE; | 48 virtual std::string PrintForDebug() OVERRIDE; |
60 | 49 |
61 // Helper methods for retrieving the values and debugging. | 50 // Helper methods for retrieving the values and debugging. |
62 std::string VerbAsString() const; | 51 std::string VerbAsString() const; |
63 const GURL& url() const { return url_; } | 52 const GURL& url() const { return url_; } |
64 const string16& url_title() const { return url_title_; } | 53 const string16& url_title() const { return url_title_; } |
65 const std::string& api_call() const { return api_call_; } | 54 const std::string& api_call() const { return api_call_; } |
66 const std::string& args() const { return args_; } | 55 const std::string& args() const { return args_; } |
67 const std::string& extra() const { return extra_; } | 56 const std::string& extra() const { return extra_; } |
68 | 57 |
69 protected: | 58 protected: |
70 virtual ~DOMAction(); | 59 virtual ~DOMAction(); |
71 | 60 |
72 private: | 61 private: |
73 DOMActionType verb_; | 62 DomActionType::Type verb_; |
74 GURL url_; | 63 GURL url_; |
75 string16 url_title_; | 64 string16 url_title_; |
76 std::string api_call_; | 65 std::string api_call_; |
77 std::string args_; | 66 std::string args_; |
78 std::string extra_; | 67 std::string extra_; |
79 | 68 |
80 DISALLOW_COPY_AND_ASSIGN(DOMAction); | 69 DISALLOW_COPY_AND_ASSIGN(DOMAction); |
81 }; | 70 }; |
82 | 71 |
83 } // namespace extensions | 72 } // namespace extensions |
84 | 73 |
85 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_DOM_ACTIONS_H_ | 74 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_DOM_ACTIONS_H_ |
86 | 75 |
OLD | NEW |