Commit ca4be8b8 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

[ios] Remove incorrect dependency of //base//ios on //ios

Conceptually, //ios is on top of //base, so having a dependency
from //base/ios on //ios is breaking the layering (this also
make it difficult to use //base without using all of Chromium).

Implement IsMultiwindowSupported() and IsSceneStartupSupported()
by checking for the scene API manifest information in the app
Info.plist which is more robust as it will work for any iOS app
build on top of //base that set the information in Info.plist
even if they do not re-use the rest of Chromium.

Bug: none
Change-Id: I5ea006ea617c284dc114b2f8f8ecd6eb2f2dcc1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2529122
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarMike Pinkerton <pinkerton@chromium.org>
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827759}
parent 3a75ada6
......@@ -1261,10 +1261,6 @@ component("base") {
"//third_party/modp_b64",
]
if (is_ios) {
deps += [ "//base/ios:ios_multi_window_buildflags" ]
}
# native_unwinder_android is intended for use solely via a dynamic feature
# module, to avoid increasing Chrome's executable size.
assert_no_deps = [ ":native_unwinder_android" ]
......
# Copyright 2020 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("//build/buildflag_header.gni")
import("//ios/build/chrome_build.gni")
buildflag_header("ios_multi_window_buildflags") {
header = "multi_window_buildflags.h"
header_dir = "base/ios"
flags = [
"IOS_MULTIWINDOW_ENABLED=$ios_enable_multi_window",
"IOS_SCENE_STARTUP_ENABLED=$ios_enable_scene_startup",
]
}
......@@ -7,12 +7,20 @@
#import <Foundation/Foundation.h>
#include <stddef.h>
#include "base/ios/multi_window_buildflags.h"
#include "base/mac/foundation_util.h"
#include "base/stl_util.h"
#include "base/system/sys_info.h"
namespace {
// Key for the scene API manifest in the application Info.plist.
NSString* const kApplicationSceneManifestKey = @"UIApplicationSceneManifest";
// Key for the boolean telling whether the multi-scene support is enabled for
// the application in the scene API manifest.
NSString* const kApplicationSupportsMultipleScenesKey =
@"UIApplicationSupportsMultipleScenes";
// Return a 3 elements array containing the major, minor and bug fix version of
// the OS.
const int32_t* OSVersionAsArray() {
......@@ -22,6 +30,19 @@ const int32_t* OSVersionAsArray() {
return digits;
}
// Return an autoreleased pointer to the dictionary configuring the scene API
// from the application Info.plist. Can be null if the application or the OS
// version does not use the scene API.
NSDictionary* SceneAPIManifestFromInfoPlist() {
// Scene API is only supported on iOS 13.0+.
if (!base::ios::IsRunningOnIOS13OrLater())
return nil;
NSBundle* main_bundle = [NSBundle mainBundle];
return base::mac::ObjCCastStrict<NSDictionary>(
[main_bundle objectForInfoDictionaryKey:kApplicationSceneManifestKey]);
}
std::string* g_icudtl_path_override = nullptr;
} // namespace
......@@ -72,21 +93,25 @@ FilePath FilePathOfEmbeddedICU() {
}
bool IsMultiwindowSupported() {
#if BUILDFLAG(IOS_MULTIWINDOW_ENABLED)
return IsRunningOnIOS13OrLater();
#else
return false;
#endif
static bool cached_value = false;
static dispatch_once_t once_token = 0;
dispatch_once(&once_token, ^{
NSDictionary* scene_api_manifest = SceneAPIManifestFromInfoPlist();
NSNumber* value = base::mac::ObjCCastStrict<NSNumber>([scene_api_manifest
objectForKey:kApplicationSupportsMultipleScenesKey]);
cached_value = [value boolValue];
});
return cached_value;
}
bool IsSceneStartupSupported() {
if (IsMultiwindowSupported())
return true;
#if BUILDFLAG(IOS_SCENE_STARTUP_ENABLED)
return base::ios::IsRunningOnIOS13OrLater();
#else
return false;
#endif
static bool cached_value = false;
static dispatch_once_t once_token = 0;
dispatch_once(&once_token, ^{
NSDictionary* scene_api_manifest = SceneAPIManifestFromInfoPlist();
cached_value = scene_api_manifest != nil;
});
return cached_value;
}
} // namespace ios
......
......@@ -170,9 +170,9 @@ source_set("app_internal") {
":blocking_scene_commands",
":content_suggestions_scheduler_app_state_agent",
":mode",
":multi_window_buildflags",
":tests_hook",
"//base",
"//base/ios:ios_multi_window_buildflags",
"//build:branding_buildflags",
"//components/bookmarks/browser",
"//components/browser_sync",
......@@ -303,6 +303,11 @@ source_set("app_internal") {
]
}
buildflag_header("multi_window_buildflags") {
header = "multi_window_buildflags.h"
flags = [ "IOS_MULTIWINDOW_ENABLED=$ios_enable_multi_window" ]
}
source_set("blocking_scene_commands") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ "blocking_scene_commands.h" ]
......
......@@ -5,7 +5,6 @@
#import "ios/chrome/app/main_application_delegate.h"
#include "base/ios/ios_util.h"
#include "base/ios/multi_window_buildflags.h"
#include "base/mac/foundation_util.h"
#include "base/metrics/user_metrics.h"
#import "ios/chrome/app/application_delegate/app_state.h"
......@@ -21,6 +20,7 @@
#import "ios/chrome/app/chrome_overlay_window.h"
#import "ios/chrome/app/main_application_delegate_testing.h"
#import "ios/chrome/app/main_controller.h"
#include "ios/chrome/app/multi_window_buildflags.h"
#import "ios/chrome/browser/ui/main/scene_controller.h"
#import "ios/chrome/browser/ui/main/scene_delegate.h"
#import "ios/chrome/browser/ui/main/scene_state.h"
......
......@@ -76,7 +76,7 @@
- (void)showOverlay {
NSArray<UIWindow*>* windows = nil;
if (IsMultiwindowSupported()) {
if (IsSceneStartupSupported()) {
if (@available(iOS 13, *)) {
windows = self.sceneState.scene.windows;
}
......
......@@ -13,10 +13,7 @@ source_set("multiwindow_util") {
"multi_window_support.mm",
]
deps = [
"//base",
"//base/ios:ios_multi_window_buildflags",
]
deps = [ "//base" ]
}
source_set("util") {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment