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

Unified Diff: chrome/browser/extensions/api/automation_internal/automation_event_router.cc

Issue 1268163002: Dispatch automation events to the last used profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add to owners file Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/automation_internal/automation_event_router.cc
diff --git a/chrome/browser/extensions/api/automation_internal/automation_event_router.cc b/chrome/browser/extensions/api/automation_internal/automation_event_router.cc
index 3e4539d6e85c5c8455ff4fdb75d1f25022b162eb..a66b85c4506974dc819c9935f55e1dd88f85ce37 100644
--- a/chrome/browser/extensions/api/automation_internal/automation_event_router.cc
+++ b/chrome/browser/extensions/api/automation_internal/automation_event_router.cc
@@ -33,27 +33,43 @@ AutomationEventRouter::AutomationEventRouter() {
content::NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
content::NotificationService::AllBrowserContextsAndSources());
+ active_profile_ = ProfileManager::GetLastUsedProfile();
+
+#if defined(OS_CHROMEOS)
+ session_state_observer_.reset(new ash::ScopedSessionStateObserver(this));
+#endif
}
AutomationEventRouter::~AutomationEventRouter() {
}
void AutomationEventRouter::RegisterListenerForOneTree(
+ const ExtensionId& extension_id,
int listener_process_id,
int listener_routing_id,
int source_ax_tree_id) {
- Register(listener_process_id, listener_routing_id, source_ax_tree_id, false);
+ Register(extension_id,
+ listener_process_id,
+ listener_routing_id,
+ source_ax_tree_id,
+ false);
}
void AutomationEventRouter::RegisterListenerWithDesktopPermission(
+ const ExtensionId& extension_id,
int listener_process_id,
int listener_routing_id) {
- Register(listener_process_id, listener_routing_id, 0, true);
+ Register(extension_id,
+ listener_process_id,
+ listener_routing_id,
+ 0 /* desktop tree ID */,
+ true);
}
void AutomationEventRouter::DispatchAccessibilityEvent(
const ExtensionMsg_AccessibilityEventParams& params) {
for (const auto& listener : listeners_) {
+ // Skip listeners that don't want to listen to this tree.
if (!listener.desktop &&
listener.tree_ids.find(params.tree_id) == listener.tree_ids.end()) {
continue;
@@ -62,7 +78,8 @@ void AutomationEventRouter::DispatchAccessibilityEvent(
content::RenderProcessHost* rph =
content::RenderProcessHost::FromID(listener.process_id);
rph->Send(new ExtensionMsg_AccessibilityEvent(listener.routing_id,
- params));
+ params,
+ listener.is_active_profile));
}
}
@@ -86,6 +103,7 @@ AutomationEventRouter::AutomationListener::~AutomationListener() {
}
void AutomationEventRouter::Register(
+ const ExtensionId& extension_id,
int listener_process_id,
int listener_routing_id,
int ax_tree_id,
@@ -102,11 +120,13 @@ void AutomationEventRouter::Register(
// Add a new entry if we don't have one with that process and routing id.
if (iter == listeners_.end()) {
AutomationListener listener;
+ listener.extension_id = extension_id;
listener.routing_id = listener_routing_id;
listener.process_id = listener_process_id;
listener.desktop = desktop;
listener.tree_ids.insert(ax_tree_id);
listeners_.push_back(listener);
+ UpdateActiveProfile();
return;
}
@@ -138,6 +158,38 @@ void AutomationEventRouter::Observe(
return item.process_id == process_id;
}),
listeners_.end());
+ UpdateActiveProfile();
+}
+
+#if defined(OS_CHROMEOS)
+void AutomationEventRouter::ActiveUserChanged(const std::string& user_id) {
+ active_profile_ = ProfileManager::GetLastUsedProfile();
+ UpdateActiveProfile();
+}
+#endif
+
+void AutomationEventRouter::UpdateActiveProfile() {
+ for (auto& listener : listeners_) {
+#if defined(OS_CHROMEOS)
+ int extension_id_count = 0;
+ for (auto listener2 : listeners_) {
dcheng 2015/08/07 21:36:09 const auto&
dmazzoni 2015/08/07 22:03:31 Done.
+ if (listener2.extension_id == listener.extension_id)
+ extension_id_count++;
+ }
+ content::RenderProcessHost* rph =
+ content::RenderProcessHost::FromID(listener.process_id);
+
+ // The purpose of is_active_profile is to ensure different instances of
+ // the same extension running in different profiles don't interfere with
+ // one another. If an automation extension is only running in one profile,
+ // always mark it as active. If it's running in two or more profiles,
+ // only mark one as active.
+ listener.is_active_profile = (extension_id_count == 1 ||
+ rph->GetBrowserContext() == active_profile_);
+#else
+ listener.is_active_profile = true;
+#endif
+ }
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698