summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
authorsail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-19 22:22:09 +0000
committersail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-19 22:22:09 +0000
commit2f516c79333708dd6759f3e3244eba20c46cfb03 (patch)
treeec027d57237dc12b98c568e44e4673df0ff73d15 /chrome/browser/ui
parent2158b2e2a18513d39e56ebab40beeaa4a6c1d667 (diff)
downloadchromium_src-2f516c79333708dd6759f3e3244eba20c46cfb03.zip
chromium_src-2f516c79333708dd6759f3e3244eba20c46cfb03.tar.gz
chromium_src-2f516c79333708dd6759f3e3244eba20c46cfb03.tar.bz2
Show global error bubble view when creating new browser window
BUG=95146 TEST= Review URL: http://codereview.chromium.org/7892022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101843 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/browser.cc77
-rw-r--r--chrome/browser/ui/browser.h6
-rw-r--r--chrome/browser/ui/browser_window.h1
-rw-r--r--chrome/browser/ui/cocoa/browser_window_cocoa.mm2
-rw-r--r--chrome/browser/ui/global_error.cc7
-rw-r--r--chrome/browser/ui/global_error.h8
-rw-r--r--chrome/browser/ui/global_error_service.cc12
-rw-r--r--chrome/browser/ui/global_error_service.h6
-rw-r--r--chrome/browser/ui/global_error_service_browsertest.cc88
-rw-r--r--chrome/browser/ui/gtk/browser_window_gtk.cc2
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc2
11 files changed, 179 insertions, 32 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index a234961..ac6cfde 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -95,6 +95,9 @@
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/find_bar/find_tab_helper.h"
+#include "chrome/browser/ui/global_error.h"
+#include "chrome/browser/ui/global_error_service.h"
+#include "chrome/browser/ui/global_error_service_factory.h"
#include "chrome/browser/ui/intents/web_intent_picker_controller.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/panels/panel.h"
@@ -277,7 +280,8 @@ Browser::Browser(Type type, Profile* profile)
new BrowserSyncedWindowDelegate(this))),
bookmark_bar_state_(BookmarkBar::HIDDEN),
fullscreened_tab_(NULL),
- tab_caused_fullscreen_(false) {
+ tab_caused_fullscreen_(false),
+ window_has_shown_(false) {
registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED,
NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
@@ -511,33 +515,8 @@ void Browser::InitBrowserWindow() {
UseCompactNavigationBarChanged();
}
- // Show the First Run information bubble if we've been told to.
PrefService* local_state = g_browser_process->local_state();
- if (!local_state)
- return;
- if (local_state->FindPreference(prefs::kShouldShowFirstRunBubble) &&
- local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) {
- FirstRun::BubbleType bubble_type = FirstRun::LARGE_BUBBLE;
- if (local_state->
- FindPreference(prefs::kShouldUseOEMFirstRunBubble) &&
- local_state->GetBoolean(prefs::kShouldUseOEMFirstRunBubble)) {
- bubble_type = FirstRun::OEM_BUBBLE;
- } else if (local_state->
- FindPreference(prefs::kShouldUseMinimalFirstRunBubble) &&
- local_state->GetBoolean(prefs::kShouldUseMinimalFirstRunBubble)) {
- bubble_type = FirstRun::MINIMAL_BUBBLE;
- }
- // Reset the preference so we don't show the bubble for subsequent windows.
- local_state->ClearPref(prefs::kShouldShowFirstRunBubble);
- window_->GetLocationBar()->ShowFirstRunBubble(bubble_type);
-
- // Suppress ntp4 bubble if first run bubble will be shown on the same page.
- PrefService* prefs = profile_->GetPrefs();
- if (prefs->GetBoolean(prefs::kHomePageIsNewTabPage)) {
- prefs->SetBoolean(prefs::kNTP4SuppressIntroOnce, true);
- }
- }
- if (local_state->FindPreference(
+ if (local_state && local_state->FindPreference(
prefs::kAutofillPersonalDataManagerFirstRun) &&
local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) {
// Notify PDM that this is a first run.
@@ -5259,3 +5238,47 @@ void Browser::ShowSyncSetup() {
void Browser::ToggleSpeechInput() {
GetSelectedTabContentsWrapper()->render_view_host()->ToggleSpeechInput();
}
+
+void Browser::OnWindowDidShow() {
+ if (window_has_shown_)
+ return;
+ window_has_shown_ = true;
+
+ bool did_show_bubble = false;
+
+ // Show the First Run information bubble if we've been told to.
+ PrefService* local_state = g_browser_process->local_state();
+ if (local_state &&
+ local_state->FindPreference(prefs::kShouldShowFirstRunBubble) &&
+ local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) {
+ FirstRun::BubbleType bubble_type = FirstRun::LARGE_BUBBLE;
+ if (local_state->
+ FindPreference(prefs::kShouldUseOEMFirstRunBubble) &&
+ local_state->GetBoolean(prefs::kShouldUseOEMFirstRunBubble)) {
+ bubble_type = FirstRun::OEM_BUBBLE;
+ } else if (local_state->
+ FindPreference(prefs::kShouldUseMinimalFirstRunBubble) &&
+ local_state->GetBoolean(prefs::kShouldUseMinimalFirstRunBubble)) {
+ bubble_type = FirstRun::MINIMAL_BUBBLE;
+ }
+ // Reset the preference so we don't show the bubble for subsequent windows.
+ local_state->ClearPref(prefs::kShouldShowFirstRunBubble);
+ window_->GetLocationBar()->ShowFirstRunBubble(bubble_type);
+ did_show_bubble = true;
+ } else if (is_type_tabbed()) {
+ GlobalErrorService* service =
+ GlobalErrorServiceFactory::GetForProfile(profile());
+ GlobalError* error = service->GetFirstGlobalErrorWithBubbleView();
+ if (error) {
+ error->ShowBubbleView(this);
+ did_show_bubble = true;
+ }
+ }
+
+ // Suppress ntp4 bubble if another bubble will be shown on the same page.
+ if (did_show_bubble) {
+ PrefService* prefs = profile_->GetPrefs();
+ if (prefs->GetBoolean(prefs::kHomePageIsNewTabPage))
+ prefs->SetBoolean(prefs::kNTP4SuppressIntroOnce, true);
+ }
+}
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index 171b272..f4d4118 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -835,6 +835,9 @@ class Browser : public TabHandlerDelegate,
// webkitRequestFullScreen.
bool is_fullscreen_for_tab() const { return fullscreened_tab_ != NULL; }
+ // Called each time the browser window is shown.
+ void OnWindowDidShow();
+
protected:
// Wrapper for the factory method in BrowserWindow. This allows subclasses to
// set their own window.
@@ -1425,6 +1428,9 @@ class Browser : public TabHandlerDelegate,
// True if the current tab entered fullscreen mode via webkitRequestFullScreen
bool tab_caused_fullscreen_;
+ // True if the browser window has been shown at least once.
+ bool window_has_shown_;
+
DISALLOW_COPY_AND_ASSIGN(Browser);
};
diff --git a/chrome/browser/ui/browser_window.h b/chrome/browser/ui/browser_window.h
index 8da015c..d8a4280 100644
--- a/chrome/browser/ui/browser_window.h
+++ b/chrome/browser/ui/browser_window.h
@@ -48,6 +48,7 @@ class BrowserWindow {
virtual ~BrowserWindow() {}
// Show the window, or activates it if it's already visible.
+ // Browser::OnWindowDidShow should be called after showing the window.
virtual void Show() = 0;
// Show the window, but do not activate it. Does nothing if window
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
index cd928a7..8fc2d22 100644
--- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
@@ -118,6 +118,8 @@ void BrowserWindowCocoa::Show() {
// Restore window animation behavior.
if (did_save_animation_behavior)
[window() setAnimationBehavior:saved_animation_behavior];
+
+ browser_->OnWindowDidShow();
}
void BrowserWindowCocoa::ShowInactive() {
diff --git a/chrome/browser/ui/global_error.cc b/chrome/browser/ui/global_error.cc
index bd32df4..f2cf17c 100644
--- a/chrome/browser/ui/global_error.cc
+++ b/chrome/browser/ui/global_error.cc
@@ -8,7 +8,7 @@
#include "grit/theme_resources.h"
#include "grit/theme_resources_standard.h"
-GlobalError::GlobalError() {
+GlobalError::GlobalError() : has_shown_bubble_view_(false) {
}
GlobalError::~GlobalError() {
@@ -22,7 +22,12 @@ int GlobalError::MenuItemIconResourceID() {
return IDR_UPDATE_MENU4;
}
+bool GlobalError::HasShownBubbleView() {
+ return has_shown_bubble_view_;
+}
+
void GlobalError::ShowBubbleView(Browser* browser) {
+ has_shown_bubble_view_ = true;
ShowBubbleView(browser, this);
}
diff --git a/chrome/browser/ui/global_error.h b/chrome/browser/ui/global_error.h
index 38a9c91..ffac75e 100644
--- a/chrome/browser/ui/global_error.h
+++ b/chrome/browser/ui/global_error.h
@@ -35,6 +35,8 @@ class GlobalError {
// Returns true if a bubble view should be shown.
virtual bool HasBubbleView() = 0;
+ // Returns true if the bubble view has been shown.
+ virtual bool HasShownBubbleView();
// Called to show the bubble view.
virtual void ShowBubbleView(Browser* browser);
// Returns the resource ID for bubble view icon.
@@ -57,9 +59,11 @@ class GlobalError {
private:
- DISALLOW_COPY_AND_ASSIGN(GlobalError);
-
static void ShowBubbleView(Browser* browser, GlobalError* error);
+
+ bool has_shown_bubble_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(GlobalError);
};
#endif // CHROME_BROWSER_UI_GLOBAL_ERROR_H_
diff --git a/chrome/browser/ui/global_error_service.cc b/chrome/browser/ui/global_error_service.cc
index 2f5166c..566276b 100644
--- a/chrome/browser/ui/global_error_service.cc
+++ b/chrome/browser/ui/global_error_service.cc
@@ -35,7 +35,7 @@ GlobalError* GlobalErrorService::GetGlobalErrorByMenuItemCommandID(
return NULL;
}
-int GlobalErrorService::GetFirstBadgeResourceID() {
+int GlobalErrorService::GetFirstBadgeResourceID() const {
for (std::vector<GlobalError*>::const_iterator
it = errors_.begin(); it != errors_.end(); ++it) {
GlobalError* error = *it;
@@ -44,3 +44,13 @@ int GlobalErrorService::GetFirstBadgeResourceID() {
}
return 0;
}
+
+GlobalError* GlobalErrorService::GetFirstGlobalErrorWithBubbleView() const {
+ for (std::vector<GlobalError*>::const_iterator
+ it = errors_.begin(); it != errors_.end(); ++it) {
+ GlobalError* error = *it;
+ if (error->HasBubbleView() && !error->HasShownBubbleView())
+ return error;
+ }
+ return NULL;
+}
diff --git a/chrome/browser/ui/global_error_service.h b/chrome/browser/ui/global_error_service.h
index 20753f3..500cf2f 100644
--- a/chrome/browser/ui/global_error_service.h
+++ b/chrome/browser/ui/global_error_service.h
@@ -39,7 +39,11 @@ class GlobalErrorService : public ProfileKeyedService {
// Gets the badge icon resource ID for the first error with a badge.
// Returns 0 if no such error exists.
- int GetFirstBadgeResourceID();
+ int GetFirstBadgeResourceID() const;
+
+ // Gets the first error that has a bubble view which hasn't been shown yet.
+ // Returns NULL if no such error exists.
+ GlobalError* GetFirstGlobalErrorWithBubbleView() const;
// Gets all errors.
const std::vector<GlobalError*>& errors() { return errors_; }
diff --git a/chrome/browser/ui/global_error_service_browsertest.cc b/chrome/browser/ui/global_error_service_browsertest.cc
new file mode 100644
index 0000000..ae97f0c
--- /dev/null
+++ b/chrome/browser/ui/global_error_service_browsertest.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/global_error_service.h"
+
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/global_error.h"
+#include "chrome/browser/ui/global_error_service_factory.h"
+#include "chrome/test/base/in_process_browser_test.h"
+
+namespace {
+
+// An error that has a bubble view.
+class BubbleViewError : public GlobalError {
+ public:
+ BubbleViewError() : bubble_view_close_count_(0) { }
+
+ int bubble_view_close_count() { return bubble_view_close_count_; }
+
+ bool HasBadge() OVERRIDE { return false; }
+ virtual int GetBadgeResourceID() OVERRIDE {
+ ADD_FAILURE();
+ return 0;
+ }
+
+ virtual bool HasMenuItem() OVERRIDE { return false; }
+ virtual int MenuItemCommandID() OVERRIDE {
+ ADD_FAILURE();
+ return 0;
+ }
+ virtual string16 MenuItemLabel() OVERRIDE {
+ ADD_FAILURE();
+ return string16();
+ }
+ virtual int MenuItemIconResourceID() OVERRIDE {
+ ADD_FAILURE();
+ return 0;
+ }
+ virtual void ExecuteMenuItem(Browser* browser) OVERRIDE { ADD_FAILURE(); }
+
+ virtual bool HasBubbleView() OVERRIDE { return true; }
+ virtual string16 GetBubbleViewTitle() OVERRIDE {
+ return string16();
+ }
+ virtual string16 GetBubbleViewMessage() OVERRIDE {
+ return string16();
+ }
+ virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE {
+ return string16();
+ }
+ virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE {
+ return string16();
+ }
+ virtual void BubbleViewDidClose() OVERRIDE {}
+ virtual void BubbleViewAcceptButtonPressed() OVERRIDE {}
+ virtual void BubbleViewCancelButtonPressed() OVERRIDE {}
+
+ private:
+ int bubble_view_close_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(BubbleViewError);
+};
+
+} // namespace
+
+class GlobalErrorServiceBrowserTest : public InProcessBrowserTest {
+};
+
+// Test that showing a error with a bubble view works.
+IN_PROC_BROWSER_TEST_F(GlobalErrorServiceBrowserTest, ShowBubbleView) {
+ // This will be deleted by the GlobalErrorService.
+ BubbleViewError* error = new BubbleViewError;
+
+ GlobalErrorService* service =
+ GlobalErrorServiceFactory::GetForProfile(browser()->profile());
+ service->AddGlobalError(error);
+
+ EXPECT_EQ(error, service->GetFirstGlobalErrorWithBubbleView());
+ EXPECT_FALSE(error->HasShownBubbleView());
+ EXPECT_EQ(0, error->bubble_view_close_count());
+
+ // Creating a second browser window should show the bubble view.
+ CreateBrowser(browser()->profile());
+ EXPECT_EQ(NULL, service->GetFirstGlobalErrorWithBubbleView());
+ EXPECT_TRUE(error->HasShownBubbleView());
+ EXPECT_EQ(0, error->bubble_view_close_count());
+}
diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc
index a670760..7a812c6 100644
--- a/chrome/browser/ui/gtk/browser_window_gtk.cc
+++ b/chrome/browser/ui/gtk/browser_window_gtk.cc
@@ -657,6 +657,8 @@ void BrowserWindowGtk::Show() {
// area, then undo it so that the render view can later adjust its own
// size.
gtk_widget_set_size_request(contents_container_->widget(), -1, -1);
+
+ browser()->OnWindowDidShow();
}
void BrowserWindowGtk::ShowInactive() {
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index 6c99897..a0580b3 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -645,6 +645,8 @@ void BrowserView::Show() {
RestoreFocus();
frame_->Show();
+
+ browser()->OnWindowDidShow();
}
void BrowserView::ShowInactive() {