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

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

Issue 266073003: Add support for distilling current WebContents (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added comment 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.h
diff --git a/components/dom_distiller/content/web_contents_main_frame_observer.h b/components/dom_distiller/content/web_contents_main_frame_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..4f7a3bbf102491891995265ca48b362b6b5f33de
--- /dev/null
+++ b/components/dom_distiller/content/web_contents_main_frame_observer.h
@@ -0,0 +1,65 @@
+// 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.
+
+#ifndef COMPONENTS_DOM_DISTILLER_CONTENT_INJECTION_WEB_CONTENTS_OBSERVER_H_
Yaron 2014/05/16 02:02:49 nit: update
nyquist 2014/05/20 19:58:37 Done.
+#define COMPONENTS_DOM_DISTILLER_CONTENT_INJECTION_WEB_CONTENTS_OBSERVER_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"
+
+namespace dom_distiller {
+
+// Tracks whether DocumentLoadedInFrame has been called for the main frame for
+// the current main frame for the given WebContents. It removes itself as an
+// observer if the WebContents is destroyed or the render process is gone.
+class WebContentsMainFrameObserver
+ : public content::WebContentsObserver,
+ public content::WebContentsUserData<WebContentsMainFrameObserver> {
+ public:
+ virtual ~WebContentsMainFrameObserver();
+
+ bool is_document_loaded_in_main_frame() {
+ return is_document_loaded_in_main_frame_;
+ }
+
+ bool is_initialized() {
+ return is_initialized_;
+ }
+
+ // content::WebContentsObserver implementation.
+ virtual void DocumentLoadedInFrame(
+ int64 frame_id,
+ content::RenderViewHost* render_view_host) OVERRIDE;
+ virtual void DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) OVERRIDE;
+ virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
+ virtual void WebContentsDestroyed() OVERRIDE;
+
+ private:
+ explicit WebContentsMainFrameObserver(content::WebContents* web_contents);
+ friend class content::WebContentsUserData<WebContentsMainFrameObserver>;
+
+ // Removes the observer and clears the WebContents member.
+ void CleanUp();
+
+ // Whether DocumentLoadedInFrame has been called for the tracked WebContents
+ // for the current main frame. This is cleared when the main frame navigates,
+ // and set again when DocumentLoadedInFrame is called for the main frame.
+ bool is_document_loaded_in_main_frame_;
+
+ // Whether this object has been correctly initialized. This is set as soon as
+ // at least one call to DidNavigateMainFrame has happened.
+ bool is_initialized_;
+
+ // The WebContents this class is tracking.
+ content::WebContents* web_contents_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebContentsMainFrameObserver);
+};
+
+} // namespace dom_distiller
+
+#endif // COMPONENTS_DOM_DISTILLER_CONTENT_INJECTION_WEB_CONTENTS_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698