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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_
14 // TODO(battre) Remove the Extension prefix.
20 namespace extensions
{
24 // This class is used by the ExtensionWarningService to represent warnings if
25 // extensions misbehave. Note that the ExtensionWarningService deals only with
26 // specific warnings that should trigger a badge on the Chrome menu button.
27 class ExtensionWarning
{
30 // Don't use this, it is only intended for the default constructor and
31 // does not have localized warning messages for the UI.
33 // An extension caused excessive network delays.
35 // This extension failed to modify a network request because the
36 // modification conflicted with a modification of another extension.
38 // This extension failed to redirect a network request because another
39 // extension with higher precedence redirected to a different target.
41 // The extension repeatedly flushed WebKit's in-memory cache, which slows
42 // down the overall performance.
43 kRepeatedCacheFlushes
,
44 // The extension failed to determine the filename of a download because
45 // another extension with higher precedence determined a different filename.
46 kDownloadFilenameConflict
,
50 // We allow copy&assign for passing containers of ExtensionWarnings between
52 ExtensionWarning(const ExtensionWarning
& other
);
54 ExtensionWarning
& operator=(const ExtensionWarning
& other
);
56 // Factory methods for various warning types.
57 static ExtensionWarning
CreateNetworkDelayWarning(
58 const std::string
& extension_id
);
59 static ExtensionWarning
CreateNetworkConflictWarning(
60 const std::string
& extension_id
);
61 static ExtensionWarning
CreateRedirectConflictWarning(
62 const std::string
& extension_id
,
63 const std::string
& winning_extension_id
,
64 const GURL
& attempted_redirect_url
,
65 const GURL
& winning_redirect_url
);
66 static ExtensionWarning
CreateRequestHeaderConflictWarning(
67 const std::string
& extension_id
,
68 const std::string
& winning_extension_id
,
69 const std::string
& conflicting_header
);
70 static ExtensionWarning
CreateResponseHeaderConflictWarning(
71 const std::string
& extension_id
,
72 const std::string
& winning_extension_id
,
73 const std::string
& conflicting_header
);
74 static ExtensionWarning
CreateCredentialsConflictWarning(
75 const std::string
& extension_id
,
76 const std::string
& winning_extension_id
);
77 static ExtensionWarning
CreateRepeatedCacheFlushesWarning(
78 const std::string
& extension_id
);
79 static ExtensionWarning
CreateDownloadFilenameConflictWarning(
80 const std::string
& losing_extension_id
,
81 const std::string
& winning_extension_id
,
82 const base::FilePath
& losing_filename
,
83 const base::FilePath
& winning_filename
);
85 // Returns the specific warning type.
86 WarningType
warning_type() const { return type_
; }
88 // Returns the id of the extension for which this warning is valid.
89 const std::string
& extension_id() const { return extension_id_
; }
91 // Returns a localized warning message.
92 std::string
GetLocalizedMessage(const ExtensionSet
* extensions
) const;
95 // Constructs a warning of type |type| for extension |extension_id|. This
96 // could indicate for example the fact that an extension conflicted with
97 // others. The |message_id| refers to an IDS_ string ID. The
98 // |message_parameters| are filled into the message template.
99 ExtensionWarning(WarningType type
,
100 const std::string
& extension_id
,
102 const std::vector
<std::string
>& message_parameters
);
105 std::string extension_id_
;
106 // IDS_* resource ID.
108 // Parameters to be filled into the string identified by |message_id_|.
109 std::vector
<std::string
> message_parameters_
;
112 // Compare ExtensionWarnings based on the tuple of (extension_id, type).
113 // The message associated with ExtensionWarnings is purely informational
114 // and does not contribute to distinguishing extensions.
115 bool operator<(const ExtensionWarning
& a
, const ExtensionWarning
& b
);
117 typedef std::set
<ExtensionWarning
> ExtensionWarningSet
;
119 } // namespace extensions
121 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_