Commit 899c3bff authored by Mathieu Perreault's avatar Mathieu Perreault Committed by Commit Bot

[Local NTP] Add config.js as top-level instead of dynamically added.

To load the NTP faster, we include config.js data in the local ntp
page's initial resources instead of later added by local_ntp.js

To achieve this, we refactor into the SearchConfigProvider and cache
the config data. It will be recomputed on Search provider change.

We also now declare the CSP as part of a <meta> tag instead of headers,
since in URLDataSource the headers are created on the IO thread and
the response on the UI thread. Doing everything in the local_ntp.html
response avoids races nicely.

Bug: 868432
Change-Id: Iab38ca2b2e032a58c2d404938065a612b08cc69a
Reviewed-on: https://chromium-review.googlesource.com/1154687Reviewed-by: default avatarChris Palmer <palmer@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Mathieu Perreault <mathp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579553}
parent 638112da
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
<link rel="stylesheet" href="chrome-search://local-ntp/local-ntp.css"></link> <link rel="stylesheet" href="chrome-search://local-ntp/local-ntp.css"></link>
<link rel="stylesheet" href="chrome-search://local-ntp/voice.css"></link> <link rel="stylesheet" href="chrome-search://local-ntp/voice.css"></link>
<link rel="stylesheet" href="chrome-search://local-ntp/custom-backgrounds.css"></link> <link rel="stylesheet" href="chrome-search://local-ntp/custom-backgrounds.css"></link>
<meta http-equiv="Content-Security-Policy"
content="{{CONTENT_SECURITY_POLICY}}">
<script src="chrome-search://local-ntp/config.js"
{{CONFIG_DATA_INTEGRITY}}></script>
<script src="chrome-search://local-ntp/custom-backgrounds.js" <script src="chrome-search://local-ntp/custom-backgrounds.js"
{{LOCAL_NTP_CUSTOM_BG_INTEGRITY}}></script> {{LOCAL_NTP_CUSTOM_BG_INTEGRITY}}></script>
<script src="chrome-search://local-ntp/local-ntp.js" <script src="chrome-search://local-ntp/local-ntp.js"
......
...@@ -1092,20 +1092,11 @@ function init() { ...@@ -1092,20 +1092,11 @@ function init() {
} }
function loadConfig() {
var configScript = document.createElement('script');
configScript.type = 'text/javascript';
configScript.src = 'chrome-search://local-ntp/config.js';
configScript.onload = init;
document.head.appendChild(configScript);
}
/** /**
* Binds event listeners. * Binds event listeners.
*/ */
function listen() { function listen() {
document.addEventListener('DOMContentLoaded', loadConfig); document.addEventListener('DOMContentLoaded', init);
} }
......
This diff is collapsed.
...@@ -47,7 +47,7 @@ class LocalNtpSource : public content::URLDataSource, ...@@ -47,7 +47,7 @@ class LocalNtpSource : public content::URLDataSource,
explicit LocalNtpSource(Profile* profile); explicit LocalNtpSource(Profile* profile);
private: private:
class GoogleSearchProviderTracker; class SearchConfigurationProvider;
class DesktopLogoObserver; class DesktopLogoObserver;
struct NtpBackgroundRequest { struct NtpBackgroundRequest {
...@@ -85,8 +85,10 @@ class LocalNtpSource : public content::URLDataSource, ...@@ -85,8 +85,10 @@ class LocalNtpSource : public content::URLDataSource,
bool ShouldServiceRequest(const GURL& url, bool ShouldServiceRequest(const GURL& url,
content::ResourceContext* resource_context, content::ResourceContext* resource_context,
int render_process_id) const override; int render_process_id) const override;
std::string GetContentSecurityPolicyScriptSrc() const override; bool ShouldAddContentSecurityPolicy() const override;
std::string GetContentSecurityPolicyChildSrc() const override;
// The Content Security Policy for the Local NTP.
std::string GetContentSecurityPolicy() const;
// Overridden from NtpBackgroundServiceObserver: // Overridden from NtpBackgroundServiceObserver:
void OnCollectionInfoAvailable() override; void OnCollectionInfoAvailable() override;
...@@ -123,7 +125,7 @@ class LocalNtpSource : public content::URLDataSource, ...@@ -123,7 +125,7 @@ class LocalNtpSource : public content::URLDataSource,
search_provider_logos::LogoService* logo_service_; search_provider_logos::LogoService* logo_service_;
std::unique_ptr<DesktopLogoObserver> logo_observer_; std::unique_ptr<DesktopLogoObserver> logo_observer_;
std::unique_ptr<GoogleSearchProviderTracker> google_tracker_; std::unique_ptr<SearchConfigurationProvider> search_config_provider_;
base::WeakPtrFactory<LocalNtpSource> weak_ptr_factory_; base::WeakPtrFactory<LocalNtpSource> weak_ptr_factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment