1 // Copyright 2015 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 CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_WEB_CONTENTS_OBSERVER_H_
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_WEB_CONTENTS_OBSERVER_H_
8 #include "base/callback.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/browser/web_contents_user_data.h"
13 namespace offline_pages
{
15 // Observes activities occurred in the page that is to be archived.
16 class OfflinePageWebContentsObserver
17 : public content::WebContentsObserver
,
18 public content::WebContentsUserData
<OfflinePageWebContentsObserver
> {
20 ~OfflinePageWebContentsObserver() override
;
22 bool is_document_loaded_in_main_frame() const {
23 return is_document_loaded_in_main_frame_
;
26 void set_main_frame_document_loaded_callback(const base::Closure
& callback
) {
27 main_frame_document_loaded_callback_
= callback
;
30 // content::WebContentsObserver:
31 void DocumentLoadedInFrame(
32 content::RenderFrameHost
* render_frame_host
) override
;
33 void DidNavigateMainFrame(
34 const content::LoadCommittedDetails
& details
,
35 const content::FrameNavigateParams
& params
) override
;
36 void RenderProcessGone(base::TerminationStatus status
) override
;
39 explicit OfflinePageWebContentsObserver(content::WebContents
* web_contents
);
40 friend class content::WebContentsUserData
<OfflinePageWebContentsObserver
>;
42 // Removes the observer and clears the WebContents member.
45 // Tracks whether the document of main frame has been loaded.
46 bool is_document_loaded_in_main_frame_
;
48 base::Closure main_frame_document_loaded_callback_
;
50 DISALLOW_COPY_AND_ASSIGN(OfflinePageWebContentsObserver
);
53 } // namespace offline_pages
55 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_WEB_CONTENTS_OBSERVER_H_