| 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/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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "components/strings/grit/components_strings.h" | 23 #include "components/strings/grit/components_strings.h" |
| 24 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
| 25 #include "content/public/browser/navigation_controller.h" | 25 #include "content/public/browser/navigation_controller.h" |
| 26 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
| 27 #include "content/public/browser/navigation_handle.h" | 27 #include "content/public/browser/navigation_handle.h" |
| 28 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
| 29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 30 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
| 31 #include "content/public/browser/web_ui_data_source.h" | 31 #include "content/public/browser/web_ui_data_source.h" |
| 32 #include "content/public/common/browser_side_navigation_policy.h" | 32 #include "content/public/common/browser_side_navigation_policy.h" |
| 33 #include "content/public/common/url_constants.h" |
| 33 #include "extensions/browser/extension_registry.h" | 34 #include "extensions/browser/extension_registry.h" |
| 34 #include "extensions/common/extension_set.h" | 35 #include "extensions/common/extension_set.h" |
| 35 | 36 |
| 36 using content::NavigationController; | 37 using content::NavigationController; |
| 37 using content::NavigationEntry; | 38 using content::NavigationEntry; |
| 38 using content::RenderFrameHost; | 39 using content::RenderFrameHost; |
| 39 using content::WebContents; | 40 using content::WebContents; |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 content::WebUIDataSource* CreateUberHTMLSource() { | 44 content::WebUIDataSource* CreateUberHTMLSource() { |
| 44 content::WebUIDataSource* source = | 45 content::WebUIDataSource* source = |
| 45 content::WebUIDataSource::Create(chrome::kChromeUIUberHost); | 46 content::WebUIDataSource::Create(chrome::kChromeUIUberHost); |
| 46 | 47 |
| 47 source->SetJsonPath("strings.js"); | 48 source->SetJsonPath("strings.js"); |
| 48 source->AddResourcePath("uber.js", IDR_UBER_JS); | 49 source->AddResourcePath("uber.js", IDR_UBER_JS); |
| 49 source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS); | 50 source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS); |
| 50 source->SetDefaultResource(IDR_UBER_HTML); | 51 source->SetDefaultResource(IDR_UBER_HTML); |
| 51 source->OverrideContentSecurityPolicyChildSrc("child-src chrome:;"); | 52 source->OverrideContentSecurityPolicyChildSrc("child-src chrome:;"); |
| 52 | 53 |
| 53 // Hack alert: continue showing "Loading..." until a real title is set. | 54 // Hack alert: continue showing "Loading..." until a real title is set. |
| 54 source->AddLocalizedString("pageTitle", IDS_TAB_LOADING_TITLE); | 55 source->AddLocalizedString("pageTitle", IDS_TAB_LOADING_TITLE); |
| 55 | 56 |
| 56 source->AddString("extensionsFrameURL", chrome::kChromeUIExtensionsFrameURL); | 57 source->AddString("extensionsFrameURL", chrome::kChromeUIExtensionsFrameURL); |
| 57 source->AddString("extensionsHost", chrome::kChromeUIExtensionsHost); | 58 source->AddString("extensionsHost", chrome::kChromeUIExtensionsHost); |
| 58 source->AddString("helpFrameURL", chrome::kChromeUIHelpFrameURL); | 59 source->AddString("helpFrameURL", chrome::kChromeUIHelpFrameURL); |
| 59 source->AddString("helpHost", chrome::kChromeUIHelpHost); | 60 source->AddString("helpHost", chrome::kChromeUIHelpHost); |
| 60 source->AddString("historyFrameURL", chrome::kChromeUIHistoryFrameURL); | 61 source->AddString("historyFrameURL", chrome::kChromeUIHistoryFrameURL); |
| 61 source->AddString("historyHost", chrome::kChromeUIHistoryHost); | 62 source->AddString("historyHost", content::kChromeUIHistoryHost); |
| 62 source->AddString("settingsFrameURL", chrome::kChromeUISettingsFrameURL); | 63 source->AddString("settingsFrameURL", chrome::kChromeUISettingsFrameURL); |
| 63 source->AddString("settingsHost", chrome::kChromeUISettingsHost); | 64 source->AddString("settingsHost", chrome::kChromeUISettingsHost); |
| 64 | 65 |
| 65 return source; | 66 return source; |
| 66 } | 67 } |
| 67 | 68 |
| 68 // Determines whether the user has an active extension of the given type. | 69 // Determines whether the user has an active extension of the given type. |
| 69 bool HasExtensionType(content::BrowserContext* browser_context, | 70 bool HasExtensionType(content::BrowserContext* browser_context, |
| 70 const std::string& extension_type) { | 71 const std::string& extension_type) { |
| 71 const extensions::ExtensionSet& extension_set = | 72 const extensions::ExtensionSet& extension_set = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 101 source->AddBoolean("hideExtensions", | 102 source->AddBoolean("hideExtensions", |
| 102 base::FeatureList::IsEnabled(features::kMaterialDesignExtensions)); | 103 base::FeatureList::IsEnabled(features::kMaterialDesignExtensions)); |
| 103 source->AddBoolean("hideSettingsAndHelp", | 104 source->AddBoolean("hideSettingsAndHelp", |
| 104 ::switches::SettingsWindowEnabled() || | 105 ::switches::SettingsWindowEnabled() || |
| 105 base::FeatureList::IsEnabled(features::kMaterialDesignSettings)); | 106 base::FeatureList::IsEnabled(features::kMaterialDesignSettings)); |
| 106 source->AddString("extensionsHost", chrome::kChromeUIExtensionsHost); | 107 source->AddString("extensionsHost", chrome::kChromeUIExtensionsHost); |
| 107 source->AddLocalizedString("extensionsDisplayName", | 108 source->AddLocalizedString("extensionsDisplayName", |
| 108 IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); | 109 IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); |
| 109 source->AddString("helpHost", chrome::kChromeUIHelpHost); | 110 source->AddString("helpHost", chrome::kChromeUIHelpHost); |
| 110 source->AddLocalizedString("helpDisplayName", IDS_ABOUT_TITLE); | 111 source->AddLocalizedString("helpDisplayName", IDS_ABOUT_TITLE); |
| 111 source->AddString("historyHost", chrome::kChromeUIHistoryHost); | 112 source->AddString("historyHost", content::kChromeUIHistoryHost); |
| 112 source->AddLocalizedString("historyDisplayName", IDS_HISTORY_TITLE); | 113 source->AddLocalizedString("historyDisplayName", IDS_HISTORY_TITLE); |
| 113 source->AddString("settingsHost", chrome::kChromeUISettingsHost); | 114 source->AddString("settingsHost", chrome::kChromeUISettingsHost); |
| 114 source->AddLocalizedString("settingsDisplayName", IDS_SETTINGS_TITLE); | 115 source->AddLocalizedString("settingsDisplayName", IDS_SETTINGS_TITLE); |
| 115 bool overrides_history = | 116 bool overrides_history = |
| 116 HasExtensionType(browser_context, chrome::kChromeUIHistoryHost); | 117 HasExtensionType(browser_context, content::kChromeUIHistoryHost); |
| 117 source->AddString("overridesHistory", overrides_history ? "yes" : "no"); | 118 source->AddString("overridesHistory", overrides_history ? "yes" : "no"); |
| 118 source->AddBoolean("hideHistory", base::FeatureList::IsEnabled( | 119 source->AddBoolean("hideHistory", base::FeatureList::IsEnabled( |
| 119 features::kMaterialDesignHistory) && | 120 features::kMaterialDesignHistory) && |
| 120 !overrides_history); | 121 !overrides_history); |
| 121 | 122 |
| 122 source->DisableDenyXFrameOptions(); | 123 source->DisableDenyXFrameOptions(); |
| 123 source->OverrideContentSecurityPolicyChildSrc("child-src chrome:;"); | 124 source->OverrideContentSecurityPolicyChildSrc("child-src chrome:;"); |
| 124 | 125 |
| 125 source->AddBoolean("profileIsGuest", profile->IsGuestSession()); | 126 source->AddBoolean("profileIsGuest", profile->IsGuestSession()); |
| 126 | 127 |
| 127 return source; | 128 return source; |
| 128 } | 129 } |
| 129 | 130 |
| 130 void UpdateHistoryNavigation(content::WebUI* web_ui) { | 131 void UpdateHistoryNavigation(content::WebUI* web_ui) { |
| 131 bool overrides_history = | 132 bool overrides_history = |
| 132 HasExtensionType(web_ui->GetWebContents()->GetBrowserContext(), | 133 HasExtensionType(web_ui->GetWebContents()->GetBrowserContext(), |
| 133 chrome::kChromeUIHistoryHost); | 134 content::kChromeUIHistoryHost); |
| 134 web_ui->CallJavascriptFunctionUnsafe( | 135 web_ui->CallJavascriptFunctionUnsafe( |
| 135 "uber_frame.setNavigationOverride", | 136 "uber_frame.setNavigationOverride", |
| 136 base::Value(chrome::kChromeUIHistoryHost), | 137 base::Value(content::kChromeUIHistoryHost), |
| 137 base::Value(overrides_history ? "yes" : "no")); | 138 base::Value(overrides_history ? "yes" : "no")); |
| 138 } | 139 } |
| 139 | 140 |
| 140 } // namespace | 141 } // namespace |
| 141 | 142 |
| 142 SubframeLogger::SubframeLogger(content::WebContents* contents) | 143 SubframeLogger::SubframeLogger(content::WebContents* contents) |
| 143 : WebContentsObserver(contents) {} | 144 : WebContentsObserver(contents) {} |
| 144 | 145 |
| 145 SubframeLogger::~SubframeLogger() {} | 146 SubframeLogger::~SubframeLogger() {} |
| 146 | 147 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 168 base::MakeUnique<SubframeLogger>(web_ui->GetWebContents()); | 169 base::MakeUnique<SubframeLogger>(web_ui->GetWebContents()); |
| 169 } | 170 } |
| 170 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), | 171 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), |
| 171 CreateUberHTMLSource()); | 172 CreateUberHTMLSource()); |
| 172 | 173 |
| 173 RegisterSubpage(chrome::kChromeUIExtensionsFrameURL, | 174 RegisterSubpage(chrome::kChromeUIExtensionsFrameURL, |
| 174 chrome::kChromeUIExtensionsHost); | 175 chrome::kChromeUIExtensionsHost); |
| 175 RegisterSubpage(chrome::kChromeUIHelpFrameURL, | 176 RegisterSubpage(chrome::kChromeUIHelpFrameURL, |
| 176 chrome::kChromeUIHelpHost); | 177 chrome::kChromeUIHelpHost); |
| 177 RegisterSubpage(chrome::kChromeUIHistoryFrameURL, | 178 RegisterSubpage(chrome::kChromeUIHistoryFrameURL, |
| 178 chrome::kChromeUIHistoryHost); | 179 content::kChromeUIHistoryHost); |
| 179 RegisterSubpage(chrome::kChromeUISettingsFrameURL, | 180 RegisterSubpage(chrome::kChromeUISettingsFrameURL, |
| 180 chrome::kChromeUISettingsHost); | 181 chrome::kChromeUISettingsHost); |
| 181 RegisterSubpage(chrome::kChromeUIUberFrameURL, | 182 RegisterSubpage(chrome::kChromeUIUberFrameURL, |
| 182 chrome::kChromeUIUberHost); | 183 chrome::kChromeUIUberHost); |
| 183 } | 184 } |
| 184 | 185 |
| 185 UberUI::~UberUI() { | 186 UberUI::~UberUI() { |
| 186 } | 187 } |
| 187 | 188 |
| 188 void UberUI::RegisterSubpage(const std::string& page_url, | 189 void UberUI::RegisterSubpage(const std::string& page_url, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // opens the default history page if one is uninstalled or disabled. | 251 // opens the default history page if one is uninstalled or disabled. |
| 251 UpdateHistoryNavigation(web_ui()); | 252 UpdateHistoryNavigation(web_ui()); |
| 252 } | 253 } |
| 253 | 254 |
| 254 void UberFrameUI::OnExtensionUnloaded( | 255 void UberFrameUI::OnExtensionUnloaded( |
| 255 content::BrowserContext* browser_context, | 256 content::BrowserContext* browser_context, |
| 256 const extensions::Extension* extension, | 257 const extensions::Extension* extension, |
| 257 extensions::UnloadedExtensionInfo::Reason reason) { | 258 extensions::UnloadedExtensionInfo::Reason reason) { |
| 258 UpdateHistoryNavigation(web_ui()); | 259 UpdateHistoryNavigation(web_ui()); |
| 259 } | 260 } |
| OLD | NEW |