OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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_ANDROID_WEBAPK_WEBAPK_BUILDER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_ |
| 7 |
| 8 #include <jni.h> |
| 9 #include <memory> |
| 10 |
| 11 #include "base/callback.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/timer/timer.h" |
| 14 #include "chrome/browser/android/shortcut_info.h" |
| 15 #include "net/url_request/url_fetcher_delegate.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 |
| 18 namespace content { |
| 19 class BrowserContext; |
| 20 } |
| 21 |
| 22 namespace net { |
| 23 class URLFetcher; |
| 24 class URLRequestContextGetter; |
| 25 } |
| 26 |
| 27 namespace webapk { |
| 28 class CreateWebApkRequest; |
| 29 } |
| 30 |
| 31 // Talks to Chrome WebAPK server and Google Play servers to generate a WebAPK on |
| 32 // the server, download it, and install it. |
| 33 class WebApkBuilder : public net::URLFetcherDelegate { |
| 34 public: |
| 35 typedef base::Callback<void(bool)> FinishCallback; |
| 36 |
| 37 WebApkBuilder(content::BrowserContext* browser_context, |
| 38 const ShortcutInfo& shortcut_info, |
| 39 const SkBitmap& shorcut_icon); |
| 40 ~WebApkBuilder() override; |
| 41 |
| 42 // Register JNI methods. |
| 43 static bool Register(JNIEnv* env); |
| 44 |
| 45 // Converts a blink::WebDisplayMode to a string. Returns one of |
| 46 // https://www.w3.org/TR/appmanifest/#dfn-fallback-display-mode |
| 47 static std::string DisplayToString(blink::WebDisplayMode display); |
| 48 |
| 49 // Converts a blink::WebScreenOrientationLockType to a string. Returns one of |
| 50 // https://www.w3.org/TR/screen-orientation/#orientationlocktype-enum |
| 51 static std::string OrientationToString( |
| 52 blink::WebScreenOrientationLockType orientation); |
| 53 |
| 54 // Talks to Chrome WebAPK server and Google Play servers to generate a WebAPK |
| 55 // on the server, download it, and install it. Calls |callback| after the |
| 56 // request to download the WebAPK is sent tot he Google Play server. |
| 57 void BuildAsync(const FinishCallback& callback); |
| 58 |
| 59 private: |
| 60 // net::URLFetcherDelegate: |
| 61 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 62 |
| 63 // Initializes |request_context_getter_| on UI thread. |
| 64 void InitializeRequestContextGetterOnUIThread(); |
| 65 |
| 66 // Sends request to WebAPK server to create WebAPK. During a successful |
| 67 // request the WebAPK server responds with a URL to send to Google Play to |
| 68 // download the generated WebAPK. |
| 69 void SendCreateWebApkRequest(); |
| 70 |
| 71 // Called with the URL to send to the Google Play server to download the |
| 72 // WebAPK. |
| 73 void OnGotMarketUrl(const std::string& signed_market_url); |
| 74 |
| 75 // Populates webapk::CreateWebApkRequest and returns it. |
| 76 std::unique_ptr<webapk::CreateWebApkRequest> MakeCreateWebApkRequest(); |
| 77 |
| 78 // Called when the request to the server times out. |
| 79 void OnTimeout(); |
| 80 |
| 81 // Called when the request to download the WebAPK is sent to the Google Play |
| 82 // server. |
| 83 void OnSuccess(); |
| 84 |
| 85 // Called if a WebAPK could not be created. WebApkBuilder only tracks the |
| 86 // generation of the WebAPK on the WebAPK server. It does not track the WebAPK |
| 87 // download and installation. OnFailure() is not called if the WebAPK could |
| 88 // not be downloaded or installed. |
| 89 void OnFailure(); |
| 90 |
| 91 content::BrowserContext* browser_context_; |
| 92 net::URLRequestContextGetter* request_context_getter_; |
| 93 |
| 94 // Sends HTTP request to WebAPK server. |
| 95 std::unique_ptr<net::URLFetcher> url_fetcher_; |
| 96 |
| 97 // Fails WebApkBuilder if WebAPK server takes too long to respond. |
| 98 base::OneShotTimer timer_; |
| 99 |
| 100 // Callback to call once WebApkBuilder succeeds or fails. |
| 101 FinishCallback finish_callback_; |
| 102 |
| 103 // Web Manifest info. |
| 104 const ShortcutInfo shortcut_info_; |
| 105 |
| 106 // WebAPK app icon. |
| 107 const SkBitmap shortcut_icon_; |
| 108 |
| 109 // WebAPK server URL. |
| 110 GURL server_url_; |
| 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(WebApkBuilder); |
| 113 }; |
| 114 |
| 115 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_ |
OLD | NEW |