summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-25 15:53:04 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-25 15:53:04 +0000
commit3a798230b07cd2b4e05fb70a1ac5653f71bea30c (patch)
tree4976f16a7f388db29eb60a9ce1833770aa56d5ee
parent5a1c07516ed74beddb54119f66f1dc67dacda4dd (diff)
downloadchromium_src-3a798230b07cd2b4e05fb70a1ac5653f71bea30c.zip
chromium_src-3a798230b07cd2b4e05fb70a1ac5653f71bea30c.tar.gz
chromium_src-3a798230b07cd2b4e05fb70a1ac5653f71bea30c.tar.bz2
Make BrowserList::GetLastActive() private, and add a friend list to BrowserList denoting who is currently allowed to call it.
http://crbug.com/129187 TEST=none Review URL: https://chromiumcodereview.appspot.com/10452021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139043 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc22
-rw-r--r--chrome/browser/automation/testing_automation_provider.h3
-rw-r--r--chrome/browser/printing/print_preview_tab_controller_browsertest.cc4
-rw-r--r--chrome/browser/ui/browser_list.cc28
-rw-r--r--chrome/browser/ui/browser_list.h97
-rw-r--r--chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc9
-rw-r--r--chrome/browser/ui/startup/default_browser_prompt.cc51
-rw-r--r--chrome/browser/ui/views/ash/user_gesture_handler.cc4
8 files changed, 149 insertions, 69 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index d86ef49..eea9313 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -4167,19 +4167,6 @@ void TestingAutomationProvider::SetExtensionStateById(
service->SetIsIncognitoEnabled(extension->id(), allow_in_incognito);
}
-namespace {
-
-// Selects the given |browser| and |tab| if not selected already.
-void EnsureTabSelected(Browser* browser, WebContents* tab) {
- if (browser->GetSelectedWebContents() != tab ||
- browser != BrowserList::GetLastActive()) {
- browser->ActivateTabAt(browser->GetIndexOfController(&tab->GetController()),
- true /* user_gesture */);
- }
-}
-
-} // namespace
-
// See TriggerPageActionById() in chrome/test/pyautolib/pyauto.py
// for sample json input.
void TestingAutomationProvider::TriggerPageActionById(
@@ -6653,3 +6640,12 @@ void TestingAutomationProvider::OnRemoveProvider() {
if (g_browser_process)
g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
}
+
+void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
+ WebContents* tab) {
+ if (browser->GetSelectedWebContents() != tab ||
+ browser != BrowserList::GetLastActive()) {
+ browser->ActivateTabAt(browser->GetIndexOfController(&tab->GetController()),
+ true /* user_gesture */);
+ }
+}
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index 979e7aa..b5192f7 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -1479,6 +1479,9 @@ class TestingAutomationProvider : public AutomationProvider,
const string16& frame_xpath, const string16& script,
IPC::Message* reply_message, content::RenderViewHost* render_view_host);
+ // Selects the given |browser| and |tab| if not selected already.
+ void EnsureTabSelected(Browser* browser, content::WebContents* tab);
+
#if defined(OS_CHROMEOS)
// Avoid scoped ptr here to avoid having to define it completely in the
// non-ChromeOS code.
diff --git a/chrome/browser/printing/print_preview_tab_controller_browsertest.cc b/chrome/browser/printing/print_preview_tab_controller_browsertest.cc
index c6d9b21..30e7ee1 100644
--- a/chrome/browser/printing/print_preview_tab_controller_browsertest.cc
+++ b/chrome/browser/printing/print_preview_tab_controller_browsertest.cc
@@ -19,8 +19,6 @@
using content::WebContents;
-namespace {
-
class PrintPreviewTabControllerBrowserTest : public InProcessBrowserTest {
public:
PrintPreviewTabControllerBrowserTest() {}
@@ -148,5 +146,3 @@ IN_PROC_BROWSER_TEST_F(PrintPreviewTabControllerBrowserTest,
EXPECT_EQ(1, browser()->tab_count());
EXPECT_TRUE(new_preview_tab);
}
-
-} // namespace
diff --git a/chrome/browser/ui/browser_list.cc b/chrome/browser/ui/browser_list.cc
index 2de4186..5bd9bfc 100644
--- a/chrome/browser/ui/browser_list.cc
+++ b/chrome/browser/ui/browser_list.cc
@@ -34,7 +34,7 @@
using content::WebContents;
-namespace {
+namespace browser {
// This object is instantiated when the first Browser object is added to the
// list and delete when the last one is removed. It watches for loads and
@@ -107,7 +107,11 @@ class BrowserActivityObserver : public content::NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(BrowserActivityObserver);
};
-BrowserActivityObserver* activity_observer = NULL;
+BrowserActivityObserver* g_activity_observer = NULL;
+
+} // namespace browser
+
+namespace {
static BrowserList::BrowserVector& browsers() {
CR_DEFINE_STATIC_LOCAL(BrowserList::BrowserVector, browser_vector, ());
@@ -138,8 +142,8 @@ void BrowserList::AddBrowser(Browser* browser) {
g_browser_process->AddRefModule();
- if (!activity_observer)
- activity_observer = new BrowserActivityObserver;
+ if (!browser::g_activity_observer)
+ browser::g_activity_observer = new browser::BrowserActivityObserver;
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_BROWSER_OPENED,
@@ -265,14 +269,6 @@ void BrowserList::SetLastActive(Browser* browser) {
}
// static
-Browser* BrowserList::GetLastActive() {
- if (!last_active_browsers().empty())
- return *(last_active_browsers().rbegin());
-
- return NULL;
-}
-
-// static
BrowserList::const_reverse_iterator BrowserList::begin_last_active() {
return last_active_browsers().rbegin();
}
@@ -311,6 +307,14 @@ bool BrowserList::IsOffTheRecordSessionActiveForProfile(Profile* profile) {
}
// static
+Browser* BrowserList::GetLastActive() {
+ if (!last_active_browsers().empty())
+ return *(last_active_browsers().rbegin());
+
+ return NULL;
+}
+
+// static
void BrowserList::RemoveBrowserFrom(Browser* browser,
BrowserVector* browser_list) {
const iterator remove_browser =
diff --git a/chrome/browser/ui/browser_list.h b/chrome/browser/ui/browser_list.h
index c2b887a..7409221 100644
--- a/chrome/browser/ui/browser_list.h
+++ b/chrome/browser/ui/browser_list.h
@@ -9,12 +9,40 @@
#include <set>
#include <vector>
+#include "base/gtest_prod_util.h"
#include "base/observer_list.h"
#include "ui/gfx/native_widget_types.h"
class Browser;
class Profile;
+namespace content {
+ class WebContents;
+}
+
+namespace browser {
+class BrowserActivityObserver;
+#if defined(OS_MACOSX)
+Browser* GetLastActiveBrowser();
+#endif
+#if defined(TOOLKIT_GTK)
+class ExtensionInstallDialog;
+#endif
+namespace internal {
+void NotifyNotDefaultBrowserCallback();
+}
+}
+
+#if defined(OS_CHROMEOS)
+namespace chromeos {
+class ScreenLocker;
+}
+#endif
+
+#if defined(USE_ASH)
+content::WebContents* GetActiveWebContents();
+#endif
+
// Stores a list of all Browser objects.
class BrowserList {
public:
@@ -53,17 +81,6 @@ class BrowserList {
// allows us to determine what the last active Browser was.
static void SetLastActive(Browser* browser);
- // Returns the Browser object whose window was most recently active. If the
- // most recently open Browser's window was closed, returns the first Browser
- // in the list. If no Browsers exist, returns NULL.
- //
- // WARNING: this is NULL until a browser becomes active. If during startup
- // a browser does not become active (perhaps the user launches Chrome, then
- // clicks on another app before the first browser window appears) then this
- // returns NULL.
- // WARNING #2: this will always be NULL in unit tests run on the bots.
- static Browser* GetLastActive();
-
// Closes all browsers for |profile|.
static void CloseAllBrowsersWithProfile(Profile* profile);
@@ -89,6 +106,64 @@ class BrowserList {
static bool IsOffTheRecordSessionActiveForProfile(Profile* profile);
private:
+ // DO NOT ADD MORE FRIENDS TO THIS LIST. This list should be reduced over
+ // time by wiring context through to the relevant code rather than using
+ // GetLastActive().
+ friend class BasePanelBrowserTest;
+ friend class BrowserView;
+ friend class CertificateViewerDialog;
+ friend class ChromeShellDelegate;
+ friend class ExtensionInstallDialogView;
+ friend class FeedbackHandler;
+ friend class GtkThemeService;
+ friend class NetworkProfileBubble;
+ friend class PrintPreviewHandler;
+ friend class PrintPreviewUnitTestBase;
+ friend class QueryTabsFunction;
+ friend class SelectFileDialogExtension;
+ friend class StartupBrowserCreatorImpl;
+ friend class TaskManager;
+ friend class TestingAutomationProvider;
+ friend class WindowSizer;
+ friend class browser::BrowserActivityObserver;
+#if defined(OS_CHROMEOS)
+ friend class chromeos::ScreenLocker;
+#endif
+#if defined(OS_MACOSX)
+ friend Browser* browser::GetLastActiveBrowser();
+#endif
+#if defined(TOOLKIT_GTK)
+ friend class browser::ExtensionInstallDialog;
+#endif
+#if defined(USE_ASH)
+ friend content::WebContents* GetActiveWebContents();
+#endif
+ friend void browser::internal::NotifyNotDefaultBrowserCallback();
+ FRIEND_TEST_ALL_PREFIXES(PrintPreviewTabControllerBrowserTest,
+ NavigateFromInitiatorTab);
+ FRIEND_TEST_ALL_PREFIXES(PrintPreviewTabControllerBrowserTest,
+ ReloadInitiatorTab);
+ FRIEND_TEST_ALL_PREFIXES(PanelBrowserTest, ActivateDeactivateMultiple);
+ FRIEND_TEST_ALL_PREFIXES(DetachToBrowserTabDragControllerTest,
+ DetachToOwnWindow);
+ FRIEND_TEST_ALL_PREFIXES(DetachToBrowserTabDragControllerTest,
+ DeleteSourceDetached);
+ FRIEND_TEST_ALL_PREFIXES(TabDragControllerTest, DetachToOwnWindow);
+ // DO NOT ADD MORE FRIENDS TO THIS LIST.
+
+ // Returns the Browser object whose window was most recently active. If the
+ // most recently open Browser's window was closed, returns the first Browser
+ // in the list. If no Browsers exist, returns NULL.
+ //
+ // WARNING: this is NULL until a browser becomes active. If during startup
+ // a browser does not become active (perhaps the user launches Chrome, then
+ // clicks on another app before the first browser window appears) then this
+ // returns NULL.
+ // WARNING #2: this will always be NULL in unit tests run on the bots.
+ // THIS FUNCTION IS PRIVATE AND NOT TO BE USED AS A REPLACEMENT FOR RELEVANT
+ // CONTEXT.
+ static Browser* GetLastActive();
+
// Helper method to remove a browser instance from a list of browsers
static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list);
};
diff --git a/chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc b/chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc
index 4a1351e..865e3cc 100644
--- a/chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc
+++ b/chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc
@@ -48,6 +48,10 @@ void AddResourceIcon(const SkBitmap* icon, void* data) {
gtk_box_pack_start(GTK_BOX(container), icon_widget, FALSE, FALSE, 0);
}
+} // namespace
+
+namespace browser {
+
// Displays the dialog when constructed, deletes itself when dialog is
// dismissed. Success/failure is passed back through the ExtensionInstallUI::
// Delegate instance.
@@ -260,7 +264,7 @@ void ExtensionInstallDialog::OnStoreLinkClick(GtkWidget* sender) {
OnResponse(dialog_, GTK_RESPONSE_CLOSE);
}
-} // namespace
+} // namespace browser
void ShowExtensionInstallDialogImpl(
Profile* profile,
@@ -279,5 +283,6 @@ void ShowExtensionInstallDialogImpl(
return;
}
- new ExtensionInstallDialog(browser_window->window(), delegate, prompt);
+ new browser::ExtensionInstallDialog(browser_window->window(), delegate,
+ prompt);
}
diff --git a/chrome/browser/ui/startup/default_browser_prompt.cc b/chrome/browser/ui/startup/default_browser_prompt.cc
index f0c27d6..53ddb0c 100644
--- a/chrome/browser/ui/startup/default_browser_prompt.cc
+++ b/chrome/browser/ui/startup/default_browser_prompt.cc
@@ -131,34 +131,15 @@ bool DefaultBrowserInfoBarDelegate::Cancel() {
return true;
}
-void NotifyNotDefaultBrowserCallback() {
- Browser* browser = BrowserList::GetLastActive();
- if (!browser)
- return; // Reached during ui tests.
-
- // In ChromeBot tests, there might be a race. This line appears to get
- // called during shutdown and |tab| can be NULL.
- TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper();
- if (!tab)
- return;
-
- // Don't show the info-bar if there are already info-bars showing.
- InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
- if (infobar_helper->infobar_count() > 0)
- return;
-
- infobar_helper->AddInfoBar(
- new DefaultBrowserInfoBarDelegate(infobar_helper,
- tab->profile()->GetPrefs()));
-}
-
void CheckDefaultBrowserCallback() {
if (ShellIntegration::IsDefaultBrowser() ||
!ShellIntegration::CanSetAsDefaultBrowser()) {
return;
}
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&NotifyNotDefaultBrowserCallback));
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&browser::internal::NotifyNotDefaultBrowserCallback));
}
} // namespace
@@ -193,4 +174,28 @@ void ShowDefaultBrowserPrompt(Profile* profile) {
}
+namespace internal {
+
+void NotifyNotDefaultBrowserCallback() {
+ Browser* browser = BrowserList::GetLastActive();
+ if (!browser)
+ return; // Reached during ui tests.
+
+ // In ChromeBot tests, there might be a race. This line appears to get
+ // called during shutdown and |tab| can be NULL.
+ TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper();
+ if (!tab)
+ return;
+
+ // Don't show the info-bar if there are already info-bars showing.
+ InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
+ if (infobar_helper->infobar_count() > 0)
+ return;
+
+ infobar_helper->AddInfoBar(
+ new DefaultBrowserInfoBarDelegate(infobar_helper,
+ tab->profile()->GetPrefs()));
+}
+
+} // namespace internal
} // namespace browser
diff --git a/chrome/browser/ui/views/ash/user_gesture_handler.cc b/chrome/browser/ui/views/ash/user_gesture_handler.cc
index 1cdabab..696c769 100644
--- a/chrome/browser/ui/views/ash/user_gesture_handler.cc
+++ b/chrome/browser/ui/views/ash/user_gesture_handler.cc
@@ -11,8 +11,6 @@
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "content/public/browser/web_contents.h"
-namespace {
-
// Returns the currently-active WebContents belonging to the active browser, or
// NULL if there's no currently-active browser.
content::WebContents* GetActiveWebContents() {
@@ -28,8 +26,6 @@ content::WebContents* GetActiveWebContents() {
return wrapper->web_contents();
}
-} // namespace
-
UserGestureHandler::UserGestureHandler() {}
UserGestureHandler::~UserGestureHandler() {}