Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/browser/extensions/activity_log/activity_log.cc

Issue 15520002: Moved DOMActionType information from extras into a real field (ActivityLog) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added prefix Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/string_util.h" 10 #include "base/string_util.h"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 std::string blocked_str = MakeCallSignature(blocked_call, args); 310 std::string blocked_str = MakeCallSignature(blocked_call, args);
311 iter->second->Notify(&Observer::OnExtensionActivity, 311 iter->second->Notify(&Observer::OnExtensionActivity,
312 extension, 312 extension,
313 ActivityLog::ACTIVITY_EXTENSION_API_BLOCK, 313 ActivityLog::ACTIVITY_EXTENSION_API_BLOCK,
314 blocked_str); 314 blocked_str);
315 } 315 }
316 if (log_activity_to_stdout_) 316 if (log_activity_to_stdout_)
317 LOG(INFO) << action->PrintForDebug(); 317 LOG(INFO) << action->PrintForDebug();
318 } 318 }
319 319
320 void ActivityLog::LogDOMActionInternal(const Extension* extension, 320 void ActivityLog::LogDOMAction(const Extension* extension,
321 const GURL& url, 321 const GURL& url,
322 const string16& url_title, 322 const string16& url_title,
323 const std::string& api_call, 323 const std::string& api_call,
324 const ListValue* args, 324 const ListValue* args,
325 const std::string& extra, 325 DomActionType::Type call_type,
326 DOMAction::DOMActionType verb) { 326 const std::string& extra) {
327 if (!IsLogEnabled()) return;
328 if (call_type == DomActionType::METHOD && api_call == "XMLHttpRequest.open")
329 call_type = DomActionType::XHR;
327 scoped_refptr<DOMAction> action = new DOMAction( 330 scoped_refptr<DOMAction> action = new DOMAction(
328 extension->id(), 331 extension->id(),
329 base::Time::Now(), 332 base::Time::Now(),
330 verb, 333 call_type,
331 url, 334 url,
332 url_title, 335 url_title,
333 api_call, 336 api_call,
334 MakeArgList(args), 337 MakeArgList(args),
335 extra); 338 extra);
336 ScheduleAndForget(&ActivityDatabase::RecordAction, action); 339 ScheduleAndForget(&ActivityDatabase::RecordAction, action);
337 340
338 // Display the action. 341 // Display the action.
339 ObserverMap::const_iterator iter = observers_.find(extension); 342 ObserverMap::const_iterator iter = observers_.find(extension);
340 if (iter != observers_.end()) { 343 if (iter != observers_.end()) {
341 // TODO(felt): This is a kludge, planning to update this when new 344 // TODO(felt): This is a kludge, planning to update this when new
342 // UI is in place. 345 // UI is in place.
343 if (verb == DOMAction::INSERTED) { 346 if (call_type == DomActionType::INSERTED) {
344 iter->second->Notify(&Observer::OnExtensionActivity, 347 iter->second->Notify(&Observer::OnExtensionActivity,
345 extension, 348 extension,
346 ActivityLog::ACTIVITY_CONTENT_SCRIPT, 349 ActivityLog::ACTIVITY_CONTENT_SCRIPT,
347 action->PrintForDebug()); 350 action->PrintForDebug());
348 } else { 351 } else {
349 iter->second->Notify(&Observer::OnExtensionActivity, 352 iter->second->Notify(&Observer::OnExtensionActivity,
350 extension, 353 extension,
351 ActivityLog::ACTIVITY_CONTENT_SCRIPT, 354 ActivityLog::ACTIVITY_CONTENT_SCRIPT,
352 MakeCallSignature(api_call, args)); 355 MakeCallSignature(api_call, args));
353 } 356 }
354 } 357 }
355 if (log_activity_to_stdout_) 358 if (log_activity_to_stdout_)
356 LOG(INFO) << action->PrintForDebug(); 359 LOG(INFO) << action->PrintForDebug();
357 } 360 }
358 361
359 void ActivityLog::LogDOMAction(const Extension* extension,
360 const GURL& url,
361 const string16& url_title,
362 const std::string& api_call,
363 const ListValue* args,
364 const std::string& extra) {
365 if (!IsLogEnabled()) return;
366 DOMAction::DOMActionType action = DOMAction::MODIFIED;
367 if (extra == "Getter") {
368 action = DOMAction::GETTER;
369 } else if (extra == "Setter") {
370 action = DOMAction::SETTER;
371 } else if (api_call == "XMLHttpRequest.open") {
372 // Has to come before the Method check because XHR is also a Method.
373 action = DOMAction::XHR;
374 } else if (extra == "Method") {
375 action = DOMAction::METHOD;
376 }
377 LogDOMActionInternal(extension,
378 url,
379 url_title,
380 api_call,
381 args,
382 extra,
383 action);
384 }
385
386 void ActivityLog::LogWebRequestAction(const Extension* extension, 362 void ActivityLog::LogWebRequestAction(const Extension* extension,
387 const GURL& url, 363 const GURL& url,
388 const std::string& api_call, 364 const std::string& api_call,
389 scoped_ptr<DictionaryValue> details, 365 scoped_ptr<DictionaryValue> details,
390 const std::string& extra) { 366 const std::string& extra) {
391 string16 null_title; 367 string16 null_title;
392 if (!IsLogEnabled()) return; 368 if (!IsLogEnabled()) return;
393 369
394 // Strip details of the web request modifications (for privacy reasons), 370 // Strip details of the web request modifications (for privacy reasons),
395 // unless testing is enabled. 371 // unless testing is enabled.
396 if (!testing_mode_) { 372 if (!testing_mode_) {
397 DictionaryValue::Iterator details_iterator(*details); 373 DictionaryValue::Iterator details_iterator(*details);
398 while (!details_iterator.IsAtEnd()) { 374 while (!details_iterator.IsAtEnd()) {
399 details->SetBoolean(details_iterator.key(), true); 375 details->SetBoolean(details_iterator.key(), true);
400 details_iterator.Advance(); 376 details_iterator.Advance();
401 } 377 }
402 } 378 }
403 std::string details_string; 379 std::string details_string;
404 JSONStringValueSerializer serializer(&details_string); 380 JSONStringValueSerializer serializer(&details_string);
405 serializer.SerializeAndOmitBinaryValues(*details); 381 serializer.SerializeAndOmitBinaryValues(*details);
406 382
407 scoped_refptr<DOMAction> action = new DOMAction( 383 scoped_refptr<DOMAction> action = new DOMAction(
408 extension->id(), 384 extension->id(),
409 base::Time::Now(), 385 base::Time::Now(),
410 DOMAction::WEBREQUEST, 386 DomActionType::WEBREQUEST,
411 url, 387 url,
412 null_title, 388 null_title,
413 api_call, 389 api_call,
414 details_string, 390 details_string,
415 extra); 391 extra);
416 ScheduleAndForget(&ActivityDatabase::RecordAction, action); 392 ScheduleAndForget(&ActivityDatabase::RecordAction, action);
417 393
418 // Display the action. 394 // Display the action.
419 ObserverMap::const_iterator iter = observers_.find(extension); 395 ObserverMap::const_iterator iter = observers_.find(extension);
420 if (iter != observers_.end()) { 396 if (iter != observers_.end()) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 if (!it->second.empty()) { 442 if (!it->second.empty()) {
467 std::string ext_scripts_str; 443 std::string ext_scripts_str;
468 for (std::set<std::string>::const_iterator it2 = it->second.begin(); 444 for (std::set<std::string>::const_iterator it2 = it->second.begin();
469 it2 != it->second.end(); 445 it2 != it->second.end();
470 ++it2) { 446 ++it2) {
471 ext_scripts_str += *it2; 447 ext_scripts_str += *it2;
472 ext_scripts_str += " "; 448 ext_scripts_str += " ";
473 } 449 }
474 scoped_ptr<ListValue> script_names(new ListValue()); 450 scoped_ptr<ListValue> script_names(new ListValue());
475 script_names->Set(0, new StringValue(ext_scripts_str)); 451 script_names->Set(0, new StringValue(ext_scripts_str));
476 LogDOMActionInternal(extension, 452 LogDOMAction(extension,
477 on_url, 453 on_url,
478 web_contents->GetTitle(), 454 web_contents->GetTitle(),
479 std::string(), // no api call here 455 std::string(), // no api call here
480 script_names.get(), 456 script_names.get(),
481 std::string(), // no extras either 457 DomActionType::INSERTED,
482 DOMAction::INSERTED); 458 std::string()); // no extras either
483 } 459 }
484 } 460 }
485 } 461 }
486 462
487 void ActivityLog::KillActivityLogDatabase() { 463 void ActivityLog::KillActivityLogDatabase() {
488 ScheduleAndForget(&ActivityDatabase::KillDatabase); 464 ScheduleAndForget(&ActivityDatabase::KillDatabase);
489 } 465 }
490 466
491 // static 467 // static
492 const char* ActivityLog::ActivityToString(Activity activity) { 468 const char* ActivityLog::ActivityToString(Activity activity) {
493 switch (activity) { 469 switch (activity) {
494 case ActivityLog::ACTIVITY_EXTENSION_API_CALL: 470 case ActivityLog::ACTIVITY_EXTENSION_API_CALL:
495 return "api_call"; 471 return "api_call";
496 case ActivityLog::ACTIVITY_EXTENSION_API_BLOCK: 472 case ActivityLog::ACTIVITY_EXTENSION_API_BLOCK:
497 return "api_block"; 473 return "api_block";
498 case ActivityLog::ACTIVITY_CONTENT_SCRIPT: 474 case ActivityLog::ACTIVITY_CONTENT_SCRIPT:
499 return "content_script"; 475 return "content_script";
500 case ActivityLog::ACTIVITY_EVENT_DISPATCH: 476 case ActivityLog::ACTIVITY_EVENT_DISPATCH:
501 return "event_dispatch"; 477 return "event_dispatch";
502 default: 478 default:
503 NOTREACHED(); 479 NOTREACHED();
504 return ""; 480 return "";
505 } 481 }
506 } 482 }
507 483
508 } // namespace extensions 484 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/activity_log/activity_log.h ('k') | chrome/browser/extensions/activity_log/activity_log_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698