| // Copyright 2014 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "components/dom_distiller/content/web_contents_main_frame_observer.h" |
| |
| #include "content/public/browser/navigation_details.h" |
| #include "content/public/browser/render_frame_host.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_observer.h" |
| #include "content/public/browser/web_contents_user_data.h" |
| |
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(dom_distiller::WebContentsMainFrameObserver); |
| |
| namespace dom_distiller { |
| |
| WebContentsMainFrameObserver::WebContentsMainFrameObserver( |
| content::WebContents* web_contents) |
| : is_document_loaded_in_main_frame_(false), is_initialized_(false) { |
| content::WebContentsObserver::Observe(web_contents); |
| } |
| |
| WebContentsMainFrameObserver::~WebContentsMainFrameObserver() { |
| CleanUp(); |
| } |
| |
| void WebContentsMainFrameObserver::DocumentLoadedInFrame( |
| content::RenderFrameHost* render_frame_host) { |
| if (!render_frame_host->GetParent()) { |
| is_document_loaded_in_main_frame_ = true; |
| } |
| } |
| |
| void WebContentsMainFrameObserver::DidNavigateMainFrame( |
| const content::LoadCommittedDetails& details, |
| const content::FrameNavigateParams& params) { |
| if (details.is_main_frame) { |
| is_document_loaded_in_main_frame_ = false; |
| is_initialized_ = true; |
| } |
| } |
| |
| void WebContentsMainFrameObserver::RenderProcessGone( |
| base::TerminationStatus status) { |
| CleanUp(); |
| } |
| |
| void WebContentsMainFrameObserver::CleanUp() { |
| content::WebContentsObserver::Observe(NULL); |
| } |
| |
| } // namespace dom_distiller |