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

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: 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..c7d55dd22538f5ce0dc8386eee55f1d2612e98ee 100644
--- a/components/dom_distiller/webui/dom_distiller_handler.cc
+++ b/components/dom_distiller/webui/dom_distiller_handler.cc
@@ -7,11 +7,14 @@
#include <vector>
#include "base/bind.h"
+#include "base/guid.h"
#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_constants.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 {
@@ -35,6 +38,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 +57,34 @@ void DomDistillerHandler::HandleAddArticle(const base::ListValue* args) {
}
}
+void DomDistillerHandler::HandleViewUrl(const base::ListValue* args) {
+ std::string url;
+ args->GetString(0, &url);
+ GURL gurl(url);
+ if (gurl.is_valid()) {
+ GURL view_url(article_scheme_ + "://" + base::GenerateGUID() + "/?" +
+ std::string(kUrlKey) + "=" +
shashi 2014/02/05 22:28:08 nit: can be refactored and maybe use: net::AppendO
nyquist 2014/02/25 20:30:24 Done.
shashi 2014/02/25 21:48:08 Is this refactored. On 2014/02/25 20:30:24, nyquis
+ net::EscapeQueryParamValue(gurl.spec(), true));
+ 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);
- DCHECK(url.is_valid());
shashi 2014/02/05 22:28:08 why remove the DCHECK?
nyquist 2014/02/25 20:30:24 Done.
- web_ui()->GetWebContents()->GetController().LoadURL(url,
- content::Referrer(), content::PAGE_TRANSITION_GENERATED,
+ GURL url(article_scheme_ + "://" + base::GenerateGUID() + "/?" +
+ std::string(kEntryIdKey) + "=" +
+ net::EscapeQueryParamValue(entry_id, true));
shashi 2014/02/05 22:28:08 nit: can be refactored and maybe use: net::AppendO
nyquist 2014/02/25 20:30:24 Done.
shashi 2014/02/25 21:48:08 Is this refactored? On 2014/02/25 20:30:24, nyquis
+ web_ui()->GetWebContents()->GetController().LoadURL(
+ url,
+ content::Referrer(),
+ content::PAGE_TRANSITION_GENERATED,
std::string());
}

Powered by Google App Engine
This is Rietveld 408576698