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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "components/dom_distiller/core/dom_distiller_service.h" | 9 #include "components/dom_distiller/core/dom_distiller_service.h" |
10 #include "components/dom_distiller/core/proto/distilled_page.pb.h" | 10 #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
11 #include "content/public/browser/web_contents.h" | |
11 #include "content/public/browser/web_ui.h" | 12 #include "content/public/browser/web_ui.h" |
12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
13 | 14 |
14 namespace dom_distiller { | 15 namespace dom_distiller { |
15 | 16 |
16 DomDistillerHandler::DomDistillerHandler(DomDistillerService* service, | 17 DomDistillerHandler::DomDistillerHandler(DomDistillerService* service, |
17 const std::string& scheme) | 18 const std::string& scheme) |
18 : weak_ptr_factory_(this), | 19 : weak_ptr_factory_(this), |
19 service_(service) { | 20 service_(service) { |
20 article_scheme_ = scheme; | 21 article_scheme_ = scheme; |
(...skipping 23 matching lines...) Expand all Loading... | |
44 if (gurl.is_valid()) | 45 if (gurl.is_valid()) |
45 service_->AddToList(gurl); | 46 service_->AddToList(gurl); |
46 else | 47 else |
47 web_ui()->CallJavascriptFunction("domDistiller.onArticleAddFailed"); | 48 web_ui()->CallJavascriptFunction("domDistiller.onArticleAddFailed"); |
48 } | 49 } |
49 | 50 |
50 void DomDistillerHandler::HandleSelectArticle(const ListValue* args) { | 51 void DomDistillerHandler::HandleSelectArticle(const ListValue* args) { |
51 std::string entry_id; | 52 std::string entry_id; |
52 args->GetString(0, &entry_id); | 53 args->GetString(0, &entry_id); |
53 | 54 |
54 // TODO(nyquist): Do something here. | 55 GURL url(article_scheme_ + std::string("://") + entry_id); |
56 DCHECK(url.is_valid()); | |
57 web_ui()->GetWebContents()->GetController().LoadURL(url, | |
Tom Sepez
2013/12/05 19:25:52
@creis - would this load into the same renderer as
Charlie Reis
2013/12/06 22:09:32
That depends on whether chrome-distiller:// URLs h
nyquist
2013/12/06 22:25:44
chrome-distiller:// does use a WebUI to render thi
Charlie Reis
2013/12/06 22:33:03
I don't think this won't guarantee that. If the u
nyquist
2014/01/08 02:00:41
Changed to implement as a data source instead.
| |
58 content::Referrer(), content::PAGE_TRANSITION_GENERATED, | |
59 std::string()); | |
55 } | 60 } |
56 | 61 |
57 void DomDistillerHandler::HandleRequestEntries(const ListValue* args) { | 62 void DomDistillerHandler::HandleRequestEntries(const ListValue* args) { |
58 base::ListValue entries; | 63 base::ListValue entries; |
59 const std::vector<ArticleEntry>& entries_specifics = service_->GetEntries(); | 64 const std::vector<ArticleEntry>& entries_specifics = service_->GetEntries(); |
60 for (std::vector<ArticleEntry>::const_iterator it = entries_specifics.begin(); | 65 for (std::vector<ArticleEntry>::const_iterator it = entries_specifics.begin(); |
61 it != entries_specifics.end(); | 66 it != entries_specifics.end(); |
62 ++it) { | 67 ++it) { |
63 const ArticleEntry& article = *it; | 68 const ArticleEntry& article = *it; |
64 DCHECK(IsEntryValid(article)); | 69 DCHECK(IsEntryValid(article)); |
65 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); | 70 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); |
66 entry->SetString("entry_id", article.entry_id()); | 71 entry->SetString("entry_id", article.entry_id()); |
67 std::string title = (!article.has_title() || article.title().empty()) ? | 72 std::string title = (!article.has_title() || article.title().empty()) ? |
68 article.entry_id() : article.title(); | 73 article.entry_id() : article.title(); |
69 entry->SetString("title", title); | 74 entry->SetString("title", title); |
70 entries.Append(entry.release()); | 75 entries.Append(entry.release()); |
71 } | 76 } |
72 web_ui()->CallJavascriptFunction("domDistiller.onReceivedEntries", entries); | 77 web_ui()->CallJavascriptFunction("domDistiller.onReceivedEntries", entries); |
73 } | 78 } |
74 | 79 |
75 } // namespace dom_distiller | 80 } // namespace dom_distiller |
OLD | NEW |