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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/common/chrome_switches.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/dom_ui/new_tab_ui.cc
===================================================================
--- chrome/browser/dom_ui/new_tab_ui.cc (revision 16871)
+++ chrome/browser/dom_ui/new_tab_ui.cc (working copy)
@@ -9,6 +9,7 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/command_line.h"
+#include "base/file_util.h"
#include "base/histogram.h"
#include "base/string_piece.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
@@ -199,6 +200,11 @@
static bool first_view() { return first_view_; }
private:
+ // In case a file path to the new new tab page was provided this tries to load
+ // the file and returns the file content if successful. This returns an empty
+ // string in case of failure.
+ static std::string GetNewNewTabFromCommandLine();
+
// Whether this is the is the first viewing of the new tab page and
// we think it is the user's startup page.
static bool first_view_;
@@ -283,11 +289,28 @@
#ifdef CHROME_PERSONALIZATION
localized_strings.SetString(L"p13nsrc", Personalization::GetNewTabSource());
#endif
- static const StringPiece new_tab_html(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- NewTabUI::EnableNewNewTabPage() ?
- IDR_NEW_NEW_TAB_HTML : IDR_NEW_TAB_HTML));
+ // In case we have the new new tab page enabled we first try to read the file
+ // provided on the command line. If that fails we just get the resource from
+ // the resource bundle.
+ StringPiece new_tab_html;
+ std::string new_tab_html_str;
+ if (NewTabUI::EnableNewNewTabPage()) {
+ new_tab_html_str = GetNewNewTabFromCommandLine();
+
+ if (!new_tab_html_str.empty()) {
+ new_tab_html = StringPiece(new_tab_html_str);
+ } else {
+ // Use the new new tab page from the resource bundle.
+ new_tab_html = ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_NEW_NEW_TAB_HTML);
+ }
+ } else {
+ // Use the default new tab page resource.
+ new_tab_html = ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_NEW_TAB_HTML);
+ }
+
const std::string full_html = jstemplate_builder::GetTemplateHtml(
new_tab_html, &localized_strings, "t" /* template root node id */);
@@ -298,6 +321,27 @@
SendResponse(request_id, html_bytes);
}
+// static
+std::string NewTabHTMLSource::GetNewNewTabFromCommandLine() {
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+ const std::wstring file_path_wstring = command_line->GetSwitchValue(
+ switches::kNewNewTabPage);
+
+#if defined(OS_WIN)
+ const FilePath::StringType file_path = file_path_wstring;
+#else
+ const FilePath::StringType file_path = WideToASCII(file_path_wstring);
+#endif
+
+ if (!file_path.empty()) {
+ std::string file_contents;
+ if (file_util::ReadFileToString(FilePath(file_path), &file_contents))
+ return file_contents;
+ }
+
+ return std::string();
+}
+
///////////////////////////////////////////////////////////////////////////////
// IncognitoTabHTMLSource
« 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