| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 const std::string GetJavaScript() { | 136 const std::string GetJavaScript() { |
| 137 return ResourceBundle::GetSharedInstance() | 137 return ResourceBundle::GetSharedInstance() |
| 138 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) | 138 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) |
| 139 .as_string(); | 139 .as_string(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 scoped_ptr<ViewerHandle> CreateViewRequest( | 142 scoped_ptr<ViewerHandle> CreateViewRequest( |
| 143 DomDistillerServiceInterface* dom_distiller_service, | 143 DomDistillerServiceInterface* dom_distiller_service, |
| 144 const std::string& path, | 144 const std::string& path, |
| 145 ViewRequestDelegate* view_request_delegate) { | 145 ViewRequestDelegate* view_request_delegate, |
| 146 const gfx::Size& render_view_size) { |
| 146 std::string entry_id = | 147 std::string entry_id = |
| 147 url_utils::GetValueForKeyInUrlPathQuery(path, kEntryIdKey); | 148 url_utils::GetValueForKeyInUrlPathQuery(path, kEntryIdKey); |
| 148 bool has_valid_entry_id = !entry_id.empty(); | 149 bool has_valid_entry_id = !entry_id.empty(); |
| 149 entry_id = StringToUpperASCII(entry_id); | 150 entry_id = StringToUpperASCII(entry_id); |
| 150 | 151 |
| 151 std::string requested_url_str = | 152 std::string requested_url_str = |
| 152 url_utils::GetValueForKeyInUrlPathQuery(path, kUrlKey); | 153 url_utils::GetValueForKeyInUrlPathQuery(path, kUrlKey); |
| 153 GURL requested_url(requested_url_str); | 154 GURL requested_url(requested_url_str); |
| 154 bool has_valid_url = url_utils::IsUrlDistillable(requested_url); | 155 bool has_valid_url = url_utils::IsUrlDistillable(requested_url); |
| 155 | 156 |
| 156 if (has_valid_entry_id && has_valid_url) { | 157 if (has_valid_entry_id && has_valid_url) { |
| 157 // It is invalid to specify a query param for both |kEntryIdKey| and | 158 // It is invalid to specify a query param for both |kEntryIdKey| and |
| 158 // |kUrlKey|. | 159 // |kUrlKey|. |
| 159 return scoped_ptr<ViewerHandle>(); | 160 return scoped_ptr<ViewerHandle>(); |
| 160 } | 161 } |
| 161 | 162 |
| 162 if (has_valid_entry_id) { | 163 if (has_valid_entry_id) { |
| 163 return dom_distiller_service->ViewEntry(view_request_delegate, | 164 return dom_distiller_service->ViewEntry( |
| 164 dom_distiller_service | 165 view_request_delegate, |
| 165 ->CreateDefaultDistillerPage(), | 166 dom_distiller_service->CreateDefaultDistillerPage(render_view_size), |
| 166 entry_id).Pass(); | 167 entry_id).Pass(); |
| 167 } else if (has_valid_url) { | 168 } else if (has_valid_url) { |
| 168 return dom_distiller_service->ViewUrl(view_request_delegate, | 169 return dom_distiller_service->ViewUrl( |
| 169 dom_distiller_service | 170 view_request_delegate, |
| 170 ->CreateDefaultDistillerPage(), | 171 dom_distiller_service->CreateDefaultDistillerPage(render_view_size), |
| 171 requested_url).Pass(); | 172 requested_url).Pass(); |
| 172 } | 173 } |
| 173 | 174 |
| 174 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|. | 175 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|. |
| 175 return scoped_ptr<ViewerHandle>(); | 176 return scoped_ptr<ViewerHandle>(); |
| 176 } | 177 } |
| 177 | 178 |
| 178 } // namespace viewer | 179 } // namespace viewer |
| 179 | 180 |
| 180 } // namespace dom_distiller | 181 } // namespace dom_distiller |
| OLD | NEW |