| 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;
|
| +}
|
|
|