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