Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: chrome/browser/extensions/extension_webnavigation_api.h

Issue 4136004: Track in which frames navigation errors occurred and don't send further navigation events for them (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/extensions
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
26 // be sent for.
27 class FrameNavigationState : public NotificationObserver {
yzshen 2010/10/27 17:43:38 1) The design says: For a specific *navigation*, t
jochen (gone - plz use gerrit) 2010/10/27 18:01:14 I think it works for that case :) I'll add a unit
28 public:
29 FrameNavigationState();
30 ~FrameNavigationState();
yzshen 2010/10/27 17:43:38 Please consider to add "virtual" for the destructo
jochen (gone - plz use gerrit) 2010/10/27 18:01:14 why? It'll just make the destructor call more expe
yzshen 2010/10/27 18:52:29 Since ~NotificationObserver is declared as "virtua
31
32 // True if navigation events for the given frame can be sent.
33 bool CanSendEvents(long long frame_id) const;
34
35 // Starts the track a frame given by its |frame_id| showing the URL |url| in
yzshen 2010/10/27 17:43:38 Do you mean "Starts to track"?
36 // a |tab_contents|.
37 void TrackFrame(long long frame_id,
38 const GURL& url,
39 bool is_main_frame,
40 const TabContents* tab_contents);
41
42 // Marks a frame as in an error state.
43 void ErrorOccurredInFrame(long long frame_id);
44
45 private:
46 typedef std::multimap<const TabContents*, long long> TabContentsToFrameIdMap;
47 typedef std::map<long long, bool> FrameIdToErrorStateMap;
48
49 // NotificationObserver implementation.
50 virtual void Observe(NotificationType type,
51 const NotificationSource& source,
52 const NotificationDetails& details);
53
54 // Remove state associated with this tab contents and all of its frames.
yzshen 2010/10/27 17:43:38 Remove -> Removes
55 void RemoveTabContentsState(const TabContents* tab_contents);
56
57 // Tracks which frames belong to a given tab contents object.
58 TabContentsToFrameIdMap tab_contents_map_;
59
60 // Tracks which frames are in an error state. Maps to true, if an error has
61 // occurred in a given frame.
62 FrameIdToErrorStateMap frame_state_map_;
63
64 // Used for tracking registrations to tab contents notifications.
65 NotificationRegistrar registrar_;
66
67 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState);
68 };
69
25 // Observes navigation notifications and routes them as events to the extension 70 // Observes navigation notifications and routes them as events to the extension
26 // system. 71 // system.
27 class ExtensionWebNavigationEventRouter : public NotificationObserver { 72 class ExtensionWebNavigationEventRouter : public NotificationObserver {
28 public: 73 public:
29 // Single instance of the event router. 74 // Single instance of the event router.
30 static ExtensionWebNavigationEventRouter* GetInstance(); 75 static ExtensionWebNavigationEventRouter* GetInstance();
31 76
32 void Init(); 77 void Init();
33 78
34 private: 79 private:
(...skipping 23 matching lines...) Expand all
58 // the details of such an event and constructs a suitable JSON formatted 103 // the details of such an event and constructs a suitable JSON formatted
59 // extension event from it. 104 // extension event from it.
60 void FailProvisionalLoadWithError(NavigationController* controller, 105 void FailProvisionalLoadWithError(NavigationController* controller,
61 ProvisionalLoadDetails* details); 106 ProvisionalLoadDetails* details);
62 107
63 // This method dispatches events to the extension message service. 108 // This method dispatches events to the extension message service.
64 void DispatchEvent(Profile* context, 109 void DispatchEvent(Profile* context,
65 const char* event_name, 110 const char* event_name,
66 const std::string& json_args); 111 const std::string& json_args);
67 112
113 // Tracks the state of the frames we are sending events for.
114 FrameNavigationState navigation_state_;
115
68 // Used for tracking registrations to navigation notifications. 116 // Used for tracking registrations to navigation notifications.
69 NotificationRegistrar registrar_; 117 NotificationRegistrar registrar_;
70 118
71 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationEventRouter); 119 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationEventRouter);
72 }; 120 };
73 121
74 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ 122 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698