| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Defines the Chrome Extensions WebNavigation API functions for observing and | 5 // Defines the Chrome Extensions WebNavigation API functions for observing and |
| 6 // intercepting navigation events, as specified in | 6 // intercepting navigation events, as specified in |
| 7 // chrome/common/extensions/api/extension_api.json. | 7 // chrome/common/extensions/api/extension_api.json. |
| 8 | 8 |
| 9 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ | 9 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ |
| 10 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ | 10 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ |
| 11 #pragma once | 11 #pragma once |
| 12 | 12 |
| 13 #include "base/singleton.h" | 13 #include "base/singleton.h" |
| 14 #include "chrome/browser/extensions/extension_function.h" | 14 #include "chrome/browser/extensions/extension_function.h" |
| 15 #include "chrome/browser/tab_contents/navigation_controller.h" | 15 #include "chrome/common/notification_observer.h" |
| 16 #include "chrome/common/notification_registrar.h" | 16 #include "chrome/common/notification_registrar.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 | 18 |
| 19 class NavigationController; |
| 20 class ProvisionalLoadDetails; |
| 21 |
| 19 // Observes navigation notifications and routes them as events to the extension | 22 // Observes navigation notifications and routes them as events to the extension |
| 20 // system. | 23 // system. |
| 21 class ExtensionWebNavigationEventRouter : public NotificationObserver { | 24 class ExtensionWebNavigationEventRouter : public NotificationObserver { |
| 22 public: | 25 public: |
| 23 // Single instance of the event router. | 26 // Single instance of the event router. |
| 24 static ExtensionWebNavigationEventRouter* GetInstance(); | 27 static ExtensionWebNavigationEventRouter* GetInstance(); |
| 25 | 28 |
| 26 void Init(); | 29 void Init(); |
| 27 | 30 |
| 28 private: | 31 private: |
| 29 friend struct DefaultSingletonTraits<ExtensionWebNavigationEventRouter>; | 32 friend struct DefaultSingletonTraits<ExtensionWebNavigationEventRouter>; |
| 30 | 33 |
| 31 ExtensionWebNavigationEventRouter() {} | 34 ExtensionWebNavigationEventRouter() {} |
| 32 virtual ~ExtensionWebNavigationEventRouter() {} | 35 virtual ~ExtensionWebNavigationEventRouter() {} |
| 33 | 36 |
| 34 // NotificationObserver implementation. | 37 // NotificationObserver implementation. |
| 35 virtual void Observe(NotificationType type, | 38 virtual void Observe(NotificationType type, |
| 36 const NotificationSource& source, | 39 const NotificationSource& source, |
| 37 const NotificationDetails& details); | 40 const NotificationDetails& details); |
| 38 | 41 |
| 39 // Handler for the NAV_ENTRY_COMMITTED event. The method takes the details of | 42 // Handler for the FRAME_PROVISIONAL_LOAD_START event. The method takes the |
| 40 // such an event and constructs a suitable JSON formatted extension event | 43 // details of such an event and constructs a suitable JSON formatted extension |
| 41 // from it. | 44 // event from it. |
| 42 void NavEntryCommitted(NavigationController* controller, | 45 void FrameProvisionalLoadStart(NavigationController* controller, |
| 43 NavigationController::LoadCommittedDetails* details); | 46 ProvisionalLoadDetails* details); |
| 47 |
| 48 // Handler for the FRAME_PROVISIONAL_LOAD_COMMITTED event. The method takes |
| 49 // the details of such an event and constructs a suitable JSON formatted |
| 50 // extension event from it. |
| 51 void FrameProvisionalLoadCommitted(NavigationController* controller, |
| 52 ProvisionalLoadDetails* details); |
| 53 |
| 54 // Handler for the FAIL_PROVISIONAL_LOAD_WITH_ERROR event. The method takes |
| 55 // the details of such an event and constructs a suitable JSON formatted |
| 56 // extension event from it. |
| 57 void FailProvisionalLoadWithError(NavigationController* controller, |
| 58 ProvisionalLoadDetails* details); |
| 44 | 59 |
| 45 // This method dispatches events to the extension message service. | 60 // This method dispatches events to the extension message service. |
| 46 void DispatchEvent(Profile* context, | 61 void DispatchEvent(Profile* context, |
| 47 const char* event_name, | 62 const char* event_name, |
| 48 const std::string& json_args); | 63 const std::string& json_args); |
| 49 | 64 |
| 50 // Used for tracking registrations to navigation notifications. | 65 // Used for tracking registrations to navigation notifications. |
| 51 NotificationRegistrar registrar_; | 66 NotificationRegistrar registrar_; |
| 52 | 67 |
| 53 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationEventRouter); | 68 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationEventRouter); |
| 54 }; | 69 }; |
| 55 | 70 |
| 56 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ | 71 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ |
| OLD | NEW |