Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(928)

Side by Side Diff: ios/web_view/internal/cwv_web_view.mm

Issue 2715343002: Add JavaScript prompts support to CWVUIDelegate. (Closed)
Patch Set: Respond to comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/context_menu_params.h"
16 #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"
17 #import "ios/web/public/web_state/ui/crw_web_delegate.h" 17 #import "ios/web/public/web_state/ui/crw_web_delegate.h"
18 #import "ios/web/public/web_state/web_state.h" 18 #import "ios/web/public/web_state/web_state.h"
19 #import "ios/web/public/web_state/web_state_delegate_bridge.h" 19 #import "ios/web/public/web_state/web_state_delegate_bridge.h"
20 #import "ios/web/public/web_state/web_state_observer_bridge.h" 20 #import "ios/web/public/web_state/web_state_observer_bridge.h"
21 #import "ios/web_view/internal/cwv_html_element_internal.h" 21 #import "ios/web_view/internal/cwv_html_element_internal.h"
22 #import "ios/web_view/internal/cwv_website_data_store_internal.h" 22 #import "ios/web_view/internal/cwv_website_data_store_internal.h"
23 #import "ios/web_view/internal/translate/web_view_translate_client.h" 23 #import "ios/web_view/internal/translate/web_view_translate_client.h"
24 #include "ios/web_view/internal/web_view_browser_state.h" 24 #include "ios/web_view/internal/web_view_browser_state.h"
25 #import "ios/web_view/internal/web_view_java_script_dialog_presenter.h"
25 #import "ios/web_view/public/cwv_ui_delegate.h" 26 #import "ios/web_view/public/cwv_ui_delegate.h"
26 #import "ios/web_view/public/cwv_web_view_configuration.h" 27 #import "ios/web_view/public/cwv_web_view_configuration.h"
27 #import "ios/web_view/public/cwv_web_view_delegate.h" 28 #import "ios/web_view/public/cwv_web_view_delegate.h"
28 #import "ios/web_view/public/cwv_website_data_store.h" 29 #import "ios/web_view/public/cwv_website_data_store.h"
29 #import "net/base/mac/url_conversions.h" 30 #import "net/base/mac/url_conversions.h"
30 #include "ui/base/page_transition_types.h" 31 #include "ui/base/page_transition_types.h"
31 #include "url/gurl.h" 32 #include "url/gurl.h"
32 33
33 #if !defined(__has_feature) || !__has_feature(objc_arc) 34 #if !defined(__has_feature) || !__has_feature(objc_arc)
34 #error "This file requires ARC support." 35 #error "This file requires ARC support."
35 #endif 36 #endif
36 37
37 @interface CWVWebView ()<CRWWebStateDelegate, CRWWebStateObserver> { 38 @interface CWVWebView ()<CRWWebStateDelegate, CRWWebStateObserver> {
38 CWVWebViewConfiguration* _configuration; 39 CWVWebViewConfiguration* _configuration;
39 std::unique_ptr<web::WebState> _webState; 40 std::unique_ptr<web::WebState> _webState;
40 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; 41 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate;
41 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; 42 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver;
42 CGFloat _loadProgress; 43 CGFloat _loadProgress;
44 // Handles presentation of JavaScript dialogs.
45 std::unique_ptr<ios_web_view::WebViewJavaScriptDialogPresenter>
46 _javaScriptDialogPresenter;
43 } 47 }
44 48
45 @end 49 @end
46 50
47 @implementation CWVWebView 51 @implementation CWVWebView
48 52
49 @synthesize delegate = _delegate; 53 @synthesize delegate = _delegate;
50 @synthesize loadProgress = _loadProgress; 54 @synthesize loadProgress = _loadProgress;
51 @synthesize UIDelegate = _UIDelegate; 55 @synthesize UIDelegate = _UIDelegate;
52 56
53 - (instancetype)initWithFrame:(CGRect)frame 57 - (instancetype)initWithFrame:(CGRect)frame
54 configuration:(CWVWebViewConfiguration*)configuration { 58 configuration:(CWVWebViewConfiguration*)configuration {
55 self = [super initWithFrame:frame]; 59 self = [super initWithFrame:frame];
56 if (self) { 60 if (self) {
57 _configuration = [configuration copy]; 61 _configuration = [configuration copy];
58 62
59 web::WebState::CreateParams webStateCreateParams( 63 web::WebState::CreateParams webStateCreateParams(
60 [configuration.websiteDataStore browserState]); 64 [configuration.websiteDataStore browserState]);
61 _webState = web::WebState::Create(webStateCreateParams); 65 _webState = web::WebState::Create(webStateCreateParams);
62 _webState->SetWebUsageEnabled(true); 66 _webState->SetWebUsageEnabled(true);
63 67
64 _webStateObserver = 68 _webStateObserver =
65 base::MakeUnique<web::WebStateObserverBridge>(_webState.get(), self); 69 base::MakeUnique<web::WebStateObserverBridge>(_webState.get(), self);
66 _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self); 70 _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self);
67 _webState->SetDelegate(_webStateDelegate.get()); 71 _webState->SetDelegate(_webStateDelegate.get());
68 72
73 _javaScriptDialogPresenter =
74 base::MakeUnique<ios_web_view::WebViewJavaScriptDialogPresenter>(
75 self, _UIDelegate);
76
69 // Initialize Translate. 77 // Initialize Translate.
70 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState.get()); 78 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState.get());
71 } 79 }
72 return self; 80 return self;
73 } 81 }
74 82
75 - (void)willMoveToSuperview:(UIView*)newSuperview { 83 - (void)willMoveToSuperview:(UIView*)newSuperview {
76 [super willMoveToSuperview:newSuperview]; 84 [super willMoveToSuperview:newSuperview];
77 UIView* subview = _webState->GetView(); 85 UIView* subview = _webState->GetView();
78 if (subview.superview == self) { 86 if (subview.superview == self) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 156
149 // Set up the translate delegate. 157 // Set up the translate delegate.
150 ios_web_view::WebViewTranslateClient* translateClient = 158 ios_web_view::WebViewTranslateClient* translateClient =
151 ios_web_view::WebViewTranslateClient::FromWebState(_webState.get()); 159 ios_web_view::WebViewTranslateClient::FromWebState(_webState.get());
152 id<CWVTranslateDelegate> translateDelegate = nil; 160 id<CWVTranslateDelegate> translateDelegate = nil;
153 if ([_delegate respondsToSelector:@selector(translateDelegate)]) 161 if ([_delegate respondsToSelector:@selector(translateDelegate)])
154 translateDelegate = [_delegate translateDelegate]; 162 translateDelegate = [_delegate translateDelegate];
155 translateClient->set_translate_delegate(translateDelegate); 163 translateClient->set_translate_delegate(translateDelegate);
156 } 164 }
157 165
166 - (void)setUIDelegate:(id<CWVUIDelegate>)UIDelegate {
167 _UIDelegate = UIDelegate;
168
169 _javaScriptDialogPresenter->SetUIDelegate(_UIDelegate);
170 }
171
158 - (void)notifyDidUpdateWithChanges:(CRIWVWebViewUpdateType)changes { 172 - (void)notifyDidUpdateWithChanges:(CRIWVWebViewUpdateType)changes {
159 SEL selector = @selector(webView:didUpdateWithChanges:); 173 SEL selector = @selector(webView:didUpdateWithChanges:);
160 if ([_delegate respondsToSelector:selector]) { 174 if ([_delegate respondsToSelector:selector]) {
161 [_delegate webView:self didUpdateWithChanges:changes]; 175 [_delegate webView:self didUpdateWithChanges:changes];
162 } 176 }
163 } 177 }
164 178
165 // ----------------------------------------------------------------------- 179 // -----------------------------------------------------------------------
166 // WebStateObserver implementation. 180 // WebStateObserver implementation.
167 181
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 mediaSource:mediaSource 217 mediaSource:mediaSource
204 text:params.link_text]; 218 text:params.link_text];
205 [_UIDelegate webView:self 219 [_UIDelegate webView:self
206 runContextMenuWithTitle:params.menu_title 220 runContextMenuWithTitle:params.menu_title
207 forHTMLElement:HTMLElement 221 forHTMLElement:HTMLElement
208 inView:params.view 222 inView:params.view
209 userGestureLocation:params.location]; 223 userGestureLocation:params.location];
210 return YES; 224 return YES;
211 } 225 }
212 226
227 - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState:
228 (web::WebState*)webState {
229 return _javaScriptDialogPresenter.get();
230 }
231
213 @end 232 @end
OLDNEW
« no previous file with comments | « ios/web_view/internal/BUILD.gn ('k') | ios/web_view/internal/web_view_java_script_dialog_presenter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698