Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/web_view/public/cwv_web_view.h" | 5 #import "ios/web_view/public/cwv_web_view.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #import "base/ios/weak_nsobject.h" | 10 #import "base/ios/weak_nsobject.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #import "ios/web/public/navigation_manager.h" | 13 #import "ios/web/public/navigation_manager.h" |
| 14 #include "ios/web/public/referrer.h" | 14 #include "ios/web/public/referrer.h" |
| 15 #import "ios/web/public/web_state/context_menu_params.h" | |
| 15 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 16 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
| 16 #import "ios/web/public/web_state/ui/crw_web_delegate.h" | 17 #import "ios/web/public/web_state/ui/crw_web_delegate.h" |
| 17 #import "ios/web/public/web_state/web_state.h" | 18 #import "ios/web/public/web_state/web_state.h" |
| 18 #import "ios/web/public/web_state/web_state_delegate_bridge.h" | 19 #import "ios/web/public/web_state/web_state_delegate_bridge.h" |
| 19 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 20 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 20 #import "ios/web_view/internal/cwv_website_data_store_internal.h" | 21 #import "ios/web_view/internal/cwv_website_data_store_internal.h" |
| 21 #import "ios/web_view/internal/translate/web_view_translate_client.h" | 22 #import "ios/web_view/internal/translate/web_view_translate_client.h" |
| 22 #include "ios/web_view/internal/web_view_browser_state.h" | 23 #include "ios/web_view/internal/web_view_browser_state.h" |
| 24 #import "ios/web_view/public/cwv_html_element.h" | |
| 25 #import "ios/web_view/public/cwv_ui_delegate.h" | |
| 23 #import "ios/web_view/public/cwv_web_view_configuration.h" | 26 #import "ios/web_view/public/cwv_web_view_configuration.h" |
| 24 #import "ios/web_view/public/cwv_web_view_delegate.h" | 27 #import "ios/web_view/public/cwv_web_view_delegate.h" |
| 25 #import "ios/web_view/public/cwv_website_data_store.h" | 28 #import "ios/web_view/public/cwv_website_data_store.h" |
| 26 #import "net/base/mac/url_conversions.h" | 29 #import "net/base/mac/url_conversions.h" |
| 27 #include "ui/base/page_transition_types.h" | 30 #include "ui/base/page_transition_types.h" |
| 28 #include "url/gurl.h" | 31 #include "url/gurl.h" |
| 29 | 32 |
| 30 #if !defined(__has_feature) || !__has_feature(objc_arc) | 33 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 31 #error "This file requires ARC support." | 34 #error "This file requires ARC support." |
| 32 #endif | 35 #endif |
| 33 | 36 |
| 34 @interface CWVWebView ()<CRWWebStateDelegate, CRWWebStateObserver> { | 37 @interface CWVWebView ()<CRWWebStateDelegate, CRWWebStateObserver> { |
| 35 CWVWebViewConfiguration* _configuration; | 38 CWVWebViewConfiguration* _configuration; |
| 36 std::unique_ptr<web::WebState> _webState; | 39 std::unique_ptr<web::WebState> _webState; |
| 37 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; | 40 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; |
| 38 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; | 41 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; |
| 39 CGFloat _loadProgress; | 42 CGFloat _loadProgress; |
| 40 } | 43 } |
| 41 | 44 |
| 42 @end | 45 @end |
| 43 | 46 |
| 44 @implementation CWVWebView | 47 @implementation CWVWebView |
| 45 | 48 |
| 46 @synthesize delegate = _delegate; | 49 @synthesize delegate = _delegate; |
| 47 @synthesize loadProgress = _loadProgress; | 50 @synthesize loadProgress = _loadProgress; |
| 51 @synthesize UIDelegate = _UIDelegate; | |
| 48 | 52 |
| 49 - (instancetype)initWithFrame:(CGRect)frame | 53 - (instancetype)initWithFrame:(CGRect)frame |
| 50 configuration:(CWVWebViewConfiguration*)configuration { | 54 configuration:(CWVWebViewConfiguration*)configuration { |
| 51 self = [super initWithFrame:frame]; | 55 self = [super initWithFrame:frame]; |
| 52 if (self) { | 56 if (self) { |
| 53 _configuration = [configuration copy]; | 57 _configuration = [configuration copy]; |
| 54 | 58 |
| 55 web::WebState::CreateParams webStateCreateParams( | 59 web::WebState::CreateParams webStateCreateParams( |
| 56 [configuration.websiteDataStore browserState]); | 60 [configuration.websiteDataStore browserState]); |
| 57 _webState = web::WebState::Create(webStateCreateParams); | 61 _webState = web::WebState::Create(webStateCreateParams); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 didFinishLoadingWithURL:[self visibleURL] | 182 didFinishLoadingWithURL:[self visibleURL] |
| 179 loadSuccess:success]; | 183 loadSuccess:success]; |
| 180 } | 184 } |
| 181 } | 185 } |
| 182 | 186 |
| 183 - (void)webState:(web::WebState*)webState | 187 - (void)webState:(web::WebState*)webState |
| 184 didChangeLoadingProgress:(double)progress { | 188 didChangeLoadingProgress:(double)progress { |
| 185 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeProgress]; | 189 [self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeProgress]; |
| 186 } | 190 } |
| 187 | 191 |
| 192 - (BOOL)webState:(web::WebState*)webState | |
| 193 handleContextMenu:(const web::ContextMenuParams&)params { | |
| 194 if ([_UIDelegate respondsToSelector:@selector | |
|
Eugene But (OOO till 7-30)
2017/02/27 16:34:06
Optional nit: do you want to reverse the condition
michaeldo
2017/02/27 19:02:05
I agree, I like that better.
| |
| 195 (webView:runContextMenuWithTitle:forHTMLElement:inView | |
|
Eugene But (OOO till 7-30)
2017/02/27 16:34:06
Optional nit: Do you want to create a local variab
michaeldo
2017/02/27 19:02:05
Done.
| |
| 196 :userGestureLocation:)]) { | |
| 197 NSURL* hyperlink = net::NSURLWithGURL(params.link_url); | |
| 198 NSURL* mediaSource = net::NSURLWithGURL(params.src_url); | |
| 199 CWVHTMLElement* htmlElement = | |
|
Eugene But (OOO till 7-30)
2017/02/27 16:34:06
s/htmlElement/HTMLElement
michaeldo
2017/02/27 19:02:06
Done.
| |
| 200 [[CWVHTMLElement alloc] initWithHyperlink:hyperlink | |
| 201 mediaSource:mediaSource | |
| 202 text:params.link_text]; | |
| 203 [_UIDelegate webView:self | |
| 204 runContextMenuWithTitle:params.menu_title | |
| 205 forHTMLElement:htmlElement | |
| 206 inView:params.view | |
| 207 userGestureLocation:params.location]; | |
| 208 return YES; | |
| 209 } | |
| 210 return NO; | |
| 211 } | |
| 212 | |
| 188 @end | 213 @end |
| OLD | NEW |