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_NAVIGATION_OBSERVER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_NAVIGATION_OBSERVER_H_ 7 8 #include <set> 9 #include <string> 10 11 #include "base/memory/scoped_ptr.h" 12 #include "chrome/browser/extensions/extension_install_prompt.h" 13 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_registrar.h" 15 16 class Profile; 17 18 namespace content { 19 class NavigationController; 20 } 21 22 namespace extensions { 23 24 // The NavigationObserver listens to navigation notifications. If the user 25 // navigates into an extension that has been disabled due to a permission 26 // increase, it prompts the user to accept the new permissions and re-enables 27 // the extension. 28 class NavigationObserver : public ExtensionInstallPrompt::Delegate, 29 public content::NotificationObserver { 30 public: 31 explicit NavigationObserver(Profile* profile); 32 virtual ~NavigationObserver(); 33 34 // content::NotificationObserver 35 virtual void Observe(int type, 36 const content::NotificationSource& source, 37 const content::NotificationDetails& details) OVERRIDE; 38 private: 39 // Registers for the NOTIFICATION_NAV_ENTRY_COMMITTED notification. 40 void RegisterForNotifications(); 41 42 // Checks if |nav_controller| has entered an extension's web extent. If it 43 // has and the extension is disabled due to a permissions increase, this 44 // prompts the user to accept the new permissions and enables the extension. 45 void PromptToEnableExtensionIfNecessary( 46 content::NavigationController* nav_controller); 47 48 // ExtensionInstallPrompt::Delegate callbacks used for the permissions prompt. 49 virtual void InstallUIProceed() OVERRIDE; 50 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; 51 52 content::NotificationRegistrar registrar_; 53 54 Profile* profile_; 55 56 // The UI used to confirm enabling extensions. 57 scoped_ptr<ExtensionInstallPrompt> extension_install_prompt_; 58 59 // The data we keep track of when prompting to enable extensions. 60 std::string in_progress_prompt_extension_id_; 61 content::NavigationController* in_progress_prompt_navigation_controller_; 62 63 // The extension ids we've already prompted the user about. 64 std::set<std::string> prompted_extensions_; 65 66 DISALLOW_COPY_AND_ASSIGN(NavigationObserver); 67 }; 68 69 } // namespace extensions 70 71 #endif // CHROME_BROWSER_EXTENSIONS_NAVIGATION_OBSERVER_H_ 72