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

Side by Side Diff: chrome/browser/dom_ui/new_tab_ui.cc

Issue 113927: Allow passing in a file path to a file that will be used for the new new tab... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/chrome_switches.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/dom_ui/new_tab_ui.h" 7 #include "chrome/browser/dom_ui/new_tab_ui.h"
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_util.h"
12 #include "base/histogram.h" 13 #include "base/histogram.h"
13 #include "base/string_piece.h" 14 #include "base/string_piece.h"
14 #include "chrome/browser/bookmarks/bookmark_model.h" 15 #include "chrome/browser/bookmarks/bookmark_model.h"
15 #include "chrome/browser/bookmarks/bookmark_utils.h" 16 #include "chrome/browser/bookmarks/bookmark_utils.h"
16 #include "chrome/browser/browser.h" 17 #include "chrome/browser/browser.h"
17 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" 19 #include "chrome/browser/dom_ui/dom_ui_favicon_source.h"
19 #include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h" 20 #include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h"
20 #include "chrome/browser/dom_ui/dom_ui_theme_source.h" 21 #include "chrome/browser/dom_ui/dom_ui_theme_source.h"
21 #include "chrome/browser/dom_ui/downloads_dom_handler.h" 22 #include "chrome/browser/dom_ui/downloads_dom_handler.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 193
193 virtual std::string GetMimeType(const std::string&) const { 194 virtual std::string GetMimeType(const std::string&) const {
194 return "text/html"; 195 return "text/html";
195 } 196 }
196 197
197 // Setters and getters for first_view. 198 // Setters and getters for first_view.
198 static void set_first_view(bool first_view) { first_view_ = first_view; } 199 static void set_first_view(bool first_view) { first_view_ = first_view; }
199 static bool first_view() { return first_view_; } 200 static bool first_view() { return first_view_; }
200 201
201 private: 202 private:
203 // In case a file path to the new new tab page was provided this tries to load
204 // the file and returns the file content if successful. This returns an empty
205 // string in case of failure.
206 static std::string GetNewNewTabFromCommandLine();
207
202 // Whether this is the is the first viewing of the new tab page and 208 // Whether this is the is the first viewing of the new tab page and
203 // we think it is the user's startup page. 209 // we think it is the user's startup page.
204 static bool first_view_; 210 static bool first_view_;
205 211
206 DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource); 212 DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource);
207 }; 213 };
208 214
209 bool NewTabHTMLSource::first_view_ = true; 215 bool NewTabHTMLSource::first_view_ = true;
210 216
211 NewTabHTMLSource::NewTabHTMLSource() 217 NewTabHTMLSource::NewTabHTMLSource()
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 SetFontAndTextDirection(&localized_strings); 282 SetFontAndTextDirection(&localized_strings);
277 283
278 // Let the tab know whether it's the first tab being viewed. 284 // Let the tab know whether it's the first tab being viewed.
279 localized_strings.SetString(L"firstview", 285 localized_strings.SetString(L"firstview",
280 first_view_ ? L"true" : std::wstring()); 286 first_view_ ? L"true" : std::wstring());
281 first_view_ = false; 287 first_view_ = false;
282 288
283 #ifdef CHROME_PERSONALIZATION 289 #ifdef CHROME_PERSONALIZATION
284 localized_strings.SetString(L"p13nsrc", Personalization::GetNewTabSource()); 290 localized_strings.SetString(L"p13nsrc", Personalization::GetNewTabSource());
285 #endif 291 #endif
286 static const StringPiece new_tab_html( 292
287 ResourceBundle::GetSharedInstance().GetRawDataResource( 293 // In case we have the new new tab page enabled we first try to read the file
288 NewTabUI::EnableNewNewTabPage() ? 294 // provided on the command line. If that fails we just get the resource from
289 IDR_NEW_NEW_TAB_HTML : IDR_NEW_TAB_HTML)); 295 // the resource bundle.
296 StringPiece new_tab_html;
297 std::string new_tab_html_str;
298 if (NewTabUI::EnableNewNewTabPage()) {
299 new_tab_html_str = GetNewNewTabFromCommandLine();
300
301 if (!new_tab_html_str.empty()) {
302 new_tab_html = StringPiece(new_tab_html_str);
303 } else {
304 // Use the new new tab page from the resource bundle.
305 new_tab_html = ResourceBundle::GetSharedInstance().GetRawDataResource(
306 IDR_NEW_NEW_TAB_HTML);
307 }
308 } else {
309 // Use the default new tab page resource.
310 new_tab_html = ResourceBundle::GetSharedInstance().GetRawDataResource(
311 IDR_NEW_TAB_HTML);
312 }
290 313
291 const std::string full_html = jstemplate_builder::GetTemplateHtml( 314 const std::string full_html = jstemplate_builder::GetTemplateHtml(
292 new_tab_html, &localized_strings, "t" /* template root node id */); 315 new_tab_html, &localized_strings, "t" /* template root node id */);
293 316
294 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 317 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
295 html_bytes->data.resize(full_html.size()); 318 html_bytes->data.resize(full_html.size());
296 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); 319 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
297 320
298 SendResponse(request_id, html_bytes); 321 SendResponse(request_id, html_bytes);
299 } 322 }
300 323
324 // static
325 std::string NewTabHTMLSource::GetNewNewTabFromCommandLine() {
326 const CommandLine* command_line = CommandLine::ForCurrentProcess();
327 const std::wstring file_path_wstring = command_line->GetSwitchValue(
328 switches::kNewNewTabPage);
329
330 #if defined(OS_WIN)
331 const FilePath::StringType file_path = file_path_wstring;
332 #else
333 const FilePath::StringType file_path = WideToASCII(file_path_wstring);
334 #endif
335
336 if (!file_path.empty()) {
337 std::string file_contents;
338 if (file_util::ReadFileToString(FilePath(file_path), &file_contents))
339 return file_contents;
340 }
341
342 return std::string();
343 }
344
301 /////////////////////////////////////////////////////////////////////////////// 345 ///////////////////////////////////////////////////////////////////////////////
302 // IncognitoTabHTMLSource 346 // IncognitoTabHTMLSource
303 347
304 class IncognitoTabHTMLSource : public ChromeURLDataManager::DataSource { 348 class IncognitoTabHTMLSource : public ChromeURLDataManager::DataSource {
305 public: 349 public:
306 // Creates our datasource and sets our user message to a specific message 350 // Creates our datasource and sets our user message to a specific message
307 // from our string bundle. 351 // from our string bundle.
308 IncognitoTabHTMLSource(); 352 IncognitoTabHTMLSource();
309 353
310 // Called when the network layer has requested a resource underneath 354 // Called when the network layer has requested a resource underneath
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 // static 1254 // static
1211 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { 1255 void NewTabUI::RegisterUserPrefs(PrefService* prefs) {
1212 MostVisitedHandler::RegisterUserPrefs(prefs); 1256 MostVisitedHandler::RegisterUserPrefs(prefs);
1213 } 1257 }
1214 1258
1215 // static 1259 // static
1216 bool NewTabUI::EnableNewNewTabPage() { 1260 bool NewTabUI::EnableNewNewTabPage() {
1217 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 1261 const CommandLine* command_line = CommandLine::ForCurrentProcess();
1218 return command_line->HasSwitch(switches::kNewNewTabPage); 1262 return command_line->HasSwitch(switches::kNewNewTabPage);
1219 } 1263 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/chrome_switches.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698