| OLD | NEW |
| (Empty) |
| 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 <memory> | |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/scoped_observer.h" | |
| 15 #include "chrome/browser/extensions/extension_install_prompt.h" | |
| 16 #include "content/public/browser/notification_observer.h" | |
| 17 #include "content/public/browser/notification_registrar.h" | |
| 18 #include "extensions/browser/extension_registry_observer.h" | |
| 19 | |
| 20 class Profile; | |
| 21 | |
| 22 namespace content { | |
| 23 class NavigationController; | |
| 24 } | |
| 25 | |
| 26 namespace extensions { | |
| 27 | |
| 28 // The NavigationObserver listens to navigation notifications. If the user | |
| 29 // navigates into an extension that has been disabled due to a permission | |
| 30 // increase, it prompts the user to accept the new permissions and re-enables | |
| 31 // the extension. | |
| 32 class NavigationObserver : public content::NotificationObserver, | |
| 33 public ExtensionRegistryObserver { | |
| 34 public: | |
| 35 explicit NavigationObserver(Profile* profile); | |
| 36 ~NavigationObserver() override; | |
| 37 | |
| 38 // content::NotificationObserver | |
| 39 void Observe(int type, | |
| 40 const content::NotificationSource& source, | |
| 41 const content::NotificationDetails& details) override; | |
| 42 | |
| 43 private: | |
| 44 // Registers for the NOTIFICATION_NAV_ENTRY_COMMITTED notification. | |
| 45 void RegisterForNotifications(); | |
| 46 | |
| 47 // Checks if |nav_controller| has entered an extension's web extent. If it | |
| 48 // has and the extension is disabled due to a permissions increase, this | |
| 49 // prompts the user to accept the new permissions and enables the extension. | |
| 50 void PromptToEnableExtensionIfNecessary( | |
| 51 content::NavigationController* nav_controller); | |
| 52 | |
| 53 void OnInstallPromptDone(ExtensionInstallPrompt::Result result); | |
| 54 | |
| 55 // extensions::ExtensionRegistryObserver: | |
| 56 void OnExtensionUninstalled(content::BrowserContext* browser_context, | |
| 57 const Extension* extension, | |
| 58 UninstallReason reason) override; | |
| 59 | |
| 60 content::NotificationRegistrar registrar_; | |
| 61 | |
| 62 Profile* profile_; | |
| 63 | |
| 64 // The UI used to confirm enabling extensions. | |
| 65 std::unique_ptr<ExtensionInstallPrompt> extension_install_prompt_; | |
| 66 | |
| 67 // The data we keep track of when prompting to enable extensions. | |
| 68 std::string in_progress_prompt_extension_id_; | |
| 69 content::NavigationController* in_progress_prompt_navigation_controller_; | |
| 70 | |
| 71 // The extension ids we've already prompted the user about. | |
| 72 std::set<std::string> prompted_extensions_; | |
| 73 | |
| 74 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | |
| 75 extension_registry_observer_; | |
| 76 | |
| 77 base::WeakPtrFactory<NavigationObserver> weak_factory_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(NavigationObserver); | |
| 80 }; | |
| 81 | |
| 82 } // namespace extensions | |
| 83 | |
| 84 #endif // CHROME_BROWSER_EXTENSIONS_NAVIGATION_OBSERVER_H_ | |
| OLD | NEW |