Commit beec774e authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Add request and response model objects for the web content area.

Adds OverlayUserData objects that contain data used to set up and
represent the user's interaction withJavaScript alerts,
confirmations, and prompts.

Bug: 941745
Change-Id: If9f021f05f2fe06ebfe0d4ea69db1261b76b8834
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636479
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664905}
parent 8fc52e62
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("web_content_area") {
sources = [
"java_script_alert_overlay.h",
"java_script_alert_overlay.mm",
"java_script_confirmation_overlay.h",
"java_script_confirmation_overlay.mm",
"java_script_dialog_source.cc",
"java_script_dialog_source.h",
"java_script_prompt_overlay.h",
"java_script_prompt_overlay.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
deps = [
"//base",
"//ios/chrome/browser/overlays",
"//url",
]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_ALERT_OVERLAY_H_
#define IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_ALERT_OVERLAY_H_
#include "ios/chrome/browser/overlays/public/overlay_user_data.h"
#include "ios/chrome/browser/overlays/public/web_content_area/java_script_dialog_source.h"
// Configuration object for OverlayRequests for JavaScript alert() calls.
class JavaScriptAlertOverlayRequestConfig
: public OverlayUserData<JavaScriptAlertOverlayRequestConfig> {
public:
~JavaScriptAlertOverlayRequestConfig() override;
// The source of the alert.
const JavaScriptDialogSource& source() const { return source_; }
// The message to be displayed in the alert.
const std::string& message() const { return message_; }
private:
OVERLAY_USER_DATA_SETUP(JavaScriptAlertOverlayRequestConfig);
JavaScriptAlertOverlayRequestConfig(const GURL& url,
bool is_main_frame,
const std::string& message);
const JavaScriptDialogSource source_;
const std::string message_;
};
#endif // IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_ALERT_OVERLAY_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/overlays/public/web_content_area/java_script_alert_overlay.h"
#include "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
OVERLAY_USER_DATA_SETUP_IMPL(JavaScriptAlertOverlayRequestConfig);
JavaScriptAlertOverlayRequestConfig::JavaScriptAlertOverlayRequestConfig(
const GURL& url,
bool is_main_frame,
const std::string& message)
: source_(url, is_main_frame), message_(message) {}
JavaScriptAlertOverlayRequestConfig::~JavaScriptAlertOverlayRequestConfig() =
default;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_CONFIRMATION_OVERLAY_H_
#define IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_CONFIRMATION_OVERLAY_H_
#include "ios/chrome/browser/overlays/public/overlay_user_data.h"
#include "ios/chrome/browser/overlays/public/web_content_area/java_script_dialog_source.h"
// Configuration object for OverlayRequests for JavaScript confirm() calls.
class JavaScriptConfirmationOverlayRequestConfig
: public OverlayUserData<JavaScriptConfirmationOverlayRequestConfig> {
public:
~JavaScriptConfirmationOverlayRequestConfig() override;
// The source of the confirmation dialog.
const JavaScriptDialogSource& source() const { return source_; }
// The message to be displayed in the confirmation dialog.
const std::string& message() const { return message_; }
private:
OVERLAY_USER_DATA_SETUP(JavaScriptConfirmationOverlayRequestConfig);
JavaScriptConfirmationOverlayRequestConfig(const GURL& url,
bool is_main_frame,
const std::string& message);
const JavaScriptDialogSource source_;
const std::string message_;
};
// User interaction info for OverlayResponses for JavaScript confirm() calls.
class JavaScriptConfirmationOverlayResponseInfo
: public OverlayUserData<JavaScriptConfirmationOverlayResponseInfo> {
public:
~JavaScriptConfirmationOverlayResponseInfo() override;
// Whether the user tapped the OK button on the dialog.
bool dialog_confirmed() const { return dialog_confirmed_; }
private:
OVERLAY_USER_DATA_SETUP(JavaScriptConfirmationOverlayResponseInfo);
JavaScriptConfirmationOverlayResponseInfo(bool dialog_confirmed);
const bool dialog_confirmed_ = false;
};
#endif // IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_CONFIRMATION_OVERLAY_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/overlays/public/web_content_area/java_script_confirmation_overlay.h"
#include "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
OVERLAY_USER_DATA_SETUP_IMPL(JavaScriptConfirmationOverlayRequestConfig);
JavaScriptConfirmationOverlayRequestConfig::
JavaScriptConfirmationOverlayRequestConfig(const GURL& url,
bool is_main_frame,
const std::string& message)
: source_(url, is_main_frame), message_(message) {}
JavaScriptConfirmationOverlayRequestConfig::
~JavaScriptConfirmationOverlayRequestConfig() = default;
OVERLAY_USER_DATA_SETUP_IMPL(JavaScriptConfirmationOverlayResponseInfo);
JavaScriptConfirmationOverlayResponseInfo::
JavaScriptConfirmationOverlayResponseInfo(bool dialog_confirmed)
: dialog_confirmed_(dialog_confirmed) {}
JavaScriptConfirmationOverlayResponseInfo::
~JavaScriptConfirmationOverlayResponseInfo() = default;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/overlays/public/web_content_area/java_script_dialog_source.h"
#include "base/logging.h"
JavaScriptDialogSource::JavaScriptDialogSource(const GURL& url,
bool is_main_frame)
: url_(url), is_main_frame_(is_main_frame) {
DCHECK(url_.is_valid());
}
JavaScriptDialogSource::~JavaScriptDialogSource() = default;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOG_SOURCE_H_
#define IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOG_SOURCE_H_
#include "url/gurl.h"
// Object used to capture the source of a JavaScript dialog.
class JavaScriptDialogSource {
public:
JavaScriptDialogSource(const GURL& url, bool is_main_frame);
~JavaScriptDialogSource();
// The URL of the page requesting the JavaScript dialog.
const GURL& url() const { return url_; }
// Whether or not the requesting page is in the main frame.
bool is_main_frame() const { return is_main_frame_; }
private:
GURL url_;
bool is_main_frame_ = false;
};
#endif // IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOG_SOURCE_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_PROMPT_OVERLAY_H_
#define IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_PROMPT_OVERLAY_H_
#include "ios/chrome/browser/overlays/public/overlay_user_data.h"
#include "ios/chrome/browser/overlays/public/web_content_area/java_script_dialog_source.h"
// Configuration object for OverlayRequests for JavaScript prompt() calls.
class JavaScriptPromptOverlayRequestConfig
: public OverlayUserData<JavaScriptPromptOverlayRequestConfig> {
public:
~JavaScriptPromptOverlayRequestConfig() override;
// The source of the prompt.
const JavaScriptDialogSource& source() const { return source_; }
// The message to be displayed in the prompt dialog.
const std::string& message() const { return message_; }
// The default text to use in the prompt's text field.
const std::string& default_prompt_value() const {
return default_prompt_value_;
}
private:
OVERLAY_USER_DATA_SETUP(JavaScriptPromptOverlayRequestConfig);
JavaScriptPromptOverlayRequestConfig(const GURL& url,
bool is_main_frame,
const std::string& message,
const std::string& default_prompt_value);
const JavaScriptDialogSource source_;
const std::string message_;
const std::string default_prompt_value_;
};
// User interaction info for OverlayResponses for JavaScript prompt() calls.
class JavaScriptPromptOverlayResponseInfo
: public OverlayUserData<JavaScriptPromptOverlayResponseInfo> {
public:
~JavaScriptPromptOverlayResponseInfo() override;
// The text entered into the prompt's field.
const std::string& text_input() const { return text_input_; }
private:
OVERLAY_USER_DATA_SETUP(JavaScriptPromptOverlayResponseInfo);
JavaScriptPromptOverlayResponseInfo(const std::string& text_input);
const std::string text_input_;
};
#endif // IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_JAVA_SCRIPT_PROMPT_OVERLAY_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/overlays/public/web_content_area/java_script_prompt_overlay.h"
#include "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
OVERLAY_USER_DATA_SETUP_IMPL(JavaScriptPromptOverlayRequestConfig);
JavaScriptPromptOverlayRequestConfig::JavaScriptPromptOverlayRequestConfig(
const GURL& url,
bool is_main_frame,
const std::string& message,
const std::string& default_prompt_value)
: source_(url, is_main_frame),
message_(message),
default_prompt_value_(default_prompt_value) {}
JavaScriptPromptOverlayRequestConfig::~JavaScriptPromptOverlayRequestConfig() =
default;
OVERLAY_USER_DATA_SETUP_IMPL(JavaScriptPromptOverlayResponseInfo);
JavaScriptPromptOverlayResponseInfo::JavaScriptPromptOverlayResponseInfo(
const std::string& text_input)
: text_input_(text_input) {}
JavaScriptPromptOverlayResponseInfo::~JavaScriptPromptOverlayResponseInfo() =
default;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment