Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1458)

Unified Diff: components/dom_distiller/webui/dom_distiller_handler.cc

Issue 151003006: Add support for distilling arbitrary URLs in DOM Distiller Viewer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added new strings to iOS whitelist Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/dom_distiller/webui/dom_distiller_handler.cc
diff --git a/components/dom_distiller/webui/dom_distiller_handler.cc b/components/dom_distiller/webui/dom_distiller_handler.cc
index ede4f40615b78c919609e262ce382bb0c0809667..59b4fb9943632871f4a4bfe638ba4680e66e109a 100644
--- a/components/dom_distiller/webui/dom_distiller_handler.cc
+++ b/components/dom_distiller/webui/dom_distiller_handler.cc
@@ -10,12 +10,30 @@
#include "base/values.h"
#include "components/dom_distiller/core/dom_distiller_service.h"
#include "components/dom_distiller/core/proto/distilled_page.pb.h"
+#include "components/dom_distiller/core/url_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
+#include "net/base/escape.h"
#include "url/gurl.h"
namespace dom_distiller {
+namespace {
+
+GURL GetViewUrlFromArgs(const std::string& scheme,
+ const base::ListValue* args) {
+ std::string url;
+ if (args->GetString(0, &url)) {
+ const GURL gurl(url);
+ if (url_utils::IsUrlDistillable(gurl)) {
+ return url_utils::GetDistillerViewUrlFromUrl(scheme, gurl);
+ }
+ }
+ return GURL();
+}
+
+} // namespace
+
DomDistillerHandler::DomDistillerHandler(DomDistillerService* service,
const std::string& scheme)
: service_(service), article_scheme_(scheme), weak_ptr_factory_(this) {}
@@ -35,6 +53,9 @@ void DomDistillerHandler::RegisterMessages() {
"selectArticle",
base::Bind(&DomDistillerHandler::HandleSelectArticle,
base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "viewUrl",
+ base::Bind(&DomDistillerHandler::HandleViewUrl, base::Unretained(this)));
}
void DomDistillerHandler::HandleAddArticle(const base::ListValue* args) {
@@ -51,13 +72,29 @@ void DomDistillerHandler::HandleAddArticle(const base::ListValue* args) {
}
}
+void DomDistillerHandler::HandleViewUrl(const base::ListValue* args) {
+ GURL view_url = GetViewUrlFromArgs(article_scheme_, args);
+ if (view_url.is_valid()) {
+ web_ui()->GetWebContents()->GetController().LoadURL(
+ view_url,
+ content::Referrer(),
+ content::PAGE_TRANSITION_GENERATED,
+ std::string());
+ } else {
+ web_ui()->CallJavascriptFunction("domDistiller.onViewUrlFailed");
+ }
+}
+
void DomDistillerHandler::HandleSelectArticle(const base::ListValue* args) {
std::string entry_id;
args->GetString(0, &entry_id);
- GURL url(article_scheme_ + std::string("://") + entry_id);
+ GURL url =
+ url_utils::GetDistillerViewUrlFromEntryId(article_scheme_, entry_id);
DCHECK(url.is_valid());
- web_ui()->GetWebContents()->GetController().LoadURL(url,
- content::Referrer(), content::PAGE_TRANSITION_GENERATED,
+ web_ui()->GetWebContents()->GetController().LoadURL(
+ url,
+ content::Referrer(),
+ content::PAGE_TRANSITION_GENERATED,
std::string());
}
@@ -74,9 +111,10 @@ void DomDistillerHandler::HandleRequestEntries(const base::ListValue* args) {
std::string title = (!article.has_title() || article.title().empty())
? article.entry_id()
: article.title();
- entry->SetString("title", title);
+ entry->SetString("title", net::EscapeForHTML(title));
entries.Append(entry.release());
}
+ // TODO(nyquist): Write a test that ensures we sanitize the data we send.
web_ui()->CallJavascriptFunction("domDistiller.onReceivedEntries", entries);
}
« no previous file with comments | « components/dom_distiller/webui/dom_distiller_handler.h ('k') | components/dom_distiller/webui/dom_distiller_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698