15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef EXTENSIONS_BROWSER_WARNING_SET_H_ 61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define EXTENSIONS_BROWSER_WARNING_SET_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <set> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector> 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochnamespace base { 15ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochclass FilePath; 16ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch} 17ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace extensions { 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ExtensionSet; 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// This class is used by the WarningService to represent warnings if extensions 231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// misbehave. Note that the WarningService deals only with specific warnings 241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// that should trigger a badge on the Chrome menu button. 251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass Warning { 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum WarningType { 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Don't use this, it is only intended for the default constructor and 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // does not have localized warning messages for the UI. 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) kInvalid = 0, 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // An extension caused excessive network delays. 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) kNetworkDelay, 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This extension failed to modify a network request because the 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // modification conflicted with a modification of another extension. 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) kNetworkConflict, 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This extension failed to redirect a network request because another 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // extension with higher precedence redirected to a different target. 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) kRedirectConflict, 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The extension repeatedly flushed WebKit's in-memory cache, which slows 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // down the overall performance. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) kRepeatedCacheFlushes, 42ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // The extension failed to determine the filename of a download because 43ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // another extension with higher precedence determined a different filename. 44ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch kDownloadFilenameConflict, 450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch kReloadTooFrequent, 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) kMaxWarningType 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // We allow copy&assign for passing containers of Warnings between threads. 501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Warning(const Warning& other); 511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ~Warning(); 521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Warning& operator=(const Warning& other); 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Factory methods for various warning types. 551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static Warning CreateNetworkDelayWarning( 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id); 571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static Warning CreateNetworkConflictWarning( 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id); 591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static Warning CreateRedirectConflictWarning( 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id, 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& winning_extension_id, 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& attempted_redirect_url, 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& winning_redirect_url); 641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static Warning CreateRequestHeaderConflictWarning( 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id, 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& winning_extension_id, 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& conflicting_header); 681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static Warning CreateResponseHeaderConflictWarning( 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id, 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& winning_extension_id, 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& conflicting_header); 721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static Warning CreateCredentialsConflictWarning( 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& extension_id, 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& winning_extension_id); 751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static Warning CreateRepeatedCacheFlushesWarning( 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id); 771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static Warning CreateDownloadFilenameConflictWarning( 78ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const std::string& losing_extension_id, 79ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const std::string& winning_extension_id, 80ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const base::FilePath& losing_filename, 81ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const base::FilePath& winning_filename); 821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static Warning CreateReloadTooFrequentWarning( 830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const std::string& extension_id); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the specific warning type. 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WarningType warning_type() const { return type_; } 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the id of the extension for which this warning is valid. 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id() const { return extension_id_; } 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns a localized warning message. 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string GetLocalizedMessage(const ExtensionSet* extensions) const; 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Constructs a warning of type |type| for extension |extension_id|. This 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // could indicate for example the fact that an extension conflicted with 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // others. The |message_id| refers to an IDS_ string ID. The 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |message_parameters| are filled into the message template. 991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Warning(WarningType type, 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id, 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int message_id, 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::vector<std::string>& message_parameters); 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WarningType type_; 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string extension_id_; 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // IDS_* resource ID. 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int message_id_; 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Parameters to be filled into the string identified by |message_id_|. 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<std::string> message_parameters_; 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Compare Warnings based on the tuple of (extension_id, type). 1131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// The message associated with Warnings is purely informational 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// and does not contribute to distinguishing extensions. 1151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool operator<(const Warning& a, const Warning& b); 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccitypedef std::set<Warning> WarningSet; 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace extensions 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif // EXTENSIONS_BROWSER_WARNING_SET_H_ 122