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..cef86fcbff1d180f9424fcc1eea537e22c55d67d 100644 |
--- a/components/dom_distiller/webui/dom_distiller_handler.cc |
+++ b/components/dom_distiller/webui/dom_distiller_handler.cc |
@@ -7,11 +7,15 @@ |
#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 "net/base/url_util.h" |
#include "url/gurl.h" |
namespace dom_distiller { |
@@ -35,6 +39,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 +58,36 @@ 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() + "/?" + |
shashi
2014/02/25 21:48:08
Probably want to use the GetDistillerViewUrl* func
nyquist
2014/02/27 00:07:37
Done.
|
+ std::string(kUrlKey) + "=" + |
+ net::EscapeQueryParamValue(gurl.spec(), true)); |
+ DCHECK(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(article_scheme_ + "://" + base::GenerateGUID() + "/?" + |
shashi
2014/02/25 21:48:08
Probably want to use the GetDistillerViewUrl* func
nyquist
2014/02/27 00:07:37
Done.
|
+ std::string(kEntryIdKey) + "=" + |
+ net::EscapeQueryParamValue(entry_id, true)); |
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()); |
} |
@@ -89,4 +119,16 @@ void DomDistillerHandler::OnArticleAdded(bool article_available) { |
} |
} |
+const GURL DomDistillerHandler::GetDistillerViewUrlFromEntryId( |
shashi
2014/02/25 21:48:08
Is this function used anywhere?
cjhopman
2014/02/25 22:25:14
Looks like this is also defined in the tests.
nyquist
2014/02/27 00:07:37
Done.
Created dom_distiller::url_utils for this an
|
+ const std::string& entry_id) const { |
+ GURL url(article_scheme_ + "://" + base::GenerateGUID()); |
+ return net::AppendOrReplaceQueryParameter(url, kEntryIdKey, entry_id); |
+} |
+ |
+const GURL DomDistillerHandler::GetDistillerViewUrlFromUrl(const GURL& view_url) |
+ const { |
+ GURL url(article_scheme_ + "://" + base::GenerateGUID()); |
shashi
2014/02/25 21:48:08
Same for this function.
nyquist
2014/02/27 00:07:37
Done.
|
+ return net::AppendOrReplaceQueryParameter(url, kUrlKey, view_url.spec()); |
+} |
+ |
} // namespace dom_distiller |