diff options
author | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-23 00:41:13 +0000 |
---|---|---|
committer | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-23 00:41:13 +0000 |
commit | 0a184b5d3f485ffeb672754b0855a7fe80d87db6 (patch) | |
tree | 0140d5ce56f38eaeb661cb9b0dfa9ce07ebe0bf6 /chrome/browser/extensions/extension_browser_event_router.cc | |
parent | ca87a0334160f3fa810c76a26b7c0191377e50b2 (diff) | |
download | chromium_src-0a184b5d3f485ffeb672754b0855a7fe80d87db6.zip chromium_src-0a184b5d3f485ffeb672754b0855a7fe80d87db6.tar.gz chromium_src-0a184b5d3f485ffeb672754b0855a7fe80d87db6.tar.bz2 |
More correct window focus changes for multi-profile and incognito.
Multi-profile: treat windows from other profiles as WINDOW_ID_NONE.
Incognito: on switching between default/OTR profile windows, send WINDOW_ID_NONE to the extensions that can't see the new window.
Also make ExtensionBrowserEventRouter listen only to events from browsers and tabs for its profile, except for window focus events.
BUG=46610, 57186, 86001
TEST=Manually tested extensions in spanning and split mode.
Review URL: http://codereview.chromium.org/7187015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90143 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_browser_event_router.cc')
-rw-r--r-- | chrome/browser/extensions/extension_browser_event_router.cc | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc index 15c6c0f..2db040b 100644 --- a/chrome/browser/extensions/extension_browser_event_router.cc +++ b/chrome/browser/extensions/extension_browser_event_router.cc @@ -98,8 +98,9 @@ void ExtensionBrowserEventRouter::Init() { ExtensionBrowserEventRouter::ExtensionBrowserEventRouter(Profile* profile) : initialized_(false), - focused_window_id_(extension_misc::kUnknownWindowId), - profile_(profile) { + profile_(profile), + focused_profile_(NULL), + focused_window_id_(extension_misc::kUnknownWindowId) { DCHECK(!profile->IsOffTheRecord()); } @@ -113,6 +114,8 @@ ExtensionBrowserEventRouter::~ExtensionBrowserEventRouter() { } void ExtensionBrowserEventRouter::OnBrowserAdded(const Browser* browser) { + if (!profile_->IsSameProfile(browser->profile())) + return; RegisterForBrowserNotifications(browser); } @@ -127,10 +130,8 @@ void ExtensionBrowserEventRouter::RegisterForBrowserNotifications( registrar_.Add(this, NotificationType::BROWSER_WINDOW_READY, Source<const Browser>(browser)); - if (browser->tabstrip_model()) { - for (int i = 0; i < browser->tabstrip_model()->count(); ++i) - RegisterForTabNotifications(browser->GetTabContentsAt(i)); - } + for (int i = 0; i < browser->tabstrip_model()->count(); ++i) + RegisterForTabNotifications(browser->GetTabContentsAt(i)); } void ExtensionBrowserEventRouter::RegisterForTabNotifications( @@ -168,6 +169,9 @@ void ExtensionBrowserEventRouter::OnBrowserWindowReady(const Browser* browser) { } void ExtensionBrowserEventRouter::OnBrowserRemoved(const Browser* browser) { + if (!profile_->IsSameProfile(browser->profile())) + return; + // Stop listening to TabStripModel events for this browser. browser->tabstrip_model()->RemoveObserver(this); @@ -196,21 +200,45 @@ void ExtensionBrowserEventRouter::ActiveWindowChanged( void ExtensionBrowserEventRouter::OnBrowserSetLastActive( const Browser* browser) { + Profile* window_profile = NULL; int window_id = extension_misc::kUnknownWindowId; - if (browser) + if (browser && profile_->IsSameProfile(browser->profile())) { + window_profile = browser->profile(); window_id = ExtensionTabUtil::GetWindowId(browser); + } if (focused_window_id_ == window_id) return; + // window_profile is either this profile's default profile, its + // incognito profile, or NULL iff this profile is losing focus. + Profile* previous_focused_profile = focused_profile_; + focused_profile_ = window_profile; focused_window_id_ = window_id; - // Note: because we use the default profile when |browser| is NULL, it means - // that all extensions hear about the event regardless of whether the browser - // that lost focus was OTR or if the extension is OTR-enabled. + + ListValue real_args; + real_args.Append(Value::CreateIntegerValue(window_id)); + std::string real_json_args; + base::JSONWriter::Write(&real_args, false, &real_json_args); + + // When switching between windows in the default and incognitoi profiles, + // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that + // can't see the new focused window across the incognito boundary. // See crbug.com/46610. - DispatchSimpleBrowserEvent(browser ? browser->profile() : profile_, - focused_window_id_, - events::kOnWindowFocusedChanged); + std::string none_json_args; + if (focused_profile_ != NULL && previous_focused_profile != NULL && + focused_profile_ != previous_focused_profile) { + ListValue none_args; + none_args.Append( + Value::CreateIntegerValue(extension_misc::kUnknownWindowId)); + base::JSONWriter::Write(&none_args, false, &none_json_args); + } + + DispatchEventsAcrossIncognito((focused_profile_ ? focused_profile_ : + previous_focused_profile), + events::kOnWindowFocusedChanged, + real_json_args, + none_json_args); } void ExtensionBrowserEventRouter::TabCreatedAt(TabContents* contents, @@ -382,6 +410,18 @@ void ExtensionBrowserEventRouter::DispatchEventToExtension( extension_id, event_name, json_args, profile, GURL()); } +void ExtensionBrowserEventRouter::DispatchEventsAcrossIncognito( + Profile* profile, + const char* event_name, + const std::string& json_args, + const std::string& cross_incognito_args) { + if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) + return; + + profile->GetExtensionEventRouter()->DispatchEventsToRenderersAcrossIncognito( + event_name, json_args, profile, cross_incognito_args, GURL()); +} + void ExtensionBrowserEventRouter::DispatchEventWithTab( Profile* profile, const std::string& extension_id, |