[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef CHROME_BROWSER_SEARCH_LOCAL_NTP_SOURCE_H_ | ||||
6 | #define CHROME_BROWSER_SEARCH_LOCAL_NTP_SOURCE_H_ | ||||
7 | |||||
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 8 | #include <memory> |
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 9 | #include <string> |
10 | #include <vector> | ||||
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 11 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 12 | #include "base/macros.h" |
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 13 | #include "base/memory/weak_ptr.h" |
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 14 | #include "base/optional.h" |
15 | #include "base/scoped_observer.h" | ||||
treib | 83e22f1 | 2017-05-10 15:12:05 | [diff] [blame] | 16 | #include "base/time/time.h" |
Marc Treib | 9028a6a | 2017-12-06 16:21:51 | [diff] [blame^] | 17 | #include "build/build_config.h" |
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 18 | #include "chrome/browser/search/one_google_bar/one_google_bar_service_observer.h" |
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 19 | #include "content/public/browser/url_data_source.h" |
20 | |||||
Marc Treib | 9028a6a | 2017-12-06 16:21:51 | [diff] [blame^] | 21 | #if defined(OS_ANDROID) |
22 | #error "Instant is only used on desktop"; | ||||
23 | #endif | ||||
24 | |||||
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 25 | struct OneGoogleBarData; |
26 | class OneGoogleBarService; | ||||
[email protected] | 5df96ab | 2013-07-17 23:14:48 | [diff] [blame] | 27 | class Profile; |
28 | |||||
Chris Pickel | 3a227ae6 | 2017-08-24 10:47:26 | [diff] [blame] | 29 | namespace search_provider_logos { |
30 | class LogoService; | ||||
31 | } // namespace search_provider_logos | ||||
32 | |||||
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 33 | // Serves HTML and resources for the local new tab page i.e. |
34 | // chrome-search://local-ntp/local-ntp.html | ||||
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 35 | class LocalNtpSource : public content::URLDataSource, |
36 | public OneGoogleBarServiceObserver { | ||||
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 37 | public: |
[email protected] | 5df96ab | 2013-07-17 23:14:48 | [diff] [blame] | 38 | explicit LocalNtpSource(Profile* profile); |
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 39 | |
40 | private: | ||||
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 41 | class GoogleSearchProviderTracker; |
Chris Pickel | 3a227ae6 | 2017-08-24 10:47:26 | [diff] [blame] | 42 | class DesktopLogoObserver; |
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 43 | |
treib | 83e22f1 | 2017-05-10 15:12:05 | [diff] [blame] | 44 | struct OneGoogleBarRequest { |
45 | OneGoogleBarRequest( | ||||
46 | base::TimeTicks start_time, | ||||
47 | const content::URLDataSource::GotDataCallback& callback); | ||||
48 | OneGoogleBarRequest(const OneGoogleBarRequest&); | ||||
49 | ~OneGoogleBarRequest(); | ||||
50 | |||||
51 | base::TimeTicks start_time; | ||||
52 | content::URLDataSource::GotDataCallback callback; | ||||
53 | }; | ||||
54 | |||||
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 55 | ~LocalNtpSource() override; |
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 56 | |
57 | // Overridden from content::URLDataSource: | ||||
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 58 | std::string GetSource() const override; |
59 | void StartDataRequest( | ||||
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 60 | const std::string& path, |
jam | edcd8b01 | 2016-09-20 02:03:58 | [diff] [blame] | 61 | const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
mostynb | fb66cb4f | 2014-10-07 09:15:42 | [diff] [blame] | 62 | const content::URLDataSource::GotDataCallback& callback) override; |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 63 | std::string GetMimeType(const std::string& path) const override; |
toyoshim | 501ba31 | 2016-11-30 08:25:55 | [diff] [blame] | 64 | bool AllowCaching() const override; |
jam | cf6f762 | 2017-05-03 22:16:28 | [diff] [blame] | 65 | bool ShouldServiceRequest(const GURL& url, |
66 | content::ResourceContext* resource_context, | ||||
67 | int render_process_id) const override; | ||||
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 68 | std::string GetContentSecurityPolicyScriptSrc() const override; |
wychen | d6eb779 | 2016-06-04 00:52:53 | [diff] [blame] | 69 | std::string GetContentSecurityPolicyChildSrc() const override; |
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 70 | |
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 71 | // Overridden from OneGoogleBarServiceObserver: |
Marc Treib | c3b58c8 | 2017-08-01 12:56:58 | [diff] [blame] | 72 | void OnOneGoogleBarDataUpdated() override; |
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 73 | void OnOneGoogleBarServiceShuttingDown() override; |
74 | |||||
treib | 83e22f1 | 2017-05-10 15:12:05 | [diff] [blame] | 75 | void ServeOneGoogleBar(const base::Optional<OneGoogleBarData>& data); |
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 76 | |
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 77 | void DefaultSearchProviderIsGoogleChanged(bool is_google); |
78 | |||||
79 | void SetDefaultSearchProviderIsGoogleOnIOThread(bool is_google); | ||||
80 | |||||
Ondrej Skopek | 4fbead8 | 2017-08-17 13:11:32 | [diff] [blame] | 81 | void GoogleBaseUrlChanged(const GURL& google_base_url); |
82 | |||||
83 | void SetGoogleBaseUrlOnIOThread(const GURL& google_base_url); | ||||
84 | |||||
treib | d718237 | 2017-04-28 11:39:11 | [diff] [blame] | 85 | Profile* const profile_; |
86 | |||||
87 | OneGoogleBarService* one_google_bar_service_; | ||||
88 | |||||
89 | ScopedObserver<OneGoogleBarService, OneGoogleBarServiceObserver> | ||||
90 | one_google_bar_service_observer_; | ||||
91 | |||||
Chris Pickel | 3a227ae6 | 2017-08-24 10:47:26 | [diff] [blame] | 92 | search_provider_logos::LogoService* logo_service_; |
93 | std::unique_ptr<DesktopLogoObserver> logo_observer_; | ||||
94 | |||||
treib | 83e22f1 | 2017-05-10 15:12:05 | [diff] [blame] | 95 | std::vector<OneGoogleBarRequest> one_google_bar_requests_; |
[email protected] | 5df96ab | 2013-07-17 23:14:48 | [diff] [blame] | 96 | |
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 97 | std::unique_ptr<GoogleSearchProviderTracker> google_tracker_; |
98 | bool default_search_provider_is_google_; | ||||
99 | // A copy of |default_search_provider_is_google_| for use on the IO thread. | ||||
100 | bool default_search_provider_is_google_io_thread_; | ||||
101 | |||||
Ondrej Skopek | 4fbead8 | 2017-08-17 13:11:32 | [diff] [blame] | 102 | GURL google_base_url_; |
103 | // A copy of |google_base_url_| for use on the IO thread. | ||||
104 | GURL google_base_url_io_thread_; | ||||
105 | |||||
treib | 3be61a9 | 2017-04-25 13:03:38 | [diff] [blame] | 106 | base::WeakPtrFactory<LocalNtpSource> weak_ptr_factory_; |
107 | |||||
[email protected] | a353643 | 2013-03-26 08:14:31 | [diff] [blame] | 108 | DISALLOW_COPY_AND_ASSIGN(LocalNtpSource); |
109 | }; | ||||
110 | |||||
111 | #endif // CHROME_BROWSER_SEARCH_LOCAL_NTP_SOURCE_H_ |