OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/memory/weak_ptr.h" | 5 #include "base/memory/weak_ptr.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "components/dom_distiller/content/distiller_page_web_contents.h" | 9 #include "components/dom_distiller/content/distiller_page_web_contents.h" |
10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" | 10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 // Helper class to know how far in the loading process the current WebContents | 125 // Helper class to know how far in the loading process the current WebContents |
126 // has come. It will call the callback either after | 126 // has come. It will call the callback either after |
127 // DidCommitProvisionalLoadForFrame or DocumentLoadedInFrame is called for the | 127 // DidCommitProvisionalLoadForFrame or DocumentLoadedInFrame is called for the |
128 // main frame, based on the value of |wait_for_document_loaded|. | 128 // main frame, based on the value of |wait_for_document_loaded|. |
129 class WebContentsMainFrameHelper : public content::WebContentsObserver { | 129 class WebContentsMainFrameHelper : public content::WebContentsObserver { |
130 public: | 130 public: |
131 WebContentsMainFrameHelper(content::WebContents* web_contents, | 131 WebContentsMainFrameHelper(content::WebContents* web_contents, |
132 const base::Closure& callback, | 132 const base::Closure& callback, |
133 bool wait_for_document_loaded) | 133 bool wait_for_document_loaded) |
134 : web_contents_(web_contents), | 134 : WebContentsObserver(web_contents), |
135 callback_(callback), | 135 callback_(callback), |
136 wait_for_document_loaded_(wait_for_document_loaded) { | 136 wait_for_document_loaded_(wait_for_document_loaded) {} |
137 content::WebContentsObserver::Observe(web_contents); | |
138 } | |
139 | 137 |
140 virtual void DidCommitProvisionalLoadForFrame( | 138 virtual void DidCommitProvisionalLoadForFrame( |
141 content::RenderFrameHost* render_frame_host, | 139 content::RenderFrameHost* render_frame_host, |
142 const GURL& url, | 140 const GURL& url, |
143 content::PageTransition transition_type) OVERRIDE { | 141 content::PageTransition transition_type) OVERRIDE { |
144 if (wait_for_document_loaded_) | 142 if (wait_for_document_loaded_) |
145 return; | 143 return; |
146 if (!render_frame_host->GetParent()) | 144 if (!render_frame_host->GetParent()) |
147 callback_.Run(); | 145 callback_.Run(); |
148 } | 146 } |
149 | 147 |
150 virtual void DocumentLoadedInFrame( | 148 virtual void DocumentLoadedInFrame( |
151 int64 frame_id, | 149 content::RenderFrameHost* render_frame_host) OVERRIDE { |
152 content::RenderViewHost* render_view_host) OVERRIDE { | |
153 if (wait_for_document_loaded_) { | 150 if (wait_for_document_loaded_) { |
154 if (web_contents_ && | 151 if (!render_frame_host->GetParent()) |
155 frame_id == web_contents_->GetMainFrame()->GetRoutingID()) { | |
156 callback_.Run(); | 152 callback_.Run(); |
157 } | |
158 } | 153 } |
159 } | 154 } |
160 | 155 |
161 private: | 156 private: |
162 content::WebContents* web_contents_; | |
163 base::Closure callback_; | 157 base::Closure callback_; |
164 bool wait_for_document_loaded_; | 158 bool wait_for_document_loaded_; |
165 }; | 159 }; |
166 | 160 |
167 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, BasicDistillationWorks) { | 161 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, BasicDistillationWorks) { |
168 DistillerPageWebContents distiller_page( | 162 DistillerPageWebContents distiller_page( |
169 shell()->web_contents()->GetBrowserContext(), | 163 shell()->web_contents()->GetBrowserContext(), |
170 scoped_ptr<SourcePageHandleWebContents>()); | 164 scoped_ptr<SourcePageHandleWebContents>()); |
171 distiller_page_ = &distiller_page; | 165 distiller_page_ = &distiller_page; |
172 | 166 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 base::RunLoop run_loop; | 341 base::RunLoop run_loop; |
348 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); | 342 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); |
349 run_loop.Run(); | 343 run_loop.Run(); |
350 | 344 |
351 // Sanity check of distillation process. | 345 // Sanity check of distillation process. |
352 EXPECT_EQ(expect_new_web_contents, distiller_page.new_web_contents_created()); | 346 EXPECT_EQ(expect_new_web_contents, distiller_page.new_web_contents_created()); |
353 EXPECT_EQ("Test Page Title", page_info_.get()->title); | 347 EXPECT_EQ("Test Page Title", page_info_.get()->title); |
354 } | 348 } |
355 | 349 |
356 } // namespace dom_distiller | 350 } // namespace dom_distiller |
OLD | NEW |