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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/i18n/time_formatting.h" | 13 #include "base/i18n/time_formatting.h" |
14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
24 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
25 #include "chrome/browser/history/history_notifications.h" | 25 #include "chrome/browser/history/history_notifications.h" |
26 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
27 #include "chrome/browser/history/web_history_service.h" | 27 #include "chrome/browser/history/web_history_service.h" |
28 #include "chrome/browser/history/web_history_service_factory.h" | 28 #include "chrome/browser/history/web_history_service_factory.h" |
29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/signin/signin_manager_factory.h" |
30 #include "chrome/browser/sync/profile_sync_service.h" | 31 #include "chrome/browser/sync/profile_sync_service.h" |
31 #include "chrome/browser/sync/profile_sync_service_factory.h" | 32 #include "chrome/browser/sync/profile_sync_service_factory.h" |
32 #include "chrome/browser/ui/browser_finder.h" | 33 #include "chrome/browser/ui/browser_finder.h" |
33 #include "chrome/browser/ui/chrome_pages.h" | 34 #include "chrome/browser/ui/chrome_pages.h" |
34 #include "chrome/browser/ui/webui/favicon_source.h" | 35 #include "chrome/browser/ui/webui/favicon_source.h" |
35 #include "chrome/browser/ui/webui/metrics_handler.h" | 36 #include "chrome/browser/ui/webui/metrics_handler.h" |
36 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
37 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
38 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
39 #include "chrome/grit/generated_resources.h" | 40 #include "chrome/grit/generated_resources.h" |
40 #include "components/bookmarks/browser/bookmark_model.h" | 41 #include "components/bookmarks/browser/bookmark_model.h" |
41 #include "components/bookmarks/browser/bookmark_utils.h" | 42 #include "components/bookmarks/browser/bookmark_utils.h" |
42 #include "components/history/core/browser/history_types.h" | 43 #include "components/history/core/browser/history_types.h" |
43 #include "components/search/search.h" | 44 #include "components/search/search.h" |
| 45 #include "components/signin/core/browser/signin_manager.h" |
44 #include "components/sync_driver/device_info.h" | 46 #include "components/sync_driver/device_info.h" |
45 #include "content/public/browser/notification_details.h" | 47 #include "content/public/browser/notification_details.h" |
46 #include "content/public/browser/notification_source.h" | 48 #include "content/public/browser/notification_source.h" |
47 #include "content/public/browser/url_data_source.h" | 49 #include "content/public/browser/url_data_source.h" |
48 #include "content/public/browser/web_ui.h" | 50 #include "content/public/browser/web_ui.h" |
49 #include "content/public/browser/web_ui_data_source.h" | 51 #include "content/public/browser/web_ui_data_source.h" |
50 #include "grit/browser_resources.h" | 52 #include "grit/browser_resources.h" |
51 #include "grit/theme_resources.h" | 53 #include "grit/theme_resources.h" |
52 #include "net/base/escape.h" | 54 #include "net/base/escape.h" |
53 #include "net/base/net_util.h" | 55 #include "net/base/net_util.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 #endif | 108 #endif |
107 | 109 |
108 // Identifiers for the type of device from which a history entry originated. | 110 // Identifiers for the type of device from which a history entry originated. |
109 static const char kDeviceTypeLaptop[] = "laptop"; | 111 static const char kDeviceTypeLaptop[] = "laptop"; |
110 static const char kDeviceTypePhone[] = "phone"; | 112 static const char kDeviceTypePhone[] = "phone"; |
111 static const char kDeviceTypeTablet[] = "tablet"; | 113 static const char kDeviceTypeTablet[] = "tablet"; |
112 | 114 |
113 content::WebUIDataSource* CreateHistoryUIHTMLSource(Profile* profile) { | 115 content::WebUIDataSource* CreateHistoryUIHTMLSource(Profile* profile) { |
114 PrefService* prefs = profile->GetPrefs(); | 116 PrefService* prefs = profile->GetPrefs(); |
115 | 117 |
| 118 // Check if the profile is authenticated. Guest profiles or incognito |
| 119 // windows may not have a sign in manager, and are considered not |
| 120 // authenticated. |
| 121 SigninManagerBase* signin_manager = |
| 122 SigninManagerFactory::GetForProfile(profile); |
| 123 bool is_authenticated = signin_manager != nullptr && |
| 124 signin_manager->IsAuthenticated(); |
| 125 |
116 content::WebUIDataSource* source = | 126 content::WebUIDataSource* source = |
117 content::WebUIDataSource::Create(chrome::kChromeUIHistoryFrameHost); | 127 content::WebUIDataSource::Create(chrome::kChromeUIHistoryFrameHost); |
118 source->AddBoolean("isUserSignedIn", | 128 source->AddBoolean("isUserSignedIn", is_authenticated); |
119 !prefs->GetString(prefs::kGoogleServicesUsername).empty()); | |
120 source->AddLocalizedString("collapseSessionMenuItemText", | 129 source->AddLocalizedString("collapseSessionMenuItemText", |
121 IDS_NEW_TAB_OTHER_SESSIONS_COLLAPSE_SESSION); | 130 IDS_NEW_TAB_OTHER_SESSIONS_COLLAPSE_SESSION); |
122 source->AddLocalizedString("expandSessionMenuItemText", | 131 source->AddLocalizedString("expandSessionMenuItemText", |
123 IDS_NEW_TAB_OTHER_SESSIONS_EXPAND_SESSION); | 132 IDS_NEW_TAB_OTHER_SESSIONS_EXPAND_SESSION); |
124 source->AddLocalizedString("restoreSessionMenuItemText", | 133 source->AddLocalizedString("restoreSessionMenuItemText", |
125 IDS_NEW_TAB_OTHER_SESSIONS_OPEN_ALL); | 134 IDS_NEW_TAB_OTHER_SESSIONS_OPEN_ALL); |
126 source->AddLocalizedString("xMore", IDS_OTHER_DEVICES_X_MORE); | 135 source->AddLocalizedString("xMore", IDS_OTHER_DEVICES_X_MORE); |
127 source->AddLocalizedString("loading", IDS_HISTORY_LOADING); | 136 source->AddLocalizedString("loading", IDS_HISTORY_LOADING); |
128 source->AddLocalizedString("title", IDS_HISTORY_TITLE); | 137 source->AddLocalizedString("title", IDS_HISTORY_TITLE); |
129 source->AddLocalizedString("newest", IDS_HISTORY_NEWEST); | 138 source->AddLocalizedString("newest", IDS_HISTORY_NEWEST); |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 Profile* profile = Profile::FromWebUI(web_ui); | 1033 Profile* profile = Profile::FromWebUI(web_ui); |
1025 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); | 1034 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); |
1026 } | 1035 } |
1027 | 1036 |
1028 // static | 1037 // static |
1029 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 1038 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
1030 ui::ScaleFactor scale_factor) { | 1039 ui::ScaleFactor scale_factor) { |
1031 return ResourceBundle::GetSharedInstance(). | 1040 return ResourceBundle::GetSharedInstance(). |
1032 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 1041 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
1033 } | 1042 } |
OLD | NEW |