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 #ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ | 5 #ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ |
6 #define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ | 6 #define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ |
7 | 7 |
8 #include "content/browser/tab_contents/navigation_controller.h" | 8 #include "content/browser/tab_contents/navigation_controller.h" |
9 #include "ipc/ipc_channel.h" | 9 #include "ipc/ipc_channel.h" |
10 | 10 |
11 struct ViewHostMsg_FrameNavigate_Params; | 11 struct ViewHostMsg_FrameNavigate_Params; |
12 | 12 |
13 // An observer API implemented by classes which are interested in various page | 13 // An observer API implemented by classes which are interested in various page |
14 // load events from TabContents. They also get a chance to filter IPC messages. | 14 // load events from TabContents. They also get a chance to filter IPC messages. |
15 class TabContentsObserver : public IPC::Channel::Listener { | 15 class TabContentsObserver : public IPC::Channel::Listener, |
16 public IPC::Message::Sender { | |
16 public: | 17 public: |
18 // Use this as a member variable in a class that uses the emptry constructor | |
Matt Perry
2011/04/05 19:18:33
nit: empty
jam
2011/04/05 19:25:38
Done.
| |
19 // version of this interface. | |
20 class Registrar { | |
21 public: | |
22 explicit Registrar(TabContentsObserver* observer); | |
23 ~Registrar(); | |
24 | |
25 // Call this to start observing a tab. Passing in NULL resets it. | |
26 // This can only be used to watch one tab at a time. If you call this and | |
27 // you're already observing another tab, the old tab won't be observed | |
28 // afterwards. | |
29 void Observe(TabContents* tab); | |
30 | |
31 private: | |
32 TabContentsObserver* observer_; | |
33 TabContents* tab_; | |
34 | |
35 DISALLOW_COPY_AND_ASSIGN(Registrar); | |
36 }; | |
37 | |
17 virtual void NavigateToPendingEntry(); | 38 virtual void NavigateToPendingEntry(); |
18 | 39 |
19 virtual void DidNavigateMainFramePostCommit( | 40 virtual void DidNavigateMainFramePostCommit( |
20 const NavigationController::LoadCommittedDetails& details, | 41 const NavigationController::LoadCommittedDetails& details, |
21 const ViewHostMsg_FrameNavigate_Params& params); | 42 const ViewHostMsg_FrameNavigate_Params& params); |
22 virtual void DidNavigateAnyFramePostCommit( | 43 virtual void DidNavigateAnyFramePostCommit( |
23 const NavigationController::LoadCommittedDetails& details, | 44 const NavigationController::LoadCommittedDetails& details, |
24 const ViewHostMsg_FrameNavigate_Params& params); | 45 const ViewHostMsg_FrameNavigate_Params& params); |
25 virtual void OnProvisionalChangeToMainFrameUrl(const GURL& url); | 46 virtual void OnProvisionalChangeToMainFrameUrl(const GURL& url); |
26 | 47 |
(...skipping 11 matching lines...) Expand all Loading... | |
38 virtual void LoadingStateChanged(TabContents* contents) { } | 59 virtual void LoadingStateChanged(TabContents* contents) { } |
39 // Called to inform the delegate that the tab content's navigation state | 60 // Called to inform the delegate that the tab content's navigation state |
40 // changed. The |changed_flags| indicates the parts of the navigation state | 61 // changed. The |changed_flags| indicates the parts of the navigation state |
41 // that have been updated, and is any combination of the | 62 // that have been updated, and is any combination of the |
42 // |TabContents::InvalidateTypes| bits. | 63 // |TabContents::InvalidateTypes| bits. |
43 virtual void NavigationStateChanged(const TabContents* source, | 64 virtual void NavigationStateChanged(const TabContents* source, |
44 unsigned changed_flags) { } | 65 unsigned changed_flags) { } |
45 #endif | 66 #endif |
46 | 67 |
47 protected: | 68 protected: |
69 // Use this constructor when the object is tied to a single TabContents for | |
70 // its entire lifetime. | |
48 explicit TabContentsObserver(TabContents* tab_contents); | 71 explicit TabContentsObserver(TabContents* tab_contents); |
72 | |
73 // Use this constructor when the object wants to observe a TabContents for | |
74 // part of its lifetime. It can use a TabContentsRegistrar member variable | |
75 // to start and stop observing. | |
76 TabContentsObserver(); | |
77 | |
49 virtual ~TabContentsObserver(); | 78 virtual ~TabContentsObserver(); |
50 | 79 |
51 // Invoked when the TabContents is being destroyed. Gives subclasses a chance | 80 // Invoked when the TabContents is being destroyed. Gives subclasses a chance |
52 // to cleanup. At the time this is invoked |tab_contents()| returns NULL. | 81 // to cleanup. At the time this is invoked |tab_contents()| returns NULL. |
53 // It is safe to delete 'this' from here. | 82 // It is safe to delete 'this' from here. |
54 virtual void OnTabContentsDestroyed(TabContents* tab); | 83 virtual void OnTabContentsDestroyed(TabContents* tab); |
55 | 84 |
56 // IPC::Channel::Listener implementation. | 85 // IPC::Channel::Listener implementation. |
57 virtual bool OnMessageReceived(const IPC::Message& message); | 86 virtual bool OnMessageReceived(const IPC::Message& message); |
58 | 87 |
59 // IPC::Message::Sender implementation. | 88 // IPC::Message::Sender implementation. |
60 virtual bool Send(IPC::Message* message); | 89 virtual bool Send(IPC::Message* message); |
61 | 90 |
62 TabContents* tab_contents() const { return tab_contents_; } | 91 TabContents* tab_contents() const { return tab_contents_; } |
63 int routing_id() const { return routing_id_; } | 92 int routing_id() const { return routing_id_; } |
64 | 93 |
94 protected: | |
95 friend class Registrar; | |
96 | |
97 void SetTabContents(TabContents* tab_contents); | |
98 | |
65 private: | 99 private: |
66 friend class TabContents; | 100 friend class TabContents; |
67 | 101 |
68 // Invoked from TabContents. Invokes OnTabContentsDestroyed and NULL out | 102 // Invoked from TabContents. Invokes OnTabContentsDestroyed and NULL out |
69 // |tab_contents_|. | 103 // |tab_contents_|. |
70 void TabContentsDestroyed(); | 104 void TabContentsDestroyed(); |
71 | 105 |
72 TabContents* tab_contents_; | 106 TabContents* tab_contents_; |
73 | 107 |
74 // The routing ID of the associated TabContents. | 108 // The routing ID of the associated TabContents. |
75 int routing_id_; | 109 int routing_id_; |
76 | 110 |
77 DISALLOW_COPY_AND_ASSIGN(TabContentsObserver); | 111 DISALLOW_COPY_AND_ASSIGN(TabContentsObserver); |
78 }; | 112 }; |
79 | 113 |
80 #endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ | 114 #endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ |
OLD | NEW |