Update To 11.40.268.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/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"
15
16 class LocationBarViewMac;
17 class LocationIconDecoration;
18
19 namespace content {
20 class WebContents;
21 }
22
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 {
29  public:
30   OriginChipDecoration(LocationBarViewMac* owner,
31                        LocationIconDecoration* location_icon);
32   ~OriginChipDecoration() override;
33
34   // Updates the origin chip's content, and display state.
35   void Update();
36
37   // Implement |ButtonDecoration|.
38   bool PreventFocus(NSPoint location) const override;
39
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;
46
47   // Implement |IconImage::Observer|.
48   void OnExtensionIconImageChanged(extensions::IconImage* image) override;
49
50   // Implement |SafeBrowsingUIManager::Observer|.
51   void OnSafeBrowsingHit(
52       const SafeBrowsingUIManager::UnsafeResource& resource) override;
53   void OnSafeBrowsingMatch(
54       const SafeBrowsingUIManager::UnsafeResource& resource) override;
55
56  private:
57   // Returns the width required to display the chip's contents.
58   CGFloat GetChipWidth() const;
59
60   // Contains attributes for drawing the origin string.
61   base::scoped_nsobject<NSMutableDictionary> attributes_;
62
63   // The extension's current icon, if the page being displayed belongs to an
64   // extension.
65   base::scoped_nsobject<NSImage> extension_icon_;
66
67   // The rectangle where the icon was last drawn. Used for hit testing to
68   // display the permissions bubble.
69   NSRect icon_rect_;
70
71   // Manages information to be displayed on the origin chip.
72   OriginChipInfo info_;
73
74   // The label currently displayed in the chip.
75   base::scoped_nsobject<NSString> label_;
76
77   // The location icon decoration. Weak.
78   LocationIconDecoration* location_icon_;
79
80   // The control view that owns this. Weak.
81   LocationBarViewMac* owner_;
82
83   DISALLOW_COPY_AND_ASSIGN(OriginChipDecoration);
84 };
85
86 #endif  // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_ORIGIN_CHIP_DECORATION_H_