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/webui/dom_distiller_handler.h" | 5 #include "components/dom_distiller/webui/dom_distiller_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "components/dom_distiller/core/dom_distiller_service.h" | 11 #include "components/dom_distiller/core/dom_distiller_service.h" |
12 #include "components/dom_distiller/core/proto/distilled_page.pb.h" | 12 #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
13 #include "content/public/browser/web_contents.h" | |
13 #include "content/public/browser/web_ui.h" | 14 #include "content/public/browser/web_ui.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 namespace dom_distiller { | 17 namespace dom_distiller { |
17 | 18 |
18 DomDistillerHandler::DomDistillerHandler(DomDistillerService* service, | 19 DomDistillerHandler::DomDistillerHandler(DomDistillerService* service, |
19 const std::string& scheme) | 20 const std::string& scheme) |
20 : service_(service), article_scheme_(scheme), weak_ptr_factory_(this) {} | 21 : service_(service), article_scheme_(scheme), weak_ptr_factory_(this) {} |
21 | 22 |
22 DomDistillerHandler::~DomDistillerHandler() {} | 23 DomDistillerHandler::~DomDistillerHandler() {} |
(...skipping 23 matching lines...) Expand all Loading... | |
46 base::Bind(base::Bind(&DomDistillerHandler::OnArticleAdded, | 47 base::Bind(base::Bind(&DomDistillerHandler::OnArticleAdded, |
47 base::Unretained(this)))); | 48 base::Unretained(this)))); |
48 } else { | 49 } else { |
49 web_ui()->CallJavascriptFunction("domDistiller.onArticleAddFailed"); | 50 web_ui()->CallJavascriptFunction("domDistiller.onArticleAddFailed"); |
50 } | 51 } |
51 } | 52 } |
52 | 53 |
53 void DomDistillerHandler::HandleSelectArticle(const base::ListValue* args) { | 54 void DomDistillerHandler::HandleSelectArticle(const base::ListValue* args) { |
54 std::string entry_id; | 55 std::string entry_id; |
55 args->GetString(0, &entry_id); | 56 args->GetString(0, &entry_id); |
56 | 57 GURL url(article_scheme_ + std::string("://") + entry_id); |
57 // TODO(nyquist): Do something here. | 58 DCHECK(url.is_valid()); |
59 web_ui()->GetWebContents()->GetController().LoadURL(url, | |
60 content::Referrer(), content::PAGE_TRANSITION_GENERATED, | |
jam
2014/01/24 22:07:55
nit: indentation
nyquist
2014/01/25 00:40:38
Done.
| |
61 std::string()); | |
58 } | 62 } |
59 | 63 |
60 void DomDistillerHandler::HandleRequestEntries(const base::ListValue* args) { | 64 void DomDistillerHandler::HandleRequestEntries(const base::ListValue* args) { |
61 base::ListValue entries; | 65 base::ListValue entries; |
62 const std::vector<ArticleEntry>& entries_specifics = service_->GetEntries(); | 66 const std::vector<ArticleEntry>& entries_specifics = service_->GetEntries(); |
63 for (std::vector<ArticleEntry>::const_iterator it = entries_specifics.begin(); | 67 for (std::vector<ArticleEntry>::const_iterator it = entries_specifics.begin(); |
64 it != entries_specifics.end(); | 68 it != entries_specifics.end(); |
65 ++it) { | 69 ++it) { |
66 const ArticleEntry& article = *it; | 70 const ArticleEntry& article = *it; |
67 DCHECK(IsEntryValid(article)); | 71 DCHECK(IsEntryValid(article)); |
(...skipping 11 matching lines...) Expand all Loading... | |
79 void DomDistillerHandler::OnArticleAdded(bool article_available) { | 83 void DomDistillerHandler::OnArticleAdded(bool article_available) { |
80 // TODO(nyquist): Update this function. | 84 // TODO(nyquist): Update this function. |
81 if (article_available) { | 85 if (article_available) { |
82 HandleRequestEntries(NULL); | 86 HandleRequestEntries(NULL); |
83 } else { | 87 } else { |
84 web_ui()->CallJavascriptFunction("domDistiller.onArticleAddFailed"); | 88 web_ui()->CallJavascriptFunction("domDistiller.onArticleAddFailed"); |
85 } | 89 } |
86 } | 90 } |
87 | 91 |
88 } // namespace dom_distiller | 92 } // namespace dom_distiller |
OLD | NEW |