| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // ====== New Architecture ===== | 5 // ====== New Architecture ===== |
| 6 // = This code is only used in the new iOS Chrome architecture. = | 6 // = This code is only used in the new iOS Chrome architecture. = |
| 7 // ============================================================================ | 7 // ============================================================================ |
| 8 | 8 |
| 9 #import "ios/chrome/app/steps/launch_to_foreground.h" | 9 #import "ios/chrome/app/steps/launch_to_foreground.h" |
| 10 | 10 |
| 11 #include "components/content_settings/core/browser/host_content_settings_map.h" | 11 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 12 #include "ios/chrome/app/application_state.h" | 12 #include "ios/chrome/app/application_state.h" |
| 13 #include "ios/chrome/browser/application_context.h" | 13 #include "ios/chrome/browser/application_context.h" |
| 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.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" | 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" | 16 #include "ios/web/public/web_capabilities.h" |
| 18 #include "ios/web/public/web_thread.h" | 17 #include "ios/web/public/web_thread.h" |
| 19 | 18 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) | 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." | 20 #error "This file requires ARC support." |
| 22 #endif | 21 #endif |
| 23 | 22 |
| 24 // Temporary class to trigger URL-opening events from a shake gesture. | 23 // Temporary class to trigger URL-opening events from a shake gesture. |
| 25 @interface ShakeCatchingWindow : UIWindow | 24 @interface ShakeCatchingWindow : UIWindow |
| 26 @end | 25 @end |
| 27 | 26 |
| 28 @implementation BeginForegrounding | 27 @implementation BeginForegrounding |
| 29 | 28 |
| 30 - (BOOL)canRunInState:(ApplicationState*)state { | 29 - (BOOL)canRunInState:(ApplicationState*)state { |
| 31 return state.phase == APPLICATION_BACKGROUNDED; | 30 return state.phase == APPLICATION_BACKGROUNDED; |
| 32 } | 31 } |
| 33 | 32 |
| 34 - (void)runInState:(ApplicationState*)state { | 33 - (void)runInState:(ApplicationState*)state { |
| 35 GetApplicationContext()->OnAppEnterForeground(); | 34 GetApplicationContext()->OnAppEnterForeground(); |
| 36 } | 35 } |
| 37 | 36 |
| 38 @end | 37 @end |
| 39 | 38 |
| 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 | 39 @implementation PrepareForUI |
| 92 | 40 |
| 93 - (BOOL)canRunInState:(ApplicationState*)state { | 41 - (BOOL)canRunInState:(ApplicationState*)state { |
| 94 return state.phase == APPLICATION_BACKGROUNDED; | 42 return state.phase == APPLICATION_BACKGROUNDED; |
| 95 } | 43 } |
| 96 | 44 |
| 97 - (void)runInState:(ApplicationState*)state { | 45 - (void)runInState:(ApplicationState*)state { |
| 98 state.window = | 46 state.window = |
| 99 [[ShakeCatchingWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | 47 [[ShakeCatchingWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; |
| 100 [state.window makeKeyWindow]; | 48 [state.window makeKeyWindow]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 121 if (motion == UIEventSubtypeMotionShake) { | 69 if (motion == UIEventSubtypeMotionShake) { |
| 122 UIApplication* app = [UIApplication sharedApplication]; | 70 UIApplication* app = [UIApplication sharedApplication]; |
| 123 [app.delegate application:app | 71 [app.delegate application:app |
| 124 openURL:[NSURL URLWithString:@"https://www.google.com"] | 72 openURL:[NSURL URLWithString:@"https://www.google.com"] |
| 125 options:@{}]; | 73 options:@{}]; |
| 126 } | 74 } |
| 127 [super motionEnded:motion withEvent:event]; | 75 [super motionEnded:motion withEvent:event]; |
| 128 } | 76 } |
| 129 | 77 |
| 130 @end | 78 @end |
| OLD | NEW |