| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/json/json_string_value_serializer.h" | 6 #include "base/json/json_string_value_serializer.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/extensions/activity_log/activity_database.h" | 10 #include "chrome/browser/extensions/activity_log/activity_database.h" |
| 11 #include "chrome/browser/extensions/activity_log/api_actions.h" | |
| 12 #include "chrome/browser/extensions/activity_log/blocked_actions.h" | |
| 13 #include "chrome/browser/extensions/activity_log/dom_actions.h" | |
| 14 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" | 11 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/extensions/dom_action_types.h" | 14 #include "chrome/common/extensions/dom_action_types.h" |
| 18 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 19 #include "sql/error_delegate_util.h" | 16 #include "sql/error_delegate_util.h" |
| 20 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 21 | 18 |
| 22 using base::Callback; | 19 using base::Callback; |
| 23 using base::FilePath; | 20 using base::FilePath; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 const char* kObsoleteTables[] = {"activitylog_apis", "activitylog_blocked", | 35 const char* kObsoleteTables[] = {"activitylog_apis", "activitylog_blocked", |
| 39 "activitylog_urls"}; | 36 "activitylog_urls"}; |
| 40 | 37 |
| 41 } // namespace | 38 } // namespace |
| 42 | 39 |
| 43 namespace extensions { | 40 namespace extensions { |
| 44 | 41 |
| 45 const char* FullStreamUIPolicy::kTableName = "activitylog_full"; | 42 const char* FullStreamUIPolicy::kTableName = "activitylog_full"; |
| 46 const char* FullStreamUIPolicy::kTableContentFields[] = { | 43 const char* FullStreamUIPolicy::kTableContentFields[] = { |
| 47 "extension_id", "time", "action_type", "api_name", "args", "page_url", | 44 "extension_id", "time", "action_type", "api_name", "args", "page_url", |
| 48 "arg_url", "other" | 45 "page_title", "arg_url", "other" |
| 49 }; | 46 }; |
| 50 const char* FullStreamUIPolicy::kTableFieldTypes[] = { | 47 const char* FullStreamUIPolicy::kTableFieldTypes[] = { |
| 51 "LONGVARCHAR NOT NULL", "INTEGER", "INTEGER", "LONGVARCHAR", "LONGVARCHAR", | 48 "LONGVARCHAR NOT NULL", "INTEGER", "INTEGER", "LONGVARCHAR", "LONGVARCHAR", |
| 52 "LONGVARCHAR", "LONGVARCHAR", "LONGVARCHAR" | 49 "LONGVARCHAR", "LONGVARCHAR", "LONGVARCHAR", "LONGVARCHAR" |
| 53 }; | 50 }; |
| 54 const int FullStreamUIPolicy::kTableFieldCount = arraysize(kTableContentFields); | 51 const int FullStreamUIPolicy::kTableFieldCount = arraysize(kTableContentFields); |
| 55 | 52 |
| 56 FullStreamUIPolicy::FullStreamUIPolicy(Profile* profile) | 53 FullStreamUIPolicy::FullStreamUIPolicy(Profile* profile) |
| 57 : ActivityLogPolicy(profile) { | 54 : ActivityLogPolicy(profile) { |
| 58 db_ = new ActivityDatabase(this); | 55 db_ = new ActivityDatabase(this); |
| 59 FilePath database_name = profile_base_path_.Append( | 56 FilePath database_name = profile_base_path_.Append( |
| 60 chrome::kExtensionActivityLogFilename); | 57 chrome::kExtensionActivityLogFilename); |
| 61 ScheduleAndForget(db_, &ActivityDatabase::Init, database_name); | 58 ScheduleAndForget(db_, &ActivityDatabase::Init, database_name); |
| 62 } | 59 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 return std::string(kKeyDomainAction); | 113 return std::string(kKeyDomainAction); |
| 117 case PARAM_KEY_URL_TITLE: | 114 case PARAM_KEY_URL_TITLE: |
| 118 return std::string(kKeyURLTitle); | 115 return std::string(kKeyURLTitle); |
| 119 case PARAM_KEY_DETAILS_STRING: | 116 case PARAM_KEY_DETAILS_STRING: |
| 120 return std::string(kKeyDetailsString); | 117 return std::string(kKeyDetailsString); |
| 121 default: | 118 default: |
| 122 return std::string(); | 119 return std::string(); |
| 123 } | 120 } |
| 124 } | 121 } |
| 125 | 122 |
| 126 scoped_ptr<base::ListValue> FullStreamUIPolicy::ProcessArguments( | 123 void FullStreamUIPolicy::ProcessArguments(scoped_refptr<Action> action) const { |
| 127 ActionType action_type, | 124 return; |
| 128 const std::string& name, | |
| 129 const base::ListValue* args) const { | |
| 130 if (args) | |
| 131 return make_scoped_ptr(args->DeepCopy()); | |
| 132 else | |
| 133 return scoped_ptr<base::ListValue>(); | |
| 134 } | 125 } |
| 135 | 126 |
| 136 std::string FullStreamUIPolicy::JoinArguments( | 127 std::string FullStreamUIPolicy::JoinArguments( |
| 137 ActionType action_type, | 128 ActionType action_type, |
| 138 const std::string& name, | 129 const std::string& name, |
| 139 const base::ListValue* args) const { | 130 const base::ListValue* args) const { |
| 140 std::string processed_args; | 131 std::string processed_args; |
| 141 if (args) { | 132 if (args) { |
| 142 base::ListValue::const_iterator it = args->begin(); | 133 base::ListValue::const_iterator it = args->begin(); |
| 143 // TODO(felt,dbabic) Think about replacing the loop with a single | 134 // TODO(felt,dbabic) Think about replacing the loop with a single |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 return processed_args; | 147 return processed_args; |
| 157 } | 148 } |
| 158 | 149 |
| 159 void FullStreamUIPolicy::ProcessWebRequestModifications( | 150 void FullStreamUIPolicy::ProcessWebRequestModifications( |
| 160 DictionaryValue& details, | 151 DictionaryValue& details, |
| 161 std::string& details_string) const { | 152 std::string& details_string) const { |
| 162 JSONStringValueSerializer serializer(&details_string); | 153 JSONStringValueSerializer serializer(&details_string); |
| 163 serializer.Serialize(details); | 154 serializer.Serialize(details); |
| 164 } | 155 } |
| 165 | 156 |
| 166 void FullStreamUIPolicy::ProcessAction( | 157 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { |
| 167 ActionType action_type, | 158 // TODO(mvrable): Right now this argument stripping updates the Action object |
| 168 const std::string& extension_id, | 159 // in place, which isn't good if there are other users of the object. When |
| 169 const std::string& name, | 160 // database writing is moved to policy class, the modifications should be |
| 170 const GURL& url_param, | 161 // made locally. |
| 171 const base::ListValue* args_in, | 162 ProcessArguments(action); |
| 172 const DictionaryValue* details) { | |
| 173 scoped_ptr<base::ListValue> args = | |
| 174 ProcessArguments(action_type, name, args_in); | |
| 175 std::string concatenated_args = JoinArguments(action_type, name, args.get()); | |
| 176 const Time now = Time::Now(); | |
| 177 scoped_refptr<Action> action; | |
| 178 std::string extra; | |
| 179 if (details) { | |
| 180 details->GetString(GetKey(PARAM_KEY_EXTRA), &extra); | |
| 181 } | |
| 182 | |
| 183 switch (action_type) { | |
| 184 case ACTION_API: { | |
| 185 action = new APIAction( | |
| 186 extension_id, | |
| 187 now, | |
| 188 APIAction::CALL, | |
| 189 name, | |
| 190 concatenated_args, | |
| 191 *args, | |
| 192 extra); | |
| 193 break; | |
| 194 } | |
| 195 case ACTION_EVENT: { | |
| 196 action = new APIAction( | |
| 197 extension_id, | |
| 198 now, | |
| 199 APIAction::EVENT_CALLBACK, | |
| 200 name, | |
| 201 concatenated_args, | |
| 202 *args, | |
| 203 extra); | |
| 204 break; | |
| 205 } | |
| 206 case ACTION_BLOCKED: { | |
| 207 int reason = 0; | |
| 208 if (details) { | |
| 209 details->GetInteger(GetKey(PARAM_KEY_REASON), &reason); | |
| 210 } | |
| 211 | |
| 212 action = new BlockedAction( | |
| 213 extension_id, | |
| 214 now, | |
| 215 name, | |
| 216 concatenated_args, | |
| 217 static_cast<BlockedAction::Reason>(reason), | |
| 218 extra); | |
| 219 break; | |
| 220 } | |
| 221 case ACTION_DOM: { | |
| 222 string16 value; | |
| 223 DomActionType::Type action_type = DomActionType::MODIFIED; | |
| 224 | |
| 225 if (details) { | |
| 226 int action_id = 0; | |
| 227 details->GetInteger(GetKey(PARAM_KEY_DOM_ACTION), &action_id); | |
| 228 action_type = static_cast<DomActionType::Type>(action_id); | |
| 229 details->GetString(GetKey(PARAM_KEY_URL_TITLE), &value); | |
| 230 } | |
| 231 | |
| 232 action = new DOMAction( | |
| 233 extension_id, | |
| 234 now, | |
| 235 action_type, | |
| 236 url_param, | |
| 237 value, | |
| 238 name, | |
| 239 concatenated_args, | |
| 240 extra); | |
| 241 break; | |
| 242 } | |
| 243 case ACTION_WEB_REQUEST: { | |
| 244 std::string details_string; | |
| 245 if (details) { | |
| 246 scoped_ptr<DictionaryValue> copy_of_details(details->DeepCopy()); | |
| 247 ProcessWebRequestModifications(*copy_of_details.get(), details_string); | |
| 248 } | |
| 249 | |
| 250 action = new DOMAction( | |
| 251 extension_id, | |
| 252 now, | |
| 253 DomActionType::WEBREQUEST, | |
| 254 url_param, | |
| 255 string16(), | |
| 256 name, | |
| 257 details_string, | |
| 258 extra); | |
| 259 break; | |
| 260 } | |
| 261 default: | |
| 262 NOTREACHED(); | |
| 263 } | |
| 264 | |
| 265 ScheduleAndForget(db_, &ActivityDatabase::RecordAction, action); | 163 ScheduleAndForget(db_, &ActivityDatabase::RecordAction, action); |
| 266 } | 164 } |
| 267 | 165 |
| 268 } // namespace extensions | 166 } // namespace extensions |
| OLD | NEW |