app_startup_parameters.mm 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2012 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. #import "ios/chrome/app/app_startup_parameters.h"
  5. #import "base/feature_list.h"
  6. #include "ios/chrome/browser/chrome_url_constants.h"
  7. #import "ios/chrome/browser/ui/ui_feature_flags.h"
  8. #import "net/base/mac/url_conversions.h"
  9. #include "net/base/url_util.h"
  10. #include "url/gurl.h"
  11. #if !defined(__has_feature) || !__has_feature(objc_arc)
  12. #error "This file requires ARC support."
  13. #endif
  14. @implementation AppStartupParameters {
  15. GURL _externalURL;
  16. GURL _completeURL;
  17. std::vector<GURL> _URLs;
  18. }
  19. @synthesize externalURLParams = _externalURLParams;
  20. @synthesize postOpeningAction = _postOpeningAction;
  21. @synthesize applicationMode = _applicationMode;
  22. // TODO(crbug.com/1021752): Remove this stub.
  23. @synthesize completePaymentRequest = _completePaymentRequest;
  24. @synthesize textQuery = _textQuery;
  25. - (const GURL&)externalURL {
  26. return _externalURL;
  27. }
  28. - (const GURL&)completeURL {
  29. return _completeURL;
  30. }
  31. - (instancetype)initWithExternalURL:(const GURL&)externalURL
  32. completeURL:(const GURL&)completeURL {
  33. self = [super init];
  34. if (self) {
  35. _externalURL = externalURL;
  36. _completeURL = completeURL;
  37. if (base::FeatureList::IsEnabled(kIOS3PIntentsInIncognito)) {
  38. _applicationMode = ApplicationModeForTabOpening::UNDETERMINED;
  39. }
  40. }
  41. return self;
  42. }
  43. - (instancetype)initWithURLs:(const std::vector<GURL>&)URLs {
  44. if (URLs.empty()) {
  45. self = [self initWithExternalURL:GURL(kChromeUINewTabURL)
  46. completeURL:GURL(kChromeUINewTabURL)];
  47. } else {
  48. self = [self initWithExternalURL:URLs.front() completeURL:URLs.front()];
  49. }
  50. if (self) {
  51. _URLs = URLs;
  52. }
  53. return self;
  54. }
  55. - (NSString*)description {
  56. NSMutableString* description =
  57. [NSMutableString stringWithFormat:@"AppStartupParameters: %s",
  58. _externalURL.spec().c_str()];
  59. if (self.launchInIncognito) {
  60. [description appendString:@", should launch in incognito"];
  61. }
  62. switch (self.postOpeningAction) {
  63. case START_QR_CODE_SCANNER:
  64. [description appendString:@", should launch QR scanner"];
  65. break;
  66. case START_VOICE_SEARCH:
  67. [description appendString:@", should launch voice search"];
  68. break;
  69. case FOCUS_OMNIBOX:
  70. [description appendString:@", should focus omnibox"];
  71. break;
  72. default:
  73. break;
  74. }
  75. if (self.completePaymentRequest) {
  76. [description appendString:@", should complete payment request"];
  77. }
  78. return description;
  79. }
  80. - (BOOL)launchInIncognito {
  81. return _applicationMode == ApplicationModeForTabOpening::INCOGNITO;
  82. }
  83. - (void)setLaunchInIncognito:(BOOL)launchInIncognito {
  84. if (launchInIncognito) {
  85. _applicationMode = ApplicationModeForTabOpening::INCOGNITO;
  86. } else {
  87. _applicationMode = ApplicationModeForTabOpening::NORMAL;
  88. }
  89. }
  90. - (void)setPostOpeningAction:(TabOpeningPostOpeningAction)action {
  91. // Only NO_ACTION or SHOW_DEFAULT_BROWSER_SETTINGS are allowed on non NTP.
  92. DCHECK(action == NO_ACTION || action == SHOW_DEFAULT_BROWSER_SETTINGS ||
  93. _externalURL == GURL(kChromeUINewTabURL));
  94. _postOpeningAction = action;
  95. }
  96. @end