blob: 8e533513833ca70033fb3bdabeed901ed227022d [file] [log] [blame]
[email protected]de7d61ff2013-08-20 11:30:411// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]9fbd3f862011-09-20 23:31:342// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]de7d61ff2013-08-20 11:30:415#include "content/shell/browser/shell.h"
[email protected]9fbd3f862011-09-20 23:31:346
avi66a07722015-12-25 23:38:127#include <stddef.h>
8
[email protected]11a65b692012-03-30 11:29:169#include "base/auto_reset.h"
[email protected]efb5f572012-01-29 10:57:3310#include "base/command_line.h"
skyostil95082a62015-06-05 19:53:0711#include "base/location.h"
avi66a07722015-12-25 23:38:1212#include "base/macros.h"
fdoray896bea12016-06-10 15:52:0113#include "base/run_loop.h"
skyostil95082a62015-06-05 19:53:0714#include "base/single_thread_task_runner.h"
[email protected]21aa99682013-06-11 07:17:0115#include "base/strings/string_number_conversions.h"
16#include "base/strings/string_util.h"
17#include "base/strings/stringprintf.h"
[email protected]74ebfb12013-06-07 20:48:0018#include "base/strings/utf_string_conversions.h"
gab30f26df2016-05-11 19:37:5519#include "base/threading/thread_task_runner_handle.h"
avi66a07722015-12-25 23:38:1220#include "build/build_config.h"
[email protected]b50452f2014-08-18 12:31:4421#include "content/public/browser/devtools_agent_host.h"
[email protected]0b659b32012-03-26 21:29:3222#include "content/public/browser/navigation_controller.h"
[email protected]b7c504c2013-05-07 14:42:1223#include "content/public/browser/navigation_entry.h"
Yutaka Hirano2109e582018-02-14 07:24:4624#include "content/public/browser/render_process_host.h"
[email protected]0b659b32012-03-26 21:29:3225#include "content/public/browser/render_view_host.h"
avif9ab5d942015-10-15 14:05:4426#include "content/public/browser/render_widget_host.h"
[email protected]0b659b32012-03-26 21:29:3227#include "content/public/browser/web_contents.h"
[email protected]7fff43e2013-05-21 20:21:1028#include "content/public/browser/web_contents_observer.h"
guoweis8efb6d892015-10-12 18:26:1729#include "content/public/common/content_switches.h"
[email protected]1596efb2013-01-17 22:13:0130#include "content/public/common/renderer_preferences.h"
guoweisc537ba22015-11-06 21:20:3131#include "content/public/common/webrtc_ip_handling_policy.h"
jochen5ce1af92016-02-17 20:39:4532#include "content/shell/browser/layout_test/blink_test_controller.h"
jyasskin8057c002015-09-10 19:09:5333#include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factory.h"
chenwilliamfed5bda2017-03-24 02:01:0634#include "content/shell/browser/layout_test/layout_test_devtools_bindings.h"
mkwst6efe7f2e62014-10-08 15:09:0135#include "content/shell/browser/layout_test/layout_test_javascript_dialog_manager.h"
lukasza8e550a02016-04-18 18:34:1736#include "content/shell/browser/layout_test/secondary_test_window_observer.h"
[email protected]de7d61ff2013-08-20 11:30:4137#include "content/shell/browser/shell_browser_main_parts.h"
38#include "content/shell/browser/shell_content_browser_client.h"
39#include "content/shell/browser/shell_devtools_frontend.h"
40#include "content/shell/browser/shell_javascript_dialog_manager.h"
carloskd9d97942017-02-16 08:58:0941#include "content/shell/common/layout_test/layout_test_switches.h"
[email protected]b7c504c2013-05-07 14:42:1242#include "content/shell/common/shell_messages.h"
43#include "content/shell/common/shell_switches.h"
Scott Violeta35f9a42018-03-22 22:00:4444#include "media/media_buildflags.h"
Blink Reformata30d4232018-04-07 15:31:0645#include "third_party/blink/public/web/web_presentation_receiver_flags.h"
[email protected]9fbd3f862011-09-20 23:31:3446
[email protected]9fbd3f862011-09-20 23:31:3447namespace content {
48
pdrcab84ee2015-03-13 21:47:0449const int kDefaultTestWindowWidthDip = 800;
50const int kDefaultTestWindowHeightDip = 600;
[email protected]1e57cab2013-05-28 04:26:1151
[email protected]e99ca5112011-09-26 17:22:5452std::vector<Shell*> Shell::windows_;
[email protected]9e00e6352012-07-30 17:05:1853base::Callback<void(Shell*)> Shell::shell_created_callback_;
[email protected]9fbd3f862011-09-20 23:31:3454
[email protected]11a65b692012-03-30 11:29:1655bool Shell::quit_message_loop_ = true;
56
[email protected]7fff43e2013-05-21 20:21:1057class Shell::DevToolsWebContentsObserver : public WebContentsObserver {
58 public:
59 DevToolsWebContentsObserver(Shell* shell, WebContents* web_contents)
60 : WebContentsObserver(web_contents),
61 shell_(shell) {
62 }
63
64 // WebContentsObserver
dchenge933b3e2014-10-21 11:44:0965 void WebContentsDestroyed() override {
[email protected]7fff43e2013-05-21 20:21:1066 shell_->OnDevToolsWebContentsDestroyed();
67 }
68
69 private:
70 Shell* shell_;
71
72 DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver);
73};
74
erikchenbee5c9622018-04-27 19:30:2575Shell::Shell(std::unique_ptr<WebContents> web_contents)
76 : WebContentsObserver(web_contents.get()),
77 web_contents_(std::move(web_contents)),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:2878 devtools_frontend_(nullptr),
[email protected]001841c92012-12-11 17:00:1379 is_fullscreen_(false),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:2880 window_(nullptr),
sadrul8b11d262015-11-12 18:41:3381#if defined(OS_MACOSX)
[email protected]86b36e672012-12-21 00:09:5182 url_edit_view_(NULL),
sadrul8b11d262015-11-12 18:41:3383#endif
Pavel Feldmanc7cd063c2017-10-06 20:04:2884 headless_(false),
85 hide_toolbar_(false) {
arthursonzognifdd49912017-08-31 08:55:2686 web_contents_->SetDelegate(this);
87
Kent Tamuracd3ebc42018-05-16 06:44:2288 if (switches::IsRunWebTestsSwitchPresent()) {
[email protected]86b36e672012-12-21 00:09:5189 headless_ = true;
Francois Doraye6161152018-03-27 22:05:3790 // In a headless shell, disable occlusion tracking. Otherwise, WebContents
91 // would always behave as if they were occluded, i.e. would not render
92 // frames and would not receive input events.
93 base::CommandLine::ForCurrentProcess()->AppendSwitch(
94 switches::kDisableBackgroundingOccludedWindowsForTesting);
95 }
Pavel Feldmanc7cd063c2017-10-06 20:04:2896
97 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
98 switches::kContentShellHideToolbar))
99 hide_toolbar_ = true;
100
[email protected]9e00e6352012-07-30 17:05:18101 windows_.push_back(this);
102
103 if (!shell_created_callback_.is_null()) {
104 shell_created_callback_.Run(this);
105 shell_created_callback_.Reset();
106 }
[email protected]9fbd3f862011-09-20 23:31:34107}
108
109Shell::~Shell() {
110 PlatformCleanUp();
[email protected]e99ca5112011-09-26 17:22:54111
112 for (size_t i = 0; i < windows_.size(); ++i) {
113 if (windows_[i] == this) {
114 windows_.erase(windows_.begin() + i);
115 break;
116 }
117 }
[email protected]11a65b692012-03-30 11:29:16118
[email protected]b53adf452014-02-07 12:55:08119 if (windows_.empty() && quit_message_loop_) {
120 if (headless_)
121 PlatformExit();
Yutaka Hirano2109e582018-02-14 07:24:46122 for (auto it = RenderProcessHost::AllHostsIterator(); !it.IsAtEnd();
123 it.Advance()) {
124 it.GetCurrentValue()->DisableKeepAliveRefCount();
125 }
skyostil95082a62015-06-05 19:53:07126 base::ThreadTaskRunnerHandle::Get()->PostTask(
Gabriel Charetteea918012018-05-16 11:53:44127 FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated());
[email protected]b53adf452014-02-07 12:55:08128 }
arthursonzognifdd49912017-08-31 08:55:26129
130 web_contents_->SetDelegate(nullptr);
[email protected]9fbd3f862011-09-20 23:31:34131}
132
erikchenbee5c9622018-04-27 19:30:25133Shell* Shell::CreateShell(std::unique_ptr<WebContents> web_contents,
[email protected]c0d036d2013-05-07 12:50:50134 const gfx::Size& initial_size) {
erikchenbee5c9622018-04-27 19:30:25135 WebContents* raw_web_contents = web_contents.get();
136 Shell* shell = new Shell(std::move(web_contents));
[email protected]c0d036d2013-05-07 12:50:50137 shell->PlatformCreateWindow(initial_size.width(), initial_size.height());
[email protected]3fd84032012-01-12 18:20:17138
[email protected]5cba3bf2012-01-14 02:40:35139 shell->PlatformSetContents();
[email protected]3fd84032012-01-12 18:20:17140
141 shell->PlatformResizeSubViews();
[email protected]1596efb2013-01-17 22:13:01142
creisb6561df2016-02-11 20:20:54143 // Note: Do not make RenderFrameHost or RenderViewHost specific state changes
144 // here, because they will be forgotten after a cross-process navigation. Use
145 // RenderFrameCreated or RenderViewCreated instead.
Kent Tamuracd3ebc42018-05-16 06:44:22146 if (switches::IsRunWebTestsSwitchPresent()) {
erikchenbee5c9622018-04-27 19:30:25147 raw_web_contents->GetMutableRendererPrefs()->use_custom_colors = false;
148 raw_web_contents->GetRenderViewHost()->SyncRendererPrefs();
[email protected]1596efb2013-01-17 22:13:01149 }
150
lukasza381b0492016-03-10 16:48:43151 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
guoweis4ee48592015-12-02 06:37:07152 if (command_line->HasSwitch(switches::kForceWebRtcIPHandlingPolicy)) {
erikchenbee5c9622018-04-27 19:30:25153 raw_web_contents->GetMutableRendererPrefs()->webrtc_ip_handling_policy =
guoweis4ee48592015-12-02 06:37:07154 command_line->GetSwitchValueASCII(
155 switches::kForceWebRtcIPHandlingPolicy);
guoweis8efb6d892015-10-12 18:26:17156 }
guoweis8efb6d892015-10-12 18:26:17157
[email protected]3fd84032012-01-12 18:20:17158 return shell;
159}
160
[email protected]11a65b692012-03-30 11:29:16161void Shell::CloseAllWindows() {
[email protected]997ec9f2012-11-21 04:44:14162 base::AutoReset<bool> auto_reset(&quit_message_loop_, false);
[email protected]b50452f2014-08-18 12:31:44163 DevToolsAgentHost::DetachAllClients();
[email protected]11a65b692012-03-30 11:29:16164 std::vector<Shell*> open_windows(windows_);
165 for (size_t i = 0; i < open_windows.size(); ++i)
166 open_windows[i]->Close();
fdoray896bea12016-06-10 15:52:01167 base::RunLoop().RunUntilIdle();
dmazzoni948fbc72015-05-17 07:57:33168 PlatformExit();
[email protected]11a65b692012-03-30 11:29:16169}
170
[email protected]9e00e6352012-07-30 17:05:18171void Shell::SetShellCreatedCallback(
172 base::Callback<void(Shell*)> shell_created_callback) {
173 DCHECK(shell_created_callback_.is_null());
Tommy Nyquist4b749d02018-03-20 21:46:29174 shell_created_callback_ = std::move(shell_created_callback);
[email protected]9e00e6352012-07-30 17:05:18175}
176
[email protected]74830f02012-01-30 22:27:04177Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) {
178 for (size_t i = 0; i < windows_.size(); ++i) {
[email protected]0b659b32012-03-26 21:29:32179 if (windows_[i]->web_contents() &&
180 windows_[i]->web_contents()->GetRenderViewHost() == rvh) {
[email protected]74830f02012-01-30 22:27:04181 return windows_[i];
182 }
183 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28184 return nullptr;
[email protected]74830f02012-01-30 22:27:04185}
186
[email protected]6153b272013-01-25 22:29:23187// static
188void Shell::Initialize() {
pdrcab84ee2015-03-13 21:47:04189 PlatformInitialize(GetShellDefaultSize());
[email protected]6153b272013-01-25 22:29:23190}
191
[email protected]a2904092013-10-15 04:53:59192gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) {
193 if (!initial_size.IsEmpty())
194 return initial_size;
pdrcab84ee2015-03-13 21:47:04195 return GetShellDefaultSize();
[email protected]a2904092013-10-15 04:53:59196}
197
[email protected]bdcf9152012-07-19 17:43:21198Shell* Shell::CreateNewWindow(BrowserContext* browser_context,
[email protected]e99ca5112011-09-26 17:22:54199 const GURL& url,
lukasza04130152016-10-21 20:26:32200 const scoped_refptr<SiteInstance>& site_instance,
[email protected]cdb806722013-01-10 14:18:23201 const gfx::Size& initial_size) {
[email protected]54944cde2012-12-09 09:24:59202 WebContents::CreateParams create_params(browser_context, site_instance);
mark a. foltzef394fce2017-10-21 09:11:02203 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
204 switches::kForcePresentationReceiverForTesting)) {
205 create_params.starting_sandbox_flags =
206 blink::kPresentationReceiverSandboxFlags;
207 }
[email protected]a2904092013-10-15 04:53:59208 create_params.initial_size = AdjustWindowSize(initial_size);
erikchenbee5c9622018-04-27 19:30:25209 std::unique_ptr<WebContents> web_contents =
Erik Chenbb8e738e2018-04-28 14:10:43210 WebContents::Create(create_params);
erikchenbee5c9622018-04-27 19:30:25211 Shell* shell =
212 CreateShell(std::move(web_contents), create_params.initial_size);
[email protected]e99ca5112011-09-26 17:22:54213 if (!url.is_empty())
214 shell->LoadURL(url);
[email protected]9fbd3f862011-09-20 23:31:34215 return shell;
216}
217
218void Shell::LoadURL(const GURL& url) {
Alex Moshchuk7e26eca2018-03-03 01:34:29219 LoadURLForFrame(
220 url, std::string(),
221 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED |
222 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR));
[email protected]d2494ff2013-02-20 08:22:37223}
224
Alex Moshchuk7e26eca2018-03-03 01:34:29225void Shell::LoadURLForFrame(const GURL& url,
226 const std::string& frame_name,
227 ui::PageTransition transition_type) {
[email protected]d2494ff2013-02-20 08:22:37228 NavigationController::LoadURLParams params(url);
[email protected]d2494ff2013-02-20 08:22:37229 params.frame_name = frame_name;
Alex Moshchuk7e26eca2018-03-03 01:34:29230 params.transition_type = transition_type;
[email protected]d2494ff2013-02-20 08:22:37231 web_contents_->GetController().LoadURLWithParams(params);
[email protected]fc2b46b2014-05-03 16:33:45232 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34233}
234
[email protected]76bdecb2014-04-16 17:58:08235void Shell::LoadDataWithBaseURL(const GURL& url, const std::string& data,
236 const GURL& base_url) {
boliuec93ea92016-02-17 22:23:07237 bool load_as_string = false;
238 LoadDataWithBaseURLInternal(url, data, base_url, load_as_string);
239}
240
241#if defined(OS_ANDROID)
242void Shell::LoadDataAsStringWithBaseURL(const GURL& url,
243 const std::string& data,
244 const GURL& base_url) {
245 bool load_as_string = true;
246 LoadDataWithBaseURLInternal(url, data, base_url, load_as_string);
247}
248#endif
249
250void Shell::LoadDataWithBaseURLInternal(const GURL& url,
251 const std::string& data,
252 const GURL& base_url,
253 bool load_as_string) {
254#if !defined(OS_ANDROID)
255 DCHECK(!load_as_string); // Only supported on Android.
256#endif
257
258 NavigationController::LoadURLParams params(GURL::EmptyGURL());
259 const std::string data_url_header = "data:text/html;charset=utf-8,";
260 if (load_as_string) {
261 params.url = GURL(data_url_header);
262 std::string data_url_as_string = data_url_header + data;
263#if defined(OS_ANDROID)
264 params.data_url_as_string =
265 base::RefCountedString::TakeString(&data_url_as_string);
266#endif
267 } else {
268 params.url = GURL(data_url_header + data);
269 }
270
[email protected]76bdecb2014-04-16 17:58:08271 params.load_type = NavigationController::LOAD_TYPE_DATA;
272 params.base_url_for_data_url = base_url;
273 params.virtual_url_for_data_url = url;
274 params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE;
275 web_contents_->GetController().LoadURLWithParams(params);
[email protected]fc2b46b2014-05-03 16:33:45276 web_contents_->Focus();
[email protected]76bdecb2014-04-16 17:58:08277}
278
[email protected]a2904092013-10-15 04:53:59279void Shell::AddNewContents(WebContents* source,
erikchenbee5c9622018-04-27 19:30:25280 std::unique_ptr<WebContents> new_contents,
[email protected]a2904092013-10-15 04:53:59281 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:39282 const gfx::Rect& initial_rect,
[email protected]a2904092013-10-15 04:53:59283 bool user_gesture,
284 bool* was_blocked) {
erikchenbee5c9622018-04-27 19:30:25285 WebContents* raw_new_contents = new_contents.get();
286 CreateShell(std::move(new_contents), AdjustWindowSize(initial_rect.size()));
Kent Tamuracd3ebc42018-05-16 06:44:22287 if (switches::IsRunWebTestsSwitchPresent())
erikchenbee5c9622018-04-27 19:30:25288 SecondaryTestWindowObserver::CreateForWebContents(raw_new_contents);
[email protected]a2904092013-10-15 04:53:59289}
290
[email protected]9fbd3f862011-09-20 23:31:34291void Shell::GoBackOrForward(int offset) {
[email protected]0b659b32012-03-26 21:29:32292 web_contents_->GetController().GoToOffset(offset);
[email protected]fc2b46b2014-05-03 16:33:45293 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34294}
295
296void Shell::Reload() {
toyoshim6142d96f2016-12-19 09:07:25297 web_contents_->GetController().Reload(ReloadType::NORMAL, false);
[email protected]fc2b46b2014-05-03 16:33:45298 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34299}
300
toyoshime5aaf6a2016-05-18 08:07:48301void Shell::ReloadBypassingCache() {
toyoshim6142d96f2016-12-19 09:07:25302 web_contents_->GetController().Reload(ReloadType::BYPASSING_CACHE, false);
toyoshime5aaf6a2016-05-18 08:07:48303 web_contents_->Focus();
304}
305
[email protected]9fbd3f862011-09-20 23:31:34306void Shell::Stop() {
[email protected]0b659b32012-03-26 21:29:32307 web_contents_->Stop();
[email protected]fc2b46b2014-05-03 16:33:45308 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34309}
310
[email protected]e3b10d12014-03-28 16:06:09311void Shell::UpdateNavigationControls(bool to_different_document) {
[email protected]0b659b32012-03-26 21:29:32312 int current_index = web_contents_->GetController().GetCurrentEntryIndex();
313 int max_index = web_contents_->GetController().GetEntryCount() - 1;
[email protected]9fbd3f862011-09-20 23:31:34314
315 PlatformEnableUIControl(BACK_BUTTON, current_index > 0);
316 PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index);
[email protected]e3b10d12014-03-28 16:06:09317 PlatformEnableUIControl(STOP_BUTTON,
318 to_different_document && web_contents_->IsLoading());
[email protected]9fbd3f862011-09-20 23:31:34319}
320
[email protected]7c17b6992012-08-09 16:16:30321void Shell::ShowDevTools() {
mohsen6eb57fb2016-07-22 03:14:08322 if (!devtools_frontend_) {
323 devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents());
324 devtools_observer_.reset(new DevToolsWebContentsObserver(
325 this, devtools_frontend_->frontend_shell()->web_contents()));
326 }
[email protected]3142e5d2014-02-07 00:54:46327
mohsen6eb57fb2016-07-22 03:14:08328 devtools_frontend_->Activate();
329 devtools_frontend_->Focus();
[email protected]7c17b6992012-08-09 16:16:30330}
331
[email protected]001841c92012-12-11 17:00:13332void Shell::CloseDevTools() {
[email protected]0773e0c2013-01-25 15:57:57333 if (!devtools_frontend_)
[email protected]001841c92012-12-11 17:00:13334 return;
[email protected]7fff43e2013-05-21 20:21:10335 devtools_observer_.reset();
[email protected]0773e0c2013-01-25 15:57:57336 devtools_frontend_->Close();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28337 devtools_frontend_ = nullptr;
[email protected]001841c92012-12-11 17:00:13338}
339
[email protected]9fbd3f862011-09-20 23:31:34340gfx::NativeView Shell::GetContentView() {
[email protected]59383c782013-04-17 16:43:27341 if (!web_contents_)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28342 return nullptr;
[email protected]fc2b46b2014-05-03 16:33:45343 return web_contents_->GetNativeView();
[email protected]9fbd3f862011-09-20 23:31:34344}
345
alexmos5a98a052016-01-06 00:15:02346WebContents* Shell::OpenURLFromTab(WebContents* source,
347 const OpenURLParams& params) {
lukasza04130152016-10-21 20:26:32348 WebContents* target = nullptr;
349 switch (params.disposition) {
350 case WindowOpenDisposition::CURRENT_TAB:
351 target = source;
352 break;
353
354 // Normally, the difference between NEW_POPUP and NEW_WINDOW is that a popup
355 // should have no toolbar, no status bar, no menu bar, no scrollbars and be
356 // not resizable. For simplicity and to enable new testing scenarios in
357 // content shell and layout tests, popups don't get special treatment below
358 // (i.e. they will have a toolbar and other things described here).
359 case WindowOpenDisposition::NEW_POPUP:
lukaszabe2f0da2017-04-25 00:43:00360 case WindowOpenDisposition::NEW_WINDOW:
361 // content_shell doesn't really support tabs, but some layout tests use
362 // middle click (which translates into kNavigationPolicyNewBackgroundTab),
363 // so we treat the cases below just like a NEW_WINDOW disposition.
364 case WindowOpenDisposition::NEW_BACKGROUND_TAB:
365 case WindowOpenDisposition::NEW_FOREGROUND_TAB: {
lukasza04130152016-10-21 20:26:32366 Shell* new_window =
367 Shell::CreateNewWindow(source->GetBrowserContext(),
368 GURL(), // Don't load anything just yet.
369 params.source_site_instance,
370 gfx::Size()); // Use default size.
371 target = new_window->web_contents();
Kent Tamuracd3ebc42018-05-16 06:44:22372 if (switches::IsRunWebTestsSwitchPresent())
lukasza04130152016-10-21 20:26:32373 SecondaryTestWindowObserver::CreateForWebContents(target);
374 break;
375 }
376
377 // No tabs in content_shell:
378 case WindowOpenDisposition::SINGLETON_TAB:
lukasza04130152016-10-21 20:26:32379 // No incognito mode in content_shell:
380 case WindowOpenDisposition::OFF_THE_RECORD:
381 // TODO(lukasza): Investigate if some layout tests might need support for
382 // SAVE_TO_DISK disposition. This would probably require that
383 // BlinkTestController always sets up and cleans up a temporary directory
384 // as the default downloads destinations for the duration of a test.
385 case WindowOpenDisposition::SAVE_TO_DISK:
386 // Ignoring requests with disposition == IGNORE_ACTION...
387 case WindowOpenDisposition::IGNORE_ACTION:
388 default:
389 return nullptr;
390 }
alexmos5a98a052016-01-06 00:15:02391
392 NavigationController::LoadURLParams load_url_params(params.url);
393 load_url_params.source_site_instance = params.source_site_instance;
394 load_url_params.transition_type = params.transition;
395 load_url_params.frame_tree_node_id = params.frame_tree_node_id;
396 load_url_params.referrer = params.referrer;
397 load_url_params.redirect_chain = params.redirect_chain;
398 load_url_params.extra_headers = params.extra_headers;
399 load_url_params.is_renderer_initiated = params.is_renderer_initiated;
alexmos5a98a052016-01-06 00:15:02400 load_url_params.should_replace_current_entry =
401 params.should_replace_current_entry;
Marijn Kruisselbrink7a0d5e182018-05-24 22:55:09402 load_url_params.blob_url_loader_factory = params.blob_url_loader_factory;
alexmos5a98a052016-01-06 00:15:02403
lukasza477a5a22016-06-16 18:28:43404 if (params.uses_post) {
405 load_url_params.load_type = NavigationController::LOAD_TYPE_HTTP_POST;
406 load_url_params.post_data = params.post_data;
alexmos5a98a052016-01-06 00:15:02407 }
408
lukasza04130152016-10-21 20:26:32409 target->GetController().LoadURLWithParams(load_url_params);
410 return target;
alexmos5a98a052016-01-06 00:15:02411}
412
[email protected]e3b10d12014-03-28 16:06:09413void Shell::LoadingStateChanged(WebContents* source,
414 bool to_different_document) {
415 UpdateNavigationControls(to_different_document);
[email protected]15aea412012-01-19 03:18:50416 PlatformSetIsLoading(source->IsLoading());
[email protected]e99ca5112011-09-26 17:22:54417}
418
Dave Tapuska3ed44192018-05-01 18:53:30419void Shell::EnterFullscreenModeForTab(
420 WebContents* web_contents,
421 const GURL& origin,
422 const blink::WebFullscreenOptions& options) {
mlamouri7a78d6fd2015-01-17 13:23:53423 ToggleFullscreenModeForTab(web_contents, true);
424}
425
426void Shell::ExitFullscreenModeForTab(WebContents* web_contents) {
427 ToggleFullscreenModeForTab(web_contents, false);
428}
429
[email protected]99c014c2012-11-27 12:03:42430void Shell::ToggleFullscreenModeForTab(WebContents* web_contents,
431 bool enter_fullscreen) {
432#if defined(OS_ANDROID)
433 PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen);
434#endif
Kent Tamuracd3ebc42018-05-16 06:44:22435 if (!switches::IsRunWebTestsSwitchPresent())
[email protected]99c014c2012-11-27 12:03:42436 return;
437 if (is_fullscreen_ != enter_fullscreen) {
438 is_fullscreen_ = enter_fullscreen;
Fady Samuel0b911822018-04-25 13:22:16439 web_contents->GetRenderViewHost()
440 ->GetWidget()
441 ->SynchronizeVisualProperties();
[email protected]99c014c2012-11-27 12:03:42442 }
443}
444
445bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const {
446#if defined(OS_ANDROID)
447 return PlatformIsFullscreenForTabOrPending(web_contents);
448#else
449 return is_fullscreen_;
450#endif
451}
452
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12453blink::WebDisplayMode Shell::GetDisplayMode(
454 const WebContents* web_contents) const {
455 // TODO : should return blink::WebDisplayModeFullscreen wherever user puts
456 // a browser window into fullscreen (not only in case of renderer-initiated
457 // fullscreen mode): crbug.com/476874.
Blink Reformat1c4d759e2017-04-09 16:34:54458 return IsFullscreenForTabOrPending(web_contents)
459 ? blink::kWebDisplayModeFullscreen
460 : blink::kWebDisplayModeBrowser;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12461}
462
[email protected]f78439002012-11-28 14:45:59463void Shell::RequestToLockMouse(WebContents* web_contents,
464 bool user_gesture,
465 bool last_unlocked_by_target) {
466 web_contents->GotResponseToLockMouseRequest(true);
467}
468
[email protected]9e00e6352012-07-30 17:05:18469void Shell::CloseContents(WebContents* source) {
470 Close();
471}
472
[email protected]067310262012-11-22 14:30:41473bool Shell::CanOverscrollContent() const {
474#if defined(USE_AURA)
475 return true;
476#else
477 return false;
478#endif
479}
480
[email protected]3bbacc5b2012-04-17 17:46:15481void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) {
[email protected]4e3c7522013-08-13 11:53:18482 PlatformSetAddressBarURL(web_contents->GetLastCommittedURL());
[email protected]e99ca5112011-09-26 17:22:54483}
484
mathiash72a5e462014-11-19 08:18:50485JavaScriptDialogManager* Shell::GetJavaScriptDialogManager(
486 WebContents* source) {
mkwst6efe7f2e62014-10-08 15:09:01487 if (!dialog_manager_) {
Kent Tamuracd3ebc42018-05-16 06:44:22488 dialog_manager_.reset(switches::IsRunWebTestsSwitchPresent()
lukasza381b0492016-03-10 16:48:43489 ? new LayoutTestJavaScriptDialogManager
490 : new ShellJavaScriptDialogManager);
mkwst6efe7f2e62014-10-08 15:09:01491 }
[email protected]71a88bb2013-02-01 22:05:15492 return dialog_manager_.get();
[email protected]f2210022012-03-29 00:36:08493}
494
dcheng6003e0b2016-04-09 18:42:34495std::unique_ptr<BluetoothChooser> Shell::RunBluetoothChooser(
jyasskin93649a52016-02-17 19:57:02496 RenderFrameHost* frame,
497 const BluetoothChooser::EventHandler& event_handler) {
Lukasz Anforowiczf227b4912017-12-22 23:08:59498 BlinkTestController* blink_test_controller = BlinkTestController::Get();
Kent Tamuracd3ebc42018-05-16 06:44:22499 if (blink_test_controller && switches::IsRunWebTestsSwitchPresent())
Lukasz Anforowiczf227b4912017-12-22 23:08:59500 return blink_test_controller->RunBluetoothChooser(frame, event_handler);
jyasskin8057c002015-09-10 19:09:53501 return nullptr;
502}
503
avia90ae4e2016-11-11 20:49:33504bool Shell::DidAddMessageToConsole(WebContents* source,
505 int32_t level,
506 const base::string16& message,
507 int32_t line_no,
508 const base::string16& source_id) {
Kent Tamuracd3ebc42018-05-16 06:44:22509 return switches::IsRunWebTestsSwitchPresent();
[email protected]efb5f572012-01-29 10:57:33510}
511
Avi Drissman8920def2018-01-31 19:53:36512void Shell::RendererUnresponsive(WebContents* source,
Avi Drissman1572e8c3c2018-02-02 19:06:36513 RenderWidgetHost* render_widget_host) {
Lukasz Anforowiczf227b4912017-12-22 23:08:59514 BlinkTestController* blink_test_controller = BlinkTestController::Get();
Kent Tamuracd3ebc42018-05-16 06:44:22515 if (blink_test_controller && switches::IsRunWebTestsSwitchPresent())
Lukasz Anforowiczf227b4912017-12-22 23:08:59516 blink_test_controller->RendererUnresponsive();
[email protected]5bf68f22012-08-31 07:38:10517}
518
[email protected]233567d2013-02-27 20:22:02519void Shell::ActivateContents(WebContents* contents) {
avif9ab5d942015-10-15 14:05:44520 contents->GetRenderViewHost()->GetWidget()->Focus();
[email protected]233567d2013-02-27 20:22:02521}
522
carloskd9d97942017-02-16 08:58:09523bool Shell::ShouldAllowRunningInsecureContent(
524 content::WebContents* web_contents,
525 bool allowed_per_prefs,
526 const url::Origin& origin,
527 const GURL& resource_url) {
528 bool allowed_by_test = false;
Lukasz Anforowiczf227b4912017-12-22 23:08:59529 BlinkTestController* blink_test_controller = BlinkTestController::Get();
Kent Tamuracd3ebc42018-05-16 06:44:22530 if (blink_test_controller && switches::IsRunWebTestsSwitchPresent()) {
carloskd9d97942017-02-16 08:58:09531 const base::DictionaryValue& test_flags =
Lukasz Anforowiczf227b4912017-12-22 23:08:59532 blink_test_controller->accumulated_layout_test_runtime_flags_changes();
carloskd9d97942017-02-16 08:58:09533 test_flags.GetBoolean("running_insecure_content_allowed", &allowed_by_test);
534 }
535
536 return allowed_per_prefs || allowed_by_test;
537}
538
Mounir Lamouri11e9ef432018-05-22 03:10:16539gfx::Size Shell::EnterPictureInPicture(const viz::SurfaceId& surface_id,
540 const gfx::Size& natural_size) {
541 // During tests, returning a fake window size to pretent the window was
542 // created and allow tests to run accordingly.
543 return switches::IsRunWebTestsSwitchPresent() ? gfx::Size(42, 42)
544 : gfx::Size(0, 0);
545}
546
pdrcab84ee2015-03-13 21:47:04547gfx::Size Shell::GetShellDefaultSize() {
548 static gfx::Size default_shell_size;
549 if (!default_shell_size.IsEmpty())
550 return default_shell_size;
551 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
552 if (command_line->HasSwitch(switches::kContentShellHostWindowSize)) {
553 const std::string size_str = command_line->GetSwitchValueASCII(
554 switches::kContentShellHostWindowSize);
555 int width, height;
556 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height));
557 default_shell_size = gfx::Size(width, height);
558 } else {
559 default_shell_size = gfx::Size(
560 kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip);
561 }
562 return default_shell_size;
563}
564
Avi Drissman93002212017-09-27 03:20:52565void Shell::TitleWasSet(NavigationEntry* entry) {
[email protected]1ef02d242013-10-07 16:18:53566 if (entry)
567 PlatformSetTitle(entry->GetTitle());
[email protected]aecc085b2012-06-01 18:15:53568}
569
[email protected]7fff43e2013-05-21 20:21:10570void Shell::OnDevToolsWebContentsDestroyed() {
571 devtools_observer_.reset();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28572 devtools_frontend_ = nullptr;
[email protected]7fff43e2013-05-21 20:21:10573}
574
[email protected]9fbd3f862011-09-20 23:31:34575} // namespace content