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.
5 #include "chrome/browser/search/most_visited_iframe_source.h"
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"
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 kSingleHTMLPath
[] = "/single.html";
25 const char kSingleCSSPath
[] = "/single.css";
26 const char kSingleJSPath
[] = "/single.js";
27 const char kUtilJSPath
[] = "/util.js";
28 const char kCommonCSSPath
[] = "/common.css";
32 MostVisitedIframeSource::MostVisitedIframeSource() {
35 MostVisitedIframeSource::~MostVisitedIframeSource() {
38 std::string
MostVisitedIframeSource::GetSource() const {
39 return chrome::kChromeSearchMostVisitedHost
;
42 void MostVisitedIframeSource::StartDataRequest(
43 const std::string
& path_and_query
,
44 int render_process_id
,
46 const content::URLDataSource::GotDataCallback
& callback
) {
47 GURL
url(chrome::kChromeSearchMostVisitedUrl
+ path_and_query
);
48 std::string
path(url
.path());
49 if (path
== kTitleHTMLPath
) {
50 SendResource(IDR_MOST_VISITED_TITLE_HTML
, callback
);
51 } else if (path
== kTitleCSSPath
) {
52 SendResource(IDR_MOST_VISITED_TITLE_CSS
, callback
);
53 } else if (path
== kTitleJSPath
) {
54 SendResource(IDR_MOST_VISITED_TITLE_JS
, callback
);
55 } else if (path
== kThumbnailHTMLPath
) {
56 SendResource(IDR_MOST_VISITED_THUMBNAIL_HTML
, callback
);
57 } else if (path
== kThumbnailCSSPath
) {
58 SendResource(IDR_MOST_VISITED_THUMBNAIL_CSS
, callback
);
59 } else if (path
== kThumbnailJSPath
) {
60 SendJSWithOrigin(IDR_MOST_VISITED_THUMBNAIL_JS
, render_process_id
,
61 render_frame_id
, callback
);
62 } else if (path
== kSingleHTMLPath
) {
63 SendResource(IDR_MOST_VISITED_SINGLE_HTML
, callback
);
64 } else if (path
== kSingleCSSPath
) {
65 SendResource(IDR_MOST_VISITED_SINGLE_CSS
, callback
);
66 } else if (path
== kSingleJSPath
) {
67 SendJSWithOrigin(IDR_MOST_VISITED_SINGLE_JS
, render_process_id
,
68 render_frame_id
, callback
);
69 } else if (path
== kUtilJSPath
) {
70 SendJSWithOrigin(IDR_MOST_VISITED_UTIL_JS
, render_process_id
,
71 render_frame_id
, callback
);
72 } else if (path
== kCommonCSSPath
) {
73 SendResource(IDR_MOST_VISITED_IFRAME_CSS
, callback
);
79 bool MostVisitedIframeSource::ServesPath(const std::string
& path
) const {
80 return path
== kTitleHTMLPath
|| path
== kTitleCSSPath
||
81 path
== kTitleJSPath
|| path
== kThumbnailHTMLPath
||
82 path
== kThumbnailCSSPath
|| path
== kThumbnailJSPath
||
83 path
== kSingleHTMLPath
|| path
== kSingleCSSPath
||
84 path
== kSingleJSPath
|| path
== kUtilJSPath
|| path
== kCommonCSSPath
;