OLD | NEW |
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" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 const std::string GetJavaScript() { | 171 const std::string GetJavaScript() { |
172 return ResourceBundle::GetSharedInstance() | 172 return ResourceBundle::GetSharedInstance() |
173 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) | 173 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) |
174 .as_string(); | 174 .as_string(); |
175 } | 175 } |
176 | 176 |
177 scoped_ptr<ViewerHandle> CreateViewRequest( | 177 scoped_ptr<ViewerHandle> CreateViewRequest( |
178 DomDistillerServiceInterface* dom_distiller_service, | 178 DomDistillerServiceInterface* dom_distiller_service, |
179 const std::string& path, | 179 const std::string& path, |
180 ViewRequestDelegate* view_request_delegate) { | 180 ViewRequestDelegate* view_request_delegate, |
| 181 const gfx::Size& render_view_size) { |
181 std::string entry_id = | 182 std::string entry_id = |
182 url_utils::GetValueForKeyInUrlPathQuery(path, kEntryIdKey); | 183 url_utils::GetValueForKeyInUrlPathQuery(path, kEntryIdKey); |
183 bool has_valid_entry_id = !entry_id.empty(); | 184 bool has_valid_entry_id = !entry_id.empty(); |
184 entry_id = StringToUpperASCII(entry_id); | 185 entry_id = StringToUpperASCII(entry_id); |
185 | 186 |
186 std::string requested_url_str = | 187 std::string requested_url_str = |
187 url_utils::GetValueForKeyInUrlPathQuery(path, kUrlKey); | 188 url_utils::GetValueForKeyInUrlPathQuery(path, kUrlKey); |
188 GURL requested_url(requested_url_str); | 189 GURL requested_url(requested_url_str); |
189 bool has_valid_url = url_utils::IsUrlDistillable(requested_url); | 190 bool has_valid_url = url_utils::IsUrlDistillable(requested_url); |
190 | 191 |
191 if (has_valid_entry_id && has_valid_url) { | 192 if (has_valid_entry_id && has_valid_url) { |
192 // It is invalid to specify a query param for both |kEntryIdKey| and | 193 // It is invalid to specify a query param for both |kEntryIdKey| and |
193 // |kUrlKey|. | 194 // |kUrlKey|. |
194 return scoped_ptr<ViewerHandle>(); | 195 return scoped_ptr<ViewerHandle>(); |
195 } | 196 } |
196 | 197 |
197 if (has_valid_entry_id) { | 198 if (has_valid_entry_id) { |
198 return dom_distiller_service->ViewEntry(view_request_delegate, | 199 return dom_distiller_service->ViewEntry( |
199 dom_distiller_service | 200 view_request_delegate, |
200 ->CreateDefaultDistillerPage(), | 201 dom_distiller_service->CreateDefaultDistillerPage(render_view_size), |
201 entry_id).Pass(); | 202 entry_id).Pass(); |
202 } else if (has_valid_url) { | 203 } else if (has_valid_url) { |
203 return dom_distiller_service->ViewUrl(view_request_delegate, | 204 return dom_distiller_service->ViewUrl( |
204 dom_distiller_service | 205 view_request_delegate, |
205 ->CreateDefaultDistillerPage(), | 206 dom_distiller_service->CreateDefaultDistillerPage(render_view_size), |
206 requested_url).Pass(); | 207 requested_url).Pass(); |
207 } | 208 } |
208 | 209 |
209 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|. | 210 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|. |
210 return scoped_ptr<ViewerHandle>(); | 211 return scoped_ptr<ViewerHandle>(); |
211 } | 212 } |
212 | 213 |
213 const std::string GetDistilledPageThemeJs(DistilledPagePrefs::Theme theme) { | 214 const std::string GetDistilledPageThemeJs(DistilledPagePrefs::Theme theme) { |
214 return "useTheme('" + GetJsTheme(theme) + "');"; | 215 return "useTheme('" + GetJsTheme(theme) + "');"; |
215 } | 216 } |
216 | 217 |
217 } // namespace viewer | 218 } // namespace viewer |
218 | 219 |
219 } // namespace dom_distiller | 220 } // namespace dom_distiller |
OLD | NEW |