diff options
author | felt@chromium.org <felt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-15 04:57:06 +0000 |
---|---|---|
committer | felt@chromium.org <felt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-15 04:57:06 +0000 |
commit | f135a395838bd2145eda4509fd03a206c42b863f (patch) | |
tree | 269a0cdd45240aa9014c09c7bca9a742df79c37b | |
parent | 2ad669a5d97593c90cc9dbdbecec53890c9246e6 (diff) | |
download | chromium_src-f135a395838bd2145eda4509fd03a206c42b863f.zip chromium_src-f135a395838bd2145eda4509fd03a206c42b863f.tar.gz chromium_src-f135a395838bd2145eda4509fd03a206c42b863f.tar.bz2 |
Alter the ActivityLog db table schemas.
Remove some arguments from LogDOMAction.
Rename URIAction to DOMAction.
Make sure db operations will be OK if we add new columns to tables.
Review URL: https://chromiumcodereview.appspot.com/12262025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182618 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/activity_actions.cc | 46 | ||||
-rw-r--r-- | chrome/browser/extensions/activity_actions.h | 10 | ||||
-rw-r--r-- | chrome/browser/extensions/activity_database.cc | 21 | ||||
-rw-r--r-- | chrome/browser/extensions/activity_database.h | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/activity_database_unittest.cc | 53 | ||||
-rw-r--r-- | chrome/browser/extensions/activity_log.cc | 191 | ||||
-rw-r--r-- | chrome/browser/extensions/activity_log.h | 32 | ||||
-rw-r--r-- | chrome/browser/extensions/activity_log_unittest.cc | 36 | ||||
-rw-r--r-- | chrome/browser/extensions/api_actions.cc | 45 | ||||
-rw-r--r-- | chrome/browser/extensions/api_actions.h | 8 | ||||
-rw-r--r-- | chrome/browser/extensions/blocked_actions.cc | 47 | ||||
-rw-r--r-- | chrome/browser/extensions/blocked_actions.h | 17 | ||||
-rw-r--r-- | chrome/browser/extensions/dom_actions.cc | 133 | ||||
-rw-r--r-- | chrome/browser/extensions/dom_actions.h | 90 | ||||
-rw-r--r-- | chrome/browser/extensions/url_actions.cc | 103 | ||||
-rw-r--r-- | chrome/browser/extensions/url_actions.h | 80 | ||||
-rw-r--r-- | chrome/chrome_browser_extensions.gypi | 5 |
17 files changed, 553 insertions, 370 deletions
diff --git a/chrome/browser/extensions/activity_actions.cc b/chrome/browser/extensions/activity_actions.cc new file mode 100644 index 0000000..0d197fa --- /dev/null +++ b/chrome/browser/extensions/activity_actions.cc @@ -0,0 +1,46 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <string> +#include "base/logging.h" +#include "base/stringprintf.h" +#include "chrome/browser/extensions/api_actions.h" + +namespace extensions { + +// static +bool Action::InitializeTableInternal(sql::Connection* db, + const char* table_name, + const char* basic_fields, + const char* content_fields[], + const int num_content_fields) { + if (!db->DoesTableExist(table_name)) { + std::string table_creator = base::StringPrintf( + "CREATE TABLE %s (%s", table_name, basic_fields); + for (int i = 0; i < num_content_fields; i++) { + table_creator += base::StringPrintf(", %s LONGVARCHAR", + content_fields[i]); + } + table_creator += ")"; + if (!db->Execute(table_creator.c_str())) + return false; + } else { + // In case we ever want to add new fields, this initializes them to be + // empty strings. + for (int i = 0; i < num_content_fields; i++) { + if (!db->DoesColumnExist(table_name, content_fields[i])) { + std::string table_updater = base::StringPrintf( + "ALTER TABLE %s ADD COLUMN %s LONGVARCHAR; ", + table_name, + content_fields[i]); + if (!db->Execute(table_updater.c_str())) + return false; + } + } + } + return true; +} + +} // namespace extensions + diff --git a/chrome/browser/extensions/activity_actions.h b/chrome/browser/extensions/activity_actions.h index ac8d9acf..1c89163 100644 --- a/chrome/browser/extensions/activity_actions.h +++ b/chrome/browser/extensions/activity_actions.h @@ -18,6 +18,9 @@ namespace extensions { // the activity log. class Action : public base::RefCountedThreadSafe<Action> { public: + // Initialize the table for a given action type. + static bool InitializeTableInternal(sql::Connection* db); + // Record the action in the database. virtual void Record(sql::Connection* db) = 0; @@ -31,6 +34,13 @@ class Action : public base::RefCountedThreadSafe<Action> { Action() {} virtual ~Action() {} + // Initialize the table for a given action type. + static bool InitializeTableInternal(sql::Connection* db, + const char* table_name, + const char* basic_fields, + const char* content_fields[], + const int num_content_fields); + private: friend class base::RefCountedThreadSafe<Action>; diff --git a/chrome/browser/extensions/activity_database.cc b/chrome/browser/extensions/activity_database.cc index 576aee7..0583312 100644 --- a/chrome/browser/extensions/activity_database.cc +++ b/chrome/browser/extensions/activity_database.cc @@ -50,9 +50,8 @@ void ActivityDatabase::Init(const base::FilePath& db_name) { db_.Preload(); - // Create the UrlAction database. - if (InitializeTable(UrlAction::kTableName, UrlAction::kTableStructure) != - sql::INIT_OK) + // Create the DOMAction database. + if (!DOMAction::InitializeTable(&db_)) return LogInitFailure(); // Create the APIAction database. @@ -60,8 +59,7 @@ void ActivityDatabase::Init(const base::FilePath& db_name) { return LogInitFailure(); // Create the BlockedAction database. - if (InitializeTable(BlockedAction::kTableName, BlockedAction::kTableStructure) - != sql::INIT_OK) + if (!BlockedAction::InitializeTable(&db_)) return LogInitFailure(); sql::InitStatus stat = committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; @@ -75,19 +73,6 @@ void ActivityDatabase::LogInitFailure() { LOG(ERROR) << "Couldn't initialize the activity log database."; } -sql::InitStatus ActivityDatabase::InitializeTable(const char* table_name, - const char* table_structure) { - if (!db_.DoesTableExist(table_name)) { - char table_creator[1000]; - base::snprintf(table_creator, - arraysize(table_creator), - "CREATE TABLE %s %s", table_name, table_structure); - if (!db_.Execute(table_creator)) - return sql::INIT_FAILURE; - } - return sql::INIT_OK; -} - void ActivityDatabase::RecordAction(scoped_refptr<Action> action) { if (initialized_) action->Record(&db_); diff --git a/chrome/browser/extensions/activity_database.h b/chrome/browser/extensions/activity_database.h index 02bdf54..ebc4595 100644 --- a/chrome/browser/extensions/activity_database.h +++ b/chrome/browser/extensions/activity_database.h @@ -10,7 +10,7 @@ #include "base/memory/ref_counted_memory.h" #include "chrome/browser/extensions/api_actions.h" #include "chrome/browser/extensions/blocked_actions.h" -#include "chrome/browser/extensions/url_actions.h" +#include "chrome/browser/extensions/dom_actions.h" #include "sql/connection.h" #include "sql/init_status.h" @@ -35,8 +35,8 @@ class ActivityDatabase : public base::RefCountedThreadSafe<ActivityDatabase> { void Init(const base::FilePath& db_name); void LogInitFailure(); - // Record a UrlAction in the database. - void RecordUrlAction(scoped_refptr<UrlAction> action); + // Record a DOMction in the database. + void RecordDOMAction(scoped_refptr<DOMAction> action); // Record a APIAction in the database. void RecordAPIAction(scoped_refptr<APIAction> action); diff --git a/chrome/browser/extensions/activity_database_unittest.cc b/chrome/browser/extensions/activity_database_unittest.cc index 1c1938c..d7b3c4b 100644 --- a/chrome/browser/extensions/activity_database_unittest.cc +++ b/chrome/browser/extensions/activity_database_unittest.cc @@ -9,7 +9,7 @@ #include "chrome/browser/extensions/activity_database.h" #include "chrome/browser/extensions/api_actions.h" #include "chrome/browser/extensions/blocked_actions.h" -#include "chrome/browser/extensions/url_actions.h" +#include "chrome/browser/extensions/dom_actions.h" #include "sql/statement.h" #include "testing/gtest/include/gtest/gtest.h" @@ -31,14 +31,14 @@ TEST(ActivityDatabaseTest, Init) { sql::Connection db; ASSERT_TRUE(db.Open(db_file)); - ASSERT_TRUE(db.DoesTableExist(UrlAction::kTableName)); + ASSERT_TRUE(db.DoesTableExist(DOMAction::kTableName)); ASSERT_TRUE(db.DoesTableExist(APIAction::kTableName)); ASSERT_TRUE(db.DoesTableExist(BlockedAction::kTableName)); db.Close(); } -// Check that actions are recorded in the db. -TEST(ActivityDatabaseTest, RecordAction) { +// Check that API actions are recorded in the db. +TEST(ActivityDatabaseTest, RecordAPIAction) { base::ScopedTempDir temp_dir; base::FilePath db_file; ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); @@ -56,7 +56,8 @@ TEST(ActivityDatabaseTest, RecordAction) { APIAction::READ, APIAction::BOOKMARK, "brewster", - ""); + "woof", + "extra"); activity_db->RecordAction(action); activity_db->Close(); activity_db->Release(); @@ -74,6 +75,45 @@ TEST(ActivityDatabaseTest, RecordAction) { ASSERT_EQ("READ", statement.ColumnString(3)); ASSERT_EQ("BOOKMARK", statement.ColumnString(4)); ASSERT_EQ("brewster", statement.ColumnString(5)); + ASSERT_EQ("woof", statement.ColumnString(6)); +} + +// Check that blocked actions are recorded in the db. +TEST(ActivityDatabaseTest, RecordBlockedAction) { + base::ScopedTempDir temp_dir; + FilePath db_file; + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); + file_util::Delete(db_file, false); + + ActivityDatabase* activity_db = new ActivityDatabase(); + activity_db->AddRef(); + activity_db->Init(db_file); + ASSERT_TRUE(activity_db->initialized()); + scoped_refptr<BlockedAction> action = new BlockedAction( + "punky", + base::Time::Now(), + "do.evilThings", + "1, 2", + "because i said so", + "extra"); + activity_db->RecordAction(action); + activity_db->Close(); + activity_db->Release(); + + sql::Connection db; + ASSERT_TRUE(db.Open(db_file)); + + ASSERT_TRUE(db.DoesTableExist(BlockedAction::kTableName)); + std::string sql_str = "SELECT * FROM " + + std::string(BlockedAction::kTableName); + sql::Statement statement(db.GetUniqueStatement(sql_str.c_str())); + ASSERT_TRUE(statement.Step()); + ASSERT_EQ("punky", statement.ColumnString(0)); + ASSERT_EQ("do.evilThings", statement.ColumnString(2)); + ASSERT_EQ("1, 2", statement.ColumnString(3)); + ASSERT_EQ("because i said so", statement.ColumnString(4)); + ASSERT_EQ("extra", statement.ColumnString(5)); } // Check that nothing explodes if the DB isn't initialized. @@ -93,7 +133,8 @@ TEST(ActivityDatabaseTest, InitFailure) { APIAction::READ, APIAction::BOOKMARK, "brewster", - ""); + "woooof", + "extra"); activity_db->RecordAction(action); activity_db->Close(); activity_db->Release(); diff --git a/chrome/browser/extensions/activity_log.cc b/chrome/browser/extensions/activity_log.cc index 5b24bef..f08b654 100644 --- a/chrome/browser/extensions/activity_log.cc +++ b/chrome/browser/extensions/activity_log.cc @@ -24,9 +24,9 @@ namespace { -// Concatenate an API call with its arguments. -std::string MakeCallSignature(const std::string& name, const ListValue* args) { - std::string call_signature = name + "("; +// Concatenate arguments. +std::string MakeArgList(const ListValue* args) { + std::string call_signature = ""; ListValue::const_iterator it = args->begin(); for (; it != args->end(); ++it) { std::string arg; @@ -37,6 +37,13 @@ std::string MakeCallSignature(const std::string& name, const ListValue* args) { call_signature += arg; } } + return call_signature; +} + +// Concatenate an API call with its arguments. +std::string MakeCallSignature(const std::string& name, const ListValue* args) { + std::string call_signature = name + "("; + call_signature += MakeArgList(args); call_signature += ")"; return call_signature; } @@ -167,141 +174,164 @@ ActivityLog* ActivityLog::GetInstance(Profile* profile) { void ActivityLog::AddObserver(const Extension* extension, ActivityLog::Observer* observer) { if (!IsLogEnabled()) return; - if (observers_.count(extension) == 0) { + if (observers_.count(extension) == 0) observers_[extension] = new ObserverListThreadSafe<Observer>; - } observers_[extension]->AddObserver(observer); } void ActivityLog::RemoveObserver(const Extension* extension, ActivityLog::Observer* observer) { - if (observers_.count(extension) == 1) { + if (observers_.count(extension) == 1) observers_[extension]->RemoveObserver(observer); - } } -void ActivityLog::LogAPIAction(const Extension* extension, - const std::string& name, - const ListValue* args, - const std::string& extra) { - if (!IsLogEnabled()) return; +void ActivityLog::LogAPIActionInternal(const Extension* extension, + const std::string& api_call, + const ListValue* args, + const std::string& extra, + const APIAction::Type type) { std::string verb, manager; - bool matches = RE2::FullMatch(name, "(.*?)\\.(.*)", &manager, &verb); + bool matches = RE2::FullMatch(api_call, "(.*?)\\.(.*)", &manager, &verb); if (matches) { - std::string call_signature = MakeCallSignature(name, args); scoped_refptr<APIAction> action = new APIAction( extension->id(), base::Time::Now(), - APIAction::CALL, + type, APIAction::StringAsVerb(verb), APIAction::StringAsTarget(manager), - call_signature, + api_call, + MakeArgList(args), extra); ScheduleAndForget(&ActivityDatabase::RecordAction, action); // Display the action. ObserverMap::const_iterator iter = observers_.find(extension); if (iter != observers_.end()) { - iter->second->Notify(&Observer::OnExtensionActivity, - extension, - ActivityLog::ACTIVITY_EXTENSION_API_CALL, - call_signature); + if (type == APIAction::CALL) { + iter->second->Notify(&Observer::OnExtensionActivity, + extension, + ActivityLog::ACTIVITY_EXTENSION_API_CALL, + MakeCallSignature(api_call, args)); + } else if (type == APIAction::EVENT_CALLBACK) { + iter->second->Notify(&Observer::OnExtensionActivity, + extension, + ActivityLog::ACTIVITY_EVENT_DISPATCH, + MakeCallSignature(api_call, args)); + } } - if (log_activity_to_stdout_) { + if (log_activity_to_stdout_) LOG(INFO) << action->PrettyPrintForDebug(); - } } else { - LOG(ERROR) << "Unknown API call! " << name; + LOG(ERROR) << "Unknown API call! " << api_call; } } +// A wrapper around LogAPIActionInternal, but we know it's an API call. +void ActivityLog::LogAPIAction(const Extension* extension, + const std::string& api_call, + const ListValue* args, + const std::string& extra) { + if (!IsLogEnabled()) return; + LogAPIActionInternal(extension, api_call, args, extra, APIAction::CALL); +} + +// A wrapper around LogAPIActionInternal, but we know it's actually an event +// being fired and triggering extension code. Having the two separate methods +// (LogAPIAction vs LogEventAction) lets us hide how we actually choose to +// handle them. Right now they're being handled almost the same. void ActivityLog::LogEventAction(const Extension* extension, - const std::string& name, + const std::string& api_call, const ListValue* args, const std::string& extra) { - std::string verb, manager; - bool matches = RE2::FullMatch(name, "(.*?)\\.(.*)", &manager, &verb); - if (matches) { - std::string call_signature = MakeCallSignature(name, args); - scoped_refptr<APIAction> action = new APIAction( - extension->id(), - base::Time::Now(), - APIAction::EVENT_CALLBACK, - APIAction::StringAsVerb(verb), - APIAction::StringAsTarget(manager), - call_signature, - extra); - ScheduleAndForget(&ActivityDatabase::RecordAction, action); - - // Display the action. - ObserverMap::const_iterator iter = observers_.find(extension); - if (iter != observers_.end()) { - iter->second->Notify(&Observer::OnExtensionActivity, - extension, - ActivityLog::ACTIVITY_EVENT_DISPATCH, - call_signature); - } - if (log_activity_to_stdout_) - LOG(INFO) << action->PrettyPrintForDebug(); - } else { - LOG(ERROR) << "Unknown event type! " << name; - } + if (!IsLogEnabled()) return; + LogAPIActionInternal(extension, + api_call, + args, + extra, + APIAction::EVENT_CALLBACK); } void ActivityLog::LogBlockedAction(const Extension* extension, - const std::string& blocked_name, + const std::string& blocked_call, const ListValue* args, const char* reason, const std::string& extra) { if (!IsLogEnabled()) return; - std::string blocked_call = MakeCallSignature(blocked_name, args); scoped_refptr<BlockedAction> action = new BlockedAction(extension->id(), base::Time::Now(), blocked_call, + MakeArgList(args), std::string(reason), extra); ScheduleAndForget(&ActivityDatabase::RecordAction, action); // Display the action. ObserverMap::const_iterator iter = observers_.find(extension); if (iter != observers_.end()) { + std::string blocked_str = MakeCallSignature(blocked_call, args); iter->second->Notify(&Observer::OnExtensionActivity, extension, ActivityLog::ACTIVITY_EXTENSION_API_BLOCK, - blocked_call); + blocked_str); } if (log_activity_to_stdout_) LOG(INFO) << action->PrettyPrintForDebug(); } -void ActivityLog::LogUrlAction(const Extension* extension, - const UrlAction::UrlActionType verb, - const GURL& url, - const string16& url_title, - const std::string& technical_message, - const std::string& extra) { - if (!IsLogEnabled()) return; - scoped_refptr<UrlAction> action = new UrlAction( - extension->id(), - base::Time::Now(), - verb, - url, - url_title, - technical_message, - extra); +void ActivityLog::LogDOMActionInternal(const Extension* extension, + const GURL& url, + const string16& url_title, + const std::string& api_call, + const ListValue* args, + const std::string& extra, + DOMAction::DOMActionType verb) { + scoped_refptr<DOMAction> action = new DOMAction( + extension->id(), + base::Time::Now(), + verb, + url, + url_title, + api_call, + MakeArgList(args), + extra); ScheduleAndForget(&ActivityDatabase::RecordAction, action); // Display the action. ObserverMap::const_iterator iter = observers_.find(extension); if (iter != observers_.end()) { - iter->second->Notify(&Observer::OnExtensionActivity, - extension, - ActivityLog::ACTIVITY_CONTENT_SCRIPT, - action->PrettyPrintForDebug()); + // TODO(felt): This is a kludge, planning to update this when new + // UI is in place. + if (verb == DOMAction::INSERTED) { + iter->second->Notify(&Observer::OnExtensionActivity, + extension, + ActivityLog::ACTIVITY_CONTENT_SCRIPT, + action->PrettyPrintForDebug()); + } else { + iter->second->Notify(&Observer::OnExtensionActivity, + extension, + ActivityLog::ACTIVITY_CONTENT_SCRIPT, + MakeCallSignature(api_call, args)); + } } if (log_activity_to_stdout_) LOG(INFO) << action->PrettyPrintForDebug(); } +void ActivityLog::LogDOMAction(const Extension* extension, + const GURL& url, + const string16& url_title, + const std::string& api_call, + const ListValue* args, + const std::string& extra) { + if (!IsLogEnabled()) return; + LogDOMActionInternal(extension, + url, + url_title, + api_call, + args, + extra, + DOMAction::MODIFIED); +} + void ActivityLog::OnScriptsExecuted( const content::WebContents* web_contents, const ExecutingScriptsMap& extension_ids, @@ -330,12 +360,15 @@ void ActivityLog::OnScriptsExecuted( ext_scripts_str += *it2; ext_scripts_str += " "; } - LogUrlAction(extension, - UrlAction::INSERTED, - on_url, - web_contents->GetTitle(), - ext_scripts_str, - ""); + scoped_ptr<ListValue> script_names(new ListValue()); + script_names->Set(0, new StringValue(ext_scripts_str)); + LogDOMActionInternal(extension, + on_url, + web_contents->GetTitle(), + "", // no api call here + script_names.get(), + "", // no extras either + DOMAction::INSERTED); } } } diff --git a/chrome/browser/extensions/activity_log.h b/chrome/browser/extensions/activity_log.h index c2f7c24..8dd066e 100644 --- a/chrome/browser/extensions/activity_log.h +++ b/chrome/browser/extensions/activity_log.h @@ -72,6 +72,7 @@ class ActivityLog : public ProfileKeyedService, // Log a successful API call made by an extension. // This will create an APIAction for storage in the database. + // (Note: implemented as a wrapper for LogAPIActionInternal.) void LogAPIAction(const Extension* extension, const std::string& name, // e.g., tabs.get const ListValue* args, // the argument values e.g. 46 @@ -79,6 +80,7 @@ class ActivityLog : public ProfileKeyedService, // Log an event notification delivered to an extension. // This will create an APIAction for storage in the database. + // (Note: implemented as a wrapper for LogAPIActionInternal.) void LogEventAction(const Extension* extension, const std::string& name, // e.g., tabs.onUpdate const ListValue* args, // arguments to the callback @@ -93,15 +95,14 @@ class ActivityLog : public ProfileKeyedService, const std::string& extra); // extra logging info // Log an interaction between an extension and a URL. - // This will create a UrlAction for storage in the database. + // This will create a DOMAction for storage in the database. // The technical message might be the list of content scripts that have been // injected, or the DOM API call; it's what's shown under "More". - void LogUrlAction(const Extension* extension, - const UrlAction::UrlActionType verb, // e.g., XHR + void LogDOMAction(const Extension* extension, const GURL& url, // target URL - const string16& url_title, // title of the URL, - // can be empty string - const std::string& technical_message, // "More" + const string16& url_title, // title of the URL + const std::string& api_call, // api call + const ListValue* args, // arguments const std::string& extra); // extra logging info // An error has happened; we want to rollback and close the db. @@ -114,6 +115,25 @@ class ActivityLog : public ProfileKeyedService, explicit ActivityLog(Profile* profile); virtual ~ActivityLog(); + // We log callbacks and API calls very similarly, so we handle them the same + // way internally. + void LogAPIActionInternal( + const Extension* extension, + const std::string& api_call, + const ListValue* args, + const std::string& extra, + const APIAction::Type type); + + // We log content script injection and DOM API calls using the same underlying + // mechanism, so they have the same internal logging structure. + void LogDOMActionInternal(const Extension* extension, + const GURL& url, + const string16& url_title, + const std::string& api_call, + const ListValue* args, + const std::string& extra, + DOMAction::DOMActionType verb); + // TabHelper::ScriptExecutionObserver implementation. // Fires when a ContentScript is executed. virtual void OnScriptsExecuted( diff --git a/chrome/browser/extensions/activity_log_unittest.cc b/chrome/browser/extensions/activity_log_unittest.cc index 15ac11f..6c1cb5e 100644 --- a/chrome/browser/extensions/activity_log_unittest.cc +++ b/chrome/browser/extensions/activity_log_unittest.cc @@ -24,7 +24,7 @@ class ActivityLogTest : public ChromeRenderViewHostTestHarness { public: ActivityLogTest() : ui_thread_(BrowserThread::UI, MessageLoop::current()), - db_thread_(BrowserThread::DB), + db_thread_(BrowserThread::DB, MessageLoop::current()), file_thread_(BrowserThread::FILE, MessageLoop::current()) {} virtual void SetUp() OVERRIDE { @@ -38,15 +38,9 @@ class ActivityLogTest : public ChromeRenderViewHostTestHarness { CommandLine::ForCurrentProcess()->AppendSwitch( switches::kEnableExtensionActivityUI); ActivityLog::RecomputeLoggingIsEnabled(); - db_thread_.Start(); } virtual ~ActivityLogTest() { - base::WaitableEvent done(false, false); - BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, - base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); - done.Wait(); - db_thread_.Stop(); MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); MessageLoop::current()->Run(); } @@ -65,6 +59,8 @@ TEST_F(ActivityLogTest, Enabled) { ASSERT_TRUE(ActivityLog::IsLogEnabled()); } +// Currently, this test basically just checks that nothing crashes. +// Need to update it to verify the writes. TEST_F(ActivityLogTest, ConstructAndLog) { ActivityLog* activity_log = ActivityLog::GetInstance(profile_); scoped_refptr<const Extension> extension = @@ -76,20 +72,15 @@ TEST_F(ActivityLogTest, ConstructAndLog) { .Build(); extension_service_->AddExtension(extension); scoped_ptr<ListValue> args(new ListValue()); - for (int i = 0; i < 30; i++) { - // Run this a bunch of times and hope that if something goes wrong with - // threading, 30 times is enough to cause it to fail. - ASSERT_TRUE(ActivityLog::IsLogEnabled()); - activity_log->LogAPIAction(extension, - std::string("tabs.testMethod"), - args.get(), - ""); - } + ASSERT_TRUE(ActivityLog::IsLogEnabled()); + activity_log->LogAPIAction(extension, + std::string("tabs.testMethod"), + args.get(), + ""); // Need to ensure the writes were completed. // TODO(felt): Need to add an event in the ActivityLog/ActivityDb to check - // whether the writes have been completed, instead of waiting. + // whether the writes have been completed. #if 0 - base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); base::FilePath db_file = profile_->GetPath().Append( chrome::kExtensionActivityLogFilename); sql::Connection db; @@ -97,13 +88,8 @@ TEST_F(ActivityLogTest, ConstructAndLog) { std::string sql_str = "SELECT * FROM " + std::string(APIAction::kTableName); sql::Statement statement(db.GetUniqueStatement(sql_str.c_str())); - if (statement.Succeeded()) { - ASSERT_TRUE(statement.Step()); - } else { - base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); - sql::Statement statement2(db.GetUniqueStatement(sql_str.c_str())); - ASSERT_TRUE(statement2.Step()); - } + ASSERT_TRUE(statement.Succeeded()); + ASSERT_TRUE(statement.Step()); ASSERT_EQ("CALL", statement.ColumnString(2)); ASSERT_EQ("UNKNOWN_VERB", statement.ColumnString(3)); ASSERT_EQ("TABS", statement.ColumnString(4)); diff --git a/chrome/browser/extensions/api_actions.cc b/chrome/browser/extensions/api_actions.cc index 7897696..ebd4725 100644 --- a/chrome/browser/extensions/api_actions.cc +++ b/chrome/browser/extensions/api_actions.cc @@ -13,14 +13,11 @@ using content::BrowserThread; namespace extensions { const char* APIAction::kTableName = "activitylog_apis"; -const char* APIAction::kTableStructure = "(" +const char* APIAction::kTableBasicFields = "extension_id LONGVARCHAR NOT NULL, " - "time INTEGER NOT NULL, " - "api_type LONGVARCHAR NOT NULL, " - "api_action_type LONGVARCHAR NOT NULL, " - "target_type LONGVARCHAR NOT NULL, " - "api_call LONGVARCHAR NOT NULL, " - "extra LONGVARCHAR NOT NULL)"; + "time INTEGER NOT NULL"; +const char* APIAction::kTableContentFields[] = + {"api_type", "api_action_type", "target_type", "api_call", "args", "extra"}; APIAction::APIAction(const std::string& extension_id, const base::Time& time, @@ -28,6 +25,7 @@ APIAction::APIAction(const std::string& extension_id, const Verb verb, const Target target, const std::string& api_call, + const std::string& args, const std::string& extra) : extension_id_(extension_id), time_(time), @@ -35,6 +33,7 @@ APIAction::APIAction(const std::string& extension_id, verb_(verb), target_(target), api_call_(api_call), + args_(args), extra_(extra) { } APIAction::~APIAction() { @@ -42,31 +41,17 @@ APIAction::~APIAction() { // static bool APIAction::InitializeTable(sql::Connection* db) { - if (!db->DoesTableExist(kTableName)) { - std::string table_creator = base::StringPrintf( - "CREATE TABLE %s %s", kTableName, kTableStructure); - if (!db->Execute(table_creator.c_str())) - return false; - } else if (!db->DoesColumnExist(kTableName, "api_type")) { - // Old versions of the table lack the api_type column. Add it if - // needed, with values defaulting to "CALL". - // - // TODO(mvrable): Remove this update code once we're fairly certain that - // everyone will have converted to the new schema. - std::string table_updater = base::StringPrintf( - "ALTER TABLE %s ADD COLUMN api_type LONGVARCHAR; " - "UPDATE %s SET api_type = 'CALL'", - kTableName, kTableName); - if (!db->Execute(table_updater.c_str())) - return false; - } - return true; + return InitializeTableInternal(db, + kTableName, + kTableBasicFields, + kTableContentFields, + arraysize(kTableContentFields)); } void APIAction::Record(sql::Connection* db) { std::string sql_str = "INSERT INTO " + std::string(kTableName) + " (extension_id, time, api_type, api_action_type, target_type," - " api_call, extra) VALUES (?,?,?,?,?,?,?)"; + " api_call, args, extra) VALUES (?,?,?,?,?,?,?,?)"; sql::Statement statement(db->GetCachedStatement( sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); statement.BindString(0, extension_id_); @@ -75,8 +60,8 @@ void APIAction::Record(sql::Connection* db) { statement.BindString(3, VerbAsString()); statement.BindString(4, TargetAsString()); statement.BindString(5, api_call_); - statement.BindString(6, extra_); - + statement.BindString(6, args_); + statement.BindString(7, extra_); if (!statement.Run()) LOG(ERROR) << "Activity log database I/O failed: " << sql_str; } @@ -90,7 +75,7 @@ std::string APIAction::PrettyPrintForDebug() { // TODO(felt): implement this for real when the UI is redesigned. return "ID: " + extension_id_ + + ", CATEGORY: " + TypeAsString() + ", VERB: " + VerbAsString() + ", TARGET: " + TargetAsString() + - ", API: " + api_call_; + ", API: " + api_call_ + ", ARGS: " + args_; } std::string APIAction::TypeAsString() const { diff --git a/chrome/browser/extensions/api_actions.h b/chrome/browser/extensions/api_actions.h index 7bcbbe8..dc7b808 100644 --- a/chrome/browser/extensions/api_actions.h +++ b/chrome/browser/extensions/api_actions.h @@ -46,7 +46,8 @@ class APIAction : public Action { }; static const char* kTableName; - static const char* kTableStructure; + static const char* kTableBasicFields; + static const char* kTableContentFields[]; // Create the database table for storing APIActions, or update the schema if // it is out of date. Any existing data is preserved. @@ -59,7 +60,8 @@ class APIAction : public Action { const Type type, // e.g. "CALL" const Verb verb, // e.g. "ADDED" const Target target, // e.g. "BOOKMARK" - const std::string& api_call, // full method signature incl args + const std::string& api_call, // full method name + const std::string& args, // the argument list const std::string& extra); // any extra logging info // Record the action in the database. @@ -75,6 +77,7 @@ class APIAction : public Action { const std::string& extension_id() const { return extension_id_; } const base::Time& time() const { return time_; } const std::string& api_call() const { return api_call_; } + const std::string& args() const { return args_; } std::string TypeAsString() const; std::string VerbAsString() const; std::string TargetAsString() const; @@ -95,6 +98,7 @@ class APIAction : public Action { Verb verb_; Target target_; std::string api_call_; + std::string args_; std::string extra_; DISALLOW_COPY_AND_ASSIGN(APIAction); diff --git a/chrome/browser/extensions/blocked_actions.cc b/chrome/browser/extensions/blocked_actions.cc index 54be11a..756d9e8 100644 --- a/chrome/browser/extensions/blocked_actions.cc +++ b/chrome/browser/extensions/blocked_actions.cc @@ -4,6 +4,7 @@ #include <string> #include "base/logging.h" +#include "base/stringprintf.h" #include "chrome/browser/extensions/blocked_actions.h" #include "content/public/browser/browser_thread.h" @@ -12,37 +13,59 @@ using content::BrowserThread; namespace extensions { const char* BlockedAction::kTableName = "activitylog_blocked"; -const char* BlockedAction::kTableStructure = "(" +const char* BlockedAction::kTableBasicFields = "extension_id LONGVARCHAR NOT NULL, " - "time INTEGER NOT NULL, " - "blocked_action LONGVARCHAR NOT NULL, " - "reason LONGVARCHAR NOT NULL, " - "extra LONGVARCHAR NOT NULL)"; + "time INTEGER NOT NULL"; +const char* BlockedAction::kTableContentFields[] = + {"api_call", "args", "reason", "extra"}; BlockedAction::BlockedAction(const std::string& extension_id, const base::Time& time, - const std::string& blocked_action, + const std::string& api_call, + const std::string& args, const std::string& reason, const std::string& extra) : extension_id_(extension_id), time_(time), - blocked_action_(blocked_action), + api_call_(api_call), + args_(args), reason_(reason), extra_(extra) { } BlockedAction::~BlockedAction() { } +// static +bool BlockedAction::InitializeTable(sql::Connection* db) { + // The original table schema was different than the existing one. + // Sqlite doesn't let you delete or modify existing columns, so we drop it. + // The old version can be identified because it had a field named + // blocked_action. Any data loss incurred here doesn't matter since these + // fields existed before we started using the AL for anything. + if (db->DoesColumnExist(kTableName, "blocked_action")) { + std::string drop_table = base::StringPrintf("DROP TABLE %s", kTableName); + if (!db->Execute(drop_table.c_str())) + return false; + } + return InitializeTableInternal(db, + kTableName, + kTableBasicFields, + kTableContentFields, + arraysize(kTableContentFields)); +} + void BlockedAction::Record(sql::Connection* db) { std::string sql_str = "INSERT INTO " + std::string(kTableName) - + " (extension_id, time, blocked_action, reason, extra) VALUES (?,?,?,?,?)"; + + " (extension_id, time, api_call, args, reason, extra)" + " VALUES (?,?,?,?,?,?)"; sql::Statement statement(db->GetCachedStatement( sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); statement.BindString(0, extension_id_); statement.BindInt64(1, time().ToInternalValue()); - statement.BindString(2, blocked_action_); - statement.BindString(3, reason_); - statement.BindString(4, extra_); + statement.BindString(2, api_call_); + statement.BindString(3, args_); + statement.BindString(4, reason_); + statement.BindString(5, extra_); if (!statement.Run()) LOG(ERROR) << "Activity log database I/O failed: " << sql_str; } @@ -54,7 +77,7 @@ std::string BlockedAction::PrettyPrintFori18n() { std::string BlockedAction::PrettyPrintForDebug() { // TODO(felt): implement this for real when the UI is redesigned. - return "ID: " + extension_id_ + ", blocked action " + blocked_action_ + + return "ID: " + extension_id_ + ", blocked action " + api_call_ + ", reason: " + reason_; } diff --git a/chrome/browser/extensions/blocked_actions.h b/chrome/browser/extensions/blocked_actions.h index 57d20bf..6492f5c 100644 --- a/chrome/browser/extensions/blocked_actions.h +++ b/chrome/browser/extensions/blocked_actions.h @@ -16,11 +16,18 @@ namespace extensions { class BlockedAction : public Action { public: static const char* kTableName; - static const char* kTableStructure; + static const char* kTableBasicFields; + static const char* kTableContentFields[]; + // Create a new database table for storing BlockedActions, or update the + // schema if it is out of date. Any existing data is preserved. + static bool InitializeTable(sql::Connection* db); + + // You must supply the id, time, api_call, and reason. BlockedAction(const std::string& extension_id, const base::Time& time, - const std::string& blocked_action, // the blocked API call + const std::string& api_call, // the blocked API call + const std::string& args, // the arguments const std::string& reason, // the reason it's blocked const std::string& extra); // any extra logging info @@ -37,7 +44,8 @@ class BlockedAction : public Action { const std::string& extension_id() const { return extension_id_; } const base::Time& time() const { return time_; } const std::string& reason() const { return reason_; } - const std::string& blocked_action() const { return blocked_action_; } + const std::string& api_call() const { return api_call_; } + const std::string& args() const { return args_; } const std::string& extra() const { return extra_; } protected: @@ -46,7 +54,8 @@ class BlockedAction : public Action { private: std::string extension_id_; base::Time time_; - std::string blocked_action_; + std::string api_call_; + std::string args_; std::string reason_; std::string extra_; diff --git a/chrome/browser/extensions/dom_actions.cc b/chrome/browser/extensions/dom_actions.cc new file mode 100644 index 0000000..9bbf771 --- /dev/null +++ b/chrome/browser/extensions/dom_actions.cc @@ -0,0 +1,133 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/logging.h" +#include "base/stringprintf.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/extensions/dom_actions.h" +#include "content/public/browser/browser_thread.h" + +using content::BrowserThread; + +namespace extensions { + +const char* DOMAction::kTableName = "activitylog_urls"; +const char* DOMAction::kTableBasicFields = + "extension_id LONGVARCHAR NOT NULL, " + "time INTEGER NOT NULL"; +const char* DOMAction::kTableContentFields[] = + {"url_action_type", "url", "url_title", "api_call", "args", "extra"}; + +DOMAction::DOMAction(const std::string& extension_id, + const base::Time& time, + const DOMActionType verb, + const GURL& url, + const string16& url_title, + const std::string& api_call, + const std::string& args, + const std::string& extra) + : extension_id_(extension_id), + time_(time), + verb_(verb), + url_(url), + url_title_(url_title), + api_call_(api_call), + args_(args), + extra_(extra) { } + +DOMAction::~DOMAction() { +} + +// static +bool DOMAction::InitializeTable(sql::Connection* db) { + // The original table schema was different than the existing one. + // Sqlite doesn't let you delete or modify existing columns, so we drop it. + // The old version can be identified because it had a field named + // tech_message. Any data loss incurred here doesn't matter since these + // fields existed before we started using the AL for anything. + if (db->DoesColumnExist(kTableName, "tech_message")) { + std::string drop_table = base::StringPrintf("DROP TABLE %s", kTableName); + if (!db->Execute(drop_table.c_str())) + return false; + } + // Now initialize the table. + bool initialized = InitializeTableInternal(db, + kTableName, + kTableBasicFields, + kTableContentFields, + arraysize(kTableContentFields)); + return initialized; +} + +void DOMAction::Record(sql::Connection* db) { + std::string sql_str = "INSERT INTO " + std::string(kTableName) + + " (extension_id, time, url_action_type, url, url_title, api_call, args," + " extra) VALUES (?,?,?,?,?,?,?,?)"; + sql::Statement statement(db->GetCachedStatement( + sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); + statement.BindString(0, extension_id_); + statement.BindInt64(1, time_.ToInternalValue()); + statement.BindString(2, VerbAsString()); + statement.BindString(3, history::URLDatabase::GURLToDatabaseURL(url_)); + statement.BindString16(4, url_title_); + statement.BindString(5, api_call_); + statement.BindString(6, args_); + statement.BindString(7, "sdf"); + if (!statement.Run()) { + LOG(ERROR) << "Activity log database I/O failed: " << sql_str; + LOG(ERROR) << "extension_id: " << extension_id_ << "; verb: " << + VerbAsString() << "; url: " << + history::URLDatabase::GURLToDatabaseURL(url_) << "; title: " << url_title_ + << "; api_call: " << api_call_ << "; args: " << args_; + } +} + +std::string DOMAction::PrettyPrintFori18n() { + // TODO(felt): implement this for real when the UI is redesigned. + return PrettyPrintForDebug(); +} + +std::string DOMAction::PrettyPrintForDebug() { + // TODO(felt): implement this for real when the UI is redesigned. + if (verb_ == INSERTED) + return "Injected scripts (" + args_ + ") onto " + + std::string(url_.spec()); + else + return "DOM API CALL: " + api_call_ + ", ARGS: " + args_; +} + +std::string DOMAction::VerbAsString() const { + switch (verb_) { + case MODIFIED: + return "MODIFIED"; + case READ: + return "READ"; + case INSERTED: + return "INSERTED"; + case XHR: + return "XHR"; + default: + NOTREACHED(); + return NULL; + } +} + +DOMAction::DOMActionType DOMAction::StringAsDOMActionType( + const std::string& str) { + if (str == "MODIFIED") { + return MODIFIED; + } else if (str == "READ") { + return READ; + } else if (str == "INSERTED") { + return INSERTED; + } else if (str == "XHR") { + return XHR; + } else { + NOTREACHED(); + return MODIFIED; // this should never happen! + } +} + +} // namespace extensions + diff --git a/chrome/browser/extensions/dom_actions.h b/chrome/browser/extensions/dom_actions.h new file mode 100644 index 0000000..2ec131e --- /dev/null +++ b/chrome/browser/extensions/dom_actions.h @@ -0,0 +1,90 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_EXTENSIONS_DOM_ACTIONS_H_ +#define CHROME_BROWSER_EXTENSIONS_DOM_ACTIONS_H_ + +#include <string> +#include "base/string16.h" +#include "base/time.h" +#include "chrome/browser/extensions/activity_actions.h" +#include "googleurl/src/gurl.h" + +namespace extensions { + +// This class describes extension actions that pertain to DOM API calls and +// content script insertions. +class DOMAction : public Action { + public: + enum DOMActionType { + MODIFIED, // For Content Script DOM manipulations + READ, // For Content Script DOM manipulations + INSERTED, // For when Content Scripts are added to pages + XHR, // When an extension core sends an XHR + }; + + static const char* kTableName; + static const char* kTableBasicFields; + static const char* kTableContentFields[]; + + // Create a new database table for storing DOMActions, or update the schema if + // it is out of date. Any existing data is preserved. + static bool InitializeTable(sql::Connection* db); + + // Create a new DOMAction to describe a new DOM API call. + // If the DOMAction is on a background page, the url & url_title may be null. + // If the DOMAction refers to a content script insertion, api_call may be null + // but args should be the name of the content script. + DOMAction(const std::string& extension_id, + const base::Time& time, + const DOMActionType verb, // what happened + const GURL& url, // the url of the page the + // script is running on + const string16& url_title, // the page title + const std::string& api_call, // the DOM API call + const std::string& args, // the args + const std::string& extra); // any extra logging info + + // Record the action in the database. + virtual void Record(sql::Connection* db) OVERRIDE; + + // Print a DOMAction with il8n substitutions for display. + virtual std::string PrettyPrintFori18n() OVERRIDE; + + // Print a DOMAction as a regular string for debugging purposes. + virtual std::string PrettyPrintForDebug() OVERRIDE; + + // Helper methods for retrieving the values. + const std::string& extension_id() const { return extension_id_; } + const base::Time& time() const { return time_; } + std::string VerbAsString() const; + const GURL& url() const { return url_; } + const string16& url_title() const { return url_title_; } + const std::string& api_call() const { return api_call_; } + const std::string& args() const { return args_; } + const std::string& extra() const { return extra_; } + + // Helper methods for restoring a DOMAction from the db. + static DOMActionType StringAsDOMActionType(const std::string& str); + + protected: + virtual ~DOMAction(); + + private: + std::string extension_id_; + base::Time time_; + DOMActionType verb_; + GURL url_; + string16 url_title_; + std::string api_call_; + std::string args_; + std::string extra_; + + DISALLOW_COPY_AND_ASSIGN(DOMAction); +}; + +} // namespace extensions + +#endif // CHROME_BROWSER_EXTENSIONS_DOM_ACTIONS_H_ + diff --git a/chrome/browser/extensions/url_actions.cc b/chrome/browser/extensions/url_actions.cc deleted file mode 100644 index 06dd541..0000000 --- a/chrome/browser/extensions/url_actions.cc +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/logging.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/extensions/url_actions.h" -#include "content/public/browser/browser_thread.h" - -using content::BrowserThread; - -namespace extensions { - -const char* UrlAction::kTableName = "activitylog_urls"; -const char* UrlAction::kTableStructure = "(" - "extension_id LONGVARCHAR NOT NULL, " - "time INTEGER NOT NULL, " - "url_action_type LONGVARCHAR NOT NULL, " - "url LONGVARCHAR NOT NULL, " - "url_title LONGVARCHAR, " - "tech_message LONGVARCHAR NOT NULL, " - "extra LONGCHAR VAR NOT NULL)"; - -UrlAction::UrlAction(const std::string& extension_id, - const base::Time& time, - const UrlActionType verb, - const GURL& url, - const string16& url_title, - const std::string& tech_message, - const std::string& extra) - : extension_id_(extension_id), - time_(time), - verb_(verb), - url_(url), - url_title_(url_title), - technical_message_(tech_message), - extra_(extra) { } - -UrlAction::~UrlAction() { -} - -void UrlAction::Record(sql::Connection* db) { - std::string sql_str = "INSERT INTO " + std::string(kTableName) + - " (extension_id, time, url_action_type, url, url_title, tech_message," - " extra) VALUES (?,?,?,?,?,?,?)"; - sql::Statement statement(db->GetCachedStatement( - sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); - statement.BindString(0, extension_id_); - statement.BindInt64(1, time_.ToInternalValue()); - statement.BindString(2, VerbAsString()); - statement.BindString(3, history::URLDatabase::GURLToDatabaseURL(url_)); - statement.BindString16(4, url_title_); - statement.BindString(5, technical_message_); - statement.BindString(6, extra_); - if (!statement.Run()) - LOG(ERROR) << "Activity log database I/O failed: " << sql_str; -} - -std::string UrlAction::PrettyPrintFori18n() { - // TODO(felt): implement this for real when the UI is redesigned. - return PrettyPrintForDebug(); -} - -std::string UrlAction::PrettyPrintForDebug() { - // TODO(felt): implement this for real when the UI is redesigned. - return "Injected scripts (" + technical_message_ + ") onto " - + std::string(url_.spec()); -} - -std::string UrlAction::VerbAsString() const { - switch (verb_) { - case MODIFIED: - return "MODIFIED"; - case READ: - return "READ"; - case INSERTED: - return "INSERTED"; - case XHR: - return "XHR"; - default: - NOTREACHED(); - return NULL; - } -} - -UrlAction::UrlActionType UrlAction::StringAsUrlActionType( - const std::string& str) { - if (str == "MODIFIED") { - return MODIFIED; - } else if (str == "READ") { - return READ; - } else if (str == "INSERTED") { - return INSERTED; - } else if (str == "XHR") { - return XHR; - } else { - NOTREACHED(); - return MODIFIED; // this should never happen! - } -} - -} // namespace extensions - diff --git a/chrome/browser/extensions/url_actions.h b/chrome/browser/extensions/url_actions.h deleted file mode 100644 index f8505c9..0000000 --- a/chrome/browser/extensions/url_actions.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_EXTENSIONS_URL_ACTIONS_H_ -#define CHROME_BROWSER_EXTENSIONS_URL_ACTIONS_H_ - -#include <string> -#include "base/string16.h" -#include "base/time.h" -#include "chrome/browser/extensions/activity_actions.h" -#include "googleurl/src/gurl.h" - -namespace extensions { - -// This class describes extension actions that pertain to Content Script -// insertion, Content Script DOM manipulations, and extension XHRs. -class UrlAction : public Action { - public: - enum UrlActionType { - MODIFIED, // For Content Script DOM manipulations - READ, // For Content Script DOM manipulations - INSERTED, // For when Content Scripts are added to pages - XHR, // When an extension core sends an XHR - }; - - static const char* kTableName; - static const char* kTableStructure; - - // Create a new UrlAction to describe a ContentScript action - // or XHR. All of the parameters should have values except for - // url_title, which can be an empty string if the ActionType is XHR. - UrlAction(const std::string& extension_id, - const base::Time& time, - const UrlActionType verb, // what happened - const GURL& url, // the url of the page or XHR - const string16& url_title, // the page title - const std::string& tech_message, // what goes under "More" - const std::string& extra); // any extra logging info - - // Record the action in the database. - virtual void Record(sql::Connection* db) OVERRIDE; - - // Print a UrlAction with il8n substitutions for display. - virtual std::string PrettyPrintFori18n() OVERRIDE; - - // Print a UrlAction as a regular string for debugging purposes. - virtual std::string PrettyPrintForDebug() OVERRIDE; - - // Helper methods for retrieving the values. - const std::string& extension_id() const { return extension_id_; } - const base::Time& time() const { return time_; } - std::string VerbAsString() const; - const GURL& url() const { return url_; } - const string16& url_title() const { return url_title_; } - const std::string& technical_message() const { return technical_message_; } - const std::string& extra() const { return extra_; } - - // Helper methods for restoring a UrlAction from the db. - static UrlActionType StringAsUrlActionType(const std::string& str); - - protected: - virtual ~UrlAction(); - - private: - std::string extension_id_; - base::Time time_; - UrlActionType verb_; - GURL url_; - string16 url_title_; - std::string technical_message_; - std::string extra_; - - DISALLOW_COPY_AND_ASSIGN(UrlAction); -}; - -} // namespace extensions - -#endif // CHROME_BROWSER_EXTENSIONS_URL_ACTIONS_H_ - diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index b78dbce..98a59a0f 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -58,6 +58,7 @@ 'browser/extensions/active_tab_permission_granter.cc', 'browser/extensions/active_tab_permission_granter.h', 'browser/extensions/activity_actions.h', + 'browser/extensions/activity_actions.cc', 'browser/extensions/activity_database.cc', 'browser/extensions/activity_database.h', 'browser/extensions/activity_log.cc', @@ -496,6 +497,8 @@ 'browser/extensions/data_deleter.h', 'browser/extensions/default_apps.cc', 'browser/extensions/default_apps.h', + 'browser/extensions/dom_actions.cc', + 'browser/extensions/dom_actions.h', 'browser/extensions/event_listener_map.cc', 'browser/extensions/event_listener_map.h', 'browser/extensions/event_names.cc', @@ -697,8 +700,6 @@ 'browser/extensions/updater/request_queue_impl.h', 'browser/extensions/updater/safe_manifest_parser.cc', 'browser/extensions/updater/safe_manifest_parser.h', - 'browser/extensions/url_actions.cc', - 'browser/extensions/url_actions.h', 'browser/extensions/user_script_listener.cc', 'browser/extensions/user_script_listener.h', 'browser/extensions/user_script_master.cc', |