diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-09 22:20:25 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-09 22:20:25 +0000 |
commit | e0ddd75a4e0c8b13e9d1b0b231399e2eed3420fd (patch) | |
tree | 119be1305c71b8f276c3078b166f541730d8660c | |
parent | 8ebabc4e5f83fe66ff719f732b99971eef067e99 (diff) | |
download | chromium_src-e0ddd75a4e0c8b13e9d1b0b231399e2eed3420fd.zip chromium_src-e0ddd75a4e0c8b13e9d1b0b231399e2eed3420fd.tar.gz chromium_src-e0ddd75a4e0c8b13e9d1b0b231399e2eed3420fd.tar.bz2 |
Add a global error messages UI
This is change adds a new UI to show global error messages. Currenlty this only supports adding a wrench menu badge and wrench menu item. I'll add a buble view in later patches. See the bug for more info.
BUG=95146
TEST=
Review URL: http://codereview.chromium.org/7792088
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100516 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm | 9 | ||||
-rw-r--r-- | chrome/browser/ui/global_error.cc | 30 | ||||
-rw-r--r-- | chrome/browser/ui/global_error.h | 63 | ||||
-rw-r--r-- | chrome/browser/ui/global_error_service.cc | 46 | ||||
-rw-r--r-- | chrome/browser/ui/global_error_service.h | 53 | ||||
-rw-r--r-- | chrome/browser/ui/global_error_service_factory.cc | 35 | ||||
-rw-r--r-- | chrome/browser/ui/global_error_service_factory.h | 39 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/browser_toolbar_gtk.cc | 16 | ||||
-rw-r--r-- | chrome/browser/ui/toolbar/wrench_menu_model.cc | 39 | ||||
-rw-r--r-- | chrome/browser/ui/views/toolbar_view.cc | 10 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 6 |
11 files changed, 337 insertions, 9 deletions
diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm index 09d2511..1fa7e3d 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm @@ -41,6 +41,8 @@ #import "chrome/browser/ui/cocoa/toolbar/toolbar_view.h" #import "chrome/browser/ui/cocoa/view_id_util.h" #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" +#include "chrome/browser/ui/global_error_service.h" +#include "chrome/browser/ui/global_error_service_factory.h" #include "chrome/browser/ui/omnibox/omnibox_view.h" #include "chrome/browser/ui/toolbar/toolbar_model.h" #include "chrome/browser/ui/toolbar/wrench_menu_model.h" @@ -564,9 +566,12 @@ class NotificationBridge : public NotificationObserver { [[wrenchButton_ cell] setOverlayImageID:UpgradeDetector::GetInstance()->GetIconResourceID( UpgradeDetector::UPGRADE_ICON_TYPE_BADGE)]; - } else { - [[wrenchButton_ cell] setOverlayImageID:0]; + return; } + + int error_badge_id = GlobalErrorServiceFactory::GetForProfile( + browser_->profile())->GetFirstBadgeResourceID(); + [[wrenchButton_ cell] setOverlayImageID:error_badge_id]; } - (void)prefChanged:(std::string*)prefName { diff --git a/chrome/browser/ui/global_error.cc b/chrome/browser/ui/global_error.cc new file mode 100644 index 0000000..be06046 --- /dev/null +++ b/chrome/browser/ui/global_error.cc @@ -0,0 +1,30 @@ +// 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.h" + +#include "grit/theme_resources.h" +#include "grit/theme_resources_standard.h" + +GlobalError::GlobalError() { +} + +GlobalError::~GlobalError() { +} + +int GlobalError::GetBadgeResourceID() { + return IDR_UPDATE_BADGE4; +} + +int GlobalError::MenuItemIconResourceID() { + return IDR_UPDATE_MENU4; +} + +void GlobalError::ShowBubbleView(Browser* browser) { + // TODO(sail) Need to implement this. +} + +int GlobalError::GetBubbleViewIconResourceID() { + return IDR_INPUT_ALERT; +} diff --git a/chrome/browser/ui/global_error.h b/chrome/browser/ui/global_error.h new file mode 100644 index 0000000..03c7897 --- /dev/null +++ b/chrome/browser/ui/global_error.h @@ -0,0 +1,63 @@ +// 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. + +#ifndef CHROME_BROWSER_UI_GLOBAL_ERROR_H_ +#define CHROME_BROWSER_UI_GLOBAL_ERROR_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/string16.h" + +class Browser; + +// This object describes a single global error. +class GlobalError { + public: + GlobalError(); + virtual ~GlobalError(); + + // Returns true if a badge should be drawn on the wrench menu button. + virtual bool HasBadge() = 0; + // Returns the resource ID of the badge icon. + virtual int GetBadgeResourceID(); + + // Returns true if a menu item should be added to the wrench menu. + virtual bool HasMenuItem() = 0; + // Returns the command ID for the menu item. + virtual int MenuItemCommandID() = 0; + // Returns the label for the menu item. + virtual string16 MenuItemLabel() = 0; + // Returns the resource ID for the menu item icon. + virtual int MenuItemIconResourceID(); + // Called when the user clicks on the menu item. + virtual void ExecuteMenuItem(Browser* browser) = 0; + + // Returns true if a bubble view should be shown. + virtual bool HasBubbleView() = 0; + // Called to show the bubble view. + virtual void ShowBubbleView(Browser* browser); + // Returns the resource ID for bubble view icon. + virtual int GetBubbleViewIconResourceID(); + // Returns the title for the bubble view. + virtual string16 GetBubbleViewTitle() = 0; + // Returns the message for the bubble view. + virtual string16 GetBubbleViewMessage() = 0; + // Returns the accept button label for the bubble view. + virtual string16 GetBubbleViewAcceptButtonLabel() = 0; + // Returns the cancel button label for the bubble view. To hide the cancel + // button return an empty string. + virtual string16 GetBubbleViewCancelButtonLabel() = 0; + // Called when the bubble view is closed. + virtual void BubbleViewDidClose() = 0; + // Called when the user clicks on the accept button. + virtual void BubbleViewAcceptButtonPressed() = 0; + // Called when teh user clicks the cancel button. + virtual void BubbleViewCancelButtonPressed() = 0; + + + private: + 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 new file mode 100644 index 0000000..2f5166c --- /dev/null +++ b/chrome/browser/ui/global_error_service.cc @@ -0,0 +1,46 @@ +// 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 <algorithm> + +#include "base/stl_util.h" +#include "chrome/browser/ui/global_error.h" + +GlobalErrorService::GlobalErrorService() { +} + +GlobalErrorService::~GlobalErrorService() { + STLDeleteElements(&errors_); +} + +void GlobalErrorService::AddGlobalError(GlobalError* error) { + errors_.push_back(error); +} + +void GlobalErrorService::RemoveGlobalError(GlobalError* error) { + errors_.erase(std::find(errors_.begin(), errors_.end(), error)); +} + +GlobalError* GlobalErrorService::GetGlobalErrorByMenuItemCommandID( + int command_id) const { + for (std::vector<GlobalError*>::const_iterator + it = errors_.begin(); it != errors_.end(); ++it) { + GlobalError* error = *it; + if (error->HasMenuItem() && command_id == error->MenuItemCommandID()) + return error; + } + return NULL; +} + +int GlobalErrorService::GetFirstBadgeResourceID() { + for (std::vector<GlobalError*>::const_iterator + it = errors_.begin(); it != errors_.end(); ++it) { + GlobalError* error = *it; + if (error->HasBadge()) + return error->GetBadgeResourceID(); + } + return 0; +} diff --git a/chrome/browser/ui/global_error_service.h b/chrome/browser/ui/global_error_service.h new file mode 100644 index 0000000..20753f3 --- /dev/null +++ b/chrome/browser/ui/global_error_service.h @@ -0,0 +1,53 @@ +// 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. + +#ifndef CHROME_BROWSER_UI_GLOBAL_ERROR_SERVICE_H_ +#define CHROME_BROWSER_UI_GLOBAL_ERROR_SERVICE_H_ +#pragma once + +#include <vector> + +#include "base/basictypes.h" +#include "chrome/browser/profiles/profile_keyed_service.h" + +class GlobalError; + +// This service manages a list of errors that are meant to be shown globally. +// If an error applies to an entire profile and not just to a tab then the +// error should be shown using this service. Examples of global errors are: +// - the previous session crashed for a given profile. +// - a sync error occurred +class GlobalErrorService : public ProfileKeyedService { + public: + GlobalErrorService(); + virtual ~GlobalErrorService(); + + // Adds the given error to the list of global errors and displays it on + // browswer windows. If no browser windows are open then the error is + // displayed once a browser window is opened. This class takes ownership of + // the error. + void AddGlobalError(GlobalError* error); + + // Hides the given error and removes it from the list of global errors. Caller + // then takes ownership of the error and is responsible for deleting it. + void RemoveGlobalError(GlobalError* error); + + // Gets the error with the given command ID or NULL if no such error exists. + // This class maintains ownership of the returned error. + GlobalError* GetGlobalErrorByMenuItemCommandID(int command_id) const; + + // Gets the badge icon resource ID for the first error with a badge. + // Returns 0 if no such error exists. + int GetFirstBadgeResourceID(); + + // Gets all errors. + const std::vector<GlobalError*>& errors() { return errors_; } + + private: + std::vector<GlobalError*> errors_; + + DISALLOW_COPY_AND_ASSIGN(GlobalErrorService); +}; + +#endif // CHROME_BROWSER_UI_GLOBAL_ERROR_SERVICE_H_ diff --git a/chrome/browser/ui/global_error_service_factory.cc b/chrome/browser/ui/global_error_service_factory.cc new file mode 100644 index 0000000..a0148eb --- /dev/null +++ b/chrome/browser/ui/global_error_service_factory.cc @@ -0,0 +1,35 @@ +// 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_factory.h" + +#include "chrome/browser/profiles/profile_dependency_manager.h" +#include "chrome/browser/ui/global_error_service.h" + +// static +GlobalErrorService* GlobalErrorServiceFactory::GetForProfile(Profile* profile) { + return static_cast<GlobalErrorService*>( + GetInstance()->GetServiceForProfile(profile, true)); +} + +// static +GlobalErrorServiceFactory* GlobalErrorServiceFactory::GetInstance() { + return Singleton<GlobalErrorServiceFactory>::get(); +} + +GlobalErrorServiceFactory::GlobalErrorServiceFactory() + : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) { +} + +GlobalErrorServiceFactory::~GlobalErrorServiceFactory() { +} + +ProfileKeyedService* GlobalErrorServiceFactory::BuildServiceInstanceFor( + Profile* profile) const { + return new GlobalErrorService(); +} + +bool GlobalErrorServiceFactory::ServiceRedirectedInIncognito() { + return true; +} diff --git a/chrome/browser/ui/global_error_service_factory.h b/chrome/browser/ui/global_error_service_factory.h new file mode 100644 index 0000000..9e64721 --- /dev/null +++ b/chrome/browser/ui/global_error_service_factory.h @@ -0,0 +1,39 @@ +// 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. + +#ifndef CHROME_BROWSER_UI_GLOBAL_ERROR_SERVICE_FACTORY_H_ +#define CHROME_BROWSER_UI_GLOBAL_ERROR_SERVICE_FACTORY_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/memory/singleton.h" +#include "chrome/browser/profiles/profile_keyed_service_factory.h" + +class GlobalErrorService; + +// Singleton that owns all GlobalErrorService and associates them with +// Profiles. Listens for the Profile's destruction notification and cleans up +// the associated GlobalErrorService. +class GlobalErrorServiceFactory : public ProfileKeyedServiceFactory { + public: + static GlobalErrorService* GetForProfile(Profile* profile); + + static GlobalErrorServiceFactory* GetInstance(); + + private: + friend struct DefaultSingletonTraits<GlobalErrorServiceFactory>; + + GlobalErrorServiceFactory(); + virtual ~GlobalErrorServiceFactory(); + + // ProfileKeyedServiceFactory: + virtual ProfileKeyedService* BuildServiceInstanceFor( + Profile* profile) const OVERRIDE; + virtual bool ServiceRedirectedInIncognito() OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(GlobalErrorServiceFactory); +}; + +#endif // CHROME_BROWSER_UI_GLOBAL_ERROR_SERVICE_FACTORY_H_ diff --git a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc index 09e6285..8e64303 100644 --- a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc @@ -20,6 +20,8 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/theme_service.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/global_error_service.h" +#include "chrome/browser/ui/global_error_service_factory.h" #include "chrome/browser/ui/gtk/accelerators_gtk.h" #include "chrome/browser/ui/gtk/back_forward_button_gtk.h" #include "chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h" @@ -619,16 +621,20 @@ bool BrowserToolbarGtk::ShouldOnlyShowLocation() const { gboolean BrowserToolbarGtk::OnWrenchMenuButtonExpose(GtkWidget* sender, GdkEventExpose* expose) { - const SkBitmap* badge = NULL; + int resource_id = 0; if (UpgradeDetector::GetInstance()->notify_upgrade()) { - badge = theme_service_->GetBitmapNamed( - UpgradeDetector::GetInstance()->GetIconResourceID( - UpgradeDetector::UPGRADE_ICON_TYPE_BADGE)); + resource_id = UpgradeDetector::GetInstance()->GetIconResourceID( + UpgradeDetector::UPGRADE_ICON_TYPE_BADGE); } else { - return FALSE; + resource_id = GlobalErrorServiceFactory::GetForProfile( + browser_->profile())->GetFirstBadgeResourceID(); } + if (!resource_id) + return FALSE; + // Draw the chrome app menu icon onto the canvas. + const SkBitmap* badge = theme_service_->GetBitmapNamed(resource_id); gfx::CanvasSkiaPaint canvas(expose, false); int x_offset = base::i18n::IsRTL() ? 0 : sender->allocation.width - badge->width(); diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc index 7b26e51..0489a57 100644 --- a/chrome/browser/ui/toolbar/wrench_menu_model.cc +++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc @@ -23,6 +23,9 @@ #include "chrome/browser/task_manager/task_manager.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_window.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/toolbar/encoding_menu_controller.h" #include "chrome/browser/upgrade_detector.h" #include "chrome/common/chrome_paths.h" @@ -39,6 +42,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/models/button_menu_item_model.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/image/image.h" #if defined(TOOLKIT_USES_GTK) #include <gtk/gtk.h> @@ -319,6 +323,13 @@ bool WrenchMenuModel::GetIconForCommandId(int command_id, } void WrenchMenuModel::ExecuteCommand(int command_id) { + GlobalError* error = GlobalErrorServiceFactory::GetForProfile( + browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); + if (error) { + error->ExecuteMenuItem(browser_); + return; + } + browser_->ExecuteCommand(command_id); } @@ -333,6 +344,11 @@ bool WrenchMenuModel::IsCommandIdChecked(int command_id) const { } bool WrenchMenuModel::IsCommandIdEnabled(int command_id) const { + GlobalError* error = GlobalErrorServiceFactory::GetForProfile( + browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); + if (error) + return true; + return browser_->command_updater()->IsCommandEnabled(command_id); } @@ -408,6 +424,8 @@ WrenchMenuModel::WrenchMenuModel() #if !defined(OS_CHROMEOS) void WrenchMenuModel::Build() { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW); AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW); @@ -498,13 +516,32 @@ void WrenchMenuModel::Build() { IDS_VIEW_INCOMPATIBILITIES)); #if defined(OS_WIN) - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); SetIcon(GetIndexOfCommandId(IDC_VIEW_INCOMPATIBILITIES), *rb.GetBitmapNamed(IDR_CONFLICT_MENU)); #endif AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); + // TODO(sail): Currently we only build the wrench menu once per browser + // window. This means that if a new error is added after the menu is built + // it won't show in the existing wrench menu. To fix this we need to some + // how update the menu if new errors are added. + const std::vector<GlobalError*>& errors = + GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors(); + for (std::vector<GlobalError*>::const_iterator + it = errors.begin(); it != errors.end(); ++it) { + GlobalError* error = *it; + if (error->HasMenuItem()) { + AddItem(error->MenuItemCommandID(), error->MenuItemLabel()); + int icon_id = error->MenuItemIconResourceID(); + if (icon_id) { + gfx::Image& image = rb.GetImageNamed(icon_id); + SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()), + *image.ToSkBitmap()); + } + } + } + if (browser_defaults::kShowExitMenuItem) { AddSeparator(); AddItemWithStringId(IDC_EXIT, IDS_EXIT); diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc index c072ebe..2d62750 100644 --- a/chrome/browser/ui/views/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar_view.cc @@ -17,6 +17,8 @@ #include "chrome/browser/ui/views/event_utils.h" #include "chrome/browser/ui/views/wrench_menu.h" #include "chrome/browser/upgrade_detector.h" +#include "chrome/browser/ui/global_error_service.h" +#include "chrome/browser/ui/global_error_service_factory.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" #include "content/browser/accessibility/browser_accessibility_state.h" @@ -266,7 +268,11 @@ SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) { incompatibility_badge_showing = false; #endif - bool add_badge = IsUpgradeRecommended() || ShouldShowIncompatibilityWarning(); + int error_badge_id = GlobalErrorServiceFactory::GetForProfile( + browser_->profile())->GetFirstBadgeResourceID(); + + bool add_badge = IsUpgradeRecommended() || + ShouldShowIncompatibilityWarning() || error_badge_id; if (!add_badge) return icon; @@ -291,6 +297,8 @@ SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) { #else NOTREACHED(); #endif + } else if (error_badge_id) { + badge = *tp->GetBitmapNamed(error_badge_id); } else { NOTREACHED(); } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 1bd0b95..7740237 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2771,6 +2771,12 @@ 'browser/ui/find_bar/find_tab_helper.h', 'browser/ui/fullscreen_exit_bubble.cc', 'browser/ui/fullscreen_exit_bubble.h', + 'browser/ui/global_error.cc', + 'browser/ui/global_error.h', + 'browser/ui/global_error_service.cc', + 'browser/ui/global_error_service.h', + 'browser/ui/global_error_service_factory.cc', + 'browser/ui/global_error_service_factory.h', 'browser/ui/gtk/about_chrome_dialog.cc', 'browser/ui/gtk/about_chrome_dialog.h', 'browser/ui/gtk/accelerators_gtk.cc', |