Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: ios/chrome/app/application_delegate/url_opener.mm

Issue 2580363002: Upstream Chrome on iOS source code [1/11]. (Closed)
Patch Set: Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #import "ios/chrome/app/application_delegate/url_opener.h"
6
7 #import <Foundation/Foundation.h>
8
9 #import "base/ios/weak_nsobject.h"
10 #import "base/mac/scoped_nsobject.h"
11 #include "base/metrics/histogram_macros.h"
12 #import "ios/chrome/app/application_delegate/app_state.h"
13 #import "ios/chrome/app/application_delegate/startup_information.h"
14 #import "ios/chrome/app/application_delegate/tab_opening.h"
15 #include "ios/chrome/app/chrome_app_startup_parameters.h"
16
17 namespace {
18 // Key of the UMA Startup.MobileSessionStartFromApps histogram.
19 const char* const kUMAMobileSessionStartFromAppsHistogram =
20 "Startup.MobileSessionStartFromApps";
21 } // namespace
22
23 @implementation URLOpener
24
25 - (instancetype)init {
26 NOTREACHED();
27 return nil;
28 }
29
30 #pragma mark - ApplicationDelegate - URL Opening methods
31
32 + (BOOL)openURL:(NSURL*)url
33 applicationActive:(BOOL)applicationActive
34 options:(NSDictionary<NSString*, id>*)options
35 tabOpener:(id<TabOpening>)tabOpener
36 startupInformation:(id<StartupInformation>)startupInformation {
37 NSString* sourceApplication =
38 options[UIApplicationOpenURLOptionsSourceApplicationKey];
39 base::scoped_nsobject<ChromeAppStartupParameters> params(
40 [ChromeAppStartupParameters
41 newChromeAppStartupParametersWithURL:url
42 fromSourceApplication:sourceApplication]);
43
44 MobileSessionCallerApp callerApp = [params callerApp];
45
46 UMA_HISTOGRAM_ENUMERATION(kUMAMobileSessionStartFromAppsHistogram, callerApp,
47 MOBILE_SESSION_CALLER_APP_COUNT);
48
49 if (startupInformation.isPresentingFirstRunUI) {
50 UMA_HISTOGRAM_ENUMERATION("FirstRun.LaunchSource", [params launchSource],
51 first_run::LAUNCH_SIZE);
52 }
53
54 if (applicationActive) {
55 // The app is already active so the applicationDidBecomeActive: method will
56 // never be called. Open the requested URL immediately and return YES if
57 // the parsed URL was valid.
58 if (params) {
59 [tabOpener dismissModalsAndOpenSelectedTabInMode:ApplicationMode::NORMAL
60 withURL:[params externalURL]
61 transition:ui::PAGE_TRANSITION_LINK
62 completion:nil];
63 return YES;
64 }
65 return NO;
66 }
67
68 // Don't record the first user action.
69 [startupInformation resetFirstUserActionRecorder];
70
71 startupInformation.startupParameters = params;
72 return startupInformation.startupParameters != nil;
73 }
74
75 + (void)handleLaunchOptions:(NSDictionary*)launchOptions
76 applicationActive:(BOOL)applicationActive
77 tabOpener:(id<TabOpening>)tabOpener
78 startupInformation:(id<StartupInformation>)startupInformation
79 appState:(AppState*)appState {
80 NSURL* url = launchOptions[UIApplicationLaunchOptionsURLKey];
81 NSString* sourceApplication =
82 launchOptions[UIApplicationLaunchOptionsSourceApplicationKey];
83
84 if (url && sourceApplication) {
85 NSDictionary<NSString*, id>* options =
86 @{UIApplicationOpenURLOptionsSourceApplicationKey : sourceApplication};
87
88 BOOL openURLResult = [URLOpener openURL:url
89 applicationActive:applicationActive
90 options:options
91 tabOpener:tabOpener
92 startupInformation:startupInformation];
93 [appState launchFromURLHandled:openURLResult];
94 }
95 }
96
97 @end
OLDNEW
« no previous file with comments | « ios/chrome/app/application_delegate/url_opener.h ('k') | ios/chrome/app/application_delegate/url_opener_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698