Commit d2723c08 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] create parameters for url loading service

To replace ChromeLoadParams,  WebLoadParams and OpenNewTabCommand as parameters passed in to LoadUrlInCurrentTab, SwitchToTab and OpenUrlInNewTab in url loading service.

Bug: 907527
Change-Id: I911985c7f62bd9d807c71e5349f194cefd1d57a0
Reviewed-on: https://chromium-review.googlesource.com/c/1488925
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636759}
parent 2260adad
......@@ -13,6 +13,8 @@ source_set("url_loading") {
"url_loading_notifier_factory.h",
"url_loading_observer_bridge.h",
"url_loading_observer_bridge.mm",
"url_loading_params.h",
"url_loading_params.mm",
"url_loading_service.h",
"url_loading_service.mm",
"url_loading_service_factory.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_URL_LOADING_URL_LOADING_PARAMS_H_
#define IOS_CHROME_BROWSER_URL_LOADING_URL_LOADING_PARAMS_H_
#import "ios/chrome/browser/ui/chrome_load_params.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/web/public/navigation_manager.h"
#include "ui/base/window_open_disposition.h"
// UrlLoadingService wrapper around web::NavigationManager::WebLoadParams,
// WindowOpenDisposition and parameters from OpenNewTabCommand.
// This is used when a URL is opened.
struct UrlLoadParams {
public:
// Initializes a UrlLoadParams intended to open in current page.
static UrlLoadParams* InCurrentTab(
const web::NavigationManager::WebLoadParams& web_params);
static UrlLoadParams* InCurrentTab(const GURL& url);
// Initializes a UrlLoadParams intended to open in a new page.
static UrlLoadParams* InNewTab(const GURL& url,
const web::Referrer& referrer,
bool in_incognito,
bool in_background,
OpenPosition append_to);
// Initializes a UrlLoadParams intended to open a new page.
static UrlLoadParams* InNewEmptyTab(bool in_incognito, bool in_background);
// Initializes a UrlLoadParams intended to open a URL from browser chrome
// (e.g., settings). This will always open in a new foreground tab in
// non-incognito mode.
static UrlLoadParams* InNewFromChromeTab(const GURL& url);
// Initializes a UrlLoadParams with |in_incognito| and an |origin_point|.
static UrlLoadParams* InNewForegroundTab(bool in_incognito,
CGPoint origin_point);
// Initializes a UrlLoadParams with |in_incognito| and an |origin_point| of
// CGPointZero.
static UrlLoadParams* InNewForegroundTab(bool in_incognito);
// Allow copying UrlLoadParams.
UrlLoadParams(const UrlLoadParams& other);
UrlLoadParams& operator=(const UrlLoadParams& other);
// The wrapped params.
web::NavigationManager::WebLoadParams web_params;
// The disposition of the URL being opened.
WindowOpenDisposition disposition;
// Parameters for when opening in new tab:
// Whether this requests opening in incognito or not.
bool in_incognito;
// Location where the new tab should be opened.
OpenPosition append_to;
// Origin point of the action triggering this command, in main window
// coordinates.
CGPoint origin_point;
// Whether or not this URL command comes from a chrome context (e.g.,
// settings), as opposed to a web page context.
bool from_chrome;
// Whether the new tab command was initiated by the user (e.g. by tapping the
// new tab button in the tools menu) or not (e.g. opening a new tab via a
// Javascript action). Defaults to |true|. Only used when the |web_params.url|
// isn't valid.
bool user_initiated;
// Whether the new tab command should also trigger the omnibox to be focused.
// Only used when the |web_params.url| isn't valid.
bool should_focus_omnibox;
private:
UrlLoadParams();
};
#endif // IOS_CHROME_BROWSER_URL_LOADING_URL_LOADING_PARAMS_H_
// Copyright 2018 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/url_loading/url_loading_params.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
UrlLoadParams* UrlLoadParams::InCurrentTab(
const web::NavigationManager::WebLoadParams& web_params) {
UrlLoadParams* params = new UrlLoadParams();
params->disposition = WindowOpenDisposition::CURRENT_TAB;
params->web_params = web_params;
return params;
}
UrlLoadParams* UrlLoadParams::InCurrentTab(const GURL& url) {
UrlLoadParams* params = new UrlLoadParams();
params->disposition = WindowOpenDisposition::CURRENT_TAB;
params->web_params = web::NavigationManager::WebLoadParams(url);
return params;
}
UrlLoadParams* UrlLoadParams::InNewTab(const GURL& url,
const web::Referrer& referrer,
bool in_incognito,
bool in_background,
OpenPosition append_to) {
UrlLoadParams* params = new UrlLoadParams();
params->disposition = in_background
? WindowOpenDisposition::NEW_BACKGROUND_TAB
: WindowOpenDisposition::NEW_FOREGROUND_TAB;
params->web_params = web::NavigationManager::WebLoadParams(url);
params->web_params.referrer = referrer;
params->in_incognito = in_incognito;
params->append_to = append_to;
params->user_initiated = true;
return params;
}
UrlLoadParams* UrlLoadParams::InNewEmptyTab(bool in_incognito,
bool in_background) {
UrlLoadParams* params = new UrlLoadParams();
params->disposition = in_background
? WindowOpenDisposition::NEW_BACKGROUND_TAB
: WindowOpenDisposition::NEW_FOREGROUND_TAB;
params->in_incognito = in_incognito;
params->user_initiated = true;
return params;
}
UrlLoadParams* UrlLoadParams::InNewFromChromeTab(const GURL& url) {
UrlLoadParams* params = new UrlLoadParams();
params->disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
params->web_params = web::NavigationManager::WebLoadParams(url);
params->append_to = kLastTab;
params->from_chrome = true;
return params;
}
UrlLoadParams* UrlLoadParams::InNewForegroundTab(bool in_incognito,
CGPoint origin_point) {
UrlLoadParams* params = new UrlLoadParams();
params->disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
params->origin_point = origin_point;
params->user_initiated = true;
return params;
}
UrlLoadParams* UrlLoadParams::InNewForegroundTab(bool in_incognito) {
UrlLoadParams* params = new UrlLoadParams();
params->disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
params->user_initiated = true;
return params;
}
UrlLoadParams::UrlLoadParams() : web_params(GURL()) {}
UrlLoadParams::UrlLoadParams(const UrlLoadParams& other)
: web_params(other.web_params), disposition(other.disposition) {}
UrlLoadParams& UrlLoadParams::operator=(const UrlLoadParams& other) {
web_params = other.web_params;
disposition = other.disposition;
return *this;
}
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