| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/history_ui.h" | 5 #include "chrome/browser/ui/webui/history_ui.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } // namespace | 173 } // namespace |
| 174 | 174 |
| 175 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 175 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 176 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); | 176 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); |
| 177 web_ui->AddMessageHandler(new MetricsHandler()); | 177 web_ui->AddMessageHandler(new MetricsHandler()); |
| 178 | 178 |
| 179 // On mobile we deal with foreign sessions differently. | 179 // On mobile we deal with foreign sessions differently. |
| 180 #if !defined(OS_ANDROID) | 180 #if !defined(OS_ANDROID) |
| 181 if (search::IsInstantExtendedAPIEnabled()) { | 181 if (search::IsInstantExtendedAPIEnabled()) { |
| 182 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); | 182 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); |
| 183 web_ui->AddMessageHandler(new HistoryLoginHandler()); | 183 web_ui->AddMessageHandler(new HistoryLoginHandler( |
| 184 base::Bind(&HistoryUI::CreateDataSource, base::Unretained(this)))); |
| 184 } | 185 } |
| 185 #endif | 186 #endif |
| 186 | 187 |
| 187 // TODO(crbug.com/595332): Since the API to query other forms of browsing | 188 // TODO(crbug.com/595332): Since the API to query other forms of browsing |
| 188 // history is not ready yet, make it possible to test the history UI as if | 189 // history is not ready yet, make it possible to test the history UI as if |
| 189 // it were. If the user opens chrome://history/?reset_ofbh, we will assume | 190 // it were. If the user opens chrome://history/?reset_ofbh, we will assume |
| 190 // that other forms of browsing history exist (for all accounts), and we will | 191 // that other forms of browsing history exist (for all accounts), and we will |
| 191 // also reset the one-time notice shown in the Clear Browsing Data dialog. | 192 // also reset the one-time notice shown in the Clear Browsing Data dialog. |
| 192 // This code should be removed as soon as the API is ready. | 193 // This code should be removed as soon as the API is ready. |
| 193 GURL url = web_ui->GetWebContents()->GetVisibleURL(); | 194 GURL url = web_ui->GetWebContents()->GetVisibleURL(); |
| 194 if (url.has_query() && url.query() == "reset_ofbh") { | 195 if (url.has_query() && url.query() == "reset_ofbh") { |
| 195 Profile::FromWebUI(web_ui)->GetPrefs()->SetInteger( | 196 Profile::FromWebUI(web_ui)->GetPrefs()->SetInteger( |
| 196 browsing_data::prefs::kClearBrowsingDataHistoryNoticeShownTimes, 0); | 197 browsing_data::prefs::kClearBrowsingDataHistoryNoticeShownTimes, 0); |
| 197 browsing_data::testing:: | 198 browsing_data::testing:: |
| 198 g_override_other_forms_of_browsing_history_query = true; | 199 g_override_other_forms_of_browsing_history_query = true; |
| 199 } | 200 } |
| 200 | 201 |
| 201 // Set up the chrome://history-frame/ source. | 202 // Set up the chrome://history-frame/ source. |
| 202 Profile* profile = Profile::FromWebUI(web_ui); | 203 CreateDataSource(); |
| 203 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); | |
| 204 } | 204 } |
| 205 | 205 |
| 206 HistoryUI::~HistoryUI() {} | 206 HistoryUI::~HistoryUI() {} |
| 207 | 207 |
| 208 // static | 208 // static |
| 209 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 209 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
| 210 ui::ScaleFactor scale_factor) { | 210 ui::ScaleFactor scale_factor) { |
| 211 return ResourceBundle::GetSharedInstance(). | 211 return ResourceBundle::GetSharedInstance(). |
| 212 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 212 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
| 213 } | 213 } |
| 214 |
| 215 // TODO(lshang): Change to not re-create data source every time after we use |
| 216 // unique_ptr instead of raw pointers for data source. |
| 217 void HistoryUI::CreateDataSource() { |
| 218 Profile* profile = Profile::FromWebUI(web_ui()); |
| 219 content::WebUIDataSource* data_source = CreateHistoryUIHTMLSource(profile); |
| 220 content::WebUIDataSource::Add(profile, data_source); |
| 221 } |
| OLD | NEW |