- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / global_error / global_error.h
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/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/strings/string16.h"
13
14 class Browser;
15 class GlobalErrorBubbleViewBase;
16
17 namespace gfx {
18 class Image;
19 }
20
21 // This object describes a single global error.
22 class GlobalError {
23  public:
24   enum Severity {
25     SEVERITY_LOW,
26     SEVERITY_MEDIUM,
27     SEVERITY_HIGH,
28   };
29
30   GlobalError();
31   virtual ~GlobalError();
32
33   // Returns the error's severity level. If there are multiple errors,
34   // the error with the highest severity will display in the menu. If not
35   // overridden, this is based on the badge resource ID.
36   virtual Severity GetSeverity();
37
38   // Returns true if a menu item should be added to the wrench menu.
39   virtual bool HasMenuItem() = 0;
40   // Returns the command ID for the menu item.
41   virtual int MenuItemCommandID() = 0;
42   // Returns the label for the menu item.
43   virtual string16 MenuItemLabel() = 0;
44   // Returns the resource ID for the menu item icon.
45   int MenuItemIconResourceID();
46   // Called when the user clicks on the menu item.
47   virtual void ExecuteMenuItem(Browser* browser) = 0;
48
49   // Returns true if a bubble view should be shown.
50   virtual bool HasBubbleView() = 0;
51   // Returns true if the bubble view has been shown.
52   virtual bool HasShownBubbleView() = 0;
53   // Called to show the bubble view.
54   virtual void ShowBubbleView(Browser* browser) = 0;
55   // Returns the bubble view.
56   virtual GlobalErrorBubbleViewBase* GetBubbleView() = 0;
57 };
58
59 // This object describes a single global error that already comes with support
60 // for showing a standard Bubble UI. Derived classes just need to supply the
61 // content to be displayed in the bubble.
62 class GlobalErrorWithStandardBubble
63     : public GlobalError,
64       public base::SupportsWeakPtr<GlobalErrorWithStandardBubble> {
65  public:
66   GlobalErrorWithStandardBubble();
67   virtual ~GlobalErrorWithStandardBubble();
68
69   // Returns an icon to use for the bubble view.
70   virtual gfx::Image GetBubbleViewIcon();
71   // Returns the title for the bubble view.
72   virtual string16 GetBubbleViewTitle() = 0;
73   // Returns the messages for the bubble view, one per line. Multiple messages
74   // are only supported on Views.
75   // TODO(yoz): Add multi-line support for GTK and Cocoa.
76   virtual std::vector<string16> GetBubbleViewMessages() = 0;
77   // Returns the accept button label for the bubble view.
78   virtual string16 GetBubbleViewAcceptButtonLabel() = 0;
79   // Returns the cancel button label for the bubble view. To hide the cancel
80   // button return an empty string.
81   virtual string16 GetBubbleViewCancelButtonLabel() = 0;
82   // Called when the bubble view is closed. |browser| is the Browser that the
83   // bubble view was shown on.
84   void BubbleViewDidClose(Browser* browser);
85   // Notifies subclasses that the bubble view is closed. |browser| is the
86   // Browser that the bubble view was shown on.
87   virtual void OnBubbleViewDidClose(Browser* browser) = 0;
88   // Called when the user clicks on the accept button. |browser| is the
89   // Browser that the bubble view was shown on.
90   virtual void BubbleViewAcceptButtonPressed(Browser* browser) = 0;
91   // Called when the user clicks the cancel button. |browser| is the
92   // Browser that the bubble view was shown on.
93   virtual void BubbleViewCancelButtonPressed(Browser* browser) = 0;
94
95   // GlobalError overrides:
96   virtual bool HasBubbleView() OVERRIDE;
97   virtual bool HasShownBubbleView() OVERRIDE;
98   virtual void ShowBubbleView(Browser* browser) OVERRIDE;
99   virtual GlobalErrorBubbleViewBase* GetBubbleView() OVERRIDE;
100
101  private:
102   bool has_shown_bubble_view_;
103   GlobalErrorBubbleViewBase* bubble_view_;
104
105   DISALLOW_COPY_AND_ASSIGN(GlobalErrorWithStandardBubble);
106 };
107
108 #endif  // CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_H_