Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / android / offline_pages / offline_page_web_contents_observer.cc
blob57b1679639f1996bbb8753ddb64d39e88f74d21d
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 #include "chrome/browser/android/offline_pages/offline_page_web_contents_observer.h"
7 #include "content/public/browser/navigation_details.h"
8 #include "content/public/browser/render_frame_host.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 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
14 offline_pages::OfflinePageWebContentsObserver);
16 namespace offline_pages {
18 OfflinePageWebContentsObserver::OfflinePageWebContentsObserver(
19 content::WebContents* web_contents)
20 : content::WebContentsObserver(web_contents),
21 is_document_loaded_in_main_frame_(false) {
24 OfflinePageWebContentsObserver::~OfflinePageWebContentsObserver() {
27 void OfflinePageWebContentsObserver::DocumentLoadedInFrame(
28 content::RenderFrameHost* render_frame_host) {
29 if (!render_frame_host->GetParent()) {
30 is_document_loaded_in_main_frame_ = true;
31 if (!main_frame_document_loaded_callback_.is_null())
32 main_frame_document_loaded_callback_.Run();
36 void OfflinePageWebContentsObserver::DidNavigateMainFrame(
37 const content::LoadCommittedDetails& details,
38 const content::FrameNavigateParams& params) {
39 if (details.is_navigation_to_different_page())
40 is_document_loaded_in_main_frame_ = false;
43 void OfflinePageWebContentsObserver::RenderProcessGone(
44 base::TerminationStatus status) {
45 CleanUp();
48 void OfflinePageWebContentsObserver::CleanUp() {
49 content::WebContentsObserver::Observe(nullptr);
52 } // namespace offline_pages