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

Side by Side Diff: components/dom_distiller/core/viewer.cc

Issue 341563002: Theme Preferences for Distilled Pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switched to Profile from PrefService Created 6 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/dom_distiller/core/viewer.h" 5 #include "components/dom_distiller/core/viewer.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "components/dom_distiller/core/dom_distiller_service.h" 13 #include "components/dom_distiller/core/dom_distiller_service.h"
14 #include "components/dom_distiller/core/proto/distilled_article.pb.h" 14 #include "components/dom_distiller/core/proto/distilled_article.pb.h"
15 #include "components/dom_distiller/core/proto/distilled_page.pb.h" 15 #include "components/dom_distiller/core/proto/distilled_page.pb.h"
16 #include "components/dom_distiller/core/reader_mode_preferences.h"
16 #include "components/dom_distiller/core/task_tracker.h" 17 #include "components/dom_distiller/core/task_tracker.h"
17 #include "components/dom_distiller/core/url_constants.h" 18 #include "components/dom_distiller/core/url_constants.h"
18 #include "components/dom_distiller/core/url_utils.h" 19 #include "components/dom_distiller/core/url_utils.h"
19 #include "grit/component_resources.h" 20 #include "grit/component_resources.h"
20 #include "grit/components_strings.h" 21 #include "grit/components_strings.h"
21 #include "net/base/escape.h" 22 #include "net/base/escape.h"
22 #include "net/url_request/url_request.h" 23 #include "net/url_request/url_request.h"
23 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
25 #include "url/gurl.h" 26 #include "url/gurl.h"
26 27
27 namespace dom_distiller { 28 namespace dom_distiller {
28 29
29 namespace { 30 namespace {
robliao 2014/06/17 23:08:16 Add an extra linebreak here.
smaslo 2014/06/18 16:57:15 Done.
31 const char WHITE[] = "#FFF";
robliao 2014/06/17 23:08:16 Sorry, I got mixed up in Chrome Windows convention
smaslo 2014/06/18 16:57:15 Done.
32 const char BLACK[] = "#000";
33
34 std::string GetBodyInsertionText(ReaderModePrefs* reader_mode_prefs) {
35 if (reader_mode_prefs->GetHighContrastPref()) {
36 std::string body_insertion_text = "background-color: ";
37 body_insertion_text += BLACK;
38 body_insertion_text += ";\ncolor: ";
39 body_insertion_text += WHITE;
40 body_insertion_text += ";";
41 return body_insertion_text;
42 }
43 else {
44 std::string body_insertion_text = "background-color: ";
45 body_insertion_text += WHITE;
46 body_insertion_text += ";\ncolor: ";
47 body_insertion_text += BLACK;
48 body_insertion_text += ";";
49 return body_insertion_text;
50 }
51 }
30 52
31 std::string ReplaceHtmlTemplateValues( 53 std::string ReplaceHtmlTemplateValues(
32 const std::string& title, 54 const std::string& title,
33 const std::string& content, 55 const std::string& content,
34 const std::string& loading_indicator_class, 56 const std::string& loading_indicator_class,
35 const std::string& original_url) { 57 const std::string& original_url) {
36 base::StringPiece html_template = 58 base::StringPiece html_template =
37 ResourceBundle::GetSharedInstance().GetRawDataResource( 59 ResourceBundle::GetSharedInstance().GetRawDataResource(
38 IDR_DOM_DISTILLER_VIEWER_HTML); 60 IDR_DOM_DISTILLER_VIEWER_HTML);
39 std::vector<std::string> substitutions; 61 std::vector<std::string> substitutions;
40 substitutions.push_back(title); // $1 62 substitutions.push_back(title); // $1
41 substitutions.push_back(kViewerCssPath); // $2 63 substitutions.push_back(kViewerCssPath); // $2
42 substitutions.push_back(kViewerJsPath); // $3 64 substitutions.push_back(kViewerJsPath); // $3
43 substitutions.push_back(title); // $4 65 substitutions.push_back(title); // $4
44 substitutions.push_back(content); // $5 66 substitutions.push_back(content); // $5
45 substitutions.push_back(loading_indicator_class); // $6 67 substitutions.push_back(loading_indicator_class); // $6
46 substitutions.push_back( 68 substitutions.push_back(
47 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_LOADING_STRING)); // $7 69 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_LOADING_STRING)); // $7
48 substitutions.push_back(original_url); // $8 70 substitutions.push_back(original_url); // $8
49 substitutions.push_back( 71 substitutions.push_back(
50 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_VIEW_ORIGINAL)); // $9 72 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_VIEW_ORIGINAL)); // $9
51 return ReplaceStringPlaceholders(html_template, substitutions, NULL); 73 return ReplaceStringPlaceholders(html_template, substitutions, NULL);
52 } 74 }
53 75
76 std::string ReplaceCSSTemplateValues(ReaderModePrefs* reader_mode_prefs) {
77 std::vector<std::string> substitutions;
78 substitutions.push_back(GetBodyInsertionText(reader_mode_prefs));
79 base::StringPiece css_template =
80 ResourceBundle::GetSharedInstance().GetRawDataResource(
81 IDR_DISTILLER_CSS);
82 return ReplaceStringPlaceholders(css_template, substitutions, NULL);
83 }
84
54 } // namespace 85 } // namespace
55 86
56 namespace viewer { 87 namespace viewer {
57 88
58 const std::string GetUnsafeIncrementalDistilledPageJs( 89 const std::string GetUnsafeIncrementalDistilledPageJs(
59 const DistilledPageProto* page_proto, 90 const DistilledPageProto* page_proto,
60 const bool is_last_page) { 91 const bool is_last_page) {
61 std::string output; 92 std::string output;
62 base::StringValue value(page_proto->html()); 93 base::StringValue value(page_proto->html());
63 base::JSONWriter::Write(&value, &output); 94 base::JSONWriter::Write(&value, &output);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 151 }
121 152
122 const std::string GetErrorPageHtml() { 153 const std::string GetErrorPageHtml() {
123 std::string title = l10n_util::GetStringUTF8( 154 std::string title = l10n_util::GetStringUTF8(
124 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); 155 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE);
125 std::string content = l10n_util::GetStringUTF8( 156 std::string content = l10n_util::GetStringUTF8(
126 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT); 157 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT);
127 return ReplaceHtmlTemplateValues(title, content, "hidden", ""); 158 return ReplaceHtmlTemplateValues(title, content, "hidden", "");
128 } 159 }
129 160
130 const std::string GetCss() { 161 const std::string GetCss(ReaderModePrefs* reader_mode_prefs) {
131 return ResourceBundle::GetSharedInstance() 162 return ReplaceCSSTemplateValues(reader_mode_prefs);
132 .GetRawDataResource(IDR_DISTILLER_CSS)
133 .as_string();
134 } 163 }
135 164
136 const std::string GetJavaScript() { 165 const std::string GetJavaScript() {
137 return ResourceBundle::GetSharedInstance() 166 return ResourceBundle::GetSharedInstance()
138 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) 167 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS)
139 .as_string(); 168 .as_string();
140 } 169 }
141 170
142 scoped_ptr<ViewerHandle> CreateViewRequest( 171 scoped_ptr<ViewerHandle> CreateViewRequest(
143 DomDistillerServiceInterface* dom_distiller_service, 172 DomDistillerServiceInterface* dom_distiller_service,
(...skipping 27 matching lines...) Expand all
171 requested_url).Pass(); 200 requested_url).Pass();
172 } 201 }
173 202
174 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|. 203 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|.
175 return scoped_ptr<ViewerHandle>(); 204 return scoped_ptr<ViewerHandle>();
176 } 205 }
177 206
178 } // namespace viewer 207 } // namespace viewer
179 208
180 } // namespace dom_distiller 209 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698