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

Unified Diff: chrome/browser/search/contextual_search_promo_source.cc

Issue 375593004: [Search] Adding a URLDataSource for search feature (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
« no previous file with comments | « chrome/browser/search/contextual_search_promo_source.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/contextual_search_promo_source.cc
diff --git a/chrome/browser/search/contextual_search_promo_source.cc b/chrome/browser/search/contextual_search_promo_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..26bbfe0a8fa661c605cfcc5cbd4537867e7fa699
--- /dev/null
+++ b/chrome/browser/search/contextual_search_promo_source.cc
@@ -0,0 +1,76 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/search/contextual_search_promo_source.h"
+
+#include "base/memory/ref_counted_memory.h"
+#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
+#include "chrome/common/url_constants.h"
+#include "grit/browser_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "url/gurl.h"
+
+namespace {
+
+const char kPromoHTMLPath[] = "/promo.html";
+const char kPromoCSSPath[] = "/promo.css";
+const char kPromoJSPath[] = "/promo.js";
+const char kPromoOptInHTMLPath[] = "/optin.html";
+const char kPromoOptOutHTMLPath[] = "/optout.html";
+
+} // namespace
+
+ContextualSearchPromoSource::ContextualSearchPromoSource() {}
+
+ContextualSearchPromoSource::~ContextualSearchPromoSource() {}
+
+void ContextualSearchPromoSource::StartDataRequest(
+ const std::string& path_and_query, int render_process_id,
+ int render_frame_id,
+ const content::URLDataSource::GotDataCallback& callback) {
+ GURL url(std::string(chrome::kChromeUIContextualSearchPromoURL) + "/" +
+ path_and_query);
+ std::string path(url.path());
+ if (path == kPromoHTMLPath) {
+ SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_HTML, callback);
+ } else if (path == kPromoCSSPath) {
+ SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_CSS, callback);
+ } else if (path == kPromoJSPath) {
+ SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_JS, callback);
+ } else if (path == kPromoOptInHTMLPath) {
+ std::string empty;
+ callback.Run(base::RefCountedString::TakeString(&empty));
+ } else if (path == kPromoOptOutHTMLPath) {
+ std::string empty;
+ callback.Run(base::RefCountedString::TakeString(&empty));
+ } else {
+ callback.Run(NULL);
+ }
+}
+
+std::string ContextualSearchPromoSource::GetSource() const {
+ return chrome::kChromeUIContextualSearchPromoHost;
+}
+
+std::string ContextualSearchPromoSource::GetMimeType(
+ const std::string& path_and_query) const {
+ std::string path(GURL("chrome://host/" + path_and_query).path());
+ if (EndsWith(path, ".js", false)) return "application/javascript";
+ if (EndsWith(path, ".png", false)) return "image/png";
+ if (EndsWith(path, ".css", false)) return "text/css";
+ if (EndsWith(path, ".html", false)) return "text/html";
+ return "";
+}
+
+bool ContextualSearchPromoSource::ShouldDenyXFrameOptions() const {
+ return false;
+}
+
+void ContextualSearchPromoSource::SendResource(
+ int resource_id, const content::URLDataSource::GotDataCallback& callback) {
+ scoped_refptr<base::RefCountedStaticMemory> response(
+ ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id));
+ callback.Run(response.get());
+}
« no previous file with comments | « chrome/browser/search/contextual_search_promo_source.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698