[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 5 | #include "content/shell/browser/shell.h" |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 6 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
Lukasz Anforowicz | 52b9372 | 2018-06-20 16:11:39 | [diff] [blame] | 9 | #include <map> |
| 10 | #include <string> |
| 11 | #include <utility> |
| 12 | |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 13 | #include "base/command_line.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 14 | #include "base/location.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 15 | #include "base/macros.h" |
Wez | 9a58a15 | 2018-06-07 18:59:33 | [diff] [blame] | 16 | #include "base/no_destructor.h" |
fdoray | 896bea1 | 2016-06-10 15:52:01 | [diff] [blame] | 17 | #include "base/run_loop.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 18 | #include "base/single_thread_task_runner.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 19 | #include "base/strings/string_number_conversions.h" |
| 20 | #include "base/strings/string_util.h" |
| 21 | #include "base/strings/stringprintf.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 22 | #include "base/strings/utf_string_conversions.h" |
gab | 30f26df | 2016-05-11 19:37:55 | [diff] [blame] | 23 | #include "base/threading/thread_task_runner_handle.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 24 | #include "build/build_config.h" |
[email protected] | b50452f | 2014-08-18 12:31:44 | [diff] [blame] | 25 | #include "content/public/browser/devtools_agent_host.h" |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 26 | #include "content/public/browser/navigation_controller.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 27 | #include "content/public/browser/navigation_entry.h" |
Yutaka Hirano | 2109e58 | 2018-02-14 07:24:46 | [diff] [blame] | 28 | #include "content/public/browser/render_process_host.h" |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 29 | #include "content/public/browser/render_view_host.h" |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 30 | #include "content/public/browser/render_widget_host.h" |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 31 | #include "content/public/browser/web_contents.h" |
guoweis | 8efb6d89 | 2015-10-12 18:26:17 | [diff] [blame] | 32 | #include "content/public/common/content_switches.h" |
guoweis | c537ba2 | 2015-11-06 21:20:31 | [diff] [blame] | 33 | #include "content/public/common/webrtc_ip_handling_policy.h" |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 34 | #include "content/shell/browser/shell_browser_main_parts.h" |
| 35 | #include "content/shell/browser/shell_content_browser_client.h" |
| 36 | #include "content/shell/browser/shell_devtools_frontend.h" |
| 37 | #include "content/shell/browser/shell_javascript_dialog_manager.h" |
Kent Tamura | f92649d88 | 2018-12-03 09:07:47 | [diff] [blame] | 38 | #include "content/shell/browser/web_test/blink_test_controller.h" |
| 39 | #include "content/shell/browser/web_test/secondary_test_window_observer.h" |
| 40 | #include "content/shell/browser/web_test/web_test_bluetooth_chooser_factory.h" |
| 41 | #include "content/shell/browser/web_test/web_test_devtools_bindings.h" |
| 42 | #include "content/shell/browser/web_test/web_test_javascript_dialog_manager.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 43 | #include "content/shell/common/shell_switches.h" |
Kent Tamura | de50311 | 2018-12-04 08:57:40 | [diff] [blame] | 44 | #include "content/shell/common/web_test/web_test_switches.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 45 | #include "media/media_buildflags.h" |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 46 | #include "third_party/blink/public/mojom/renderer_preferences.mojom.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 47 | #include "third_party/blink/public/web/web_presentation_receiver_flags.h" |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 48 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 49 | namespace content { |
| 50 | |
Wez | cbf4a04 | 2018-06-13 16:29:12 | [diff] [blame] | 51 | // Null until/unless the default main message loop is running. |
| 52 | base::NoDestructor<base::OnceClosure> g_quit_main_message_loop; |
Wez | 9a58a15 | 2018-06-07 18:59:33 | [diff] [blame] | 53 | |
pdr | cab84ee | 2015-03-13 21:47:04 | [diff] [blame] | 54 | const int kDefaultTestWindowWidthDip = 800; |
| 55 | const int kDefaultTestWindowHeightDip = 600; |
[email protected] | 1e57cab | 2013-05-28 04:26:11 | [diff] [blame] | 56 | |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 57 | std::vector<Shell*> Shell::windows_; |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame^] | 58 | base::OnceCallback<void(Shell*)> Shell::shell_created_callback_; |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 59 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 60 | class Shell::DevToolsWebContentsObserver : public WebContentsObserver { |
| 61 | public: |
| 62 | DevToolsWebContentsObserver(Shell* shell, WebContents* web_contents) |
| 63 | : WebContentsObserver(web_contents), |
| 64 | shell_(shell) { |
| 65 | } |
| 66 | |
| 67 | // WebContentsObserver |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 68 | void WebContentsDestroyed() override { |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 69 | shell_->OnDevToolsWebContentsDestroyed(); |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | Shell* shell_; |
| 74 | |
| 75 | DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver); |
| 76 | }; |
| 77 | |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 78 | Shell::Shell(std::unique_ptr<WebContents> web_contents, |
| 79 | bool should_set_delegate) |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 80 | : WebContentsObserver(web_contents.get()), |
| 81 | web_contents_(std::move(web_contents)), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 82 | devtools_frontend_(nullptr), |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 83 | is_fullscreen_(false), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 84 | window_(nullptr), |
sadrul | 8b11d26 | 2015-11-12 18:41:33 | [diff] [blame] | 85 | #if defined(OS_MACOSX) |
[email protected] | 86b36e67 | 2012-12-21 00:09:51 | [diff] [blame] | 86 | url_edit_view_(NULL), |
sadrul | 8b11d26 | 2015-11-12 18:41:33 | [diff] [blame] | 87 | #endif |
Pavel Feldman | c7cd063c | 2017-10-06 20:04:28 | [diff] [blame] | 88 | headless_(false), |
| 89 | hide_toolbar_(false) { |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 90 | if (should_set_delegate) |
| 91 | web_contents_->SetDelegate(this); |
arthursonzogni | fdd4991 | 2017-08-31 08:55:26 | [diff] [blame] | 92 | |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 93 | if (switches::IsRunWebTestsSwitchPresent()) { |
jonross | 2618570 | 2019-04-08 18:54:10 | [diff] [blame] | 94 | headless_ = !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 95 | switches::kDisableHeadlessMode); |
| 96 | // Disable occlusion tracking. In a headless shell WebContents would always |
| 97 | // behave as if they were occluded, i.e. would not render frames and would |
| 98 | // not receive input events. For non-headless mode we do not want tests |
| 99 | // running in parallel to trigger occlusion tracking. |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 100 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 101 | switches::kDisableBackgroundingOccludedWindowsForTesting); |
| 102 | } |
Pavel Feldman | c7cd063c | 2017-10-06 20:04:28 | [diff] [blame] | 103 | |
| 104 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 105 | switches::kContentShellHideToolbar)) |
| 106 | hide_toolbar_ = true; |
| 107 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 108 | windows_.push_back(this); |
| 109 | |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame^] | 110 | if (shell_created_callback_) |
| 111 | std::move(shell_created_callback_).Run(this); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | Shell::~Shell() { |
| 115 | PlatformCleanUp(); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 116 | |
| 117 | for (size_t i = 0; i < windows_.size(); ++i) { |
| 118 | if (windows_[i] == this) { |
| 119 | windows_.erase(windows_.begin() + i); |
| 120 | break; |
| 121 | } |
| 122 | } |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 123 | |
Sergey Ulanov | f0875d1 | 2019-01-03 20:33:23 | [diff] [blame] | 124 | // Always destroy WebContents before calling PlatformExit(). WebContents |
| 125 | // destruction sequence may depend on the resources destroyed in |
| 126 | // PlatformExit() (e.g. the display::Screen singleton). |
| 127 | web_contents_->SetDelegate(nullptr); |
| 128 | web_contents_.reset(); |
| 129 | |
Wez | 9a58a15 | 2018-06-07 18:59:33 | [diff] [blame] | 130 | if (windows_.empty()) { |
[email protected] | b53adf45 | 2014-02-07 12:55:08 | [diff] [blame] | 131 | if (headless_) |
| 132 | PlatformExit(); |
Yutaka Hirano | 2109e58 | 2018-02-14 07:24:46 | [diff] [blame] | 133 | for (auto it = RenderProcessHost::AllHostsIterator(); !it.IsAtEnd(); |
| 134 | it.Advance()) { |
| 135 | it.GetCurrentValue()->DisableKeepAliveRefCount(); |
| 136 | } |
Wez | cbf4a04 | 2018-06-13 16:29:12 | [diff] [blame] | 137 | if (*g_quit_main_message_loop) |
| 138 | std::move(*g_quit_main_message_loop).Run(); |
[email protected] | b53adf45 | 2014-02-07 12:55:08 | [diff] [blame] | 139 | } |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 140 | } |
| 141 | |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 142 | Shell* Shell::CreateShell(std::unique_ptr<WebContents> web_contents, |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 143 | const gfx::Size& initial_size, |
| 144 | bool should_set_delegate) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 145 | WebContents* raw_web_contents = web_contents.get(); |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 146 | Shell* shell = new Shell(std::move(web_contents), should_set_delegate); |
[email protected] | c0d036d | 2013-05-07 12:50:50 | [diff] [blame] | 147 | shell->PlatformCreateWindow(initial_size.width(), initial_size.height()); |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 148 | |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 149 | shell->PlatformSetContents(); |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 150 | |
| 151 | shell->PlatformResizeSubViews(); |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 152 | |
creis | b6561df | 2016-02-11 20:20:54 | [diff] [blame] | 153 | // Note: Do not make RenderFrameHost or RenderViewHost specific state changes |
| 154 | // here, because they will be forgotten after a cross-process navigation. Use |
| 155 | // RenderFrameCreated or RenderViewCreated instead. |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 156 | if (switches::IsRunWebTestsSwitchPresent()) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 157 | raw_web_contents->GetMutableRendererPrefs()->use_custom_colors = false; |
| 158 | raw_web_contents->GetRenderViewHost()->SyncRendererPrefs(); |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 159 | } |
| 160 | |
lukasza | 381b049 | 2016-03-10 16:48:43 | [diff] [blame] | 161 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
guoweis | 4ee4859 | 2015-12-02 06:37:07 | [diff] [blame] | 162 | if (command_line->HasSwitch(switches::kForceWebRtcIPHandlingPolicy)) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 163 | raw_web_contents->GetMutableRendererPrefs()->webrtc_ip_handling_policy = |
guoweis | 4ee4859 | 2015-12-02 06:37:07 | [diff] [blame] | 164 | command_line->GetSwitchValueASCII( |
| 165 | switches::kForceWebRtcIPHandlingPolicy); |
guoweis | 8efb6d89 | 2015-10-12 18:26:17 | [diff] [blame] | 166 | } |
guoweis | 8efb6d89 | 2015-10-12 18:26:17 | [diff] [blame] | 167 | |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 168 | return shell; |
| 169 | } |
| 170 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 171 | void Shell::CloseAllWindows() { |
[email protected] | b50452f | 2014-08-18 12:31:44 | [diff] [blame] | 172 | DevToolsAgentHost::DetachAllClients(); |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 173 | std::vector<Shell*> open_windows(windows_); |
Wez | cbf4a04 | 2018-06-13 16:29:12 | [diff] [blame] | 174 | for (size_t i = 0; i < open_windows.size(); ++i) |
| 175 | open_windows[i]->Close(); |
| 176 | |
| 177 | // Pump the message loop to allow window teardown tasks to run. |
| 178 | base::RunLoop().RunUntilIdle(); |
| 179 | |
Wez | 7d3eb01 | 2018-06-20 22:51:28 | [diff] [blame] | 180 | // If there were no windows open then the message loop quit closure will |
| 181 | // not have been run. |
| 182 | if (*g_quit_main_message_loop) |
| 183 | std::move(*g_quit_main_message_loop).Run(); |
| 184 | |
dmazzoni | 948fbc7 | 2015-05-17 07:57:33 | [diff] [blame] | 185 | PlatformExit(); |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 186 | } |
| 187 | |
Wez | cbf4a04 | 2018-06-13 16:29:12 | [diff] [blame] | 188 | void Shell::SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) { |
| 189 | *g_quit_main_message_loop = std::move(quit_closure); |
| 190 | } |
| 191 | |
Wez | 7d3eb01 | 2018-06-20 22:51:28 | [diff] [blame] | 192 | void Shell::QuitMainMessageLoopForTesting() { |
John Budorick | 7732d4d0 | 2018-07-30 19:02:54 | [diff] [blame] | 193 | DCHECK(*g_quit_main_message_loop); |
Wez | 7d3eb01 | 2018-06-20 22:51:28 | [diff] [blame] | 194 | std::move(*g_quit_main_message_loop).Run(); |
| 195 | } |
| 196 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 197 | void Shell::SetShellCreatedCallback( |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame^] | 198 | base::OnceCallback<void(Shell*)> shell_created_callback) { |
| 199 | DCHECK(!shell_created_callback_); |
Tommy Nyquist | 4b749d0 | 2018-03-20 21:46:29 | [diff] [blame] | 200 | shell_created_callback_ = std::move(shell_created_callback); |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 201 | } |
| 202 | |
David Benjamin | f62c666 | 2019-03-21 20:25:04 | [diff] [blame] | 203 | Shell* Shell::FromWebContents(WebContents* web_contents) { |
| 204 | for (Shell* window : windows_) { |
| 205 | if (window->web_contents() && window->web_contents() == web_contents) { |
| 206 | return window; |
[email protected] | 74830f0 | 2012-01-30 22:27:04 | [diff] [blame] | 207 | } |
| 208 | } |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 209 | return nullptr; |
[email protected] | 74830f0 | 2012-01-30 22:27:04 | [diff] [blame] | 210 | } |
| 211 | |
[email protected] | 6153b27 | 2013-01-25 22:29:23 | [diff] [blame] | 212 | void Shell::Initialize() { |
pdr | cab84ee | 2015-03-13 21:47:04 | [diff] [blame] | 213 | PlatformInitialize(GetShellDefaultSize()); |
[email protected] | 6153b27 | 2013-01-25 22:29:23 | [diff] [blame] | 214 | } |
| 215 | |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 216 | gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) { |
| 217 | if (!initial_size.IsEmpty()) |
| 218 | return initial_size; |
pdr | cab84ee | 2015-03-13 21:47:04 | [diff] [blame] | 219 | return GetShellDefaultSize(); |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 220 | } |
| 221 | |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame] | 222 | Shell* Shell::CreateNewWindow(BrowserContext* browser_context, |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 223 | const GURL& url, |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 224 | const scoped_refptr<SiteInstance>& site_instance, |
[email protected] | cdb80672 | 2013-01-10 14:18:23 | [diff] [blame] | 225 | const gfx::Size& initial_size) { |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 226 | WebContents::CreateParams create_params(browser_context, site_instance); |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 227 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 228 | switches::kForcePresentationReceiverForTesting)) { |
| 229 | create_params.starting_sandbox_flags = |
| 230 | blink::kPresentationReceiverSandboxFlags; |
| 231 | } |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 232 | create_params.initial_size = AdjustWindowSize(initial_size); |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 233 | std::unique_ptr<WebContents> web_contents = |
Erik Chen | bb8e738e | 2018-04-28 14:10:43 | [diff] [blame] | 234 | WebContents::Create(create_params); |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 235 | Shell* shell = |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 236 | CreateShell(std::move(web_contents), create_params.initial_size, |
| 237 | true /* should_set_delegate */); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 238 | if (!url.is_empty()) |
| 239 | shell->LoadURL(url); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 240 | return shell; |
| 241 | } |
| 242 | |
Daniel Murphy | 16ed078 | 2018-05-26 00:15:13 | [diff] [blame] | 243 | Shell* Shell::CreateNewWindowWithSessionStorageNamespace( |
| 244 | BrowserContext* browser_context, |
| 245 | const GURL& url, |
| 246 | const scoped_refptr<SiteInstance>& site_instance, |
| 247 | const gfx::Size& initial_size, |
| 248 | scoped_refptr<SessionStorageNamespace> session_storage_namespace) { |
| 249 | WebContents::CreateParams create_params(browser_context, site_instance); |
| 250 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 251 | switches::kForcePresentationReceiverForTesting)) { |
| 252 | create_params.starting_sandbox_flags = |
| 253 | blink::kPresentationReceiverSandboxFlags; |
| 254 | } |
| 255 | create_params.initial_size = AdjustWindowSize(initial_size); |
| 256 | std::map<std::string, scoped_refptr<SessionStorageNamespace>> |
| 257 | session_storages; |
| 258 | session_storages[""] = session_storage_namespace; |
| 259 | std::unique_ptr<WebContents> web_contents = |
| 260 | WebContents::CreateWithSessionStorage(create_params, session_storages); |
| 261 | Shell* shell = |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 262 | CreateShell(std::move(web_contents), create_params.initial_size, |
| 263 | true /* should_set_delegate */); |
Daniel Murphy | 16ed078 | 2018-05-26 00:15:13 | [diff] [blame] | 264 | if (!url.is_empty()) |
| 265 | shell->LoadURL(url); |
| 266 | return shell; |
| 267 | } |
| 268 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 269 | void Shell::LoadURL(const GURL& url) { |
Alex Moshchuk | 7e26eca | 2018-03-03 01:34:29 | [diff] [blame] | 270 | LoadURLForFrame( |
| 271 | url, std::string(), |
| 272 | ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 273 | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)); |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 274 | } |
| 275 | |
Alex Moshchuk | 7e26eca | 2018-03-03 01:34:29 | [diff] [blame] | 276 | void Shell::LoadURLForFrame(const GURL& url, |
| 277 | const std::string& frame_name, |
| 278 | ui::PageTransition transition_type) { |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 279 | NavigationController::LoadURLParams params(url); |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 280 | params.frame_name = frame_name; |
Alex Moshchuk | 7e26eca | 2018-03-03 01:34:29 | [diff] [blame] | 281 | params.transition_type = transition_type; |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 282 | web_contents_->GetController().LoadURLWithParams(params); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 283 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 284 | } |
| 285 | |
[email protected] | 76bdecb | 2014-04-16 17:58:08 | [diff] [blame] | 286 | void Shell::LoadDataWithBaseURL(const GURL& url, const std::string& data, |
| 287 | const GURL& base_url) { |
boliu | ec93ea9 | 2016-02-17 22:23:07 | [diff] [blame] | 288 | bool load_as_string = false; |
| 289 | LoadDataWithBaseURLInternal(url, data, base_url, load_as_string); |
| 290 | } |
| 291 | |
| 292 | #if defined(OS_ANDROID) |
| 293 | void Shell::LoadDataAsStringWithBaseURL(const GURL& url, |
| 294 | const std::string& data, |
| 295 | const GURL& base_url) { |
| 296 | bool load_as_string = true; |
| 297 | LoadDataWithBaseURLInternal(url, data, base_url, load_as_string); |
| 298 | } |
| 299 | #endif |
| 300 | |
| 301 | void Shell::LoadDataWithBaseURLInternal(const GURL& url, |
| 302 | const std::string& data, |
| 303 | const GURL& base_url, |
| 304 | bool load_as_string) { |
| 305 | #if !defined(OS_ANDROID) |
| 306 | DCHECK(!load_as_string); // Only supported on Android. |
| 307 | #endif |
| 308 | |
| 309 | NavigationController::LoadURLParams params(GURL::EmptyGURL()); |
| 310 | const std::string data_url_header = "data:text/html;charset=utf-8,"; |
| 311 | if (load_as_string) { |
| 312 | params.url = GURL(data_url_header); |
| 313 | std::string data_url_as_string = data_url_header + data; |
| 314 | #if defined(OS_ANDROID) |
| 315 | params.data_url_as_string = |
| 316 | base::RefCountedString::TakeString(&data_url_as_string); |
| 317 | #endif |
| 318 | } else { |
| 319 | params.url = GURL(data_url_header + data); |
| 320 | } |
| 321 | |
[email protected] | 76bdecb | 2014-04-16 17:58:08 | [diff] [blame] | 322 | params.load_type = NavigationController::LOAD_TYPE_DATA; |
| 323 | params.base_url_for_data_url = base_url; |
| 324 | params.virtual_url_for_data_url = url; |
| 325 | params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE; |
| 326 | web_contents_->GetController().LoadURLWithParams(params); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 327 | web_contents_->Focus(); |
[email protected] | 76bdecb | 2014-04-16 17:58:08 | [diff] [blame] | 328 | } |
| 329 | |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 330 | void Shell::AddNewContents(WebContents* source, |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 331 | std::unique_ptr<WebContents> new_contents, |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 332 | WindowOpenDisposition disposition, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 333 | const gfx::Rect& initial_rect, |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 334 | bool user_gesture, |
| 335 | bool* was_blocked) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 336 | WebContents* raw_new_contents = new_contents.get(); |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 337 | CreateShell( |
| 338 | std::move(new_contents), AdjustWindowSize(initial_rect.size()), |
| 339 | !delay_popup_contents_delegate_for_testing_ /* should_set_delegate */); |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 340 | if (switches::IsRunWebTestsSwitchPresent()) |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 341 | SecondaryTestWindowObserver::CreateForWebContents(raw_new_contents); |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 342 | } |
| 343 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 344 | void Shell::GoBackOrForward(int offset) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 345 | web_contents_->GetController().GoToOffset(offset); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 346 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | void Shell::Reload() { |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 350 | web_contents_->GetController().Reload(ReloadType::NORMAL, false); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 351 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 352 | } |
| 353 | |
toyoshim | e5aaf6a | 2016-05-18 08:07:48 | [diff] [blame] | 354 | void Shell::ReloadBypassingCache() { |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 355 | web_contents_->GetController().Reload(ReloadType::BYPASSING_CACHE, false); |
toyoshim | e5aaf6a | 2016-05-18 08:07:48 | [diff] [blame] | 356 | web_contents_->Focus(); |
| 357 | } |
| 358 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 359 | void Shell::Stop() { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 360 | web_contents_->Stop(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 361 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 362 | } |
| 363 | |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 364 | void Shell::UpdateNavigationControls(bool to_different_document) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 365 | int current_index = web_contents_->GetController().GetCurrentEntryIndex(); |
| 366 | int max_index = web_contents_->GetController().GetEntryCount() - 1; |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 367 | |
| 368 | PlatformEnableUIControl(BACK_BUTTON, current_index > 0); |
| 369 | PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index); |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 370 | PlatformEnableUIControl(STOP_BUTTON, |
| 371 | to_different_document && web_contents_->IsLoading()); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 372 | } |
| 373 | |
[email protected] | 7c17b699 | 2012-08-09 16:16:30 | [diff] [blame] | 374 | void Shell::ShowDevTools() { |
mohsen | 6eb57fb | 2016-07-22 03:14:08 | [diff] [blame] | 375 | if (!devtools_frontend_) { |
| 376 | devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents()); |
| 377 | devtools_observer_.reset(new DevToolsWebContentsObserver( |
| 378 | this, devtools_frontend_->frontend_shell()->web_contents())); |
| 379 | } |
[email protected] | 3142e5d | 2014-02-07 00:54:46 | [diff] [blame] | 380 | |
mohsen | 6eb57fb | 2016-07-22 03:14:08 | [diff] [blame] | 381 | devtools_frontend_->Activate(); |
| 382 | devtools_frontend_->Focus(); |
[email protected] | 7c17b699 | 2012-08-09 16:16:30 | [diff] [blame] | 383 | } |
| 384 | |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 385 | void Shell::CloseDevTools() { |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 386 | if (!devtools_frontend_) |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 387 | return; |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 388 | devtools_observer_.reset(); |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 389 | devtools_frontend_->Close(); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 390 | devtools_frontend_ = nullptr; |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 391 | } |
| 392 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 393 | gfx::NativeView Shell::GetContentView() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 394 | if (!web_contents_) |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 395 | return nullptr; |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 396 | return web_contents_->GetNativeView(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 397 | } |
| 398 | |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 399 | WebContents* Shell::OpenURLFromTab(WebContents* source, |
| 400 | const OpenURLParams& params) { |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 401 | WebContents* target = nullptr; |
| 402 | switch (params.disposition) { |
| 403 | case WindowOpenDisposition::CURRENT_TAB: |
| 404 | target = source; |
| 405 | break; |
| 406 | |
| 407 | // Normally, the difference between NEW_POPUP and NEW_WINDOW is that a popup |
| 408 | // should have no toolbar, no status bar, no menu bar, no scrollbars and be |
| 409 | // not resizable. For simplicity and to enable new testing scenarios in |
Kent Tamura | 21d1de6 | 2018-12-10 04:45:20 | [diff] [blame] | 410 | // content shell and web tests, popups don't get special treatment below |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 411 | // (i.e. they will have a toolbar and other things described here). |
| 412 | case WindowOpenDisposition::NEW_POPUP: |
lukasza | be2f0da | 2017-04-25 00:43:00 | [diff] [blame] | 413 | case WindowOpenDisposition::NEW_WINDOW: |
Kent Tamura | 21d1de6 | 2018-12-10 04:45:20 | [diff] [blame] | 414 | // content_shell doesn't really support tabs, but some web tests use |
lukasza | be2f0da | 2017-04-25 00:43:00 | [diff] [blame] | 415 | // middle click (which translates into kNavigationPolicyNewBackgroundTab), |
| 416 | // so we treat the cases below just like a NEW_WINDOW disposition. |
| 417 | case WindowOpenDisposition::NEW_BACKGROUND_TAB: |
| 418 | case WindowOpenDisposition::NEW_FOREGROUND_TAB: { |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 419 | Shell* new_window = |
| 420 | Shell::CreateNewWindow(source->GetBrowserContext(), |
| 421 | GURL(), // Don't load anything just yet. |
| 422 | params.source_site_instance, |
| 423 | gfx::Size()); // Use default size. |
| 424 | target = new_window->web_contents(); |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 425 | if (switches::IsRunWebTestsSwitchPresent()) |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 426 | SecondaryTestWindowObserver::CreateForWebContents(target); |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | // No tabs in content_shell: |
| 431 | case WindowOpenDisposition::SINGLETON_TAB: |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 432 | // No incognito mode in content_shell: |
| 433 | case WindowOpenDisposition::OFF_THE_RECORD: |
Kent Tamura | 21d1de6 | 2018-12-10 04:45:20 | [diff] [blame] | 434 | // TODO(lukasza): Investigate if some web tests might need support for |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 435 | // SAVE_TO_DISK disposition. This would probably require that |
| 436 | // BlinkTestController always sets up and cleans up a temporary directory |
| 437 | // as the default downloads destinations for the duration of a test. |
| 438 | case WindowOpenDisposition::SAVE_TO_DISK: |
| 439 | // Ignoring requests with disposition == IGNORE_ACTION... |
| 440 | case WindowOpenDisposition::IGNORE_ACTION: |
| 441 | default: |
| 442 | return nullptr; |
| 443 | } |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 444 | |
| 445 | NavigationController::LoadURLParams load_url_params(params.url); |
Nasko Oskov | 93e7c55c | 2018-12-19 01:59:29 | [diff] [blame] | 446 | load_url_params.initiator_origin = params.initiator_origin; |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 447 | load_url_params.source_site_instance = params.source_site_instance; |
| 448 | load_url_params.transition_type = params.transition; |
| 449 | load_url_params.frame_tree_node_id = params.frame_tree_node_id; |
| 450 | load_url_params.referrer = params.referrer; |
| 451 | load_url_params.redirect_chain = params.redirect_chain; |
| 452 | load_url_params.extra_headers = params.extra_headers; |
| 453 | load_url_params.is_renderer_initiated = params.is_renderer_initiated; |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 454 | load_url_params.should_replace_current_entry = |
| 455 | params.should_replace_current_entry; |
Marijn Kruisselbrink | 7a0d5e18 | 2018-05-24 22:55:09 | [diff] [blame] | 456 | load_url_params.blob_url_loader_factory = params.blob_url_loader_factory; |
Robert Ogden | 011a808 | 2019-01-23 19:04:54 | [diff] [blame] | 457 | load_url_params.reload_type = params.reload_type; |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 458 | |
lukasza | 477a5a2 | 2016-06-16 18:28:43 | [diff] [blame] | 459 | if (params.uses_post) { |
| 460 | load_url_params.load_type = NavigationController::LOAD_TYPE_HTTP_POST; |
| 461 | load_url_params.post_data = params.post_data; |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 462 | } |
| 463 | |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 464 | target->GetController().LoadURLWithParams(load_url_params); |
| 465 | return target; |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 466 | } |
| 467 | |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 468 | void Shell::LoadingStateChanged(WebContents* source, |
| 469 | bool to_different_document) { |
| 470 | UpdateNavigationControls(to_different_document); |
[email protected] | 15aea41 | 2012-01-19 03:18:50 | [diff] [blame] | 471 | PlatformSetIsLoading(source->IsLoading()); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 472 | } |
| 473 | |
Dave Tapuska | 3ed4419 | 2018-05-01 18:53:30 | [diff] [blame] | 474 | void Shell::EnterFullscreenModeForTab( |
| 475 | WebContents* web_contents, |
| 476 | const GURL& origin, |
| 477 | const blink::WebFullscreenOptions& options) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 478 | ToggleFullscreenModeForTab(web_contents, true); |
| 479 | } |
| 480 | |
| 481 | void Shell::ExitFullscreenModeForTab(WebContents* web_contents) { |
| 482 | ToggleFullscreenModeForTab(web_contents, false); |
| 483 | } |
| 484 | |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 485 | void Shell::ToggleFullscreenModeForTab(WebContents* web_contents, |
| 486 | bool enter_fullscreen) { |
| 487 | #if defined(OS_ANDROID) |
| 488 | PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen); |
| 489 | #endif |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 490 | if (!switches::IsRunWebTestsSwitchPresent()) |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 491 | return; |
| 492 | if (is_fullscreen_ != enter_fullscreen) { |
| 493 | is_fullscreen_ = enter_fullscreen; |
Fady Samuel | 0b91182 | 2018-04-25 13:22:16 | [diff] [blame] | 494 | web_contents->GetRenderViewHost() |
| 495 | ->GetWidget() |
| 496 | ->SynchronizeVisualProperties(); |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
| 500 | bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const { |
| 501 | #if defined(OS_ANDROID) |
| 502 | return PlatformIsFullscreenForTabOrPending(web_contents); |
| 503 | #else |
| 504 | return is_fullscreen_; |
| 505 | #endif |
| 506 | } |
| 507 | |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 508 | blink::WebDisplayMode Shell::GetDisplayMode( |
| 509 | const WebContents* web_contents) const { |
Lukasz Anforowicz | 52b9372 | 2018-06-20 16:11:39 | [diff] [blame] | 510 | // TODO: should return blink::WebDisplayModeFullscreen wherever user puts |
| 511 | // a browser window into fullscreen (not only in case of renderer-initiated |
| 512 | // fullscreen mode): crbug.com/476874. |
| 513 | return IsFullscreenForTabOrPending(web_contents) |
| 514 | ? blink::kWebDisplayModeFullscreen |
| 515 | : blink::kWebDisplayModeBrowser; |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 516 | } |
| 517 | |
[email protected] | f7843900 | 2012-11-28 14:45:59 | [diff] [blame] | 518 | void Shell::RequestToLockMouse(WebContents* web_contents, |
| 519 | bool user_gesture, |
| 520 | bool last_unlocked_by_target) { |
| 521 | web_contents->GotResponseToLockMouseRequest(true); |
| 522 | } |
| 523 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 524 | void Shell::CloseContents(WebContents* source) { |
| 525 | Close(); |
| 526 | } |
| 527 | |
[email protected] | 06731026 | 2012-11-22 14:30:41 | [diff] [blame] | 528 | bool Shell::CanOverscrollContent() const { |
| 529 | #if defined(USE_AURA) |
| 530 | return true; |
| 531 | #else |
| 532 | return false; |
| 533 | #endif |
| 534 | } |
| 535 | |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 536 | void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
[email protected] | 4e3c752 | 2013-08-13 11:53:18 | [diff] [blame] | 537 | PlatformSetAddressBarURL(web_contents->GetLastCommittedURL()); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 538 | } |
| 539 | |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 540 | JavaScriptDialogManager* Shell::GetJavaScriptDialogManager( |
| 541 | WebContents* source) { |
mkwst | 6efe7f2e6 | 2014-10-08 15:09:01 | [diff] [blame] | 542 | if (!dialog_manager_) { |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 543 | dialog_manager_.reset(switches::IsRunWebTestsSwitchPresent() |
Kent Tamura | f92649d88 | 2018-12-03 09:07:47 | [diff] [blame] | 544 | ? new WebTestJavaScriptDialogManager |
lukasza | 381b049 | 2016-03-10 16:48:43 | [diff] [blame] | 545 | : new ShellJavaScriptDialogManager); |
mkwst | 6efe7f2e6 | 2014-10-08 15:09:01 | [diff] [blame] | 546 | } |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 547 | return dialog_manager_.get(); |
[email protected] | f221002 | 2012-03-29 00:36:08 | [diff] [blame] | 548 | } |
| 549 | |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 550 | std::unique_ptr<BluetoothChooser> Shell::RunBluetoothChooser( |
jyasskin | 93649a5 | 2016-02-17 19:57:02 | [diff] [blame] | 551 | RenderFrameHost* frame, |
| 552 | const BluetoothChooser::EventHandler& event_handler) { |
Lukasz Anforowicz | f227b491 | 2017-12-22 23:08:59 | [diff] [blame] | 553 | BlinkTestController* blink_test_controller = BlinkTestController::Get(); |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 554 | if (blink_test_controller && switches::IsRunWebTestsSwitchPresent()) |
Lukasz Anforowicz | f227b491 | 2017-12-22 23:08:59 | [diff] [blame] | 555 | return blink_test_controller->RunBluetoothChooser(frame, event_handler); |
jyasskin | 8057c00 | 2015-09-10 19:09:53 | [diff] [blame] | 556 | return nullptr; |
| 557 | } |
| 558 | |
avi | a90ae4e | 2016-11-11 20:49:33 | [diff] [blame] | 559 | bool Shell::DidAddMessageToConsole(WebContents* source, |
Lowell Manners | 1de5242e | 2019-04-25 10:18:46 | [diff] [blame] | 560 | blink::mojom::ConsoleMessageLevel log_level, |
avi | a90ae4e | 2016-11-11 20:49:33 | [diff] [blame] | 561 | const base::string16& message, |
| 562 | int32_t line_no, |
| 563 | const base::string16& source_id) { |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 564 | return switches::IsRunWebTestsSwitchPresent(); |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 565 | } |
| 566 | |
Lucas Furukawa Gadani | 06548fb | 2019-01-15 05:01:25 | [diff] [blame] | 567 | void Shell::PortalWebContentsCreated(WebContents* portal_web_contents) { |
| 568 | if (switches::IsRunWebTestsSwitchPresent()) |
| 569 | SecondaryTestWindowObserver::CreateForWebContents(portal_web_contents); |
| 570 | } |
| 571 | |
Lukasz Anforowicz | 52b9372 | 2018-06-20 16:11:39 | [diff] [blame] | 572 | void Shell::RendererUnresponsive( |
| 573 | WebContents* source, |
| 574 | RenderWidgetHost* render_widget_host, |
| 575 | base::RepeatingClosure hang_monitor_restarter) { |
Lukasz Anforowicz | f227b491 | 2017-12-22 23:08:59 | [diff] [blame] | 576 | BlinkTestController* blink_test_controller = BlinkTestController::Get(); |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 577 | if (blink_test_controller && switches::IsRunWebTestsSwitchPresent()) |
Lukasz Anforowicz | f227b491 | 2017-12-22 23:08:59 | [diff] [blame] | 578 | blink_test_controller->RendererUnresponsive(); |
[email protected] | 5bf68f2 | 2012-08-31 07:38:10 | [diff] [blame] | 579 | } |
| 580 | |
[email protected] | 233567d | 2013-02-27 20:22:02 | [diff] [blame] | 581 | void Shell::ActivateContents(WebContents* contents) { |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 582 | contents->GetRenderViewHost()->GetWidget()->Focus(); |
[email protected] | 233567d | 2013-02-27 20:22:02 | [diff] [blame] | 583 | } |
| 584 | |
Lucas Furukawa Gadani | c5c0cd0 | 2018-10-04 20:32:33 | [diff] [blame] | 585 | std::unique_ptr<WebContents> Shell::SwapWebContents( |
| 586 | WebContents* old_contents, |
| 587 | std::unique_ptr<WebContents> new_contents, |
| 588 | bool did_start_load, |
| 589 | bool did_finish_load) { |
| 590 | DCHECK_EQ(old_contents, web_contents_.get()); |
| 591 | new_contents->SetDelegate(this); |
| 592 | web_contents_->SetDelegate(nullptr); |
| 593 | std::swap(web_contents_, new_contents); |
| 594 | PlatformSetContents(); |
| 595 | PlatformSetAddressBarURL(web_contents_->GetLastCommittedURL()); |
| 596 | LoadingStateChanged(web_contents_.get(), true); |
| 597 | return new_contents; |
| 598 | } |
| 599 | |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 600 | bool Shell::ShouldAllowRunningInsecureContent( |
| 601 | content::WebContents* web_contents, |
| 602 | bool allowed_per_prefs, |
| 603 | const url::Origin& origin, |
| 604 | const GURL& resource_url) { |
| 605 | bool allowed_by_test = false; |
Lukasz Anforowicz | f227b491 | 2017-12-22 23:08:59 | [diff] [blame] | 606 | BlinkTestController* blink_test_controller = BlinkTestController::Get(); |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 607 | if (blink_test_controller && switches::IsRunWebTestsSwitchPresent()) { |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 608 | const base::DictionaryValue& test_flags = |
Kent Tamura | 679c7c4 | 2018-12-05 03:21:10 | [diff] [blame] | 609 | blink_test_controller->accumulated_web_test_runtime_flags_changes(); |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 610 | test_flags.GetBoolean("running_insecure_content_allowed", &allowed_by_test); |
| 611 | } |
| 612 | |
| 613 | return allowed_per_prefs || allowed_by_test; |
| 614 | } |
| 615 | |
François Beaufort | f09e446 | 2019-01-18 14:34:51 | [diff] [blame] | 616 | gfx::Size Shell::EnterPictureInPicture(content::WebContents* web_contents, |
| 617 | const viz::SurfaceId& surface_id, |
Mounir Lamouri | 11e9ef43 | 2018-05-22 03:10:16 | [diff] [blame] | 618 | const gfx::Size& natural_size) { |
François Beaufort | 480ee2d | 2018-10-24 14:05:17 | [diff] [blame] | 619 | // During tests, returning a fake window size (same aspect ratio) to pretend |
| 620 | // the window was created and allow tests to run accordingly. |
| 621 | return switches::IsRunWebTestsSwitchPresent() ? natural_size |
Mounir Lamouri | 11e9ef43 | 2018-05-22 03:10:16 | [diff] [blame] | 622 | : gfx::Size(0, 0); |
| 623 | } |
| 624 | |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 625 | bool Shell::ShouldResumeRequestsForCreatedWindow() { |
| 626 | return !delay_popup_contents_delegate_for_testing_; |
| 627 | } |
| 628 | |
pdr | cab84ee | 2015-03-13 21:47:04 | [diff] [blame] | 629 | gfx::Size Shell::GetShellDefaultSize() { |
| 630 | static gfx::Size default_shell_size; |
| 631 | if (!default_shell_size.IsEmpty()) |
| 632 | return default_shell_size; |
| 633 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 634 | if (command_line->HasSwitch(switches::kContentShellHostWindowSize)) { |
| 635 | const std::string size_str = command_line->GetSwitchValueASCII( |
| 636 | switches::kContentShellHostWindowSize); |
| 637 | int width, height; |
| 638 | CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height)); |
| 639 | default_shell_size = gfx::Size(width, height); |
| 640 | } else { |
| 641 | default_shell_size = gfx::Size( |
| 642 | kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip); |
| 643 | } |
| 644 | return default_shell_size; |
| 645 | } |
| 646 | |
Avi Drissman | 9300221 | 2017-09-27 03:20:52 | [diff] [blame] | 647 | void Shell::TitleWasSet(NavigationEntry* entry) { |
[email protected] | 1ef02d24 | 2013-10-07 16:18:53 | [diff] [blame] | 648 | if (entry) |
| 649 | PlatformSetTitle(entry->GetTitle()); |
[email protected] | aecc085b | 2012-06-01 18:15:53 | [diff] [blame] | 650 | } |
| 651 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 652 | void Shell::OnDevToolsWebContentsDestroyed() { |
| 653 | devtools_observer_.reset(); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 654 | devtools_frontend_ = nullptr; |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 655 | } |
| 656 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 657 | } // namespace content |