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

Unified Diff: chrome/browser/privacy_blacklist/blocked_response.cc

Issue 252001: Privacy Blacklist Unblock... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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: chrome/browser/privacy_blacklist/blocked_response.cc
===================================================================
--- chrome/browser/privacy_blacklist/blocked_response.cc (revision 27622)
+++ chrome/browser/privacy_blacklist/blocked_response.cc (working copy)
@@ -7,15 +7,34 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/logging.h"
+#include "base/string_util.h"
#include "base/values.h"
#include "chrome/browser/privacy_blacklist/blacklist.h"
#include "chrome/common/jstemplate_builder.h"
+#include "chrome/common/url_constants.h"
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
-namespace BlockedResponse {
+namespace {
-std::string GetHTML(const Blacklist::Match* match) {
+unsigned long Hash(std::set<std::string>::iterator i) {
+ return (unsigned long)(i.operator->());
+}
+
+std::string Dehash(unsigned long l) {
+ return *(std::string*)l;
+}
+
+}
+
+namespace chrome {
+
+const char kUnblockScheme[] = "chrome-unblock";
+
+const char kBlockScheme[] = "chrome-block";
+
+std::string BlockedResponse::GetHTML(const std::string& url,
+ const Blacklist::Match* match) {
DictionaryValue strings;
strings.SetString(L"title", l10n_util::GetString(IDS_BLACKLIST_TITLE));
strings.SetString(L"message", l10n_util::GetString(IDS_BLACKLIST_MESSAGE));
@@ -39,15 +58,47 @@
strings.SetString(L"name", entry->provider()->name());
strings.SetString(L"url", entry->provider()->url());
+ strings.SetString(L"bypass", GetUnblockedURL(url));
const base::StringPiece html =
ResourceBundle::GetSharedInstance().GetRawDataResource(IDR_BLACKLIST_HTML);
return jstemplate_builder::GetI18nTemplateHtml(html, &strings);
}
-std::string GetImage(const Blacklist::Match*) {
+std::string BlockedResponse::GetImage(const Blacklist::Match*) {
return ResourceBundle::GetSharedInstance().
GetDataResource(IDR_BLACKLIST_IMAGE);
}
-} // namespace BlockedResponse
+std::string BlockedResponse::GetHeaders(const std::string& url) {
+ return
+ "HTTP/1.1 200 OK\nContent-Type: text/html\nlocation: "
+ + GetBlockedURL(url) + "\n" + "Cache-Control: no-store";
+}
+
+std::string BlockedResponse::GetBlockedURL(const std::string& url) {
+ return std::string(kBlockScheme) + "://" + url;
+}
+
+std::string BlockedResponse::GetUnblockedURL(const std::string& url) {
+ std::set<std::string>::iterator i = blocked_.insert(blocked_.end(), url);
+
+ char buf[64];
+ base::snprintf(buf, 64, "%s://%lX", kUnblockScheme, Hash(i));
+ return buf;
+}
+
+std::string BlockedResponse::GetOriginalURL(const std::string& url) {
+ unsigned long l = 0;
+
+ // Read the address of the url.
+ if (sscanf(url.c_str() + sizeof(kUnblockScheme) + 2, "%lX", &l)) {
+ std::size_t p = url.find('/', sizeof(kUnblockScheme) + 2);
+ if (p != std::string::npos)
+ return Dehash(l) + url.substr(p+1);
+ return Dehash(l);
+ }
+ return chrome::kAboutBlankURL;
+}
+
+} // end namespace chrome
« no previous file with comments | « chrome/browser/privacy_blacklist/blocked_response.h ('k') | chrome/browser/renderer_host/resource_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698