Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / search / most_visited_iframe_source.cc
blob126bec215d26cf80110aedb4d833105dd514f5ac
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/command_line.h"
8 #include "base/metrics/histogram.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/search/local_files_ntp_source.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/user_metrics.h"
15 #include "grit/browser_resources.h"
16 #include "net/base/url_util.h"
17 #include "url/gurl.h"
19 namespace {
21 const char kTitleHTMLPath[] = "/title.html";
22 const char kTitleCSSPath[] = "/title.css";
23 const char kTitleJSPath[] = "/title.js";
24 const char kThumbnailHTMLPath[] = "/thumbnail.html";
25 const char kThumbnailCSSPath[] = "/thumbnail.css";
26 const char kThumbnailJSPath[] = "/thumbnail.js";
27 const char kSingleHTMLPath[] = "/single.html";
28 const char kSingleCSSPath[] = "/single.css";
29 const char kSingleJSPath[] = "/single.js";
30 const char kUtilJSPath[] = "/util.js";
31 const char kCommonCSSPath[] = "/common.css";
33 } // namespace
35 MostVisitedIframeSource::MostVisitedIframeSource() {
38 MostVisitedIframeSource::~MostVisitedIframeSource() {
41 std::string MostVisitedIframeSource::GetSource() const {
42 return chrome::kChromeSearchMostVisitedHost;
45 void MostVisitedIframeSource::StartDataRequest(
46 const std::string& path_and_query,
47 int render_process_id,
48 int render_frame_id,
49 const content::URLDataSource::GotDataCallback& callback) {
50 GURL url(chrome::kChromeSearchMostVisitedUrl + path_and_query);
51 std::string path(url.path());
53 #if !defined(OFFICIAL_BUILD)
54 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
55 if (command_line->HasSwitch(switches::kLocalNtpReload)) {
56 std::string rel_path = "most_visited_" + path.substr(1);
57 if (path == kSingleJSPath) {
58 std::string origin;
59 if (!GetOrigin(render_process_id, render_frame_id, &origin)) {
60 callback.Run(NULL);
61 return;
63 local_ntp::SendLocalFileResourceWithOrigin(rel_path, origin, callback);
64 } else {
65 local_ntp::SendLocalFileResource(rel_path, callback);
67 return;
69 #endif
71 if (path == kTitleHTMLPath) {
72 SendResource(IDR_MOST_VISITED_TITLE_HTML, callback);
73 } else if (path == kTitleCSSPath) {
74 SendResource(IDR_MOST_VISITED_TITLE_CSS, callback);
75 } else if (path == kTitleJSPath) {
76 SendResource(IDR_MOST_VISITED_TITLE_JS, callback);
77 } else if (path == kThumbnailHTMLPath) {
78 SendResource(IDR_MOST_VISITED_THUMBNAIL_HTML, callback);
79 } else if (path == kThumbnailCSSPath) {
80 SendResource(IDR_MOST_VISITED_THUMBNAIL_CSS, callback);
81 } else if (path == kThumbnailJSPath) {
82 SendJSWithOrigin(IDR_MOST_VISITED_THUMBNAIL_JS, render_process_id,
83 render_frame_id, callback);
84 } else if (path == kSingleHTMLPath) {
85 SendResource(IDR_MOST_VISITED_SINGLE_HTML, callback);
86 } else if (path == kSingleCSSPath) {
87 SendResource(IDR_MOST_VISITED_SINGLE_CSS, callback);
88 } else if (path == kSingleJSPath) {
89 SendJSWithOrigin(IDR_MOST_VISITED_SINGLE_JS, render_process_id,
90 render_frame_id, callback);
91 } else if (path == kUtilJSPath) {
92 SendJSWithOrigin(IDR_MOST_VISITED_UTIL_JS, render_process_id,
93 render_frame_id, callback);
94 } else if (path == kCommonCSSPath) {
95 SendResource(IDR_MOST_VISITED_IFRAME_CSS, callback);
96 } else {
97 callback.Run(NULL);
101 bool MostVisitedIframeSource::ServesPath(const std::string& path) const {
102 return path == kTitleHTMLPath || path == kTitleCSSPath ||
103 path == kTitleJSPath || path == kThumbnailHTMLPath ||
104 path == kThumbnailCSSPath || path == kThumbnailJSPath ||
105 path == kSingleHTMLPath || path == kSingleCSSPath ||
106 path == kSingleJSPath || path == kUtilJSPath || path == kCommonCSSPath;