OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" | 5 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" |
6 | 6 |
7 #include "content/public/browser/navigation_details.h" | 7 #include "content/public/browser/navigation_details.h" |
8 #include "content/public/browser/render_frame_host.h" | 8 #include "content/public/browser/render_frame_host.h" |
9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "content/public/browser/web_contents_observer.h" | 10 #include "content/public/browser/web_contents_observer.h" |
11 #include "content/public/browser/web_contents_user_data.h" | 11 #include "content/public/browser/web_contents_user_data.h" |
12 | 12 |
13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(dom_distiller::WebContentsMainFrameObserver); | 13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(dom_distiller::WebContentsMainFrameObserver); |
14 | 14 |
15 namespace dom_distiller { | 15 namespace dom_distiller { |
16 | 16 |
17 WebContentsMainFrameObserver::WebContentsMainFrameObserver( | 17 WebContentsMainFrameObserver::WebContentsMainFrameObserver( |
18 content::WebContents* web_contents) | 18 content::WebContents* web_contents) |
19 : is_document_loaded_in_main_frame_(false), | 19 : is_document_loaded_in_main_frame_(false), is_initialized_(false) { |
20 is_initialized_(false), | |
21 web_contents_(web_contents) { | |
22 content::WebContentsObserver::Observe(web_contents); | 20 content::WebContentsObserver::Observe(web_contents); |
23 } | 21 } |
24 | 22 |
25 WebContentsMainFrameObserver::~WebContentsMainFrameObserver() { | 23 WebContentsMainFrameObserver::~WebContentsMainFrameObserver() { |
26 CleanUp(); | 24 CleanUp(); |
27 } | 25 } |
28 | 26 |
29 void WebContentsMainFrameObserver::DocumentLoadedInFrame( | 27 void WebContentsMainFrameObserver::DocumentLoadedInFrame( |
30 int64 frame_id, | 28 content::RenderFrameHost* render_frame_host) { |
31 content::RenderViewHost* render_view_host) { | 29 if (!render_frame_host->GetParent()) { |
32 if (web_contents_ && | |
33 frame_id == web_contents_->GetMainFrame()->GetRoutingID()) { | |
34 is_document_loaded_in_main_frame_ = true; | 30 is_document_loaded_in_main_frame_ = true; |
35 } | 31 } |
36 } | 32 } |
37 | 33 |
38 void WebContentsMainFrameObserver::DidNavigateMainFrame( | 34 void WebContentsMainFrameObserver::DidNavigateMainFrame( |
39 const content::LoadCommittedDetails& details, | 35 const content::LoadCommittedDetails& details, |
40 const content::FrameNavigateParams& params) { | 36 const content::FrameNavigateParams& params) { |
41 if (details.is_main_frame) { | 37 if (details.is_main_frame) { |
42 is_document_loaded_in_main_frame_ = false; | 38 is_document_loaded_in_main_frame_ = false; |
43 is_initialized_ = true; | 39 is_initialized_ = true; |
44 } | 40 } |
45 } | 41 } |
46 | 42 |
47 void WebContentsMainFrameObserver::RenderProcessGone( | 43 void WebContentsMainFrameObserver::RenderProcessGone( |
48 base::TerminationStatus status) { | 44 base::TerminationStatus status) { |
49 CleanUp(); | 45 CleanUp(); |
50 } | 46 } |
51 | 47 |
52 void WebContentsMainFrameObserver::WebContentsDestroyed() { | |
53 CleanUp(); | |
54 } | |
55 | |
56 void WebContentsMainFrameObserver::CleanUp() { | 48 void WebContentsMainFrameObserver::CleanUp() { |
57 content::WebContentsObserver::Observe(NULL); | 49 content::WebContentsObserver::Observe(NULL); |
58 web_contents_ = NULL; | |
59 } | 50 } |
60 | 51 |
61 } // namespace dom_distiller | 52 } // namespace dom_distiller |
OLD | NEW |