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

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: Fix crash 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 7be3332d2e80e193420d070684884a7a387a7097..a790d0c976ac7104fb0ea63192c2295230bd1a9f 100644
--- a/chrome/browser/extensions/api/automation_internal/automation_event_router.cc
+++ b/chrome/browser/extensions/api/automation_internal/automation_event_router.cc
@@ -11,6 +11,7 @@
#include "base/stl_util.h"
#include "base/values.h"
#include "chrome/browser/accessibility/ax_tree_id_registry.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/extensions/api/automation_internal.h"
#include "chrome/common/extensions/chrome_extension_messages.h"
#include "content/public/browser/notification_service.h"
@@ -34,27 +35,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,
David Tseng 2015/08/05 22:24:36 nit: /* desktop tree id */
dmazzoni 2015/08/05 22:53:39 Done.
+ true);
}
void AutomationEventRouter::DispatchAccessibilityEvent(
const ExtensionMsg_AccessibilityEventParams& params) {
for (const auto& listener : listeners_) {
+ // Reject listeners that don't want to listen to this tree.
David Tseng 2015/08/05 22:24:36 nit: Skip?
dmazzoni 2015/08/05 22:53:39 Done.
if (!listener.desktop &&
listener.tree_ids.find(params.tree_id) == listener.tree_ids.end()) {
continue;
@@ -63,7 +80,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));
}
}
@@ -87,6 +105,7 @@ AutomationEventRouter::AutomationListener::~AutomationListener() {
}
void AutomationEventRouter::Register(
+ const ExtensionId& extension_id,
int listener_process_id,
int listener_routing_id,
int ax_tree_id,
@@ -103,11 +122,14 @@ 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);
+ listener.is_active_profile = true;
David Tseng 2015/08/05 22:24:36 Does this default make sense?
dmazzoni 2015/08/05 22:53:39 Deleted because we just call UpdateActiveProfile,
listeners_.push_back(listener);
+ UpdateActiveProfile();
return;
}
@@ -139,6 +161,30 @@ void AutomationEventRouter::Observe(
return item.process_id == process_id;
}),
listeners_.end());
+ UpdateActiveProfile();
+}
+
+void AutomationEventRouter::ActiveUserChanged(const std::string& user_id) {
+ active_profile_ = ProfileManager::GetLastUsedProfile();
+ UpdateActiveProfile();
+}
+
+void AutomationEventRouter::UpdateActiveProfile() {
+ for (auto& listener : listeners_) {
+#if defined(OS_CHROMEOS)
David Tseng 2015/08/05 22:24:36 Can this be USE_ASH instead?
dmazzoni 2015/08/05 22:53:39 No, because that'd be true on Windows, which uses
+ int extension_id_count = 0;
+ for (auto listener2 : listeners_) {
+ if (listener2.extension_id == listener.extension_id)
+ extension_id_count++;
+ }
+ content::RenderProcessHost* rph =
+ content::RenderProcessHost::FromID(listener.process_id);
+ listener.is_active_profile = (extension_id_count == 1 ||
David Tseng 2015/08/05 22:24:36 Does this condition make sense? If I understand co
dmazzoni 2015/08/05 22:53:39 Yes, that's intentional. The idea is only to preve
+ rph->GetBrowserContext() == active_profile_);
+#else
+ listener.is_active_profile = true;
+#endif
+ }
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698