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