| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 13 #include <map> |
| 14 | 14 |
| 15 #include "base/memory/singleton.h" | |
| 16 #include "chrome/browser/extensions/extension_function.h" | 15 #include "chrome/browser/extensions/extension_function.h" |
| 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "content/browser/tab_contents/tab_contents_observer.h" | 17 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 18 #include "content/common/notification_observer.h" | 18 #include "content/common/notification_observer.h" |
| 19 #include "content/common/notification_registrar.h" | 19 #include "content/common/notification_registrar.h" |
| 20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 21 | 21 |
| 22 class TabContents; | 22 class TabContents; |
| 23 struct ViewHostMsg_CreateWindow_Params; | 23 struct ViewHostMsg_CreateWindow_Params; |
| 24 | 24 |
| 25 // Tracks the navigation state of all frames currently known to the | 25 // Tracks the navigation state of all frames currently known to the |
| 26 // webNavigation API. It is mainly used to track in which frames an error | 26 // webNavigation API. It is mainly used to track in which frames an error |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // Tracks the state of the frames we are sending events for. | 125 // Tracks the state of the frames we are sending events for. |
| 126 FrameNavigationState navigation_state_; | 126 FrameNavigationState navigation_state_; |
| 127 | 127 |
| 128 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationTabObserver); | 128 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationTabObserver); |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 // Observes navigation notifications and routes them as events to the extension | 131 // Observes navigation notifications and routes them as events to the extension |
| 132 // system. | 132 // system. |
| 133 class ExtensionWebNavigationEventRouter : public NotificationObserver { | 133 class ExtensionWebNavigationEventRouter : public NotificationObserver { |
| 134 public: | 134 public: |
| 135 // Returns the singleton instance of the event router. | 135 explicit ExtensionWebNavigationEventRouter(Profile* profile); |
| 136 static ExtensionWebNavigationEventRouter* GetInstance(); | 136 virtual ~ExtensionWebNavigationEventRouter(); |
| 137 | 137 |
| 138 // Invoked by the extensions service once the extension system is fully set | 138 // Invoked by the extensions service once the extension system is fully set |
| 139 // up and can start dispatching events to extensions. | 139 // up and can start dispatching events to extensions. |
| 140 void Init(); | 140 void Init(); |
| 141 | 141 |
| 142 private: | 142 private: |
| 143 friend struct DefaultSingletonTraits<ExtensionWebNavigationEventRouter>; | |
| 144 | |
| 145 ExtensionWebNavigationEventRouter(); | |
| 146 virtual ~ExtensionWebNavigationEventRouter(); | |
| 147 | |
| 148 // NotificationObserver implementation. | 143 // NotificationObserver implementation. |
| 149 virtual void Observe(NotificationType type, | 144 virtual void Observe(NotificationType type, |
| 150 const NotificationSource& source, | 145 const NotificationSource& source, |
| 151 const NotificationDetails& details); | 146 const NotificationDetails& details); |
| 152 | 147 |
| 153 // Handler for the CREATING_NEW_WINDOW event. The method takes the details of | 148 // Handler for the CREATING_NEW_WINDOW event. The method takes the details of |
| 154 // such an event and constructs a suitable JSON formatted extension event from | 149 // such an event and constructs a suitable JSON formatted extension event from |
| 155 // it. | 150 // it. |
| 156 void CreatingNewWindow(TabContents* tab_content, | 151 void CreatingNewWindow(TabContents* tab_content, |
| 157 const ViewHostMsg_CreateWindow_Params* details); | 152 const ViewHostMsg_CreateWindow_Params* details); |
| 158 | 153 |
| 159 // Used for tracking registrations to navigation notifications. | 154 // Used for tracking registrations to navigation notifications. |
| 160 NotificationRegistrar registrar_; | 155 NotificationRegistrar registrar_; |
| 161 | 156 |
| 157 // The profile that owns us via ExtensionService. |
| 158 Profile* profile_; |
| 159 |
| 162 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationEventRouter); | 160 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationEventRouter); |
| 163 }; | 161 }; |
| 164 | 162 |
| 165 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ | 163 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ |
| OLD | NEW |