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

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

Issue 12840003: Implement local NTP for fallback. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Respond to Samarth's comments. Created 7 years, 9 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/search/local_ntp_source.cc
diff --git a/chrome/browser/search/local_ntp_source.cc b/chrome/browser/search/local_ntp_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..19dc0653a3f14137162ff21523f04a9b69a2a26f
--- /dev/null
+++ b/chrome/browser/search/local_ntp_source.cc
@@ -0,0 +1,92 @@
+// Copyright 2013 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/local_ntp_source.h"
+
+#include "base/logging.h"
+#include "base/memory/ref_counted_memory.h"
+#include "base/string_util.h"
+#include "chrome/common/url_constants.h"
+#include "content/public/common/content_client.h"
+#include "googleurl/src/gurl.h"
+#include "grit/browser_resources.h"
+#include "grit/ui_resources.h"
+#include "net/url_request/url_request.h"
+
+namespace {
+
+const char kHTMLFilename[] = "local-ntp.html";
+const char kJSFilename[] = "local-ntp.js";
+const char kCSSFilename[] = "local-ntp.css";
+const char kCloseBarFilename[] = "images/close_bar.png";
+const char kCloseBarHoverFilename[] = "images/close_bar_hover.png";
+const char kCloseBarActiveFilename[] = "images/close_bar_active.png";
+
+} // namespace
+
+LocalNTPSource::LocalNTPSource() {
+}
+
+LocalNTPSource::~LocalNTPSource() {
+}
+
+std::string LocalNTPSource::GetSource() {
+ return chrome::kChromeSearchLocalNTPHost;
+}
+
+void LocalNTPSource::StartDataRequest(
+ const std::string& path,
+ bool is_incognito,
+ const content::URLDataSource::GotDataCallback& callback) {
+ int identifier = -1;
+ if (path == kHTMLFilename) {
+ identifier = IDR_LOCAL_NTP_HTML;
+ } else if (path == kJSFilename) {
+ identifier = IDR_LOCAL_NTP_JS;
+ } else if (path == kCSSFilename) {
+ identifier = IDR_LOCAL_NTP_CSS;
+ } else if (path == kCloseBarFilename) {
+ identifier = IDR_CLOSE_BAR;
+ } else if (path == kCloseBarHoverFilename) {
+ identifier = IDR_CLOSE_BAR_H;
+ } else if (path == kCloseBarActiveFilename) {
+ identifier = IDR_CLOSE_BAR_P;
+ } else {
+ callback.Run(NULL);
+ return;
+ }
+
+ scoped_refptr<base::RefCountedStaticMemory> response(
+ content::GetContentClient()->GetDataResourceBytes(identifier));
+ callback.Run(response);
+}
+
+std::string LocalNTPSource::GetMimeType(
+ const std::string& path) const {
+ if (path == kHTMLFilename)
+ return "text/html";
+ if (path == kJSFilename)
+ return "application/javascript";
+ if (path == kCSSFilename)
+ return "text/css";
+ if (path == kCloseBarFilename || path == kCloseBarHoverFilename ||
+ path == kCloseBarActiveFilename)
+ return "image/png";
+ return "";
+}
+
+bool LocalNTPSource::ShouldServiceRequest(
+ const net::URLRequest* request) const {
+ DCHECK_EQ(request->url().host(), chrome::kChromeSearchLocalNTPHost);
+
+ if (request->url().SchemeIs(chrome::kChromeSearchScheme)) {
+ DCHECK(StartsWithASCII(request->url().path(), "/", true));
+ std::string filename = request->url().path().substr(1);
+ return filename == kHTMLFilename || filename == kJSFilename ||
+ filename == kCSSFilename || filename == kCloseBarFilename ||
+ filename == kCloseBarHoverFilename ||
+ filename == kCloseBarActiveFilename;
+ }
+ return false;
+}

Powered by Google App Engine
This is Rietveld 408576698