OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
6 #define CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 // Return a string identifying this app for metrics. | 97 // Return a string identifying this app for metrics. |
98 virtual std::string GetAppIdentifier(); | 98 virtual std::string GetAppIdentifier(); |
99 | 99 |
100 // Return a string describing what type of banner is being created. Used when | 100 // Return a string describing what type of banner is being created. Used when |
101 // alerting websites that a banner is about to be created. | 101 // alerting websites that a banner is about to be created. |
102 virtual std::string GetBannerType(); | 102 virtual std::string GetBannerType(); |
103 | 103 |
104 // Returns a string parameter for a devtools console message corresponding to | 104 // Returns a string parameter for a devtools console message corresponding to |
105 // |code|. Returns the empty string if |code| requires no parameter. | 105 // |code|. Returns the empty string if |code| requires no parameter. |
106 std::string GetErrorParam(InstallableErrorCode code); | 106 std::string GetStatusParam(InstallableStatusCode code); |
107 | 107 |
108 // Returns the ideal and minimum icon sizes required for being installable. | 108 // Returns the ideal and minimum icon sizes required for being installable. |
109 virtual int GetIdealIconSizeInDp(); | 109 virtual int GetIdealIconSizeInDp(); |
110 virtual int GetMinimumIconSizeInDp(); | 110 virtual int GetMinimumIconSizeInDp(); |
111 | 111 |
112 // Returns a WeakPtr to this object. Exposed so subclasses/infobars may | 112 // Returns a WeakPtr to this object. Exposed so subclasses/infobars may |
113 // may bind callbacks without needing their own WeakPtrFactory. | 113 // may bind callbacks without needing their own WeakPtrFactory. |
114 base::WeakPtr<AppBannerManager> GetWeakPtr(); | 114 base::WeakPtr<AppBannerManager> GetWeakPtr(); |
115 | 115 |
116 // Returns true if |is_debug_mode_| is true or the | 116 // Returns true if |is_debug_mode_| is true or the |
117 // kBypassAppBannerEngagementChecks flag is set. | 117 // kBypassAppBannerEngagementChecks flag is set. |
118 bool IsDebugMode() const; | 118 virtual bool IsDebugMode() const; |
119 | 119 |
120 // Returns true if the webapp at |start_url| has already been installed. | 120 // Returns true if the webapp at |start_url| has already been installed. |
121 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, | 121 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, |
122 const GURL& start_url); | 122 const GURL& start_url); |
123 | 123 |
124 // Callback invoked by the InstallableManager once it has fetched the page's | 124 // Callback invoked by the InstallableManager once it has fetched the page's |
125 // manifest. | 125 // manifest. |
126 void OnDidGetManifest(const InstallableData& result); | 126 void OnDidGetManifest(const InstallableData& result); |
127 | 127 |
128 // Run at the conclusion of OnDidGetManifest. For web app banners, this calls | 128 // Run at the conclusion of OnDidGetManifest. For web app banners, this calls |
129 // back to the InstallableManager to continue checking criteria. For native | 129 // back to the InstallableManager to continue checking criteria. For native |
130 // app banners, this checks whether native apps are preferred in the manifest, | 130 // app banners, this checks whether native apps are preferred in the manifest, |
131 // and calls to Java to verify native app details. If a native banner isn't or | 131 // and calls to Java to verify native app details. If a native banner isn't or |
132 // can't be requested, it continues with the web app banner checks. | 132 // can't be requested, it continues with the web app banner checks. |
133 virtual void PerformInstallableCheck(); | 133 virtual void PerformInstallableCheck(); |
134 | 134 |
135 // Callback invoked by the InstallableManager once it has finished checking | 135 // Callback invoked by the InstallableManager once it has finished checking |
136 // all other installable properties. | 136 // all other installable properties. |
137 void OnDidPerformInstallableCheck(const InstallableData& result); | 137 void OnDidPerformInstallableCheck(const InstallableData& result); |
138 | 138 |
139 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR | 139 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR |
140 // metric being recorded. | 140 // metric being recorded. |
141 void RecordDidShowBanner(const std::string& event_name); | 141 void RecordDidShowBanner(const std::string& event_name); |
142 | 142 |
143 // Logs an error message corresponding to |code| to the devtools console | 143 // Logs an error message corresponding to |code| to the devtools console |
144 // attached to |web_contents|. Does nothing if IsDebugMode() returns false. | 144 // attached to |web_contents|. Does nothing if IsDebugMode() returns false. |
145 void ReportError(content::WebContents* web_contents, | 145 void ReportStatus(content::WebContents* web_contents, |
146 InstallableErrorCode code); | 146 InstallableStatusCode code); |
147 | 147 |
148 // Stops the banner pipeline. Any callback currently running will terminate | 148 // Stops the banner pipeline, preventing any outstanding callbacks from |
149 // the next time they check |is_active_|. | 149 // running and resetting the manager state. This method is virtual to allow |
| 150 // tests to intercept it and verify correct behaviour. |
150 virtual void Stop(); | 151 virtual void Stop(); |
151 | 152 |
152 // Sends a message to the renderer that the page has met the requirements to | 153 // Sends a message to the renderer that the page has met the requirements to |
153 // show a banner. The page can respond to cancel the banner (and possibly | 154 // show a banner. The page can respond to cancel the banner (and possibly |
154 // display it later), or otherwise allow it to be shown. This is virtual to | 155 // display it later), or otherwise allow it to be shown. This is virtual to |
155 // allow tests to mock out the renderer IPC. | 156 // allow tests to mock out the renderer IPC. |
156 virtual void SendBannerPromptRequest(); | 157 virtual void SendBannerPromptRequest(); |
157 | 158 |
158 // content::WebContentsObserver overrides. | 159 // content::WebContentsObserver overrides. |
159 void DidStartNavigation(content::NavigationHandle* handle) override; | 160 void DidStartNavigation(content::NavigationHandle* handle) override; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 bool load_finished_; | 252 bool load_finished_; |
252 | 253 |
253 // Record whether the page decides to defer showing the banner, and if it | 254 // Record whether the page decides to defer showing the banner, and if it |
254 // requests for it to be shown later on. | 255 // requests for it to be shown later on. |
255 bool was_canceled_by_page_; | 256 bool was_canceled_by_page_; |
256 bool page_requested_prompt_; | 257 bool page_requested_prompt_; |
257 | 258 |
258 // Whether we should be logging errors to the console for this request. | 259 // Whether we should be logging errors to the console for this request. |
259 bool is_debug_mode_; | 260 bool is_debug_mode_; |
260 | 261 |
| 262 // Whether the installable status has been logged for this run. |
| 263 bool need_to_log_status_; |
| 264 |
261 // The concrete subclasses of this class are expected to have their lifetimes | 265 // The concrete subclasses of this class are expected to have their lifetimes |
262 // scoped to the WebContents which they are observing. This allows us to use | 266 // scoped to the WebContents which they are observing. This allows us to use |
263 // weak pointers for callbacks. | 267 // weak pointers for callbacks. |
264 base::WeakPtrFactory<AppBannerManager> weak_factory_; | 268 base::WeakPtrFactory<AppBannerManager> weak_factory_; |
265 | 269 |
266 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 270 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
267 }; | 271 }; |
268 | 272 |
269 } // namespace banners | 273 } // namespace banners |
270 | 274 |
271 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 275 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
OLD | NEW |