Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Side by Side Diff: chrome/browser/ui/webui/uber/uber_ui.cc

Issue 2830983005: Remove old webui History page on desktop and mobile (Closed)
Patch Set: merge Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/uber/uber_ui.h" 5 #include "chrome/browser/ui/webui/uber/uber_ui.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 11 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
12 #include "chrome/browser/ui/webui/extensions/extensions_ui.h" 12 #include "chrome/browser/ui/webui/extensions/extensions_ui.h"
13 #include "chrome/browser/ui/webui/log_web_ui_url.h" 13 #include "chrome/browser/ui/webui/log_web_ui_url.h"
14 #include "chrome/browser/ui/webui/md_history_ui.h"
15 #include "chrome/browser/ui/webui/options/options_ui.h" 14 #include "chrome/browser/ui/webui/options/options_ui.h"
16 #include "chrome/common/chrome_features.h" 15 #include "chrome/common/chrome_features.h"
17 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/extensions/chrome_manifest_url_handlers.h" 17 #include "chrome/common/extensions/chrome_manifest_url_handlers.h"
19 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
20 #include "chrome/grit/browser_resources.h" 19 #include "chrome/grit/browser_resources.h"
21 #include "chrome/grit/chromium_strings.h" 20 #include "chrome/grit/chromium_strings.h"
22 #include "chrome/grit/generated_resources.h" 21 #include "chrome/grit/generated_resources.h"
23 #include "components/strings/grit/components_strings.h" 22 #include "components/strings/grit/components_strings.h"
24 #include "content/public/browser/browser_context.h" 23 #include "content/public/browser/browser_context.h"
25 #include "content/public/browser/navigation_controller.h" 24 #include "content/public/browser/navigation_controller.h"
26 #include "content/public/browser/navigation_entry.h" 25 #include "content/public/browser/navigation_entry.h"
27 #include "content/public/browser/navigation_handle.h" 26 #include "content/public/browser/navigation_handle.h"
28 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
29 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
30 #include "content/public/browser/web_ui.h" 29 #include "content/public/browser/web_ui.h"
31 #include "content/public/browser/web_ui_data_source.h" 30 #include "content/public/browser/web_ui_data_source.h"
32 #include "content/public/common/browser_side_navigation_policy.h" 31 #include "content/public/common/browser_side_navigation_policy.h"
33 #include "extensions/browser/extension_registry.h"
34 #include "extensions/common/extension_set.h"
35 32
36 using content::NavigationController; 33 using content::NavigationController;
37 using content::NavigationEntry; 34 using content::NavigationEntry;
38 using content::RenderFrameHost; 35 using content::RenderFrameHost;
39 using content::WebContents; 36 using content::WebContents;
40 37
41 namespace { 38 namespace {
42 39
43 content::WebUIDataSource* CreateUberHTMLSource() { 40 content::WebUIDataSource* CreateUberHTMLSource() {
44 content::WebUIDataSource* source = 41 content::WebUIDataSource* source =
45 content::WebUIDataSource::Create(chrome::kChromeUIUberHost); 42 content::WebUIDataSource::Create(chrome::kChromeUIUberHost);
46 43
47 source->SetJsonPath("strings.js"); 44 source->SetJsonPath("strings.js");
48 source->AddResourcePath("uber.js", IDR_UBER_JS); 45 source->AddResourcePath("uber.js", IDR_UBER_JS);
49 source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS); 46 source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS);
50 source->SetDefaultResource(IDR_UBER_HTML); 47 source->SetDefaultResource(IDR_UBER_HTML);
51 source->OverrideContentSecurityPolicyChildSrc("child-src chrome:;"); 48 source->OverrideContentSecurityPolicyChildSrc("child-src chrome:;");
52 49
53 // Hack alert: continue showing "Loading..." until a real title is set. 50 // Hack alert: continue showing "Loading..." until a real title is set.
54 source->AddLocalizedString("pageTitle", IDS_TAB_LOADING_TITLE); 51 source->AddLocalizedString("pageTitle", IDS_TAB_LOADING_TITLE);
55 52
56 source->AddString("extensionsFrameURL", chrome::kChromeUIExtensionsFrameURL); 53 source->AddString("extensionsFrameURL", chrome::kChromeUIExtensionsFrameURL);
57 source->AddString("extensionsHost", chrome::kChromeUIExtensionsHost); 54 source->AddString("extensionsHost", chrome::kChromeUIExtensionsHost);
58 source->AddString("helpFrameURL", chrome::kChromeUIHelpFrameURL); 55 source->AddString("helpFrameURL", chrome::kChromeUIHelpFrameURL);
59 source->AddString("helpHost", chrome::kChromeUIHelpHost); 56 source->AddString("helpHost", chrome::kChromeUIHelpHost);
60 source->AddString("historyFrameURL", chrome::kChromeUIHistoryFrameURL);
61 source->AddString("historyHost", chrome::kChromeUIHistoryHost);
62 source->AddString("settingsFrameURL", chrome::kChromeUISettingsFrameURL); 57 source->AddString("settingsFrameURL", chrome::kChromeUISettingsFrameURL);
63 source->AddString("settingsHost", chrome::kChromeUISettingsHost); 58 source->AddString("settingsHost", chrome::kChromeUISettingsHost);
64 59
65 return source; 60 return source;
66 } 61 }
67 62
68 // Determines whether the user has an active extension of the given type.
69 bool HasExtensionType(content::BrowserContext* browser_context,
70 const std::string& extension_type) {
71 const extensions::ExtensionSet& extension_set =
72 extensions::ExtensionRegistry::Get(browser_context)->enabled_extensions();
73 for (extensions::ExtensionSet::const_iterator iter = extension_set.begin();
74 iter != extension_set.end(); ++iter) {
75 const extensions::URLOverrides::URLOverrideMap& map =
76 extensions::URLOverrides::GetChromeURLOverrides(iter->get());
77 if (base::ContainsKey(map, extension_type))
78 return true;
79 }
80
81 return false;
82 }
83
84 content::WebUIDataSource* CreateUberFrameHTMLSource( 63 content::WebUIDataSource* CreateUberFrameHTMLSource(
85 content::BrowserContext* browser_context) { 64 content::BrowserContext* browser_context) {
86 content::WebUIDataSource* source = 65 content::WebUIDataSource* source =
87 content::WebUIDataSource::Create(chrome::kChromeUIUberFrameHost); 66 content::WebUIDataSource::Create(chrome::kChromeUIUberFrameHost);
88 Profile* profile = Profile::FromBrowserContext(browser_context); 67 Profile* profile = Profile::FromBrowserContext(browser_context);
89 68
90 source->SetJsonPath("strings.js"); 69 source->SetJsonPath("strings.js");
91 source->AddResourcePath("uber_frame.js", IDR_UBER_FRAME_JS); 70 source->AddResourcePath("uber_frame.js", IDR_UBER_FRAME_JS);
92 source->SetDefaultResource(IDR_UBER_FRAME_HTML); 71 source->SetDefaultResource(IDR_UBER_FRAME_HTML);
93 72
94 // TODO(jhawkins): Attempt to get rid of IDS_SHORT_PRODUCT_OS_NAME. 73 // TODO(jhawkins): Attempt to get rid of IDS_SHORT_PRODUCT_OS_NAME.
95 #if defined(OS_CHROMEOS) 74 #if defined(OS_CHROMEOS)
96 source->AddLocalizedString("shortProductName", IDS_SHORT_PRODUCT_OS_NAME); 75 source->AddLocalizedString("shortProductName", IDS_SHORT_PRODUCT_OS_NAME);
97 #else 76 #else
98 source->AddLocalizedString("shortProductName", IDS_SHORT_PRODUCT_NAME); 77 source->AddLocalizedString("shortProductName", IDS_SHORT_PRODUCT_NAME);
99 #endif // defined(OS_CHROMEOS) 78 #endif // defined(OS_CHROMEOS)
100 79
101 source->AddBoolean("hideExtensions", 80 source->AddBoolean("hideExtensions",
102 base::FeatureList::IsEnabled(features::kMaterialDesignExtensions)); 81 base::FeatureList::IsEnabled(features::kMaterialDesignExtensions));
103 source->AddBoolean("hideSettingsAndHelp", 82 source->AddBoolean("hideSettingsAndHelp",
104 ::switches::SettingsWindowEnabled() || 83 ::switches::SettingsWindowEnabled() ||
105 base::FeatureList::IsEnabled(features::kMaterialDesignSettings)); 84 base::FeatureList::IsEnabled(features::kMaterialDesignSettings));
106 source->AddString("extensionsHost", chrome::kChromeUIExtensionsHost); 85 source->AddString("extensionsHost", chrome::kChromeUIExtensionsHost);
107 source->AddLocalizedString("extensionsDisplayName", 86 source->AddLocalizedString("extensionsDisplayName",
108 IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); 87 IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE);
109 source->AddString("helpHost", chrome::kChromeUIHelpHost); 88 source->AddString("helpHost", chrome::kChromeUIHelpHost);
110 source->AddLocalizedString("helpDisplayName", IDS_ABOUT_TITLE); 89 source->AddLocalizedString("helpDisplayName", IDS_ABOUT_TITLE);
111 source->AddString("historyHost", chrome::kChromeUIHistoryHost);
112 source->AddLocalizedString("historyDisplayName", IDS_HISTORY_TITLE);
113 source->AddString("settingsHost", chrome::kChromeUISettingsHost); 90 source->AddString("settingsHost", chrome::kChromeUISettingsHost);
114 source->AddLocalizedString("settingsDisplayName", IDS_SETTINGS_TITLE); 91 source->AddLocalizedString("settingsDisplayName", IDS_SETTINGS_TITLE);
115 bool overrides_history =
116 HasExtensionType(browser_context, chrome::kChromeUIHistoryHost);
117 source->AddString("overridesHistory", overrides_history ? "yes" : "no");
118 source->AddBoolean("hideHistory", base::FeatureList::IsEnabled(
119 features::kMaterialDesignHistory) &&
120 !overrides_history);
121 92
122 source->DisableDenyXFrameOptions(); 93 source->DisableDenyXFrameOptions();
123 source->OverrideContentSecurityPolicyChildSrc("child-src chrome:;"); 94 source->OverrideContentSecurityPolicyChildSrc("child-src chrome:;");
124 95
125 source->AddBoolean("profileIsGuest", profile->IsGuestSession()); 96 source->AddBoolean("profileIsGuest", profile->IsGuestSession());
126 97
127 return source; 98 return source;
128 } 99 }
129 100
130 void UpdateHistoryNavigation(content::WebUI* web_ui) {
131 bool overrides_history =
132 HasExtensionType(web_ui->GetWebContents()->GetBrowserContext(),
133 chrome::kChromeUIHistoryHost);
134 web_ui->CallJavascriptFunctionUnsafe(
135 "uber_frame.setNavigationOverride",
136 base::Value(chrome::kChromeUIHistoryHost),
137 base::Value(overrides_history ? "yes" : "no"));
138 }
139
140 } // namespace 101 } // namespace
141 102
142 SubframeLogger::SubframeLogger(content::WebContents* contents) 103 SubframeLogger::SubframeLogger(content::WebContents* contents)
143 : WebContentsObserver(contents) {} 104 : WebContentsObserver(contents) {}
144 105
145 SubframeLogger::~SubframeLogger() {} 106 SubframeLogger::~SubframeLogger() {}
146 107
147 void SubframeLogger::DidFinishNavigation( 108 void SubframeLogger::DidFinishNavigation(
148 content::NavigationHandle* navigation_handle) { 109 content::NavigationHandle* navigation_handle) {
149 if (!navigation_handle->HasCommitted()) 110 if (!navigation_handle->HasCommitted())
150 return; 111 return;
151 112
152 const GURL& url = navigation_handle->GetURL(); 113 const GURL& url = navigation_handle->GetURL();
153 if (url == chrome::kChromeUIExtensionsFrameURL || 114 if (url == chrome::kChromeUIExtensionsFrameURL ||
154 url == chrome::kChromeUIHelpFrameURL || 115 url == chrome::kChromeUIHelpFrameURL ||
155 url == chrome::kChromeUIHistoryFrameURL ||
156 url == chrome::kChromeUISettingsFrameURL || 116 url == chrome::kChromeUISettingsFrameURL ||
157 url == chrome::kChromeUIUberFrameURL) { 117 url == chrome::kChromeUIUberFrameURL) {
158 webui::LogWebUIUrl(url); 118 webui::LogWebUIUrl(url);
159 } 119 }
160 } 120 }
161 121
162 UberUI::UberUI(content::WebUI* web_ui) : WebUIController(web_ui) { 122 UberUI::UberUI(content::WebUI* web_ui) : WebUIController(web_ui) {
163 subframe_logger_ = base::MakeUnique<SubframeLogger>(web_ui->GetWebContents()); 123 subframe_logger_ = base::MakeUnique<SubframeLogger>(web_ui->GetWebContents());
164 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), 124 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(),
165 CreateUberHTMLSource()); 125 CreateUberHTMLSource());
166 126
167 RegisterSubpage(chrome::kChromeUIExtensionsFrameURL, 127 RegisterSubpage(chrome::kChromeUIExtensionsFrameURL,
168 chrome::kChromeUIExtensionsHost); 128 chrome::kChromeUIExtensionsHost);
169 RegisterSubpage(chrome::kChromeUIHelpFrameURL, 129 RegisterSubpage(chrome::kChromeUIHelpFrameURL,
170 chrome::kChromeUIHelpHost); 130 chrome::kChromeUIHelpHost);
171 RegisterSubpage(chrome::kChromeUIHistoryFrameURL,
172 chrome::kChromeUIHistoryHost);
173 RegisterSubpage(chrome::kChromeUISettingsFrameURL, 131 RegisterSubpage(chrome::kChromeUISettingsFrameURL,
174 chrome::kChromeUISettingsHost); 132 chrome::kChromeUISettingsHost);
175 RegisterSubpage(chrome::kChromeUIUberFrameURL, 133 RegisterSubpage(chrome::kChromeUIUberFrameURL,
176 chrome::kChromeUIUberHost); 134 chrome::kChromeUIUberHost);
177 } 135 }
178 136
179 UberUI::~UberUI() { 137 UberUI::~UberUI() {
180 } 138 }
181 139
182 void UberUI::RegisterSubpage(const std::string& page_url, 140 void UberUI::RegisterSubpage(const std::string& page_url,
(...skipping 28 matching lines...) Expand all
211 // The message was sent from a subpage. 169 // The message was sent from a subpage.
212 // TODO(jam) fix this to use interface 170 // TODO(jam) fix this to use interface
213 // return subpage->second->GetController()->OverrideHandleWebUIMessage( 171 // return subpage->second->GetController()->OverrideHandleWebUIMessage(
214 // source_url, message, args); 172 // source_url, message, args);
215 subpage->second->ProcessWebUIMessage(source_url, message, args); 173 subpage->second->ProcessWebUIMessage(source_url, message, args);
216 return true; 174 return true;
217 } 175 }
218 176
219 // UberFrameUI 177 // UberFrameUI
220 178
221 UberFrameUI::UberFrameUI(content::WebUI* web_ui) 179 UberFrameUI::UberFrameUI(content::WebUI* web_ui) : WebUIController(web_ui) {
222 : WebUIController(web_ui),
223 extension_registry_observer_(this) {
224 content::BrowserContext* browser_context = 180 content::BrowserContext* browser_context =
225 web_ui->GetWebContents()->GetBrowserContext(); 181 web_ui->GetWebContents()->GetBrowserContext();
226 content::WebUIDataSource::Add(browser_context, 182 content::WebUIDataSource::Add(browser_context,
227 CreateUberFrameHTMLSource(browser_context)); 183 CreateUberFrameHTMLSource(browser_context));
228
229 // Register as an observer for when extensions are loaded and unloaded.
230 extension_registry_observer_.Add(
231 extensions::ExtensionRegistry::Get(browser_context));
232 } 184 }
233 185
234 UberFrameUI::~UberFrameUI() { 186 UberFrameUI::~UberFrameUI() {
235 } 187 }
236
237 void UberFrameUI::OnExtensionLoaded(content::BrowserContext* browser_context,
238 const extensions::Extension* extension) {
239 // We listen for notifications that indicate an extension has been loaded
240 // (i.e., has been installed and/or enabled) or unloaded (i.e., has been
241 // uninstalled and/or disabled). If one of these events has occurred, then
242 // we must update the behavior of the History navigation element so that
243 // it opens the history extension if one is installed and enabled or
244 // opens the default history page if one is uninstalled or disabled.
245 UpdateHistoryNavigation(web_ui());
246 }
247
248 void UberFrameUI::OnExtensionUnloaded(
249 content::BrowserContext* browser_context,
250 const extensions::Extension* extension,
251 extensions::UnloadedExtensionReason reason) {
252 UpdateHistoryNavigation(web_ui());
253 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/uber/uber_ui.h ('k') | chrome/browser/ui/webui/uber/uber_ui_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698