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 "chrome/browser/extensions/activity_log.h" | 5 #include "chrome/browser/extensions/activity_log.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 if (!IsLogEnabled()) return; | 349 if (!IsLogEnabled()) return; |
350 LogDOMActionInternal(extension, | 350 LogDOMActionInternal(extension, |
351 url, | 351 url, |
352 url_title, | 352 url_title, |
353 api_call, | 353 api_call, |
354 args, | 354 args, |
355 extra, | 355 extra, |
356 DOMAction::MODIFIED); | 356 DOMAction::MODIFIED); |
357 } | 357 } |
358 | 358 |
| 359 void ActivityLog::LogWebRequestAction(const Extension* extension, |
| 360 const GURL& url, |
| 361 const std::string& api_call, |
| 362 scoped_ptr<DictionaryValue> details, |
| 363 const std::string& extra) { |
| 364 string16 null_title; |
| 365 if (!IsLogEnabled()) return; |
| 366 |
| 367 // Strip details of the web request modifications (for privacy reasons), |
| 368 // unless testing is enabled. |
| 369 if (!testing_mode_) { |
| 370 DictionaryValue::Iterator details_iterator(*details); |
| 371 while (!details_iterator.IsAtEnd()) { |
| 372 details->SetBoolean(details_iterator.key(), true); |
| 373 details_iterator.Advance(); |
| 374 } |
| 375 } |
| 376 std::string details_string; |
| 377 JSONStringValueSerializer serializer(&details_string); |
| 378 serializer.SerializeAndOmitBinaryValues(*details); |
| 379 |
| 380 scoped_refptr<DOMAction> action = new DOMAction( |
| 381 extension->id(), |
| 382 base::Time::Now(), |
| 383 DOMAction::WEBREQUEST, |
| 384 url, |
| 385 null_title, |
| 386 api_call, |
| 387 details_string, |
| 388 extra); |
| 389 ScheduleAndForget(&ActivityDatabase::RecordAction, action); |
| 390 |
| 391 // Display the action. |
| 392 ObserverMap::const_iterator iter = observers_.find(extension); |
| 393 if (iter != observers_.end()) { |
| 394 iter->second->Notify(&Observer::OnExtensionActivity, |
| 395 extension, |
| 396 ActivityLog::ACTIVITY_CONTENT_SCRIPT, |
| 397 action->PrettyPrintForDebug()); |
| 398 } |
| 399 if (log_activity_to_stdout_) |
| 400 LOG(INFO) << action->PrettyPrintForDebug(); |
| 401 } |
| 402 |
359 void ActivityLog::GetActions( | 403 void ActivityLog::GetActions( |
360 const std::string& extension_id, | 404 const std::string& extension_id, |
361 const int day, | 405 const int day, |
362 const base::Callback | 406 const base::Callback |
363 <void(scoped_ptr<std::vector<scoped_refptr<Action> > >)>& callback) { | 407 <void(scoped_ptr<std::vector<scoped_refptr<Action> > >)>& callback) { |
364 if (!db_) return; | 408 if (!db_) return; |
365 BrowserThread::PostTaskAndReplyWithResult( | 409 BrowserThread::PostTaskAndReplyWithResult( |
366 BrowserThread::DB, | 410 BrowserThread::DB, |
367 FROM_HERE, | 411 FROM_HERE, |
368 base::Bind(&ActivityDatabase::GetActions, | 412 base::Bind(&ActivityDatabase::GetActions, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 return "content_script"; | 475 return "content_script"; |
432 case ActivityLog::ACTIVITY_EVENT_DISPATCH: | 476 case ActivityLog::ACTIVITY_EVENT_DISPATCH: |
433 return "event_dispatch"; | 477 return "event_dispatch"; |
434 default: | 478 default: |
435 NOTREACHED(); | 479 NOTREACHED(); |
436 return ""; | 480 return ""; |
437 } | 481 } |
438 } | 482 } |
439 | 483 |
440 } // namespace extensions | 484 } // namespace extensions |
OLD | NEW |