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 <map> | 13 #include <map> |
14 | 14 |
15 #include "base/singleton.h" | 15 #include "base/singleton.h" |
16 #include "chrome/browser/extensions/extension_function.h" | 16 #include "chrome/browser/extensions/extension_function.h" |
17 #include "chrome/common/notification_observer.h" | 17 #include "chrome/common/notification_observer.h" |
18 #include "chrome/common/notification_registrar.h" | 18 #include "chrome/common/notification_registrar.h" |
19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
20 | 20 |
21 class NavigationController; | 21 class NavigationController; |
22 class ProvisionalLoadDetails; | 22 class ProvisionalLoadDetails; |
23 class TabContents; | 23 class TabContents; |
24 | 24 |
25 // Tracks which frames are in an error state, and no navigation events should | 25 // Tracks which frames are in an error state, and no navigation events should |
26 // be sent for. | 26 // be sent for. |
brettw
2010/11/23 22:44:09
This comment and the name of the class don't reall
jochen (gone - plz use gerrit)
2010/11/24 07:37:37
It's the latter.
Done.
| |
27 class FrameNavigationState { | 27 class FrameNavigationState { |
28 public: | 28 public: |
29 FrameNavigationState(); | 29 FrameNavigationState(); |
30 ~FrameNavigationState(); | 30 ~FrameNavigationState(); |
31 | 31 |
32 // True if navigation events for the given frame can be sent. | 32 // True if navigation events for the given frame can be sent. |
33 bool CanSendEvents(long long frame_id) const; | 33 bool CanSendEvents(long long frame_id) const; |
brettw
2010/11/23 22:44:09
What is the goal here of using "long long"? I've n
jochen (gone - plz use gerrit)
2010/11/24 07:37:37
In WebKit, you'd use long long instead. Since that
| |
34 | 34 |
35 // Starts to track a frame given by its |frame_id| showing the URL |url| in | 35 // Starts to track a frame given by its |frame_id| showing the URL |url| in |
36 // a |tab_contents|. | 36 // a |tab_contents|. |
37 void TrackFrame(long long frame_id, | 37 void TrackFrame(long long frame_id, |
38 const GURL& url, | 38 const GURL& url, |
39 bool is_main_frame, | 39 bool is_main_frame, |
40 const TabContents* tab_contents); | 40 const TabContents* tab_contents); |
41 | 41 |
42 // Returns the URL corresponding to a tracked frame given by its |frame_id|. | 42 // Returns the URL corresponding to a tracked frame given by its |frame_id|. |
43 GURL GetUrl(long long frame_id) const; | 43 GURL GetUrl(long long frame_id) const; |
(...skipping 18 matching lines...) Expand all Loading... | |
62 | 62 |
63 // Tracks which frames belong to a given tab contents object. | 63 // Tracks which frames belong to a given tab contents object. |
64 TabContentsToFrameIdMap tab_contents_map_; | 64 TabContentsToFrameIdMap tab_contents_map_; |
65 | 65 |
66 // Tracks the state of known frames. | 66 // Tracks the state of known frames. |
67 FrameIdToStateMap frame_state_map_; | 67 FrameIdToStateMap frame_state_map_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState); | 69 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState); |
70 }; | 70 }; |
71 | 71 |
72 | |
72 // Observes navigation notifications and routes them as events to the extension | 73 // Observes navigation notifications and routes them as events to the extension |
73 // system. | 74 // system. |
74 class ExtensionWebNavigationEventRouter : public NotificationObserver { | 75 class ExtensionWebNavigationEventRouter : public NotificationObserver { |
75 public: | 76 public: |
76 // Single instance of the event router. | 77 // Single instance of the event router. |
brettw
2010/11/23 22:44:09
Function comments should be descriptive, so this s
jochen (gone - plz use gerrit)
2010/11/24 07:37:37
Done.
| |
77 static ExtensionWebNavigationEventRouter* GetInstance(); | 78 static ExtensionWebNavigationEventRouter* GetInstance(); |
78 | 79 |
79 void Init(); | 80 void Init(); |
brettw
2010/11/23 22:44:09
Who must call this? Normally if I see an init func
jochen (gone - plz use gerrit)
2010/11/24 07:37:37
Done.
| |
80 | 81 |
81 private: | 82 private: |
82 friend struct DefaultSingletonTraits<ExtensionWebNavigationEventRouter>; | 83 friend struct DefaultSingletonTraits<ExtensionWebNavigationEventRouter>; |
83 | 84 |
84 ExtensionWebNavigationEventRouter() {} | 85 ExtensionWebNavigationEventRouter() {} |
85 virtual ~ExtensionWebNavigationEventRouter() {} | 86 virtual ~ExtensionWebNavigationEventRouter() {} |
86 | 87 |
87 // NotificationObserver implementation. | 88 // NotificationObserver implementation. |
88 virtual void Observe(NotificationType type, | 89 virtual void Observe(NotificationType type, |
89 const NotificationSource& source, | 90 const NotificationSource& source, |
(...skipping 19 matching lines...) Expand all Loading... | |
109 // Handler for the FRAME_DID_FINISH_LOAD event. The method takes the frame | 110 // Handler for the FRAME_DID_FINISH_LOAD event. The method takes the frame |
110 // ID and constructs a suitable JSON formatted extension event from it. | 111 // ID and constructs a suitable JSON formatted extension event from it. |
111 void FrameDidFinishLoad(NavigationController* controller, long long frame_id); | 112 void FrameDidFinishLoad(NavigationController* controller, long long frame_id); |
112 | 113 |
113 // Handler for the FAIL_PROVISIONAL_LOAD_WITH_ERROR event. The method takes | 114 // Handler for the FAIL_PROVISIONAL_LOAD_WITH_ERROR event. The method takes |
114 // the details of such an event and constructs a suitable JSON formatted | 115 // the details of such an event and constructs a suitable JSON formatted |
115 // extension event from it. | 116 // extension event from it. |
116 void FailProvisionalLoadWithError(NavigationController* controller, | 117 void FailProvisionalLoadWithError(NavigationController* controller, |
117 ProvisionalLoadDetails* details); | 118 ProvisionalLoadDetails* details); |
118 | 119 |
119 // This method dispatches events to the extension message service. | 120 // This method dispatches events to the extension message service. |
brettw
2010/11/23 22:44:09
"This method dispatches..." -> "Dispatches..."
jochen (gone - plz use gerrit)
2010/11/24 07:37:37
Done.
| |
120 void DispatchEvent(Profile* context, | 121 void DispatchEvent(Profile* context, |
121 const char* event_name, | 122 const char* event_name, |
122 const std::string& json_args); | 123 const std::string& json_args); |
123 | 124 |
124 // Tracks the state of the frames we are sending events for. | 125 // Tracks the state of the frames we are sending events for. |
125 FrameNavigationState navigation_state_; | 126 FrameNavigationState navigation_state_; |
126 | 127 |
127 // Used for tracking registrations to navigation notifications. | 128 // Used for tracking registrations to navigation notifications. |
128 NotificationRegistrar registrar_; | 129 NotificationRegistrar registrar_; |
129 | 130 |
130 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationEventRouter); | 131 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationEventRouter); |
131 }; | 132 }; |
132 | 133 |
133 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ | 134 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ |
OLD | NEW |