#include "base/process/process.h"
#include "base/values.h"
#include "build/build_config.h"
-#include "chrome/browser/extensions/activity_log/activity_action_constants.h"
-#include "chrome/browser/extensions/activity_log/activity_log.h"
-#include "chrome/browser/extensions/api/activity_log_private/activity_log_private_api.h"
#include "chrome/browser/extensions/extension_function_registry.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_system.h"
-#include "chrome/browser/extensions/extension_util.h"
-#include "chrome/browser/extensions/extension_web_ui.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
#include "chrome/common/extensions/extension_messages.h"
-#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/result_codes.h"
+#include "extensions/browser/api_activity_monitor.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/browser/extensions_browser_client.h"
+#include "extensions/browser/process_manager.h"
#include "extensions/browser/process_map.h"
#include "extensions/browser/quota_service.h"
#include "extensions/common/extension_api.h"
using extensions::Extension;
using extensions::ExtensionAPI;
+using extensions::ExtensionsBrowserClient;
using extensions::ExtensionSystem;
using extensions::Feature;
+using content::BrowserThread;
using content::RenderViewHost;
namespace {
-void LogSuccess(const std::string& extension_id,
- const std::string& api_name,
- scoped_ptr<base::ListValue> args,
- content::BrowserContext* browser_context) {
- // The ActivityLog can only be accessed from the main (UI) thread. If we're
- // running on the wrong thread, re-dispatch from the main thread.
+// Notifies the ApiActivityMonitor that an extension API function has been
+// called. May be called from any thread.
+void NotifyApiFunctionCalled(const std::string& extension_id,
+ const std::string& api_name,
+ scoped_ptr<base::ListValue> args,
+ content::BrowserContext* browser_context) {
+ // The ApiActivityMonitor can only be accessed from the main (UI) thread. If
+ // we're running on the wrong thread, re-dispatch from the main thread.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE,
- base::Bind(&LogSuccess,
+ base::Bind(&NotifyApiFunctionCalled,
extension_id,
api_name,
base::Passed(&args),
browser_context));
- } else {
- extensions::ActivityLog* activity_log =
- extensions::ActivityLog::GetInstance(browser_context);
- scoped_refptr<extensions::Action> action =
- new extensions::Action(extension_id,
- base::Time::Now(),
- extensions::Action::ACTION_API_CALL,
- api_name);
- action->set_args(args.Pass());
- activity_log->LogAction(action);
+ return;
}
+ // The BrowserContext may become invalid after the task above is posted.
+ if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context))
+ return;
+
+ extensions::ApiActivityMonitor* monitor =
+ ExtensionsBrowserClient::Get()->GetApiActivityMonitor(browser_context);
+ if (monitor)
+ monitor->OnApiFunctionCalled(extension_id, api_name, args.Pass());
}
// Separate copy of ExtensionAPI used for IO thread extension functions. We need
base::TimeTicks::Now());
if (violation_error.empty()) {
scoped_ptr<base::ListValue> args(params.arguments.DeepCopy());
- LogSuccess(extension->id(),
- params.name,
- args.Pass(),
- static_cast<content::BrowserContext*>(browser_context));
+ NotifyApiFunctionCalled(
+ extension->id(),
+ params.name,
+ args.Pass(),
+ static_cast<content::BrowserContext*>(browser_context));
function->Run();
} else {
function->OnQuotaExceeded(violation_error);
DCHECK(render_view_host || render_frame_host);
// TODO(yzshen): There is some shared logic between this method and
// DispatchOnIOThread(). It is nice to deduplicate.
- ExtensionSystem* extension_system =
- ExtensionSystem::GetForBrowserContext(browser_context_);
- ExtensionService* service = extension_system->extension_service();
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(browser_context_);
if (!process_map)
return;
- const Extension* extension = service->extensions()->GetByID(
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(browser_context_);
+ const Extension* extension = registry->enabled_extensions().GetByID(
params.extension_id);
- if (!extension)
- extension = service->extensions()->GetHostedAppByURL(params.source_url);
+ if (!extension) {
+ extension =
+ registry->enabled_extensions().GetHostedAppByURL(params.source_url);
+ }
int process_id = render_view_host ? render_view_host->GetProcess()->GetID() :
render_frame_host->GetProcess()->GetID();
function_ui->set_dispatcher(AsWeakPtr());
function_ui->set_context(browser_context_);
function->set_include_incognito(
- extensions::util::CanCrossIncognito(extension, browser_context_));
+ ExtensionsBrowserClient::Get()->CanExtensionCrossIncognito(
+ extension, browser_context_));
if (!CheckPermissions(function.get(), extension, params, callback))
return;
- extensions::QuotaService* quota = service->quota_service();
+ ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_);
+ extensions::QuotaService* quota = extension_system->quota_service();
std::string violation_error = quota->Assess(extension->id(),
function.get(),
¶ms.arguments,
// See crbug.com/39178.
ExternalProtocolHandler::PermitLaunchUrl();
- LogSuccess(extension->id(), params.name, args.Pass(), browser_context_);
+ NotifyApiFunctionCalled(
+ extension->id(), params.name, args.Pass(), browser_context_);
function->Run();
} else {
function->OnQuotaExceeded(violation_error);
// if function->Run() ended up closing the tab that owns us.
// Check if extension was uninstalled by management.uninstall.
- if (!service->extensions()->GetByID(params.extension_id))
+ if (!registry->enabled_extensions().GetByID(params.extension_id))
return;
// We only adjust the keepalive count for UIThreadExtensionFunction for
void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted(
const Extension* extension) {
- ExtensionSystem::GetForBrowserContext(browser_context_)->process_manager()->
+ ExtensionSystem::Get(browser_context_)->process_manager()->
DecrementLazyKeepaliveCount(extension);
}
function->set_extension(extension);
function->set_profile_id(profile);
function->set_response_callback(callback);
+ function->set_source_tab_id(params.source_tab_id);
return function;
}