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_COCOA_LOCATION_BAR_ORIGIN_CHIP_DECORATION_H_
6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_ORIGIN_CHIP_DECORATION_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/mac/scoped_nsobject.h"
11 #include "chrome/browser/extensions/extension_icon_image.h"
12 #include "chrome/browser/safe_browsing/ui_manager.h"
13 #include "chrome/browser/ui/cocoa/location_bar/button_decoration.h"
14 #include "chrome/browser/ui/toolbar/origin_chip_info.h"
16 class LocationBarViewMac;
22 // Origin chip button, which is placed leading the omnibox and contains the
23 // current site's host. Clicking the chip reveals the page's URL, and clicking
24 // the icon on the chip reveals the permissions bubble.
25 class OriginChipDecoration : public ButtonDecoration,
26 public extensions::IconImage::Observer,
27 public SafeBrowsingUIManager::Observer {
29 explicit OriginChipDecoration(LocationBarViewMac* owner);
30 virtual ~OriginChipDecoration();
32 // Updates the origin chip's content, and display state.
35 // Implement |LocationBarDecoration|.
36 virtual CGFloat GetWidthForSpace(CGFloat width) OVERRIDE;
37 virtual void DrawInFrame(NSRect frame, NSView* control_view) OVERRIDE;
38 virtual NSString* GetToolTip() OVERRIDE;
39 virtual bool OnMousePressed(NSRect frame) OVERRIDE;
41 // Implement |IconImage::Observer|.
42 virtual void OnExtensionIconImageChanged(
43 extensions::IconImage* image) OVERRIDE;
45 // Implement |SafeBrowsingUIManager::Observer|.
46 virtual void OnSafeBrowsingHit(
47 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
48 virtual void OnSafeBrowsingMatch(
49 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
52 // Returns whether the origin chip should be shown or not.
53 bool ShouldShow() const;
55 // Returns the width required to display the chip's contents.
56 CGFloat GetChipWidth() const;
58 // Contains attributes for drawing the origin string.
59 base::scoped_nsobject<NSMutableDictionary> attributes_;
61 // The extension's current icon, if the page being displayed belongs to an
63 base::scoped_nsobject<NSImage> extension_icon_;
65 // Manages information to be displayed on the origin chip.
68 // The label currently displayed in the chip.
69 base::scoped_nsobject<NSString> label_;
71 // The control view that owns this. Weak.
72 LocationBarViewMac* owner_;
74 DISALLOW_COPY_AND_ASSIGN(OriginChipDecoration);
77 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_ORIGIN_CHIP_DECORATION_H_