1// Copyright (c) 2012 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_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ 6#define CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ 7 8#include <map> 9#include <vector> 10 11#include "base/macros.h" 12#include "base/memory/linked_ptr.h" 13#include "base/scoped_observer.h" 14#include "extensions/browser/extension_registry_observer.h" 15 16class ExtensionAction; 17 18namespace content { 19class WebContents; 20class BrowserContext; 21} 22 23namespace extensions { 24class Extension; 25class ExtensionActionManager; 26class ExtensionRegistry; 27 28// Provides the UI with the current page actions for extensions. The execution 29// of these actions is handled in the ExtensionActionAPI. 30class LocationBarController : public ExtensionRegistryObserver { 31 public: 32 explicit LocationBarController(content::WebContents* web_contents); 33 virtual ~LocationBarController(); 34 35 // Returns the actions which should be displayed in the location bar. 36 std::vector<ExtensionAction*> GetCurrentActions(); 37 38 private: 39 // ExtensionRegistryObserver implementation. 40 virtual void OnExtensionLoaded( 41 content::BrowserContext* browser_context, 42 const Extension* extension) OVERRIDE; 43 virtual void OnExtensionUnloaded( 44 content::BrowserContext* browser_context, 45 const Extension* extension, 46 UnloadedExtensionInfo::Reason reason) OVERRIDE; 47 48 // The associated WebContents. 49 content::WebContents* web_contents_; 50 51 // The associated BrowserContext. 52 content::BrowserContext* browser_context_; 53 54 // The ExtensionActionManager to provide page actions. 55 ExtensionActionManager* action_manager_; 56 57 // Whether or not to show page actions in the location bar at all. (This is 58 // false with the toolbar redesign enabled.) 59 bool should_show_page_actions_; 60 61 // Manufactured page actions that have been generated for extensions that want 62 // to run a script, but were blocked. 63 typedef std::map<std::string, linked_ptr<ExtensionAction> > 64 ExtensionActionMap; 65 ExtensionActionMap active_script_actions_; 66 67 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 68 extension_registry_observer_; 69 70 DISALLOW_COPY_AND_ASSIGN(LocationBarController); 71}; 72 73} // namespace extensions 74 75#endif // CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ 76