blob: 015c98aebced566c6749359d762f2c969460c2a0 [file] [log] [blame]
[email protected]b20729fe2012-01-25 21:42:521// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7c1490da2011-10-11 18:53:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
hanxic7e55202014-08-28 14:13:215#ifndef EXTENSIONS_BROWSER_WARNING_SET_H_
6#define EXTENSIONS_BROWSER_WARNING_SET_H_
[email protected]7c1490da2011-10-11 18:53:257
8#include <set>
9#include <string>
[email protected]b4d3771d2012-11-14 14:44:1010#include <vector>
[email protected]7c1490da2011-10-11 18:53:2511
[email protected]a6483d22013-07-03 22:11:0012#include "url/gurl.h"
[email protected]7c1490da2011-10-11 18:53:2513
[email protected]dc6cb142013-08-10 18:14:5214namespace base {
15class FilePath;
16}
17
[email protected]b4d3771d2012-11-14 14:44:1018namespace extensions {
19
[email protected]289c44b2013-12-17 03:26:5720class ExtensionSet;
21
hanxic7e55202014-08-28 14:13:2122// This class is used by the WarningService to represent warnings if extensions
23// misbehave. Note that the WarningService deals only with specific warnings
24// that should trigger a badge on the Chrome menu button.
25class Warning {
[email protected]7c1490da2011-10-11 18:53:2526 public:
27 enum WarningType {
28 // Don't use this, it is only intended for the default constructor and
29 // does not have localized warning messages for the UI.
30 kInvalid = 0,
31 // An extension caused excessive network delays.
32 kNetworkDelay,
[email protected]a9632c9f2011-10-26 16:04:1633 // This extension failed to modify a network request because the
34 // modification conflicted with a modification of another extension.
35 kNetworkConflict,
[email protected]b4d3771d2012-11-14 14:44:1036 // This extension failed to redirect a network request because another
37 // extension with higher precedence redirected to a different target.
38 kRedirectConflict,
[email protected]fd50e7b2011-11-03 09:20:2539 // The extension repeatedly flushed WebKit's in-memory cache, which slows
40 // down the overall performance.
41 kRepeatedCacheFlushes,
[email protected]dc6cb142013-08-10 18:14:5242 // The extension failed to determine the filename of a download because
43 // another extension with higher precedence determined a different filename.
44 kDownloadFilenameConflict,
[email protected]e9d7496e2014-04-18 01:25:4645 kReloadTooFrequent,
[email protected]7c1490da2011-10-11 18:53:2546 kMaxWarningType
47 };
48
hanxic7e55202014-08-28 14:13:2149 // We allow copy&assign for passing containers of Warnings between threads.
50 Warning(const Warning& other);
51 ~Warning();
52 Warning& operator=(const Warning& other);
[email protected]7c1490da2011-10-11 18:53:2553
[email protected]b4d3771d2012-11-14 14:44:1054 // Factory methods for various warning types.
hanxic7e55202014-08-28 14:13:2155 static Warning CreateNetworkDelayWarning(
[email protected]b4d3771d2012-11-14 14:44:1056 const std::string& extension_id);
hanxic7e55202014-08-28 14:13:2157 static Warning CreateNetworkConflictWarning(
[email protected]b4d3771d2012-11-14 14:44:1058 const std::string& extension_id);
hanxic7e55202014-08-28 14:13:2159 static Warning CreateRedirectConflictWarning(
[email protected]7c1490da2011-10-11 18:53:2560 const std::string& extension_id,
[email protected]b4d3771d2012-11-14 14:44:1061 const std::string& winning_extension_id,
62 const GURL& attempted_redirect_url,
63 const GURL& winning_redirect_url);
hanxic7e55202014-08-28 14:13:2164 static Warning CreateRequestHeaderConflictWarning(
[email protected]b4d3771d2012-11-14 14:44:1065 const std::string& extension_id,
66 const std::string& winning_extension_id,
67 const std::string& conflicting_header);
hanxic7e55202014-08-28 14:13:2168 static Warning CreateResponseHeaderConflictWarning(
[email protected]b4d3771d2012-11-14 14:44:1069 const std::string& extension_id,
70 const std::string& winning_extension_id,
71 const std::string& conflicting_header);
hanxic7e55202014-08-28 14:13:2172 static Warning CreateCredentialsConflictWarning(
[email protected]b4d3771d2012-11-14 14:44:1073 const std::string& extension_id,
74 const std::string& winning_extension_id);
hanxic7e55202014-08-28 14:13:2175 static Warning CreateRepeatedCacheFlushesWarning(
[email protected]b4d3771d2012-11-14 14:44:1076 const std::string& extension_id);
hanxic7e55202014-08-28 14:13:2177 static Warning CreateDownloadFilenameConflictWarning(
[email protected]dc6cb142013-08-10 18:14:5278 const std::string& losing_extension_id,
79 const std::string& winning_extension_id,
80 const base::FilePath& losing_filename,
81 const base::FilePath& winning_filename);
hanxic7e55202014-08-28 14:13:2182 static Warning CreateReloadTooFrequentWarning(
[email protected]e9d7496e2014-04-18 01:25:4683 const std::string& extension_id);
[email protected]7c1490da2011-10-11 18:53:2584
[email protected]b4d3771d2012-11-14 14:44:1085 // Returns the specific warning type.
86 WarningType warning_type() const { return type_; }
[email protected]a9632c9f2011-10-26 16:04:1687
[email protected]b4d3771d2012-11-14 14:44:1088 // Returns the id of the extension for which this warning is valid.
89 const std::string& extension_id() const { return extension_id_; }
90
91 // Returns a localized warning message.
92 std::string GetLocalizedMessage(const ExtensionSet* extensions) const;
[email protected]7c1490da2011-10-11 18:53:2593
94 private:
[email protected]b4d3771d2012-11-14 14:44:1095 // 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.
hanxic7e55202014-08-28 14:13:2199 Warning(WarningType type,
[email protected]b4d3771d2012-11-14 14:44:10100 const std::string& extension_id,
101 int message_id,
102 const std::vector<std::string>& message_parameters);
[email protected]7c1490da2011-10-11 18:53:25103
[email protected]b4d3771d2012-11-14 14:44:10104 WarningType type_;
105 std::string extension_id_;
106 // IDS_* resource ID.
107 int message_id_;
108 // Parameters to be filled into the string identified by |message_id_|.
109 std::vector<std::string> message_parameters_;
[email protected]7c1490da2011-10-11 18:53:25110};
111
hanxic7e55202014-08-28 14:13:21112// Compare Warnings based on the tuple of (extension_id, type).
113// The message associated with Warnings is purely informational
[email protected]b4d3771d2012-11-14 14:44:10114// and does not contribute to distinguishing extensions.
hanxic7e55202014-08-28 14:13:21115bool operator<(const Warning& a, const Warning& b);
[email protected]b4d3771d2012-11-14 14:44:10116
hanxic7e55202014-08-28 14:13:21117typedef std::set<Warning> WarningSet;
[email protected]b4d3771d2012-11-14 14:44:10118
119} // namespace extensions
120
hanxic7e55202014-08-28 14:13:21121#endif // EXTENSIONS_BROWSER_WARNING_SET_H_