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