| 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/core/page_distiller.h" | 5 #include "components/dom_distiller/core/page_distiller.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 void PageDistiller::OnExecuteJavaScriptDone(const GURL& page_url, | 58 void PageDistiller::OnExecuteJavaScriptDone(const GURL& page_url, |
| 59 const base::Value* value) { | 59 const base::Value* value) { |
| 60 DVLOG(1) << "Distillation complete; extracting resources for " | 60 DVLOG(1) << "Distillation complete; extracting resources for " |
| 61 << page_url.spec(); | 61 << page_url.spec(); |
| 62 | 62 |
| 63 scoped_ptr<DistilledPageInfo> page_info(new DistilledPageInfo()); | 63 scoped_ptr<DistilledPageInfo> page_info(new DistilledPageInfo()); |
| 64 std::string result; | 64 std::string result; |
| 65 const base::ListValue* result_list = NULL; | 65 const base::ListValue* result_list = NULL; |
| 66 bool found_content = false; |
| 66 if (!value->GetAsList(&result_list)) { | 67 if (!value->GetAsList(&result_list)) { |
| 67 base::MessageLoop::current()->PostTask( | 68 base::MessageLoop::current()->PostTask( |
| 68 FROM_HERE, | 69 FROM_HERE, |
| 69 base::Bind(page_distiller_callback_, base::Passed(&page_info), false)); | 70 base::Bind(page_distiller_callback_, base::Passed(&page_info), false)); |
| 70 } else { | 71 } else { |
| 71 int i = 0; | 72 int i = 0; |
| 72 for (base::ListValue::const_iterator iter = result_list->begin(); | 73 for (base::ListValue::const_iterator iter = result_list->begin(); |
| 73 iter != result_list->end(); | 74 iter != result_list->end(); |
| 74 ++iter, ++i) { | 75 ++iter, ++i) { |
| 75 std::string item; | 76 std::string item; |
| 76 (*iter)->GetAsString(&item); | 77 (*iter)->GetAsString(&item); |
| 77 // The JavaScript returns an array where the first element is the title, | 78 // The JavaScript returns an array where the first element is the title, |
| 78 // the second element is the article content HTML, and the remaining | 79 // the second element is the article content HTML, and the remaining |
| 79 // elements are image URLs referenced in the HTML. | 80 // elements are image URLs referenced in the HTML. |
| 80 switch (i) { | 81 switch (i) { |
| 81 case 0: | 82 case 0: |
| 82 page_info->title = item; | 83 page_info->title = item; |
| 83 break; | 84 break; |
| 84 case 1: | 85 case 1: |
| 85 page_info->html = item; | 86 page_info->html = item; |
| 87 found_content = true; |
| 86 break; | 88 break; |
| 87 case 2: | 89 case 2: |
| 88 page_info->next_page_url = item; | 90 page_info->next_page_url = item; |
| 89 break; | 91 break; |
| 90 case 3: | 92 case 3: |
| 91 page_info->prev_page_url = item; | 93 page_info->prev_page_url = item; |
| 92 break; | 94 break; |
| 93 default: | 95 default: |
| 94 page_info->image_urls.push_back(item); | 96 GURL unvalidated_gurl(item); |
| 97 if (!unvalidated_gurl.is_empty() && unvalidated_gurl.is_valid()) { |
| 98 page_info->image_urls.push_back(item); |
| 99 } |
| 95 } | 100 } |
| 96 } | 101 } |
| 97 base::MessageLoop::current()->PostTask( | 102 base::MessageLoop::current()->PostTask( |
| 98 FROM_HERE, | 103 FROM_HERE, |
| 99 base::Bind(page_distiller_callback_, base::Passed(&page_info), true)); | 104 base::Bind(page_distiller_callback_, |
| 105 base::Passed(&page_info), |
| 106 found_content)); |
| 100 } | 107 } |
| 101 } | 108 } |
| 102 | 109 |
| 103 } // namespace dom_distiller | 110 } // namespace dom_distiller |
| OLD | NEW |