Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / location_bar / origin_chip_decoration.h
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.
4
5 #ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_ORIGIN_CHIP_DECORATION_H_
6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_ORIGIN_CHIP_DECORATION_H_
7
8 #import <Cocoa/Cocoa.h>
9
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"
15
16 class LocationBarViewMac;
17
18 namespace content {
19 class WebContents;
20 }
21
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 {
28  public:
29   explicit OriginChipDecoration(LocationBarViewMac* owner);
30   virtual ~OriginChipDecoration();
31
32   // Updates the origin chip's content, and display state.
33   void Update();
34
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;
40
41   // Implement |IconImage::Observer|.
42   virtual void OnExtensionIconImageChanged(
43       extensions::IconImage* image) OVERRIDE;
44
45   // Implement |SafeBrowsingUIManager::Observer|.
46   virtual void OnSafeBrowsingHit(
47       const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
48   virtual void OnSafeBrowsingMatch(
49       const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
50
51  private:
52   // Returns whether the origin chip should be shown or not.
53   bool ShouldShow() const;
54
55   // Returns the width required to display the chip's contents.
56   CGFloat GetChipWidth() const;
57
58   // Contains attributes for drawing the origin string.
59   base::scoped_nsobject<NSMutableDictionary> attributes_;
60
61   // The extension's current icon, if the page being displayed belongs to an
62   // extension.
63   base::scoped_nsobject<NSImage> extension_icon_;
64
65   // Manages information to be displayed on the origin chip.
66   OriginChipInfo info_;
67
68   // The label currently displayed in the chip.
69   base::scoped_nsobject<NSString> label_;
70
71   // The control view that owns this. Weak.
72   LocationBarViewMac* owner_;
73
74   DISALLOW_COPY_AND_ASSIGN(OriginChipDecoration);
75 };
76
77 #endif  // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_ORIGIN_CHIP_DECORATION_H_