| Index: chrome/browser/android/webapk/webapk_builder.h
|
| diff --git a/chrome/browser/android/webapk/webapk_builder.h b/chrome/browser/android/webapk/webapk_builder.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..76ac5d504cf3528f3699068c09415ffae554886a
|
| --- /dev/null
|
| +++ b/chrome/browser/android/webapk/webapk_builder.h
|
| @@ -0,0 +1,115 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_
|
| +#define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_
|
| +
|
| +#include <jni.h>
|
| +#include <memory>
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/macros.h"
|
| +#include "base/timer/timer.h"
|
| +#include "chrome/browser/android/shortcut_info.h"
|
| +#include "net/url_request/url_fetcher_delegate.h"
|
| +#include "third_party/skia/include/core/SkBitmap.h"
|
| +
|
| +namespace content {
|
| +class BrowserContext;
|
| +}
|
| +
|
| +namespace net {
|
| +class URLFetcher;
|
| +class URLRequestContextGetter;
|
| +}
|
| +
|
| +namespace webapk {
|
| +class CreateWebApkRequest;
|
| +}
|
| +
|
| +// Talks to Chrome WebAPK server and Google Play servers to generate a WebAPK on
|
| +// the server, download it, and install it.
|
| +class WebApkBuilder : public net::URLFetcherDelegate {
|
| + public:
|
| + typedef base::Callback<void(bool)> FinishCallback;
|
| +
|
| + WebApkBuilder(content::BrowserContext* browser_context,
|
| + const ShortcutInfo& shortcut_info,
|
| + const SkBitmap& shorcut_icon);
|
| + ~WebApkBuilder() override;
|
| +
|
| + // Register JNI methods.
|
| + static bool Register(JNIEnv* env);
|
| +
|
| + // Converts a blink::WebDisplayMode to a string. Returns one of
|
| + // https://www.w3.org/TR/appmanifest/#dfn-fallback-display-mode
|
| + static std::string DisplayToString(blink::WebDisplayMode display);
|
| +
|
| + // Converts a blink::WebScreenOrientationLockType to a string. Returns one of
|
| + // https://www.w3.org/TR/screen-orientation/#orientationlocktype-enum
|
| + static std::string OrientationToString(
|
| + blink::WebScreenOrientationLockType orientation);
|
| +
|
| + // Talks to Chrome WebAPK server and Google Play servers to generate a WebAPK
|
| + // on the server, download it, and install it. Calls |callback| after the
|
| + // request to download the WebAPK is sent tot he Google Play server.
|
| + void BuildAsync(const FinishCallback& callback);
|
| +
|
| + private:
|
| + // net::URLFetcherDelegate:
|
| + void OnURLFetchComplete(const net::URLFetcher* source) override;
|
| +
|
| + // Initializes |request_context_getter_| on UI thread.
|
| + void InitializeRequestContextGetterOnUIThread();
|
| +
|
| + // Sends request to WebAPK server to create WebAPK. During a successful
|
| + // request the WebAPK server responds with a URL to send to Google Play to
|
| + // download the generated WebAPK.
|
| + void SendCreateWebApkRequest();
|
| +
|
| + // Called with the URL to send to the Google Play server to download the
|
| + // WebAPK.
|
| + void OnGotMarketUrl(const std::string& signed_market_url);
|
| +
|
| + // Populates webapk::CreateWebApkRequest and returns it.
|
| + std::unique_ptr<webapk::CreateWebApkRequest> MakeCreateWebApkRequest();
|
| +
|
| + // Called when the request to the server times out.
|
| + void OnTimeout();
|
| +
|
| + // Called when the request to download the WebAPK is sent to the Google Play
|
| + // server.
|
| + void OnSuccess();
|
| +
|
| + // Called if a WebAPK could not be created. WebApkBuilder only tracks the
|
| + // generation of the WebAPK on the WebAPK server. It does not track the WebAPK
|
| + // download and installation. OnFailure() is not called if the WebAPK could
|
| + // not be downloaded or installed.
|
| + void OnFailure();
|
| +
|
| + content::BrowserContext* browser_context_;
|
| + net::URLRequestContextGetter* request_context_getter_;
|
| +
|
| + // Sends HTTP request to WebAPK server.
|
| + std::unique_ptr<net::URLFetcher> url_fetcher_;
|
| +
|
| + // Fails WebApkBuilder if WebAPK server takes too long to respond.
|
| + base::OneShotTimer timer_;
|
| +
|
| + // Callback to call once WebApkBuilder succeeds or fails.
|
| + FinishCallback finish_callback_;
|
| +
|
| + // Web Manifest info.
|
| + const ShortcutInfo shortcut_info_;
|
| +
|
| + // WebAPK app icon.
|
| + const SkBitmap shortcut_icon_;
|
| +
|
| + // WebAPK server URL.
|
| + GURL server_url_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(WebApkBuilder);
|
| +};
|
| +
|
| +#endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_
|
|
|