1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_H_ 6 #define CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_H_ 7 8 #include <vector> 9 10 #include "base/macros.h" 11 #include "base/memory/weak_ptr.h" 12 #include "base/strings/string16.h" 13 #include "ui/base/models/image_model.h" 14 15 class Browser; 16 class GlobalErrorBubbleViewBase; 17 18 // This object describes a single global error. 19 class GlobalError { 20 public: 21 enum Severity { 22 SEVERITY_LOW, 23 SEVERITY_MEDIUM, 24 SEVERITY_HIGH, 25 }; 26 27 GlobalError(); 28 virtual ~GlobalError(); 29 30 // Returns the error's severity level. If there are multiple errors, 31 // the error with the highest severity will display in the menu. If not 32 // overridden, this is based on the badge resource ID. 33 virtual Severity GetSeverity(); 34 35 // Returns true if a menu item should be added to the app menu. 36 virtual bool HasMenuItem() = 0; 37 // Returns the command ID for the menu item. 38 virtual int MenuItemCommandID() = 0; 39 // Returns the label for the menu item. 40 virtual base::string16 MenuItemLabel() = 0; 41 // Returns the menu item icon. 42 virtual ui::ImageModel MenuItemIcon(); 43 // Called when the user clicks on the menu item. 44 virtual void ExecuteMenuItem(Browser* browser) = 0; 45 46 // Returns true if a bubble view should be shown. 47 virtual bool HasBubbleView() = 0; 48 // Returns true if the bubble view has been shown. 49 virtual bool HasShownBubbleView() = 0; 50 // Called to show the bubble view. 51 virtual void ShowBubbleView(Browser* browser) = 0; 52 // Returns the bubble view. 53 virtual GlobalErrorBubbleViewBase* GetBubbleView() = 0; 54 }; 55 56 // This object describes a single global error that already comes with support 57 // for showing a standard Bubble UI. Derived classes just need to supply the 58 // content to be displayed in the bubble. 59 class GlobalErrorWithStandardBubble 60 : public GlobalError, 61 public base::SupportsWeakPtr<GlobalErrorWithStandardBubble> { 62 public: 63 GlobalErrorWithStandardBubble(); 64 ~GlobalErrorWithStandardBubble() override; 65 66 // Override these methods to customize the contents of the error bubble: 67 virtual base::string16 GetBubbleViewTitle() = 0; 68 virtual std::vector<base::string16> GetBubbleViewMessages() = 0; 69 virtual base::string16 GetBubbleViewAcceptButtonLabel() = 0; 70 virtual bool ShouldShowCloseButton() const; 71 virtual bool ShouldAddElevationIconToAcceptButton(); 72 virtual base::string16 GetBubbleViewCancelButtonLabel() = 0; 73 virtual int GetDefaultDialogButton() const; 74 virtual bool ShouldCloseOnDeactivate() const; 75 virtual base::string16 GetBubbleViewDetailsButtonLabel(); 76 77 // Override these methods to be notified when events happen on the bubble: 78 virtual void OnBubbleViewDidClose(Browser* browser) = 0; 79 virtual void BubbleViewAcceptButtonPressed(Browser* browser) = 0; 80 virtual void BubbleViewCancelButtonPressed(Browser* browser) = 0; 81 virtual void BubbleViewDetailsButtonPressed(Browser* browser); 82 83 // GlobalError overrides: 84 bool HasBubbleView() override; 85 bool HasShownBubbleView() override; 86 void ShowBubbleView(Browser* browser) override; 87 GlobalErrorBubbleViewBase* GetBubbleView() override; 88 89 // This method is used by the View to notify this object that the bubble has 90 // closed. Do not call it. It is only virtual for unit tests; do not override 91 // it either. 92 virtual void BubbleViewDidClose(Browser* browser); 93 94 private: 95 bool has_shown_bubble_view_ = false; 96 GlobalErrorBubbleViewBase* bubble_view_ = nullptr; 97 98 DISALLOW_COPY_AND_ASSIGN(GlobalErrorWithStandardBubble); 99 }; 100 101 #endif // CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_H_ 102