Don't preload rarely seen large images
[chromium-blink-merge.git] / components / dom_distiller / content / web_contents_main_frame_observer.h
blobe1a62990a528686fa4547a07433093509e74f319
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.
5 #ifndef COMPONENTS_DOM_DISTILLER_CONTENT_WEB_CONTENTS_MAIN_FRAME_OBSERVER_H_
6 #define COMPONENTS_DOM_DISTILLER_CONTENT_WEB_CONTENTS_MAIN_FRAME_OBSERVER_H_
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"
12 namespace dom_distiller {
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 ~WebContentsMainFrameObserver() override;
23 bool is_document_loaded_in_main_frame() {
24 return is_document_loaded_in_main_frame_;
27 bool is_initialized() { return is_initialized_; }
29 // content::WebContentsObserver implementation.
30 void DocumentLoadedInFrame(
31 content::RenderFrameHost* render_frame_host) override;
32 void DidNavigateMainFrame(
33 const content::LoadCommittedDetails& details,
34 const content::FrameNavigateParams& params) override;
35 void RenderProcessGone(base::TerminationStatus status) override;
37 private:
38 explicit WebContentsMainFrameObserver(content::WebContents* web_contents);
39 friend class content::WebContentsUserData<WebContentsMainFrameObserver>;
41 // Removes the observer and clears the WebContents member.
42 void CleanUp();
44 // Whether DocumentLoadedInFrame has been called for the tracked WebContents
45 // for the current main frame. This is cleared when the main frame navigates,
46 // and set again when DocumentLoadedInFrame is called for the main frame.
47 bool is_document_loaded_in_main_frame_;
49 // Whether this object has been correctly initialized. This is set as soon as
50 // at least one call to DidNavigateMainFrame has happened.
51 bool is_initialized_;
53 DISALLOW_COPY_AND_ASSIGN(WebContentsMainFrameObserver);
56 } // namespace dom_distiller
58 #endif // COMPONENTS_DOM_DISTILLER_CONTENT_WEB_CONTENTS_MAIN_FRAME_OBSERVER_H_