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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "chrome/browser/history/web_history_service_factory.h" | 12 #include "chrome/browser/history/web_history_service_factory.h" |
13 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 13 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
16 #include "chrome/browser/ui/webui/browsing_history_handler.h" | 16 #include "chrome/browser/ui/webui/browsing_history_handler.h" |
17 #include "chrome/browser/ui/webui/metrics_handler.h" | 17 #include "chrome/browser/ui/webui/metrics_handler.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 22 #include "components/browsing_data_ui/history_notice_utils.h" |
22 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
23 #include "components/search/search.h" | 24 #include "components/search/search.h" |
24 #include "components/signin/core/browser/signin_manager.h" | 25 #include "components/signin/core/browser/signin_manager.h" |
| 26 #include "content/public/browser/web_contents.h" |
25 #include "content/public/browser/web_ui.h" | 27 #include "content/public/browser/web_ui.h" |
26 #include "content/public/browser/web_ui_data_source.h" | 28 #include "content/public/browser/web_ui_data_source.h" |
| 29 #include "content/public/common/referrer.h" |
27 #include "grit/browser_resources.h" | 30 #include "grit/browser_resources.h" |
28 #include "grit/components_scaled_resources.h" | 31 #include "grit/components_scaled_resources.h" |
29 #include "grit/components_strings.h" | 32 #include "grit/components_strings.h" |
30 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
31 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/base/page_transition_types.h" |
32 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
33 | 37 |
34 #if !defined(OS_ANDROID) | 38 #if !defined(OS_ANDROID) |
35 #include "chrome/browser/ui/webui/foreign_session_handler.h" | 39 #include "chrome/browser/ui/webui/foreign_session_handler.h" |
36 #include "chrome/browser/ui/webui/history_login_handler.h" | 40 #include "chrome/browser/ui/webui/history_login_handler.h" |
37 #endif | 41 #endif |
38 | 42 |
39 static const char kStringsJsFile[] = "strings.js"; | 43 static const char kStringsJsFile[] = "strings.js"; |
40 static const char kHistoryJsFile[] = "history.js"; | 44 static const char kHistoryJsFile[] = "history.js"; |
41 static const char kOtherDevicesJsFile[] = "other_devices.js"; | 45 static const char kOtherDevicesJsFile[] = "other_devices.js"; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 source->AddResourcePath(kHistoryJsFile, IDR_HISTORY_JS); | 167 source->AddResourcePath(kHistoryJsFile, IDR_HISTORY_JS); |
164 source->AddResourcePath(kOtherDevicesJsFile, IDR_OTHER_DEVICES_JS); | 168 source->AddResourcePath(kOtherDevicesJsFile, IDR_OTHER_DEVICES_JS); |
165 source->SetDefaultResource(IDR_HISTORY_HTML); | 169 source->SetDefaultResource(IDR_HISTORY_HTML); |
166 source->DisableDenyXFrameOptions(); | 170 source->DisableDenyXFrameOptions(); |
167 | 171 |
168 return source; | 172 return source; |
169 } | 173 } |
170 | 174 |
171 } // namespace | 175 } // namespace |
172 | 176 |
173 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 177 HistoryUI::HistoryUI(content::WebUI* web_ui) |
| 178 : WebUIController(web_ui), |
| 179 WebContentsObserver(web_ui->GetWebContents()) { |
174 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); | 180 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); |
175 web_ui->AddMessageHandler(new MetricsHandler()); | 181 web_ui->AddMessageHandler(new MetricsHandler()); |
176 | 182 |
177 // On mobile we deal with foreign sessions differently. | 183 // On mobile we deal with foreign sessions differently. |
178 #if !defined(OS_ANDROID) | 184 #if !defined(OS_ANDROID) |
179 if (search::IsInstantExtendedAPIEnabled()) { | 185 if (search::IsInstantExtendedAPIEnabled()) { |
180 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); | 186 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); |
181 web_ui->AddMessageHandler(new HistoryLoginHandler()); | 187 web_ui->AddMessageHandler(new HistoryLoginHandler()); |
182 } | 188 } |
183 #endif | 189 #endif |
184 | 190 |
185 // Set up the chrome://history-frame/ source. | 191 // Set up the chrome://history-frame/ source. |
186 Profile* profile = Profile::FromWebUI(web_ui); | 192 Profile* profile = Profile::FromWebUI(web_ui); |
187 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); | 193 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); |
188 } | 194 } |
189 | 195 |
190 HistoryUI::~HistoryUI() {} | 196 HistoryUI::~HistoryUI() {} |
191 | 197 |
192 // static | 198 // static |
193 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 199 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
194 ui::ScaleFactor scale_factor) { | 200 ui::ScaleFactor scale_factor) { |
195 return ResourceBundle::GetSharedInstance(). | 201 return ResourceBundle::GetSharedInstance(). |
196 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 202 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
197 } | 203 } |
| 204 |
| 205 void HistoryUI::DidStopLoading() { |
| 206 // TODO(crbug.com/595332): Since the API to query other forms of browsing |
| 207 // history is not ready yet, make it possible to test the history UI as if |
| 208 // it were. If the user opens chrome://history/?reset_ofbh, we will assume |
| 209 // that other forms of browsing history exist (for all accounts), and we will |
| 210 // also reset the one-time notice shown in the Clear Browsing Data dialog. |
| 211 // This code should be removed as soon as the API is ready. |
| 212 GURL url = web_ui()->GetWebContents()->GetVisibleURL(); |
| 213 if (!url.is_valid() || url.query() != "reset_ofbh") |
| 214 return; |
| 215 |
| 216 Profile::FromWebUI(web_ui())->GetPrefs()->SetInteger( |
| 217 prefs::kClearBrowsingDataHistoryNoticeShownTimes, 0); |
| 218 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 219 browsing_data_ui::switches::kOverrideOtherFormsOfBrowsingHistoryQuery); |
| 220 web_ui()->GetWebContents()->GetController().LoadURL( |
| 221 GURL(chrome::kChromeUIHistoryURL), |
| 222 content::Referrer(), |
| 223 ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
| 224 std::string()); |
| 225 } |
OLD | NEW |