| 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 "components/dom_distiller/content/distiller_page_web_contents.h" | 5 #include "components/dom_distiller/content/distiller_page_web_contents.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 148 |
| 149 void DistillerPageWebContents::DidFailLoad( | 149 void DistillerPageWebContents::DidFailLoad( |
| 150 content::RenderFrameHost* render_frame_host, | 150 content::RenderFrameHost* render_frame_host, |
| 151 const GURL& validated_url, | 151 const GURL& validated_url, |
| 152 int error_code, | 152 int error_code, |
| 153 const base::string16& error_description) { | 153 const base::string16& error_description) { |
| 154 if (!render_frame_host->GetParent()) { | 154 if (!render_frame_host->GetParent()) { |
| 155 content::WebContentsObserver::Observe(NULL); | 155 content::WebContentsObserver::Observe(NULL); |
| 156 DCHECK(state_ == LOADING_PAGE || state_ == EXECUTING_JAVASCRIPT); | 156 DCHECK(state_ == LOADING_PAGE || state_ == EXECUTING_JAVASCRIPT); |
| 157 state_ = PAGELOAD_FAILED; | 157 state_ = PAGELOAD_FAILED; |
| 158 scoped_ptr<base::Value> empty(base::Value::CreateNullValue()); | 158 scoped_ptr<base::Value> empty = base::Value::CreateNullValue(); |
| 159 OnWebContentsDistillationDone(GURL(), empty.get()); | 159 OnWebContentsDistillationDone(GURL(), empty.get()); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 void DistillerPageWebContents::ExecuteJavaScript() { | 163 void DistillerPageWebContents::ExecuteJavaScript() { |
| 164 content::RenderFrameHost* frame = web_contents_->GetMainFrame(); | 164 content::RenderFrameHost* frame = web_contents_->GetMainFrame(); |
| 165 DCHECK(frame); | 165 DCHECK(frame); |
| 166 DCHECK_EQ(LOADING_PAGE, state_); | 166 DCHECK_EQ(LOADING_PAGE, state_); |
| 167 state_ = EXECUTING_JAVASCRIPT; | 167 state_ = EXECUTING_JAVASCRIPT; |
| 168 content::WebContentsObserver::Observe(NULL); | 168 content::WebContentsObserver::Observe(NULL); |
| 169 web_contents_->Stop(); | 169 web_contents_->Stop(); |
| 170 DVLOG(1) << "Beginning distillation"; | 170 DVLOG(1) << "Beginning distillation"; |
| 171 frame->ExecuteJavaScript( | 171 frame->ExecuteJavaScript( |
| 172 base::UTF8ToUTF16(script_), | 172 base::UTF8ToUTF16(script_), |
| 173 base::Bind(&DistillerPageWebContents::OnWebContentsDistillationDone, | 173 base::Bind(&DistillerPageWebContents::OnWebContentsDistillationDone, |
| 174 base::Unretained(this), | 174 base::Unretained(this), |
| 175 web_contents_->GetLastCommittedURL())); | 175 web_contents_->GetLastCommittedURL())); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void DistillerPageWebContents::OnWebContentsDistillationDone( | 178 void DistillerPageWebContents::OnWebContentsDistillationDone( |
| 179 const GURL& page_url, | 179 const GURL& page_url, |
| 180 const base::Value* value) { | 180 const base::Value* value) { |
| 181 DCHECK(state_ == PAGELOAD_FAILED || state_ == EXECUTING_JAVASCRIPT); | 181 DCHECK(state_ == PAGELOAD_FAILED || state_ == EXECUTING_JAVASCRIPT); |
| 182 state_ = IDLE; | 182 state_ = IDLE; |
| 183 DistillerPage::OnDistillationDone(page_url, value); | 183 DistillerPage::OnDistillationDone(page_url, value); |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace dom_distiller | 186 } // namespace dom_distiller |
| OLD | NEW |