Commit bf330ad1 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Cleanup] Use in-class member initialization for NavigateParams

NavigateParams has a number of different constructors and many different
variables. Having each constructor define the value for the member in
the initializer list makes it hard to see what's changing between the
constructors.

Instead, use in-class member initialization for the default values to
make a) defaults clear and b) deviation from these defaults clear.

Bonus: -80 LOC.

Bug: None
Change-Id: I26ecc6e1b27989017dba154e1e012cdab541a58a
Reviewed-on: https://chromium-review.googlesource.com/775079Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517680}
parent 583cd55a
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/ui/browser_navigator_params.h" #include "chrome/browser/ui/browser_navigator_params.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/page_navigator.h" #include "content/public/browser/page_navigator.h"
...@@ -21,102 +20,26 @@ namespace chrome { ...@@ -21,102 +20,26 @@ namespace chrome {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
NavigateParams::NavigateParams(WebContents* a_target_contents) NavigateParams::NavigateParams(WebContents* a_target_contents)
: frame_tree_node_id(-1), : target_contents(a_target_contents) {}
uses_post(false),
target_contents(a_target_contents),
source_contents(nullptr),
disposition(WindowOpenDisposition::CURRENT_TAB),
opener(nullptr),
trusted_source(false),
transition(ui::PAGE_TRANSITION_LINK),
is_renderer_initiated(false),
tabstrip_index(-1),
tabstrip_add_types(TabStripModel::ADD_ACTIVE),
window_action(NO_ACTION),
user_gesture(true),
path_behavior(RESPECT),
ref_behavior(IGNORE_REF),
initiating_profile(nullptr),
should_replace_current_entry(false),
created_with_opener(false),
started_from_context_menu(false) {}
#else #else
NavigateParams::NavigateParams(Browser* a_browser, NavigateParams::NavigateParams(Browser* a_browser,
const GURL& a_url, const GURL& a_url,
ui::PageTransition a_transition) ui::PageTransition a_transition)
: url(a_url), : url(a_url), transition(a_transition), browser(a_browser) {}
frame_tree_node_id(-1),
uses_post(false),
target_contents(NULL),
source_contents(NULL),
disposition(WindowOpenDisposition::CURRENT_TAB),
opener(nullptr),
trusted_source(false),
transition(a_transition),
is_renderer_initiated(false),
tabstrip_index(-1),
tabstrip_add_types(TabStripModel::ADD_ACTIVE),
window_action(NO_ACTION),
user_gesture(true),
path_behavior(RESPECT),
ref_behavior(IGNORE_REF),
browser(a_browser),
initiating_profile(NULL),
should_replace_current_entry(false),
created_with_opener(false),
started_from_context_menu(false) {}
NavigateParams::NavigateParams(Browser* a_browser, NavigateParams::NavigateParams(Browser* a_browser,
WebContents* a_target_contents) WebContents* a_target_contents)
: frame_tree_node_id(-1), : target_contents(a_target_contents), browser(a_browser) {}
uses_post(false),
target_contents(a_target_contents),
source_contents(NULL),
disposition(WindowOpenDisposition::CURRENT_TAB),
opener(nullptr),
trusted_source(false),
transition(ui::PAGE_TRANSITION_LINK),
is_renderer_initiated(false),
tabstrip_index(-1),
tabstrip_add_types(TabStripModel::ADD_ACTIVE),
window_action(NO_ACTION),
user_gesture(true),
path_behavior(RESPECT),
ref_behavior(IGNORE_REF),
browser(a_browser),
initiating_profile(NULL),
should_replace_current_entry(false),
created_with_opener(false),
started_from_context_menu(false) {}
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
NavigateParams::NavigateParams(Profile* a_profile, NavigateParams::NavigateParams(Profile* a_profile,
const GURL& a_url, const GURL& a_url,
ui::PageTransition a_transition) ui::PageTransition a_transition)
: url(a_url), : url(a_url),
frame_tree_node_id(-1),
uses_post(false),
target_contents(NULL),
source_contents(NULL),
disposition(WindowOpenDisposition::NEW_FOREGROUND_TAB), disposition(WindowOpenDisposition::NEW_FOREGROUND_TAB),
opener(nullptr),
trusted_source(false),
transition(a_transition), transition(a_transition),
is_renderer_initiated(false),
tabstrip_index(-1),
tabstrip_add_types(TabStripModel::ADD_ACTIVE),
window_action(SHOW_WINDOW), window_action(SHOW_WINDOW),
user_gesture(true), initiating_profile(a_profile) {}
path_behavior(RESPECT),
ref_behavior(IGNORE_REF),
#if !defined(OS_ANDROID)
browser(NULL),
#endif
initiating_profile(a_profile),
should_replace_current_entry(false),
created_with_opener(false),
started_from_context_menu(false) {
}
NavigateParams::NavigateParams(const NavigateParams& other) = default; NavigateParams::NavigateParams(const NavigateParams& other) = default;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "content/public/browser/global_request_id.h" #include "content/public/browser/global_request_id.h"
#include "content/public/browser/site_instance.h" #include "content/public/browser/site_instance.h"
#include "content/public/common/referrer.h" #include "content/public/common/referrer.h"
...@@ -77,14 +78,14 @@ struct NavigateParams { ...@@ -77,14 +78,14 @@ struct NavigateParams {
std::string frame_name; std::string frame_name;
// The browser-global ID of the frame to navigate, or -1 for the main frame. // The browser-global ID of the frame to navigate, or -1 for the main frame.
int frame_tree_node_id; int frame_tree_node_id = -1;
// Any redirect URLs that occurred for this navigation before |url|. // Any redirect URLs that occurred for this navigation before |url|.
// Usually empty. // Usually empty.
std::vector<GURL> redirect_chain; std::vector<GURL> redirect_chain;
// Indicates whether this navigation will be sent using POST. // Indicates whether this navigation will be sent using POST.
bool uses_post; bool uses_post = false;
// The post data when the navigation uses POST. // The post data when the navigation uses POST.
scoped_refptr<content::ResourceRequestBody> post_data; scoped_refptr<content::ResourceRequestBody> post_data;
...@@ -106,7 +107,7 @@ struct NavigateParams { ...@@ -106,7 +107,7 @@ struct NavigateParams {
// a new WebContents, this field will remain NULL and the // a new WebContents, this field will remain NULL and the
// WebContents deleted if the WebContents it created is // WebContents deleted if the WebContents it created is
// not added to a TabStripModel before Navigate() returns. // not added to a TabStripModel before Navigate() returns.
content::WebContents* target_contents; content::WebContents* target_contents = nullptr;
// [in] The WebContents that initiated the Navigate() request if such // [in] The WebContents that initiated the Navigate() request if such
// context is necessary. Default is NULL, i.e. no context. // context is necessary. Default is NULL, i.e. no context.
...@@ -115,7 +116,7 @@ struct NavigateParams { ...@@ -115,7 +116,7 @@ struct NavigateParams {
// Navigate(). However, if the originating page is from a different // Navigate(). However, if the originating page is from a different
// profile (e.g. an OFF_THE_RECORD page originating from a non-OTR // profile (e.g. an OFF_THE_RECORD page originating from a non-OTR
// window), then |source_contents| is reset to NULL. // window), then |source_contents| is reset to NULL.
content::WebContents* source_contents; content::WebContents* source_contents = nullptr;
// The disposition requested by the navigation source. Default is // The disposition requested by the navigation source. Default is
// CURRENT_TAB. What follows is a set of coercions that happen to this value // CURRENT_TAB. What follows is a set of coercions that happen to this value
...@@ -132,34 +133,30 @@ struct NavigateParams { ...@@ -132,34 +133,30 @@ struct NavigateParams {
// If disposition is one of NEW_WINDOW, NEW_POPUP, NEW_FOREGROUND_TAB or // If disposition is one of NEW_WINDOW, NEW_POPUP, NEW_FOREGROUND_TAB or
// SINGLETON_TAB, then TabStripModel::ADD_ACTIVE is automatically added to // SINGLETON_TAB, then TabStripModel::ADD_ACTIVE is automatically added to
// |tabstrip_add_types|. // |tabstrip_add_types|.
WindowOpenDisposition disposition; WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB;
// Allows setting the opener for the case when new WebContents are created // Allows setting the opener for the case when new WebContents are created
// (i.e. when |disposition| asks for a new tab or window). // (i.e. when |disposition| asks for a new tab or window).
content::RenderFrameHost* opener; content::RenderFrameHost* opener = nullptr;
// Sets browser->is_trusted_source. Default is false. // Sets browser->is_trusted_source.
bool trusted_source; bool trusted_source = false;
// The transition type of the navigation. Default is // The transition type of the navigation.
// ui::PAGE_TRANSITION_LINK when target_contents is specified in the ui::PageTransition transition = ui::PAGE_TRANSITION_LINK;
// constructor.
ui::PageTransition transition;
// Whether this navigation was initiated by the renderer process. Default is // Whether this navigation was initiated by the renderer process.
// false. bool is_renderer_initiated = false;
bool is_renderer_initiated;
// The index the caller would like the tab to be positioned at in the // The index the caller would like the tab to be positioned at in the
// TabStrip. The actual index will be determined by the TabHandler in // TabStrip. The actual index will be determined by the TabHandler in
// accordance with |add_types|. Defaults to -1 (allows the TabHandler to // accordance with |add_types|. The default allows the TabHandler to decide.
// decide). int tabstrip_index = -1;
int tabstrip_index;
// A bitmask of values defined in TabStripModel::AddTabTypes. Helps // A bitmask of values defined in TabStripModel::AddTabTypes. Helps
// determine where to insert a new tab and whether or not it should be // determine where to insert a new tab and whether or not it should be
// selected, among other properties. Default is ADD_ACTIVE. // selected, among other properties.
int tabstrip_add_types; int tabstrip_add_types = TabStripModel::ADD_ACTIVE;
// If non-empty, the new tab is an app tab. // If non-empty, the new tab is an app tab.
std::string extension_app_id; std::string extension_app_id;
...@@ -184,11 +181,10 @@ struct NavigateParams { ...@@ -184,11 +181,10 @@ struct NavigateParams {
// Default is NO_ACTION (don't show or activate the window). // Default is NO_ACTION (don't show or activate the window).
// If disposition is NEW_WINDOW or NEW_POPUP, and |window_action| is set to // If disposition is NEW_WINDOW or NEW_POPUP, and |window_action| is set to
// NO_ACTION, |window_action| will be set to SHOW_WINDOW. // NO_ACTION, |window_action| will be set to SHOW_WINDOW.
WindowAction window_action; WindowAction window_action = NO_ACTION;
// If false then the navigation was not initiated by a user gesture. // If false then the navigation was not initiated by a user gesture.
// Default is true. bool user_gesture = true;
bool user_gesture;
// What to do with the path component of the URL for singleton navigations. // What to do with the path component of the URL for singleton navigations.
enum PathBehavior { enum PathBehavior {
...@@ -199,8 +195,7 @@ struct NavigateParams { ...@@ -199,8 +195,7 @@ struct NavigateParams {
// Ignore path when finding existing tab, don't navigate tab. // Ignore path when finding existing tab, don't navigate tab.
IGNORE_AND_STAY_PUT, IGNORE_AND_STAY_PUT,
}; };
// Default is RESPECT. PathBehavior path_behavior = RESPECT;
PathBehavior path_behavior;
// What to do with the ref component of the URL for singleton navigations. // What to do with the ref component of the URL for singleton navigations.
enum RefBehavior { enum RefBehavior {
...@@ -209,8 +204,7 @@ struct NavigateParams { ...@@ -209,8 +204,7 @@ struct NavigateParams {
// Two URLs with differing refs are different. // Two URLs with differing refs are different.
RESPECT_REF, RESPECT_REF,
}; };
// Default is IGNORE. RefBehavior ref_behavior = IGNORE_REF;
RefBehavior ref_behavior;
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
// [in] Specifies a Browser object where the navigation could occur or the // [in] Specifies a Browser object where the navigation could occur or the
...@@ -225,22 +219,22 @@ struct NavigateParams { ...@@ -225,22 +219,22 @@ struct NavigateParams {
// Navigate(), the caller is responsible for showing it so that its // Navigate(), the caller is responsible for showing it so that its
// window can assume responsibility for the Browser's lifetime (Browser // window can assume responsibility for the Browser's lifetime (Browser
// objects are deleted when the user closes a visible browser window). // objects are deleted when the user closes a visible browser window).
Browser* browser; Browser* browser = nullptr;
#endif #endif
// The profile that is initiating the navigation. If there is a non-NULL // The profile that is initiating the navigation. If there is a non-NULL
// browser passed in via |browser|, it's profile will be used instead. // browser passed in via |browser|, it's profile will be used instead.
Profile* initiating_profile; Profile* initiating_profile = nullptr;
// Indicates whether this navigation should replace the current // Indicates whether this navigation should replace the current
// navigation entry. // navigation entry.
bool should_replace_current_entry; bool should_replace_current_entry = false;
// Indicates whether |target_contents| is being created with a window.opener. // Indicates whether |target_contents| is being created with a window.opener.
bool created_with_opener; bool created_with_opener = false;
// Whether or not the related navigation was started in the context menu. // Whether or not the related navigation was started in the context menu.
bool started_from_context_menu; bool started_from_context_menu = false;
// SiteInstance of the frame that initiated the navigation or null if we // SiteInstance of the frame that initiated the navigation or null if we
// don't know it. This should be assigned from the OpenURLParams of the // don't know it. This should be assigned from the OpenURLParams of the
......
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