Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Unified Diff: components/dom_distiller/content/web_contents_main_frame_observer.cc

Issue 266073003: Add support for distilling current WebContents (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ed1bbab54913297f32b046d9b02ff7f8bfdcaa22
--- /dev/null
+++ b/components/dom_distiller/content/web_contents_main_frame_observer.cc
@@ -0,0 +1,61 @@
+// 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() {
+ CleanUp();
+}
+
+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
« no previous file with comments | « components/dom_distiller/content/web_contents_main_frame_observer.h ('k') | components/dom_distiller/core/distiller_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698