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

Side by Side Diff: ios/chrome/browser/ui/dialogs/dialog_presenter.mm

Issue 2957423002: Check page URL origin to determine JavaScript alert titles. (Closed)
Patch Set: Created 3 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/dialogs/dialog_presenter.h" 5 #import "ios/chrome/browser/ui/dialogs/dialog_presenter.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <map> 8 #include <map>
9 9
10 #import "base/ios/block_types.h" 10 #import "base/ios/block_types.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 self.presentedDialogCoordinator != nil); 127 self.presentedDialogCoordinator != nil);
128 return self.presentedDialogCoordinator != nil; 128 return self.presentedDialogCoordinator != nil;
129 } 129 }
130 130
131 #pragma mark - Public 131 #pragma mark - Public
132 132
133 - (void)runJavaScriptAlertPanelWithMessage:(NSString*)message 133 - (void)runJavaScriptAlertPanelWithMessage:(NSString*)message
134 requestURL:(const GURL&)requestURL 134 requestURL:(const GURL&)requestURL
135 webState:(web::WebState*)webState 135 webState:(web::WebState*)webState
136 completionHandler:(void (^)(void))completionHandler { 136 completionHandler:(void (^)(void))completionHandler {
137 NSString* title = 137 NSString* title = [DialogPresenter
138 [DialogPresenter localizedTitleForJavaScriptAlertFromPage:requestURL]; 138 localizedTitleForJavaScriptAlertFromPage:requestURL
139 mainFrameURL:webState->GetLastCommittedURL()];
139 AlertCoordinator* alertCoordinator = 140 AlertCoordinator* alertCoordinator =
140 [[AlertCoordinator alloc] initWithBaseViewController:self.viewController 141 [[AlertCoordinator alloc] initWithBaseViewController:self.viewController
141 title:title 142 title:title
142 message:message]; 143 message:message];
143 144
144 // Handler. 145 // Handler.
145 __weak DialogPresenter* weakSelf = self; 146 __weak DialogPresenter* weakSelf = self;
146 __weak AlertCoordinator* weakCoordinator = alertCoordinator; 147 __weak AlertCoordinator* weakCoordinator = alertCoordinator;
147 ProceduralBlock OKHandler = ^{ 148 ProceduralBlock OKHandler = ^{
148 if (completionHandler) 149 if (completionHandler)
(...skipping 14 matching lines...) Expand all
163 [self setUpBlockingOptionForCoordinator:alertCoordinator webState:webState]; 164 [self setUpBlockingOptionForCoordinator:alertCoordinator webState:webState];
164 165
165 [self addDialogCoordinator:alertCoordinator forWebState:webState]; 166 [self addDialogCoordinator:alertCoordinator forWebState:webState];
166 } 167 }
167 168
168 - (void)runJavaScriptConfirmPanelWithMessage:(NSString*)message 169 - (void)runJavaScriptConfirmPanelWithMessage:(NSString*)message
169 requestURL:(const GURL&)requestURL 170 requestURL:(const GURL&)requestURL
170 webState:(web::WebState*)webState 171 webState:(web::WebState*)webState
171 completionHandler: 172 completionHandler:
172 (void (^)(BOOL isConfirmed))completionHandler { 173 (void (^)(BOOL isConfirmed))completionHandler {
173 NSString* title = 174 NSString* title = [DialogPresenter
174 [DialogPresenter localizedTitleForJavaScriptAlertFromPage:requestURL]; 175 localizedTitleForJavaScriptAlertFromPage:requestURL
176 mainFrameURL:webState->GetLastCommittedURL()];
PL 2017/06/28 23:18:34 Is GetLastCommittedURL() the right URL to use here
175 AlertCoordinator* alertCoordinator = 177 AlertCoordinator* alertCoordinator =
176 [[AlertCoordinator alloc] initWithBaseViewController:self.viewController 178 [[AlertCoordinator alloc] initWithBaseViewController:self.viewController
177 title:title 179 title:title
178 message:message]; 180 message:message];
179 181
180 // Actions. 182 // Actions.
181 ProceduralBlock confirmAction = ^{ 183 ProceduralBlock confirmAction = ^{
182 if (completionHandler) 184 if (completionHandler)
183 completionHandler(YES); 185 completionHandler(YES);
184 }; 186 };
(...skipping 15 matching lines...) Expand all
200 202
201 [self addDialogCoordinator:alertCoordinator forWebState:webState]; 203 [self addDialogCoordinator:alertCoordinator forWebState:webState];
202 } 204 }
203 205
204 - (void)runJavaScriptTextInputPanelWithPrompt:(NSString*)message 206 - (void)runJavaScriptTextInputPanelWithPrompt:(NSString*)message
205 defaultText:(NSString*)defaultText 207 defaultText:(NSString*)defaultText
206 requestURL:(const GURL&)requestURL 208 requestURL:(const GURL&)requestURL
207 webState:(web::WebState*)webState 209 webState:(web::WebState*)webState
208 completionHandler: 210 completionHandler:
209 (void (^)(NSString* input))completionHandler { 211 (void (^)(NSString* input))completionHandler {
210 NSString* title = 212 NSString* title = [DialogPresenter
211 [DialogPresenter localizedTitleForJavaScriptAlertFromPage:requestURL]; 213 localizedTitleForJavaScriptAlertFromPage:requestURL
214 mainFrameURL:webState->GetLastCommittedURL()];
212 InputAlertCoordinator* alertCoordinator = [[InputAlertCoordinator alloc] 215 InputAlertCoordinator* alertCoordinator = [[InputAlertCoordinator alloc]
213 initWithBaseViewController:self.viewController 216 initWithBaseViewController:self.viewController
214 title:title 217 title:title
215 message:message]; 218 message:message];
216 219
217 // Actions. 220 // Actions.
218 __weak InputAlertCoordinator* weakCoordinator = alertCoordinator; 221 __weak InputAlertCoordinator* weakCoordinator = alertCoordinator;
219 ProceduralBlock confirmAction = ^{ 222 ProceduralBlock confirmAction = ^{
220 if (completionHandler) { 223 if (completionHandler) {
221 NSString* textInput = [weakCoordinator textFields].firstObject.text; 224 NSString* textInput = [weakCoordinator textFields].firstObject.text;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // displayed. 346 // displayed.
344 if (self.blockingConfirmationCoordinator) 347 if (self.blockingConfirmationCoordinator)
345 return; 348 return;
346 // The active TabModel can't be changed while a JavaScript dialog is shown. 349 // The active TabModel can't be changed while a JavaScript dialog is shown.
347 DCHECK(!self.showingDialog); 350 DCHECK(!self.showingDialog);
348 if (_active && !_queuedWebStates.empty() && !self.delegate.presenting) 351 if (_active && !_queuedWebStates.empty() && !self.delegate.presenting)
349 [self showNextDialog]; 352 [self showNextDialog];
350 } 353 }
351 354
352 + (NSString*)localizedTitleForJavaScriptAlertFromPage:(const GURL&)pageURL { 355 + (NSString*)localizedTitleForJavaScriptAlertFromPage:(const GURL&)pageURL {
356 return [self localizedTitleForJavaScriptAlertFromPage:pageURL
357 mainFrameURL:pageURL];
358 }
359
360 + (NSString*)localizedTitleForJavaScriptAlertFromPage:(const GURL&)pageURL
361 mainFrameURL:
362 (const GURL&)mainFrameURL {
353 NSString* localizedTitle = nil; 363 NSString* localizedTitle = nil;
354 NSString* hostname = base::SysUTF8ToNSString(pageURL.host()); 364 NSString* hostname = base::SysUTF8ToNSString(pageURL.host());
355 if (!hostname.length) { 365
366 bool is_same_origin_as_main_frame =
Eugene But (OOO till 7-30) 2017/06/29 01:00:01 s/is_same_origin_as_main_frame/sameOriginAsMainFra
PL 2017/06/29 20:02:21 Thanks! I'm not sure how long it will take me to g
367 pageURL.GetOrigin() == mainFrameURL.GetOrigin();
368
369 if (!is_same_origin_as_main_frame) {
356 localizedTitle = l10n_util::GetNSString( 370 localizedTitle = l10n_util::GetNSString(
357 IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME); 371 IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME);
358 } else { 372 } else {
359 localizedTitle = l10n_util::GetNSStringF( 373 localizedTitle = l10n_util::GetNSStringF(
360 IDS_JAVASCRIPT_MESSAGEBOX_TITLE, base::SysNSStringToUTF16(hostname)); 374 IDS_JAVASCRIPT_MESSAGEBOX_TITLE, base::SysNSStringToUTF16(hostname));
361 } 375 }
362 return localizedTitle; 376 return localizedTitle;
363 } 377 }
364 378
365 #pragma mark - Private methods. 379 #pragma mark - Private methods.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 style:UIAlertActionStyleDestructive]; 521 style:UIAlertActionStyleDestructive];
508 [confirmationCoordinator addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL) 522 [confirmationCoordinator addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL)
509 action:cancelHandler 523 action:cancelHandler
510 style:UIAlertActionStyleCancel]; 524 style:UIAlertActionStyleCancel];
511 [weakSelf setBlockingConfirmationCoordinator:confirmationCoordinator]; 525 [weakSelf setBlockingConfirmationCoordinator:confirmationCoordinator];
512 [[weakSelf blockingConfirmationCoordinator] start]; 526 [[weakSelf blockingConfirmationCoordinator] start];
513 } copy]; 527 } copy];
514 } 528 }
515 529
516 @end 530 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698