Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / location_bar / origin_chip_info.h
blob9e11e3570766b6ab93a4ccd9b322da28a8028915
1 // Copyright 2014 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_UI_LOCATION_BAR_ORIGIN_CHIP_INFO_H_
6 #define CHROME_BROWSER_UI_LOCATION_BAR_ORIGIN_CHIP_INFO_H_
8 #include "base/strings/string16.h"
9 #include "chrome/browser/ui/toolbar/toolbar_model.h"
10 #include "extensions/browser/extension_icon_image.h"
12 class GURL;
13 class Profile;
15 namespace content {
16 class WebContents;
19 // This class manages the information to be displayed by the origin chip.
20 class OriginChipInfo {
21 public:
22 // The |owner| owns this OriginChipInfo and must outlive it. If the current
23 // origin is an extension, the |owner|'s OnExtensionIconImageChanged()
24 // method will be called whenever the icon changes.
25 OriginChipInfo(extensions::IconImage::Observer* owner, Profile* profile);
26 ~OriginChipInfo();
28 // Updates the current state. Returns whether the displayable information has
29 // changed.
30 bool Update(const content::WebContents* web_contents,
31 const ToolbarModel* toolbar_model);
33 // Returns the label to be displayed by the origin chip.
34 const base::string16& label() const { return label_; }
36 // Returns the tooltip to be used for the origin chip.
37 base::string16 Tooltip() const;
39 // Returns the ID of the icon to be displayed by the origin chip. Note that
40 // if |owner_|'s OnExtensionIconImageChanged() method was called with
41 // anything else than NULL, that icon has precedence over whatever this method
42 // returns.
43 int icon() const { return icon_; }
45 // Returns the full URL.
46 const GURL& displayed_url() const { return displayed_url_; }
48 // Returns the security level of the current URL.
49 ToolbarModel::SecurityLevel security_level() const { return security_level_; }
51 // Returns whether the current URL is known to be malware or not.
52 bool is_url_malware() const { return is_url_malware_; }
54 private:
55 // The observer which will receive OnExtensionIconImageChanged() calls.
56 extensions::IconImage::Observer* owner_;
58 Profile* profile_;
60 // State used to determine whether the |label_| and |icon_| need to be
61 // recomputed.
62 GURL displayed_url_;
63 ToolbarModel::SecurityLevel security_level_;
64 bool is_url_malware_;
66 // The label and icon to be displayed by the origin chip.
67 base::string16 label_;
68 int icon_;
70 // extensions::IconImage instance, used for observing changes in an
71 // extension's icon, when the current page belongs to an extension.
72 scoped_ptr<extensions::IconImage> extension_icon_image_;
74 DISALLOW_COPY_AND_ASSIGN(OriginChipInfo);
77 // This class is left here to prevent breaking the views code. It will be
78 // removed soon, and the functions will become local to origin_chip.cc.
79 class OriginChip {
80 public:
81 // Detects client-side or SB malware/phishing hits. Used to decide whether the
82 // origin chip should indicate that the current page has malware or is a known
83 // phishing page.
84 static bool IsMalware(const GURL& url, const content::WebContents* tab);
86 // Gets the label to display on the Origin Chip for the specified URL. The
87 // |profile| is needed in case the URL is from an extension.
88 static base::string16 LabelFromURLForProfile(const GURL& provided_url,
89 Profile* profile);
92 #endif // CHROME_BROWSER_UI_LOCATION_BAR_ORIGIN_CHIP_INFO_H_