OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
6 #include <vector> | 6 #include <vector> |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
27 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 27 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
29 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
30 #include "third_party/re2/re2/re2.h" | 30 #include "third_party/re2/re2/re2.h" |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Concatenate arguments. | 34 // Concatenate arguments. |
35 std::string MakeArgList(const ListValue* args) { | 35 std::string MakeArgList(const base::ListValue* args) { |
36 std::string call_signature; | 36 std::string call_signature; |
37 ListValue::const_iterator it = args->begin(); | 37 base::ListValue::const_iterator it = args->begin(); |
38 for (; it != args->end(); ++it) { | 38 for (; it != args->end(); ++it) { |
39 std::string arg; | 39 std::string arg; |
40 JSONStringValueSerializer serializer(&arg); | 40 JSONStringValueSerializer serializer(&arg); |
41 if (serializer.SerializeAndOmitBinaryValues(**it)) { | 41 if (serializer.SerializeAndOmitBinaryValues(**it)) { |
42 if (it != args->begin()) | 42 if (it != args->begin()) |
43 call_signature += ", "; | 43 call_signature += ", "; |
44 call_signature += arg; | 44 call_signature += arg; |
45 } | 45 } |
46 } | 46 } |
47 return call_signature; | 47 return call_signature; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 void ActivityLog::AddObserver(ActivityLog::Observer* observer) { | 230 void ActivityLog::AddObserver(ActivityLog::Observer* observer) { |
231 observers_->AddObserver(observer); | 231 observers_->AddObserver(observer); |
232 } | 232 } |
233 | 233 |
234 void ActivityLog::RemoveObserver(ActivityLog::Observer* observer) { | 234 void ActivityLog::RemoveObserver(ActivityLog::Observer* observer) { |
235 observers_->RemoveObserver(observer); | 235 observers_->RemoveObserver(observer); |
236 } | 236 } |
237 | 237 |
238 void ActivityLog::LogAPIActionInternal(const std::string& extension_id, | 238 void ActivityLog::LogAPIActionInternal(const std::string& extension_id, |
239 const std::string& api_call, | 239 const std::string& api_call, |
240 ListValue* args, | 240 base::ListValue* args, |
241 const std::string& extra, | 241 const std::string& extra, |
242 const APIAction::Type type) { | 242 const APIAction::Type type) { |
243 std::string verb, manager; | 243 std::string verb, manager; |
244 bool matches = RE2::FullMatch(api_call, "(.*?)\\.(.*)", &manager, &verb); | 244 bool matches = RE2::FullMatch(api_call, "(.*?)\\.(.*)", &manager, &verb); |
245 if (matches) { | 245 if (matches) { |
246 if (!args->empty() && manager == "tabs") { | 246 if (!args->empty() && manager == "tabs") { |
247 APIAction::LookupTabId(api_call, args, profile_); | 247 APIAction::LookupTabId(api_call, args, profile_); |
248 } | 248 } |
249 | 249 |
250 if (policy_) { | 250 if (policy_) { |
(...skipping 25 matching lines...) Expand all Loading... |
276 observers_->Notify(&Observer::OnExtensionActivity, action); | 276 observers_->Notify(&Observer::OnExtensionActivity, action); |
277 if (testing_mode_) LOG(INFO) << action->PrintForDebug(); | 277 if (testing_mode_) LOG(INFO) << action->PrintForDebug(); |
278 } else { | 278 } else { |
279 LOG(ERROR) << "Unknown API call! " << api_call; | 279 LOG(ERROR) << "Unknown API call! " << api_call; |
280 } | 280 } |
281 } | 281 } |
282 | 282 |
283 // A wrapper around LogAPIActionInternal, but we know it's an API call. | 283 // A wrapper around LogAPIActionInternal, but we know it's an API call. |
284 void ActivityLog::LogAPIAction(const std::string& extension_id, | 284 void ActivityLog::LogAPIAction(const std::string& extension_id, |
285 const std::string& api_call, | 285 const std::string& api_call, |
286 ListValue* args, | 286 base::ListValue* args, |
287 const std::string& extra) { | 287 const std::string& extra) { |
288 if (!IsLogEnabled() || | 288 if (!IsLogEnabled() || |
289 ActivityLogAPI::IsExtensionWhitelisted(extension_id)) return; | 289 ActivityLogAPI::IsExtensionWhitelisted(extension_id)) return; |
290 LogAPIActionInternal(extension_id, | 290 LogAPIActionInternal(extension_id, |
291 api_call, | 291 api_call, |
292 args, | 292 args, |
293 extra, | 293 extra, |
294 APIAction::CALL); | 294 APIAction::CALL); |
295 } | 295 } |
296 | 296 |
297 // A wrapper around LogAPIActionInternal, but we know it's actually an event | 297 // A wrapper around LogAPIActionInternal, but we know it's actually an event |
298 // being fired and triggering extension code. Having the two separate methods | 298 // being fired and triggering extension code. Having the two separate methods |
299 // (LogAPIAction vs LogEventAction) lets us hide how we actually choose to | 299 // (LogAPIAction vs LogEventAction) lets us hide how we actually choose to |
300 // handle them. Right now they're being handled almost the same. | 300 // handle them. Right now they're being handled almost the same. |
301 void ActivityLog::LogEventAction(const std::string& extension_id, | 301 void ActivityLog::LogEventAction(const std::string& extension_id, |
302 const std::string& api_call, | 302 const std::string& api_call, |
303 ListValue* args, | 303 base::ListValue* args, |
304 const std::string& extra) { | 304 const std::string& extra) { |
305 if (!IsLogEnabled() || | 305 if (!IsLogEnabled() || |
306 ActivityLogAPI::IsExtensionWhitelisted(extension_id)) return; | 306 ActivityLogAPI::IsExtensionWhitelisted(extension_id)) return; |
307 LogAPIActionInternal(extension_id, | 307 LogAPIActionInternal(extension_id, |
308 api_call, | 308 api_call, |
309 args, | 309 args, |
310 extra, | 310 extra, |
311 APIAction::EVENT_CALLBACK); | 311 APIAction::EVENT_CALLBACK); |
312 } | 312 } |
313 | 313 |
314 void ActivityLog::LogBlockedAction(const std::string& extension_id, | 314 void ActivityLog::LogBlockedAction(const std::string& extension_id, |
315 const std::string& blocked_call, | 315 const std::string& blocked_call, |
316 ListValue* args, | 316 base::ListValue* args, |
317 BlockedAction::Reason reason, | 317 BlockedAction::Reason reason, |
318 const std::string& extra) { | 318 const std::string& extra) { |
319 if (!IsLogEnabled() || | 319 if (!IsLogEnabled() || |
320 ActivityLogAPI::IsExtensionWhitelisted(extension_id)) return; | 320 ActivityLogAPI::IsExtensionWhitelisted(extension_id)) return; |
321 | 321 |
322 if (policy_) { | 322 if (policy_) { |
323 scoped_ptr<base::DictionaryValue> details(new DictionaryValue()); | 323 scoped_ptr<base::DictionaryValue> details(new DictionaryValue()); |
324 std::string key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_REASON); | 324 std::string key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_REASON); |
325 details->SetInteger(key, static_cast<int>(reason)); | 325 details->SetInteger(key, static_cast<int>(reason)); |
326 key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_EXTRA); | 326 key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_EXTRA); |
(...skipping 14 matching lines...) Expand all Loading... |
341 reason, | 341 reason, |
342 extra); | 342 extra); |
343 observers_->Notify(&Observer::OnExtensionActivity, action); | 343 observers_->Notify(&Observer::OnExtensionActivity, action); |
344 if (testing_mode_) LOG(INFO) << action->PrintForDebug(); | 344 if (testing_mode_) LOG(INFO) << action->PrintForDebug(); |
345 } | 345 } |
346 | 346 |
347 void ActivityLog::LogDOMAction(const std::string& extension_id, | 347 void ActivityLog::LogDOMAction(const std::string& extension_id, |
348 const GURL& url, | 348 const GURL& url, |
349 const string16& url_title, | 349 const string16& url_title, |
350 const std::string& api_call, | 350 const std::string& api_call, |
351 const ListValue* args, | 351 const base::ListValue* args, |
352 DomActionType::Type call_type, | 352 DomActionType::Type call_type, |
353 const std::string& extra) { | 353 const std::string& extra) { |
354 if (!IsLogEnabled() || | 354 if (!IsLogEnabled() || |
355 ActivityLogAPI::IsExtensionWhitelisted(extension_id)) return; | 355 ActivityLogAPI::IsExtensionWhitelisted(extension_id)) return; |
356 if (call_type == DomActionType::METHOD && api_call == "XMLHttpRequest.open") | 356 if (call_type == DomActionType::METHOD && api_call == "XMLHttpRequest.open") |
357 call_type = DomActionType::XHR; | 357 call_type = DomActionType::XHR; |
358 | 358 |
359 if (policy_) { | 359 if (policy_) { |
360 scoped_ptr<base::DictionaryValue> details(new DictionaryValue()); | 360 scoped_ptr<base::DictionaryValue> details(new DictionaryValue()); |
361 std::string key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_DOM_ACTION); | 361 std::string key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_DOM_ACTION); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 // of content scripts will be empty. We don't want to log it because | 473 // of content scripts will be empty. We don't want to log it because |
474 // the call to tabs.executeScript will have already been logged anyway. | 474 // the call to tabs.executeScript will have already been logged anyway. |
475 if (!it->second.empty()) { | 475 if (!it->second.empty()) { |
476 std::string ext_scripts_str; | 476 std::string ext_scripts_str; |
477 for (std::set<std::string>::const_iterator it2 = it->second.begin(); | 477 for (std::set<std::string>::const_iterator it2 = it->second.begin(); |
478 it2 != it->second.end(); | 478 it2 != it->second.end(); |
479 ++it2) { | 479 ++it2) { |
480 ext_scripts_str += *it2; | 480 ext_scripts_str += *it2; |
481 ext_scripts_str += " "; | 481 ext_scripts_str += " "; |
482 } | 482 } |
483 scoped_ptr<ListValue> script_names(new ListValue()); | 483 scoped_ptr<base::ListValue> script_names(new base::ListValue()); |
484 script_names->Set(0, new StringValue(ext_scripts_str)); | 484 script_names->Set(0, new base::StringValue(ext_scripts_str)); |
485 LogDOMAction(extension->id(), | 485 LogDOMAction(extension->id(), |
486 on_url, | 486 on_url, |
487 web_contents->GetTitle(), | 487 web_contents->GetTitle(), |
488 std::string(), // no api call here | 488 std::string(), // no api call here |
489 script_names.get(), | 489 script_names.get(), |
490 DomActionType::INSERTED, | 490 DomActionType::INSERTED, |
491 extra); | 491 extra); |
492 } | 492 } |
493 } | 493 } |
494 } | 494 } |
495 | 495 |
496 } // namespace extensions | 496 } // namespace extensions |
OLD | NEW |