• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/search/most_visited_iframe_source.h"
6 
7 #include "base/metrics/histogram.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h"
10 #include "chrome/common/url_constants.h"
11 #include "content/public/browser/user_metrics.h"
12 #include "grit/browser_resources.h"
13 #include "net/base/url_util.h"
14 #include "url/gurl.h"
15 
16 namespace {
17 
18 const char kTitleHTMLPath[] = "/title.html";
19 const char kTitleCSSPath[] = "/title.css";
20 const char kTitleJSPath[] = "/title.js";
21 const char kThumbnailHTMLPath[] = "/thumbnail.html";
22 const char kThumbnailCSSPath[] = "/thumbnail.css";
23 const char kThumbnailJSPath[] = "/thumbnail.js";
24 const char kUtilJSPath[] = "/util.js";
25 const char kCommonCSSPath[] = "/common.css";
26 
27 }  // namespace
28 
MostVisitedIframeSource()29 MostVisitedIframeSource::MostVisitedIframeSource() {
30 }
31 
~MostVisitedIframeSource()32 MostVisitedIframeSource::~MostVisitedIframeSource() {
33 }
34 
35 const int MostVisitedIframeSource::kNumMostVisited = 8;
36 const char MostVisitedIframeSource::kMostVisitedHistogramName[] =
37     "NewTabPage.MostVisited";
38 
GetSource() const39 std::string MostVisitedIframeSource::GetSource() const {
40   return chrome::kChromeSearchMostVisitedHost;
41 }
42 
StartDataRequest(const std::string & path_and_query,int render_process_id,int render_frame_id,const content::URLDataSource::GotDataCallback & callback)43 void MostVisitedIframeSource::StartDataRequest(
44     const std::string& path_and_query,
45     int render_process_id,
46     int render_frame_id,
47     const content::URLDataSource::GotDataCallback& callback) {
48   GURL url(chrome::kChromeSearchMostVisitedUrl + path_and_query);
49   std::string path(url.path());
50   if (path == kTitleHTMLPath) {
51     SendResource(IDR_MOST_VISITED_TITLE_HTML, callback);
52   } else if (path == kTitleCSSPath) {
53     SendResource(IDR_MOST_VISITED_TITLE_CSS, callback);
54   } else if (path == kTitleJSPath) {
55     SendResource(IDR_MOST_VISITED_TITLE_JS, callback);
56   } else if (path == kThumbnailHTMLPath) {
57     SendResource(IDR_MOST_VISITED_THUMBNAIL_HTML, callback);
58   } else if (path == kThumbnailCSSPath) {
59     SendResource(IDR_MOST_VISITED_THUMBNAIL_CSS, callback);
60   } else if (path == kThumbnailJSPath) {
61     SendJSWithOrigin(IDR_MOST_VISITED_THUMBNAIL_JS, render_process_id,
62                      render_frame_id, callback);
63   } else if (path == kUtilJSPath) {
64     SendJSWithOrigin(IDR_MOST_VISITED_UTIL_JS, render_process_id,
65                      render_frame_id, callback);
66   } else if (path == kCommonCSSPath) {
67     SendResource(IDR_MOST_VISITED_IFRAME_CSS, callback);
68   } else {
69     callback.Run(NULL);
70   }
71 }
72 
ServesPath(const std::string & path) const73 bool MostVisitedIframeSource::ServesPath(const std::string& path) const {
74   return path == kTitleHTMLPath || path == kTitleCSSPath ||
75          path == kTitleJSPath || path == kThumbnailHTMLPath ||
76          path == kThumbnailCSSPath || path == kThumbnailJSPath ||
77          path == kUtilJSPath || path == kCommonCSSPath;
78 }
79