Home | History | Annotate | Download | only in location_bar
      1 // Copyright (c) 2010 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_PAGE_ACTION_DECORATION_H_
      6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_PAGE_ACTION_DECORATION_H_
      7 #pragma once
      8 
      9 #include "chrome/browser/extensions/image_loading_tracker.h"
     10 #import "chrome/browser/ui/cocoa/location_bar/image_decoration.h"
     11 #include "googleurl/src/gurl.h"
     12 
     13 class ExtensionAction;
     14 @class ExtensionActionContextMenu;
     15 class LocationBarViewMac;
     16 class Profile;
     17 class TabContents;
     18 
     19 // PageActionDecoration is used to display the icon for a given Page
     20 // Action and notify the extension when the icon is clicked.
     21 
     22 class PageActionDecoration : public ImageDecoration,
     23                              public ImageLoadingTracker::Observer,
     24                              public NotificationObserver {
     25  public:
     26   PageActionDecoration(LocationBarViewMac* owner,
     27                        Profile* profile,
     28                        ExtensionAction* page_action);
     29   virtual ~PageActionDecoration();
     30 
     31   ExtensionAction* page_action() { return page_action_; }
     32   int current_tab_id() { return current_tab_id_; }
     33   void set_preview_enabled(bool enabled) { preview_enabled_ = enabled; }
     34   bool preview_enabled() const { return preview_enabled_; }
     35 
     36   // Overridden from |ImageLoadingTracker::Observer|.
     37   virtual void OnImageLoaded(
     38       SkBitmap* image, const ExtensionResource& resource, int index);
     39 
     40   // Called to notify the Page Action that it should determine whether
     41   // to be visible or hidden. |contents| is the TabContents that is
     42   // active, |url| is the current page URL.
     43   void UpdateVisibility(TabContents* contents, const GURL& url);
     44 
     45   // Sets the tooltip for this Page Action image.
     46   void SetToolTip(NSString* tooltip);
     47   void SetToolTip(std::string tooltip);
     48 
     49   // Get the point where extension info bubbles should point within
     50   // the given decoration frame.
     51   NSPoint GetBubblePointInFrame(NSRect frame);
     52 
     53   // Overridden from |LocationBarDecoration|
     54   virtual CGFloat GetWidthForSpace(CGFloat width);
     55   virtual bool AcceptsMousePress();
     56   virtual bool OnMousePressed(NSRect frame);
     57   virtual NSString* GetToolTip();
     58   virtual NSMenu* GetMenu();
     59 
     60  private:
     61   // Overridden from NotificationObserver:
     62   virtual void Observe(NotificationType type,
     63                        const NotificationSource& source,
     64                        const NotificationDetails& details);
     65 
     66   // The location bar view that owns us.
     67   LocationBarViewMac* owner_;
     68 
     69   // The current profile (not owned by us).
     70   Profile* profile_;
     71 
     72   // The Page Action that this view represents. The Page Action is not
     73   // owned by us, it resides in the extension of this particular
     74   // profile.
     75   ExtensionAction* page_action_;
     76 
     77   // A cache of images the Page Actions might need to show, mapped by
     78   // path.
     79   typedef std::map<std::string, SkBitmap> PageActionMap;
     80   PageActionMap page_action_icons_;
     81 
     82   // The object that is waiting for the image loading to complete
     83   // asynchronously.
     84   ImageLoadingTracker tracker_;
     85 
     86   // The tab id we are currently showing the icon for.
     87   int current_tab_id_;
     88 
     89   // The URL we are currently showing the icon for.
     90   GURL current_url_;
     91 
     92   // The string to show for a tooltip.
     93   scoped_nsobject<NSString> tooltip_;
     94 
     95   // The context menu for the Page Action.
     96   scoped_nsobject<ExtensionActionContextMenu> menu_;
     97 
     98   // This is used for post-install visual feedback. The page_action
     99   // icon is briefly shown even if it hasn't been enabled by its
    100   // extension.
    101   bool preview_enabled_;
    102 
    103   // Used to register for notifications received by
    104   // NotificationObserver.
    105   NotificationRegistrar registrar_;
    106 
    107   DISALLOW_COPY_AND_ASSIGN(PageActionDecoration);
    108 };
    109 
    110 #endif  // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_PAGE_ACTION_DECORATION_H_
    111