• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef COMPONENTS_DOM_DISTILLER_CONTENT_WEB_CONTENTS_MAIN_FRAME_OBSERVER_H_
6 #define COMPONENTS_DOM_DISTILLER_CONTENT_WEB_CONTENTS_MAIN_FRAME_OBSERVER_H_
7 
8 #include "content/public/browser/web_contents.h"
9 #include "content/public/browser/web_contents_observer.h"
10 #include "content/public/browser/web_contents_user_data.h"
11 
12 namespace dom_distiller {
13 
14 // Tracks whether DocumentLoadedInFrame has been called for the main frame for
15 // the current main frame for the given WebContents. It removes itself as an
16 // observer if the WebContents is destroyed or the render process is gone.
17 class WebContentsMainFrameObserver
18     : public content::WebContentsObserver,
19       public content::WebContentsUserData<WebContentsMainFrameObserver> {
20  public:
21   virtual ~WebContentsMainFrameObserver();
22 
is_document_loaded_in_main_frame()23   bool is_document_loaded_in_main_frame() {
24     return is_document_loaded_in_main_frame_;
25   }
26 
is_initialized()27   bool is_initialized() { return is_initialized_; }
28 
29   // content::WebContentsObserver implementation.
30   virtual void DocumentLoadedInFrame(
31       int64 frame_id,
32       content::RenderViewHost* render_view_host) OVERRIDE;
33   virtual void DidNavigateMainFrame(
34       const content::LoadCommittedDetails& details,
35       const content::FrameNavigateParams& params) OVERRIDE;
36   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
37   virtual void WebContentsDestroyed() OVERRIDE;
38 
39  private:
40   explicit WebContentsMainFrameObserver(content::WebContents* web_contents);
41   friend class content::WebContentsUserData<WebContentsMainFrameObserver>;
42 
43   // Removes the observer and clears the WebContents member.
44   void CleanUp();
45 
46   // Whether DocumentLoadedInFrame has been called for the tracked WebContents
47   // for the current main frame. This is cleared when the main frame navigates,
48   // and set again when DocumentLoadedInFrame is called for the main frame.
49   bool is_document_loaded_in_main_frame_;
50 
51   // Whether this object has been correctly initialized. This is set as soon as
52   // at least one call to DidNavigateMainFrame has happened.
53   bool is_initialized_;
54 
55   // The WebContents this class is tracking.
56   content::WebContents* web_contents_;
57 
58   DISALLOW_COPY_AND_ASSIGN(WebContentsMainFrameObserver);
59 };
60 
61 }  // namespace dom_distiller
62 
63 #endif  // COMPONENTS_DOM_DISTILLER_CONTENT_WEB_CONTENTS_MAIN_FRAME_OBSERVER_H_
64