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

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

Issue 2886002: NTP: Remove command line flag that allowed a local file to be used for the ne... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 5 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.h » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/dom_ui/ntp_resource_cache.h" 5 #include "chrome/browser/dom_ui/ntp_resource_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "app/animation.h" 10 #include "app/animation.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 "http://www.google.com/support/chrome/bin/answer.py?answer=165139"; 57 "http://www.google.com/support/chrome/bin/answer.py?answer=165139";
58 58
59 // The URL to be loaded to display Help. 59 // The URL to be loaded to display Help.
60 const char* const kHelpContentUrl = 60 const char* const kHelpContentUrl =
61 "http://www.google.com/support/chrome/"; 61 "http://www.google.com/support/chrome/";
62 62
63 std::wstring GetUrlWithLang(const char* const url) { 63 std::wstring GetUrlWithLang(const char* const url) {
64 return ASCIIToWide(google_util::AppendGoogleLocaleParam(GURL(url)).spec()); 64 return ASCIIToWide(google_util::AppendGoogleLocaleParam(GURL(url)).spec());
65 } 65 }
66 66
67 // In case a file path to the new tab page was provided this tries to load
68 // the file and returns the file content if successful. This returns an
69 // empty string in case of failure.
70 std::string GetCustomNewTabPageFromCommandLine() {
71 const CommandLine* command_line = CommandLine::ForCurrentProcess();
72 const FilePath file_path = command_line->GetSwitchValuePath(
73 switches::kNewTabPage);
74
75 if (!file_path.empty()) {
76 // Read the file contents in, blocking the UI thread of the browser.
77 // This is for testing purposes only! It is used to test new versions of
78 // the new tab page using a special command line option. Never use this
79 // in a way that will be used by default in product.
80 std::string file_contents;
81 if (file_util::ReadFileToString(FilePath(file_path), &file_contents))
82 return file_contents;
83 }
84
85 return std::string();
86 }
87
88 std::string SkColorToRGBAString(SkColor color) { 67 std::string SkColorToRGBAString(SkColor color) {
89 // We convert the alpha using DoubleToString because StringPrintf will use 68 // We convert the alpha using DoubleToString because StringPrintf will use
90 // locale specific formatters (e.g., use , instead of . in German). 69 // locale specific formatters (e.g., use , instead of . in German).
91 return StringPrintf("rgba(%d,%d,%d,%s)", SkColorGetR(color), 70 return StringPrintf("rgba(%d,%d,%d,%s)", SkColorGetR(color),
92 SkColorGetG(color), SkColorGetB(color), 71 SkColorGetG(color), SkColorGetB(color),
93 DoubleToString(SkColorGetA(color) / 255.0).c_str()); 72 DoubleToString(SkColorGetA(color) / 255.0).c_str());
94 } 73 }
95 74
96 // Get the CSS string for the background position on the new tab page for the 75 // Get the CSS string for the background position on the new tab page for the
97 // states when the bar is attached or detached. 76 // states when the bar is attached or detached.
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 bool has_3d = 299 bool has_3d =
321 command_line->HasSwitch(switches::kEnableAcceleratedCompositing); 300 command_line->HasSwitch(switches::kEnableAcceleratedCompositing);
322 localized_strings.SetString(L"has_3d", has_3d ? "true" : "false"); 301 localized_strings.SetString(L"has_3d", has_3d ? "true" : "false");
323 302
324 // Pass the shown_sections pref early so that we can prevent flicker. 303 // Pass the shown_sections pref early so that we can prevent flicker.
325 ShownSectionsHandler::SetFirstAppLauncherRunPref(profile_->GetPrefs()); 304 ShownSectionsHandler::SetFirstAppLauncherRunPref(profile_->GetPrefs());
326 const int shown_sections = profile_->GetPrefs()->GetInteger( 305 const int shown_sections = profile_->GetPrefs()->GetInteger(
327 prefs::kNTPShownSections); 306 prefs::kNTPShownSections);
328 localized_strings.SetInteger(L"shown_sections", shown_sections); 307 localized_strings.SetInteger(L"shown_sections", shown_sections);
329 308
330 // In case we have the new new tab page enabled we first try to read the file 309 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance().
331 // provided on the command line. If that fails we just get the resource from 310 GetRawDataResource(IDR_NEW_NEW_TAB_HTML));
332 // the resource bundle.
333 base::StringPiece new_tab_html;
334 std::string new_tab_html_str;
335 new_tab_html_str = GetCustomNewTabPageFromCommandLine();
336
337 if (!new_tab_html_str.empty()) {
338 new_tab_html = base::StringPiece(new_tab_html_str);
339 }
340
341 if (new_tab_html.empty()) {
342 new_tab_html = ResourceBundle::GetSharedInstance().GetRawDataResource(
343 IDR_NEW_NEW_TAB_HTML);
344 }
345 311
346 // Inject the template data into the HTML so that it is available before any 312 // Inject the template data into the HTML so that it is available before any
347 // layout is needed. 313 // layout is needed.
348 std::string json_html; 314 std::string json_html;
349 jstemplate_builder::AppendJsonHtml(&localized_strings, &json_html); 315 jstemplate_builder::AppendJsonHtml(&localized_strings, &json_html);
350 316
351 static const base::StringPiece template_data_placeholder( 317 static const base::StringPiece template_data_placeholder(
352 "<!-- template data placeholder -->"); 318 "<!-- template data placeholder -->");
353 size_t pos = new_tab_html.find(template_data_placeholder); 319 size_t pos = new_tab_html.find(template_data_placeholder);
354 320
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 // Create the string from our template and the replacements. 447 // Create the string from our template and the replacements.
482 const std::string css_string = ReplaceStringPlaceholders( 448 const std::string css_string = ReplaceStringPlaceholders(
483 new_tab_theme_css, subst, NULL); 449 new_tab_theme_css, subst, NULL);
484 std::string full_css = ReplaceStringPlaceholders(css_string, subst2, NULL); 450 std::string full_css = ReplaceStringPlaceholders(css_string, subst2, NULL);
485 451
486 new_tab_css_ = new RefCountedBytes; 452 new_tab_css_ = new RefCountedBytes;
487 new_tab_css_->data.resize(full_css.size()); 453 new_tab_css_->data.resize(full_css.size());
488 std::copy(full_css.begin(), full_css.end(), 454 std::copy(full_css.begin(), full_css.end(),
489 new_tab_css_->data.begin()); 455 new_tab_css_->data.begin());
490 } 456 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698