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

Unified Diff: ios/chrome/browser/ui/dialogs/dialog_presenter.mm

Issue 2957423002: Check page URL origin to determine JavaScript alert titles. (Closed)
Patch Set: Small tweak Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/dialogs/dialog_presenter.mm
diff --git a/ios/chrome/browser/ui/dialogs/dialog_presenter.mm b/ios/chrome/browser/ui/dialogs/dialog_presenter.mm
index 123efbab920d3da285aa64f346a7ec44cd282959..fb530ba1883461be744b829d0a910ffb95165470 100644
--- a/ios/chrome/browser/ui/dialogs/dialog_presenter.mm
+++ b/ios/chrome/browser/ui/dialogs/dialog_presenter.mm
@@ -91,6 +91,12 @@ NSString* const kJavaScriptDialogTextFieldAccessibiltyIdentifier =
// The block to use for the JavaScript dialog blocking option for |coordinator|.
- (ProceduralBlock)blockingActionForCoordinator:(AlertCoordinator*)coordinator;
+// Creates a title for the alert based on the URL (|pageURL|), and its
+// relationship to the |mainFrameURL| (typically these are identical except for
+// when posting alerts from an embedded iframe).
++ (NSString*)localizedTitleForJavaScriptAlertFromPage:(const GURL&)pageURL
+ mainFrameURL:(const GURL&)mainFrameURL;
+
@end
@implementation DialogPresenter
@@ -134,8 +140,9 @@ NSString* const kJavaScriptDialogTextFieldAccessibiltyIdentifier =
requestURL:(const GURL&)requestURL
webState:(web::WebState*)webState
completionHandler:(void (^)(void))completionHandler {
- NSString* title =
- [DialogPresenter localizedTitleForJavaScriptAlertFromPage:requestURL];
+ NSString* title = [DialogPresenter
+ localizedTitleForJavaScriptAlertFromPage:requestURL
+ mainFrameURL:webState->GetLastCommittedURL()];
AlertCoordinator* alertCoordinator =
[[AlertCoordinator alloc] initWithBaseViewController:self.viewController
title:title
@@ -170,8 +177,9 @@ NSString* const kJavaScriptDialogTextFieldAccessibiltyIdentifier =
webState:(web::WebState*)webState
completionHandler:
(void (^)(BOOL isConfirmed))completionHandler {
- NSString* title =
- [DialogPresenter localizedTitleForJavaScriptAlertFromPage:requestURL];
+ NSString* title = [DialogPresenter
+ localizedTitleForJavaScriptAlertFromPage:requestURL
+ mainFrameURL:webState->GetLastCommittedURL()];
AlertCoordinator* alertCoordinator =
[[AlertCoordinator alloc] initWithBaseViewController:self.viewController
title:title
@@ -207,8 +215,9 @@ NSString* const kJavaScriptDialogTextFieldAccessibiltyIdentifier =
webState:(web::WebState*)webState
completionHandler:
(void (^)(NSString* input))completionHandler {
- NSString* title =
- [DialogPresenter localizedTitleForJavaScriptAlertFromPage:requestURL];
+ NSString* title = [DialogPresenter
+ localizedTitleForJavaScriptAlertFromPage:requestURL
+ mainFrameURL:webState->GetLastCommittedURL()];
InputAlertCoordinator* alertCoordinator = [[InputAlertCoordinator alloc]
initWithBaseViewController:self.viewController
title:title
@@ -349,10 +358,15 @@ NSString* const kJavaScriptDialogTextFieldAccessibiltyIdentifier =
[self showNextDialog];
}
-+ (NSString*)localizedTitleForJavaScriptAlertFromPage:(const GURL&)pageURL {
++ (NSString*)localizedTitleForJavaScriptAlertFromPage:(const GURL&)pageURL
+ mainFrameURL:
+ (const GURL&)mainFrameURL {
NSString* localizedTitle = nil;
NSString* hostname = base::SysUTF8ToNSString(pageURL.host());
- if (!hostname.length) {
+
+ bool sameOriginAsMainFrame = pageURL.GetOrigin() == mainFrameURL.GetOrigin();
+
+ if (!sameOriginAsMainFrame) {
localizedTitle = l10n_util::GetNSString(
IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME);
} else {
« no previous file with comments | « ios/chrome/browser/ui/dialogs/dialog_presenter.h ('k') | ios/chrome/browser/ui/dialogs/dialog_presenter_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698