Chromium Code Reviews| Index: components/dom_distiller/content/web_contents_main_frame_observer.cc |
| diff --git a/components/dom_distiller/content/web_contents_main_frame_observer.cc b/components/dom_distiller/content/web_contents_main_frame_observer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f44d7f62179bf9c4d03b3589eac359ba84548790 |
| --- /dev/null |
| +++ b/components/dom_distiller/content/web_contents_main_frame_observer.cc |
| @@ -0,0 +1,60 @@ |
| +// 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), |
| + web_contents_(web_contents) { |
| + content::WebContentsObserver::Observe(web_contents); |
| +} |
| + |
| +WebContentsMainFrameObserver::~WebContentsMainFrameObserver() { |
| +} |
|
Yaron
2014/05/22 18:25:02
Call CleanUp to be safe? (i.e. if you're deleted,
nyquist
2014/05/22 23:00:54
Done.
|
| + |
| +void WebContentsMainFrameObserver::DocumentLoadedInFrame( |
| + int64 frame_id, |
| + content::RenderViewHost* render_view_host) { |
| + if (web_contents_ && |
| + frame_id == web_contents_->GetMainFrame()->GetRoutingID()) { |
| + 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::WebContentsDestroyed() { |
| + CleanUp(); |
| +} |
| + |
| +void WebContentsMainFrameObserver::CleanUp() { |
| + content::WebContentsObserver::Observe(NULL); |
| + web_contents_ = NULL; |
| +} |
| + |
| +} // namespace dom_distiller |