| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 #import "ios/chrome/browser/ui/static_content/static_html_native_content.h" | 5 #import "ios/chrome/browser/ui/static_content/static_html_native_content.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/scoped_nsobject.h" | |
| 9 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.
h" | 8 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.
h" |
| 10 #include "ios/chrome/browser/ui/static_content/static_html_view_controller.h" | 9 #include "ios/chrome/browser/ui/static_content/static_html_view_controller.h" |
| 11 #import "ios/chrome/browser/ui/url_loader.h" | 10 #import "ios/chrome/browser/ui/url_loader.h" |
| 12 #include "ios/web/public/referrer.h" | 11 #include "ios/web/public/referrer.h" |
| 13 | 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
| 14 @interface StaticHtmlNativeContent () | 17 @interface StaticHtmlNativeContent () |
| 15 // Designated initializer. | 18 // Designated initializer. |
| 16 - (instancetype)initWithLoader:(id<UrlLoader>)loader | 19 - (instancetype)initWithLoader:(id<UrlLoader>)loader |
| 17 staticHTMLViewController:(StaticHtmlViewController*)HTMLViewController | 20 staticHTMLViewController:(StaticHtmlViewController*)HTMLViewController |
| 18 URL:(const GURL&)URL; | 21 URL:(const GURL&)URL; |
| 19 @end | 22 @end |
| 20 | 23 |
| 21 @implementation StaticHtmlNativeContent { | 24 @implementation StaticHtmlNativeContent { |
| 22 // The url of the controller. | 25 // The url of the controller. |
| 23 GURL _URL; | 26 GURL _URL; |
| 24 // YES is web views are allowed to be created. | 27 // YES is web views are allowed to be created. |
| 25 BOOL _webUsageEnabled; | 28 BOOL _webUsageEnabled; |
| 26 // The static HTML view controller that is used to display the content in | 29 // The static HTML view controller that is used to display the content in |
| 27 // a web view. | 30 // a web view. |
| 28 base::scoped_nsobject<StaticHtmlViewController> _staticHTMLViewController; | 31 StaticHtmlViewController* _staticHTMLViewController; |
| 29 // Responsible for loading a particular URL. | 32 // Responsible for loading a particular URL. |
| 30 id<UrlLoader> _loader; // weak | 33 id<UrlLoader> _loader; // weak |
| 31 // The controller handling the overscroll actions. | 34 // The controller handling the overscroll actions. |
| 32 base::scoped_nsobject<OverscrollActionsController> | 35 OverscrollActionsController* _overscrollActionsController; |
| 33 _overscrollActionsController; | |
| 34 } | 36 } |
| 35 | 37 |
| 36 #pragma mark - | 38 #pragma mark - |
| 37 #pragma mark Public | 39 #pragma mark Public |
| 38 | 40 |
| 39 - (instancetype)initWithLoader:(id<UrlLoader>)loader | 41 - (instancetype)initWithLoader:(id<UrlLoader>)loader |
| 40 staticHTMLViewController:(StaticHtmlViewController*)HTMLViewController | 42 staticHTMLViewController:(StaticHtmlViewController*)HTMLViewController |
| 41 URL:(const GURL&)URL { | 43 URL:(const GURL&)URL { |
| 42 DCHECK(loader); | 44 DCHECK(loader); |
| 43 DCHECK(HTMLViewController); | 45 DCHECK(HTMLViewController); |
| 44 // No DCHECK for URL (invalid URL is a valid input). | 46 // No DCHECK for URL (invalid URL is a valid input). |
| 45 if (self = [super init]) { | 47 if (self = [super init]) { |
| 46 web::Referrer referrer(URL, web::ReferrerPolicyDefault); | 48 web::Referrer referrer(URL, web::ReferrerPolicyDefault); |
| 47 [HTMLViewController setLoader:loader referrer:referrer]; | 49 [HTMLViewController setLoader:loader referrer:referrer]; |
| 48 _URL = URL; | 50 _URL = URL; |
| 49 _loader = loader; | 51 _loader = loader; |
| 50 _staticHTMLViewController.reset([HTMLViewController retain]); | 52 _staticHTMLViewController = HTMLViewController; |
| 51 } | 53 } |
| 52 return self; | 54 return self; |
| 53 } | 55 } |
| 54 | 56 |
| 55 - (instancetype)initWithResourcePathResource:(NSString*)resourcePath | 57 - (instancetype)initWithResourcePathResource:(NSString*)resourcePath |
| 56 loader:(id<UrlLoader>)loader | 58 loader:(id<UrlLoader>)loader |
| 57 browserState:(web::BrowserState*)browserState | 59 browserState:(web::BrowserState*)browserState |
| 58 url:(const GURL&)URL { | 60 url:(const GURL&)URL { |
| 59 DCHECK(loader); | 61 DCHECK(loader); |
| 60 DCHECK(browserState); | 62 DCHECK(browserState); |
| 61 DCHECK(URL.is_valid()); | 63 DCHECK(URL.is_valid()); |
| 62 DCHECK(resourcePath); | 64 DCHECK(resourcePath); |
| 63 base::scoped_nsobject<StaticHtmlViewController> HTMLViewController( | 65 StaticHtmlViewController* HTMLViewController = |
| 64 [[StaticHtmlViewController alloc] initWithResource:resourcePath | 66 [[StaticHtmlViewController alloc] initWithResource:resourcePath |
| 65 browserState:browserState]); | 67 browserState:browserState]; |
| 66 return [self initWithLoader:loader | 68 return [self initWithLoader:loader |
| 67 staticHTMLViewController:HTMLViewController | 69 staticHTMLViewController:HTMLViewController |
| 68 URL:URL]; | 70 URL:URL]; |
| 69 } | 71 } |
| 70 | 72 |
| 71 - (void)dealloc { | 73 - (void)dealloc { |
| 72 [[self scrollView] setDelegate:nil]; | 74 [[self scrollView] setDelegate:nil]; |
| 73 [super dealloc]; | |
| 74 } | 75 } |
| 75 | 76 |
| 76 - (void)loadURL:(const GURL&)URL | 77 - (void)loadURL:(const GURL&)URL |
| 77 referrer:(const web::Referrer&)referrer | 78 referrer:(const web::Referrer&)referrer |
| 78 transition:(ui::PageTransition)transition | 79 transition:(ui::PageTransition)transition |
| 79 rendererInitiated:(BOOL)rendererInitiated { | 80 rendererInitiated:(BOOL)rendererInitiated { |
| 80 [_loader loadURL:URL | 81 [_loader loadURL:URL |
| 81 referrer:referrer | 82 referrer:referrer |
| 82 transition:transition | 83 transition:transition |
| 83 rendererInitiated:rendererInitiated]; | 84 rendererInitiated:rendererInitiated]; |
| 84 } | 85 } |
| 85 | 86 |
| 86 - (OverscrollActionsController*)overscrollActionsController { | 87 - (OverscrollActionsController*)overscrollActionsController { |
| 87 return _overscrollActionsController.get(); | 88 return _overscrollActionsController; |
| 88 } | 89 } |
| 89 | 90 |
| 90 - (void)setOverscrollActionsController: | 91 - (void)setOverscrollActionsController: |
| 91 (OverscrollActionsController*)controller { | 92 (OverscrollActionsController*)controller { |
| 92 _overscrollActionsController.reset([controller retain]); | 93 _overscrollActionsController = controller; |
| 93 [[self scrollView] setDelegate:controller]; | 94 [[self scrollView] setDelegate:controller]; |
| 94 } | 95 } |
| 95 | 96 |
| 96 #pragma mark - | 97 #pragma mark - |
| 97 #pragma mark CRWNativeContent implementation | 98 #pragma mark CRWNativeContent implementation |
| 98 | 99 |
| 99 - (void)willBeDismissed { | 100 - (void)willBeDismissed { |
| 100 // Invalidate the _overscrollActionsController but let the animation finish. | 101 // Invalidate the _overscrollActionsController but let the animation finish. |
| 101 [_overscrollActionsController scheduleInvalidate]; | 102 [_overscrollActionsController scheduleInvalidate]; |
| 102 } | 103 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 - (void)setScrollEnabled:(BOOL)enabled { | 149 - (void)setScrollEnabled:(BOOL)enabled { |
| 149 [_staticHTMLViewController setScrollEnabled:enabled]; | 150 [_staticHTMLViewController setScrollEnabled:enabled]; |
| 150 } | 151 } |
| 151 | 152 |
| 152 - (void)setWebUsageEnabled:(BOOL)webUsageEnabled { | 153 - (void)setWebUsageEnabled:(BOOL)webUsageEnabled { |
| 153 if (_webUsageEnabled == webUsageEnabled) { | 154 if (_webUsageEnabled == webUsageEnabled) { |
| 154 return; | 155 return; |
| 155 } | 156 } |
| 156 _webUsageEnabled = webUsageEnabled; | 157 _webUsageEnabled = webUsageEnabled; |
| 157 if (!_webUsageEnabled) { | 158 if (!_webUsageEnabled) { |
| 158 _staticHTMLViewController.reset(); | 159 _staticHTMLViewController = nil; |
| 159 } | 160 } |
| 160 } | 161 } |
| 161 | 162 |
| 162 - (UIScrollView*)scrollView { | 163 - (UIScrollView*)scrollView { |
| 163 return [_staticHTMLViewController scrollView]; | 164 return [_staticHTMLViewController scrollView]; |
| 164 } | 165 } |
| 165 | 166 |
| 166 @end | 167 @end |
| OLD | NEW |