OLD | NEW |
(Empty) | |
| 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 // Defines the Chrome Extensions WebNavigation API functions for observing and |
| 6 // intercepting navigation events, as specified in |
| 7 // chrome/common/extensions/api/extension_api.json. |
| 8 |
| 9 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ |
| 10 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ |
| 11 #pragma once |
| 12 |
| 13 #include "base/singleton.h" |
| 14 #include "chrome/browser/extensions/extension_function.h" |
| 15 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 16 #include "chrome/common/notification_registrar.h" |
| 17 #include "googleurl/src/gurl.h" |
| 18 |
| 19 // Observes navigation notifications and routes them as events to the extension |
| 20 // system. |
| 21 class ExtensionWebNavigationEventRouter : public NotificationObserver { |
| 22 public: |
| 23 // Single instance of the event router. |
| 24 static ExtensionWebNavigationEventRouter* GetInstance(); |
| 25 |
| 26 void Init(); |
| 27 |
| 28 private: |
| 29 friend struct DefaultSingletonTraits<ExtensionWebNavigationEventRouter>; |
| 30 |
| 31 ExtensionWebNavigationEventRouter() {} |
| 32 virtual ~ExtensionWebNavigationEventRouter() {} |
| 33 |
| 34 // NotificationObserver implementation. |
| 35 virtual void Observe(NotificationType type, |
| 36 const NotificationSource& source, |
| 37 const NotificationDetails& details); |
| 38 |
| 39 // Handler for the NAV_ENTRY_COMMITTED event. The method takes the details of |
| 40 // such an event and constructs a suitable JSON formatted extension event |
| 41 // from it. |
| 42 void NavEntryCommitted(NavigationController* controller, |
| 43 NavigationController::LoadCommittedDetails* details); |
| 44 |
| 45 // This method dispatches events to the extension message service. |
| 46 void DispatchEvent(Profile* context, |
| 47 const char* event_name, |
| 48 const std::string& json_args); |
| 49 |
| 50 // Used for tracking registrations to navigation notifications. |
| 51 NotificationRegistrar registrar_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationEventRouter); |
| 54 }; |
| 55 |
| 56 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ |
OLD | NEW |