From 490622b4da85c59e3d64bde33d622c40387e2dc6 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Fri, 24 Jun 2016 14:51:03 -0700 Subject: [PATCH] Add a wrapper for accessing the URL launcher service. (#4688) --- packages/flutter/lib/services.dart | 1 + .../lib/src/services/url_launcher.dart | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 packages/flutter/lib/src/services/url_launcher.dart diff --git a/packages/flutter/lib/services.dart b/packages/flutter/lib/services.dart index 58806bb091..9ce4b8f12f 100644 --- a/packages/flutter/lib/services.dart +++ b/packages/flutter/lib/services.dart @@ -30,3 +30,4 @@ export 'src/services/path_provider.dart'; export 'src/services/shell.dart'; export 'src/services/system_chrome.dart'; export 'src/services/system_sound.dart'; +export 'src/services/url_launcher.dart'; diff --git a/packages/flutter/lib/src/services/url_launcher.dart b/packages/flutter/lib/src/services/url_launcher.dart new file mode 100644 index 0000000000..08b46c221f --- /dev/null +++ b/packages/flutter/lib/src/services/url_launcher.dart @@ -0,0 +1,44 @@ +// 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. + +import 'dart:async'; + +import 'package:sky_services/flutter/platform/url_launcher.mojom.dart' as mojom; +import 'shell.dart'; + +mojom.UrlLauncherProxy _initUrlLauncherProxy() { + return shell.connectToApplicationService( + mojom.UrlLauncher.serviceName, + mojom.UrlLauncher.connectToService); +} + +final mojom.UrlLauncherProxy _connectedUrlLauncherService = _initUrlLauncherProxy(); + +/// Allows applications to delegate responsbility of handling certain URLs to +/// the underlying platform. +class UrlLauncher { + UrlLauncher._(); + + /// Parse the specified URL string and delegate handling of the same to the + /// underlying platform. + /// + /// Arguments: + /// + /// * [urlString]: The URL string to be parsed by the underlying platform and + /// before it attempts to launch the same. + /// + /// Return Value: + /// + /// boolean indicating if the intent to handle the URL was successfully + /// conveyed to the to underlying platform and the platform could + /// successfully handle the same. The platform is responsible for URL + /// parsing. + static Future launch(String urlString) { + Completer completer = new Completer(); + _connectedUrlLauncherService.launch(urlString, (bool success) { + completer.complete(success); + }); + return completer.future; + } +}