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/safe_browsing/ui_manager.h"
12 #include "chrome/browser/ui/cocoa/location_bar/button_decoration.h"
13 #include "chrome/browser/ui/location_bar/origin_chip_info.h"
14 #include "extensions/browser/extension_icon_image.h"
16 class LocationBarViewMac;
17 class LocationIconDecoration;
23 // Origin chip button, which is placed leading the omnibox and contains the
24 // current site's host. Clicking the chip reveals the page's URL, and clicking
25 // the icon on the chip reveals the permissions bubble.
26 class OriginChipDecoration : public ButtonDecoration,
27 public extensions::IconImage::Observer,
28 public SafeBrowsingUIManager::Observer {
30 OriginChipDecoration(LocationBarViewMac* owner,
31 LocationIconDecoration* location_icon);
32 ~OriginChipDecoration() override;
34 // Updates the origin chip's content, and display state.
37 // Implement |ButtonDecoration|.
38 bool PreventFocus(NSPoint location) const override;
40 // Implement |LocationBarDecoration|.
41 CGFloat GetWidthForSpace(CGFloat width) override;
42 void DrawInFrame(NSRect frame, NSView* control_view) override;
43 NSString* GetToolTip() override;
44 bool OnMousePressed(NSRect frame, NSPoint location) override;
45 NSPoint GetBubblePointInFrame(NSRect frame) override;
47 // Implement |IconImage::Observer|.
48 void OnExtensionIconImageChanged(extensions::IconImage* image) override;
50 // Implement |SafeBrowsingUIManager::Observer|.
51 void OnSafeBrowsingHit(
52 const SafeBrowsingUIManager::UnsafeResource& resource) override;
53 void OnSafeBrowsingMatch(
54 const SafeBrowsingUIManager::UnsafeResource& resource) override;
57 // Returns the width required to display the chip's contents.
58 CGFloat GetChipWidth() const;
60 // Contains attributes for drawing the origin string.
61 base::scoped_nsobject<NSMutableDictionary> attributes_;
63 // The extension's current icon, if the page being displayed belongs to an
65 base::scoped_nsobject<NSImage> extension_icon_;
67 // The rectangle where the icon was last drawn. Used for hit testing to
68 // display the permissions bubble.
71 // Manages information to be displayed on the origin chip.
74 // The label currently displayed in the chip.
75 base::scoped_nsobject<NSString> label_;
77 // The location icon decoration. Weak.
78 LocationIconDecoration* location_icon_;
80 // The control view that owns this. Weak.
81 LocationBarViewMac* owner_;
83 DISALLOW_COPY_AND_ASSIGN(OriginChipDecoration);
86 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_ORIGIN_CHIP_DECORATION_H_