OLD | NEW |
(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 // ====== New Architecture ===== |
| 6 // = This code is only used in the new iOS Chrome architecture. = |
| 7 // ============================================================================ |
| 8 |
| 9 #import "ios/chrome/app/steps/launch_to_foreground.h" |
| 10 |
| 11 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 12 #include "ios/chrome/app/application_state.h" |
| 13 #include "ios/chrome/browser/application_context.h" |
| 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 15 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory.
h" |
| 16 #include "ios/net/cookies/cookie_store_ios.h" |
| 17 #include "ios/web/public/web_capabilities.h" |
| 18 #include "ios/web/public/web_thread.h" |
| 19 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." |
| 22 #endif |
| 23 |
| 24 // Temporary class to trigger URL-opening events from a shake gesture. |
| 25 @interface ShakeCatchingWindow : UIWindow |
| 26 @end |
| 27 |
| 28 @implementation BeginForegrounding |
| 29 |
| 30 - (BOOL)canRunInState:(ApplicationState*)state { |
| 31 return state.phase == APPLICATION_BACKGROUNDED; |
| 32 } |
| 33 |
| 34 - (void)runInState:(ApplicationState*)state { |
| 35 GetApplicationContext()->OnAppEnterForeground(); |
| 36 } |
| 37 |
| 38 @end |
| 39 |
| 40 @implementation BrowserStateInitializer |
| 41 |
| 42 - (BOOL)canRunInState:(ApplicationState*)state { |
| 43 return state.browserState && state.phase == APPLICATION_BACKGROUNDED; |
| 44 } |
| 45 |
| 46 - (void)runInState:(ApplicationState*)state { |
| 47 DCHECK(!state.browserState->IsOffTheRecord()); |
| 48 [self setInitialCookiesPolicy:state.browserState]; |
| 49 } |
| 50 |
| 51 // Copied verbatim from MainController. |
| 52 - (void)setInitialCookiesPolicy:(ios::ChromeBrowserState*)browserState { |
| 53 DCHECK(browserState); |
| 54 net::CookieStoreIOS::CookiePolicy policy = net::CookieStoreIOS::BLOCK; |
| 55 |
| 56 auto settingsFactory = |
| 57 ios::HostContentSettingsMapFactory::GetForBrowserState(browserState); |
| 58 DCHECK(settingsFactory); |
| 59 ContentSetting cookieSetting = settingsFactory->GetDefaultContentSetting( |
| 60 CONTENT_SETTINGS_TYPE_COOKIES, nullptr); |
| 61 |
| 62 if (!web::IsAcceptCookieControlSupported()) { |
| 63 // Override the Accept Cookie policy as ALLOW is the only policy |
| 64 // supported by //web. |
| 65 policy = net::CookieStoreIOS::ALLOW; |
| 66 if (cookieSetting == CONTENT_SETTING_BLOCK) { |
| 67 settingsFactory->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, |
| 68 CONTENT_SETTING_ALLOW); |
| 69 } |
| 70 } else { |
| 71 switch (cookieSetting) { |
| 72 case CONTENT_SETTING_ALLOW: |
| 73 policy = net::CookieStoreIOS::ALLOW; |
| 74 break; |
| 75 case CONTENT_SETTING_BLOCK: |
| 76 policy = net::CookieStoreIOS::BLOCK; |
| 77 break; |
| 78 default: |
| 79 NOTREACHED() << "Unsupported cookie policy."; |
| 80 break; |
| 81 } |
| 82 } |
| 83 |
| 84 web::WebThread::PostTask( |
| 85 web::WebThread::IO, FROM_HERE, |
| 86 base::Bind(&net::CookieStoreIOS::SetCookiePolicy, policy)); |
| 87 } |
| 88 |
| 89 @end |
| 90 |
| 91 @implementation PrepareForUI |
| 92 |
| 93 - (BOOL)canRunInState:(ApplicationState*)state { |
| 94 return state.phase == APPLICATION_BACKGROUNDED; |
| 95 } |
| 96 |
| 97 - (void)runInState:(ApplicationState*)state { |
| 98 state.window = |
| 99 [[ShakeCatchingWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; |
| 100 [state.window makeKeyWindow]; |
| 101 } |
| 102 |
| 103 @end |
| 104 |
| 105 @implementation CompleteForegrounding |
| 106 - (BOOL)canRunInState:(ApplicationState*)state { |
| 107 return state.window.keyWindow && state.phase == APPLICATION_BACKGROUNDED; |
| 108 } |
| 109 |
| 110 - (void)runInState:(ApplicationState*)state { |
| 111 state.phase = APPLICATION_FOREGROUNDED; |
| 112 } |
| 113 |
| 114 @end |
| 115 |
| 116 @implementation ShakeCatchingWindow |
| 117 |
| 118 #pragma mark - UIResponder |
| 119 |
| 120 - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent*)event { |
| 121 if (motion == UIEventSubtypeMotionShake) { |
| 122 UIApplication* app = [UIApplication sharedApplication]; |
| 123 [app.delegate application:app |
| 124 openURL:[NSURL URLWithString:@"https://www.google.com"] |
| 125 options:@{}]; |
| 126 } |
| 127 [super motionEnded:motion withEvent:event]; |
| 128 } |
| 129 |
| 130 @end |
OLD | NEW |