blob: e2831bbb63de94b81c7ebd51e36dbaddea1181af [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"
gabf64a25e2017-05-12 19:42:5613#include "base/message_loop/message_loop.h"
fdoray896bea12016-06-10 15:52:0114#include "base/run_loop.h"
skyostil95082a62015-06-05 19:53:0715#include "base/single_thread_task_runner.h"
[email protected]21aa99682013-06-11 07:17:0116#include "base/strings/string_number_conversions.h"
17#include "base/strings/string_util.h"
18#include "base/strings/stringprintf.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
gab30f26df2016-05-11 19:37:5520#include "base/threading/thread_task_runner_handle.h"
avi66a07722015-12-25 23:38:1221#include "build/build_config.h"
[email protected]b50452f2014-08-18 12:31:4422#include "content/public/browser/devtools_agent_host.h"
[email protected]0b659b32012-03-26 21:29:3223#include "content/public/browser/navigation_controller.h"
[email protected]b7c504c2013-05-07 14:42:1224#include "content/public/browser/navigation_entry.h"
Yutaka Hirano2109e582018-02-14 07:24:4625#include "content/public/browser/render_process_host.h"
[email protected]0b659b32012-03-26 21:29:3226#include "content/public/browser/render_view_host.h"
avif9ab5d942015-10-15 14:05:4427#include "content/public/browser/render_widget_host.h"
[email protected]0b659b32012-03-26 21:29:3228#include "content/public/browser/web_contents.h"
[email protected]7fff43e2013-05-21 20:21:1029#include "content/public/browser/web_contents_observer.h"
guoweis8efb6d892015-10-12 18:26:1730#include "content/public/common/content_switches.h"
[email protected]1596efb2013-01-17 22:13:0131#include "content/public/common/renderer_preferences.h"
guoweisc537ba22015-11-06 21:20:3132#include "content/public/common/webrtc_ip_handling_policy.h"
jochen5ce1af92016-02-17 20:39:4533#include "content/shell/browser/layout_test/blink_test_controller.h"
jyasskin8057c002015-09-10 19:09:5334#include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factory.h"
chenwilliamfed5bda2017-03-24 02:01:0635#include "content/shell/browser/layout_test/layout_test_devtools_bindings.h"
mkwst6efe7f2e62014-10-08 15:09:0136#include "content/shell/browser/layout_test/layout_test_javascript_dialog_manager.h"
lukasza8e550a02016-04-18 18:34:1737#include "content/shell/browser/layout_test/secondary_test_window_observer.h"
[email protected]de7d61ff2013-08-20 11:30:4138#include "content/shell/browser/shell_browser_main_parts.h"
39#include "content/shell/browser/shell_content_browser_client.h"
40#include "content/shell/browser/shell_devtools_frontend.h"
41#include "content/shell/browser/shell_javascript_dialog_manager.h"
carloskd9d97942017-02-16 08:58:0942#include "content/shell/common/layout_test/layout_test_switches.h"
[email protected]b7c504c2013-05-07 14:42:1243#include "content/shell/common/shell_messages.h"
44#include "content/shell/common/shell_switches.h"
Scott Violeta35f9a42018-03-22 22:00:4445#include "media/media_buildflags.h"
Blink Reformata30d4232018-04-07 15:31:0646#include "third_party/blink/public/web/web_presentation_receiver_flags.h"
[email protected]9fbd3f862011-09-20 23:31:3447
[email protected]9fbd3f862011-09-20 23:31:3448namespace content {
49
pdrcab84ee2015-03-13 21:47:0450const int kDefaultTestWindowWidthDip = 800;
51const int kDefaultTestWindowHeightDip = 600;
[email protected]1e57cab2013-05-28 04:26:1152
[email protected]e99ca5112011-09-26 17:22:5453std::vector<Shell*> Shell::windows_;
[email protected]9e00e6352012-07-30 17:05:1854base::Callback<void(Shell*)> Shell::shell_created_callback_;
[email protected]9fbd3f862011-09-20 23:31:3455
[email protected]11a65b692012-03-30 11:29:1656bool Shell::quit_message_loop_ = true;
57
[email protected]7fff43e2013-05-21 20:21:1058class Shell::DevToolsWebContentsObserver : public WebContentsObserver {
59 public:
60 DevToolsWebContentsObserver(Shell* shell, WebContents* web_contents)
61 : WebContentsObserver(web_contents),
62 shell_(shell) {
63 }
64
65 // WebContentsObserver
dchenge933b3e2014-10-21 11:44:0966 void WebContentsDestroyed() override {
[email protected]7fff43e2013-05-21 20:21:1067 shell_->OnDevToolsWebContentsDestroyed();
68 }
69
70 private:
71 Shell* shell_;
72
73 DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver);
74};
75
erikchenbee5c9622018-04-27 19:30:2576Shell::Shell(std::unique_ptr<WebContents> web_contents)
77 : WebContentsObserver(web_contents.get()),
78 web_contents_(std::move(web_contents)),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:2879 devtools_frontend_(nullptr),
[email protected]001841c92012-12-11 17:00:1380 is_fullscreen_(false),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:2881 window_(nullptr),
sadrul8b11d262015-11-12 18:41:3382#if defined(OS_MACOSX)
[email protected]86b36e672012-12-21 00:09:5183 url_edit_view_(NULL),
sadrul8b11d262015-11-12 18:41:3384#endif
Pavel Feldmanc7cd063c2017-10-06 20:04:2885 headless_(false),
86 hide_toolbar_(false) {
arthursonzognifdd49912017-08-31 08:55:2687 web_contents_->SetDelegate(this);
88
Francois Doraye6161152018-03-27 22:05:3789 if (switches::IsRunLayoutTestSwitchPresent()) {
[email protected]86b36e672012-12-21 00:09:5190 headless_ = true;
Francois Doraye6161152018-03-27 22:05:3791 // In a headless shell, disable occlusion tracking. Otherwise, WebContents
92 // would always behave as if they were occluded, i.e. would not render
93 // frames and would not receive input events.
94 base::CommandLine::ForCurrentProcess()->AppendSwitch(
95 switches::kDisableBackgroundingOccludedWindowsForTesting);
96 }
Pavel Feldmanc7cd063c2017-10-06 20:04:2897
98 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
99 switches::kContentShellHideToolbar))
100 hide_toolbar_ = true;
101
[email protected]9e00e6352012-07-30 17:05:18102 windows_.push_back(this);
103
104 if (!shell_created_callback_.is_null()) {
105 shell_created_callback_.Run(this);
106 shell_created_callback_.Reset();
107 }
[email protected]9fbd3f862011-09-20 23:31:34108}
109
110Shell::~Shell() {
111 PlatformCleanUp();
[email protected]e99ca5112011-09-26 17:22:54112
113 for (size_t i = 0; i < windows_.size(); ++i) {
114 if (windows_[i] == this) {
115 windows_.erase(windows_.begin() + i);
116 break;
117 }
118 }
[email protected]11a65b692012-03-30 11:29:16119
[email protected]b53adf452014-02-07 12:55:08120 if (windows_.empty() && quit_message_loop_) {
121 if (headless_)
122 PlatformExit();
Yutaka Hirano2109e582018-02-14 07:24:46123 for (auto it = RenderProcessHost::AllHostsIterator(); !it.IsAtEnd();
124 it.Advance()) {
125 it.GetCurrentValue()->DisableKeepAliveRefCount();
126 }
skyostil95082a62015-06-05 19:53:07127 base::ThreadTaskRunnerHandle::Get()->PostTask(
ki.stfu800779242015-10-12 22:46:26128 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
[email protected]b53adf452014-02-07 12:55:08129 }
arthursonzognifdd49912017-08-31 08:55:26130
131 web_contents_->SetDelegate(nullptr);
[email protected]9fbd3f862011-09-20 23:31:34132}
133
erikchenbee5c9622018-04-27 19:30:25134Shell* Shell::CreateShell(std::unique_ptr<WebContents> web_contents,
[email protected]c0d036d2013-05-07 12:50:50135 const gfx::Size& initial_size) {
erikchenbee5c9622018-04-27 19:30:25136 WebContents* raw_web_contents = web_contents.get();
137 Shell* shell = new Shell(std::move(web_contents));
[email protected]c0d036d2013-05-07 12:50:50138 shell->PlatformCreateWindow(initial_size.width(), initial_size.height());
[email protected]3fd84032012-01-12 18:20:17139
[email protected]5cba3bf2012-01-14 02:40:35140 shell->PlatformSetContents();
[email protected]3fd84032012-01-12 18:20:17141
142 shell->PlatformResizeSubViews();
[email protected]1596efb2013-01-17 22:13:01143
creisb6561df2016-02-11 20:20:54144 // Note: Do not make RenderFrameHost or RenderViewHost specific state changes
145 // here, because they will be forgotten after a cross-process navigation. Use
146 // RenderFrameCreated or RenderViewCreated instead.
lukasza381b0492016-03-10 16:48:43147 if (switches::IsRunLayoutTestSwitchPresent()) {
erikchenbee5c9622018-04-27 19:30:25148 raw_web_contents->GetMutableRendererPrefs()->use_custom_colors = false;
149 raw_web_contents->GetRenderViewHost()->SyncRendererPrefs();
[email protected]1596efb2013-01-17 22:13:01150 }
151
Brett Wilson0748bf412016-11-22 17:55:46152#if BUILDFLAG(ENABLE_WEBRTC)
lukasza381b0492016-03-10 16:48:43153 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
guoweis4ee48592015-12-02 06:37:07154 if (command_line->HasSwitch(switches::kForceWebRtcIPHandlingPolicy)) {
erikchenbee5c9622018-04-27 19:30:25155 raw_web_contents->GetMutableRendererPrefs()->webrtc_ip_handling_policy =
guoweis4ee48592015-12-02 06:37:07156 command_line->GetSwitchValueASCII(
157 switches::kForceWebRtcIPHandlingPolicy);
guoweis8efb6d892015-10-12 18:26:17158 }
159#endif
160
[email protected]3fd84032012-01-12 18:20:17161 return shell;
162}
163
[email protected]11a65b692012-03-30 11:29:16164void Shell::CloseAllWindows() {
[email protected]997ec9f2012-11-21 04:44:14165 base::AutoReset<bool> auto_reset(&quit_message_loop_, false);
[email protected]b50452f2014-08-18 12:31:44166 DevToolsAgentHost::DetachAllClients();
[email protected]11a65b692012-03-30 11:29:16167 std::vector<Shell*> open_windows(windows_);
168 for (size_t i = 0; i < open_windows.size(); ++i)
169 open_windows[i]->Close();
fdoray896bea12016-06-10 15:52:01170 base::RunLoop().RunUntilIdle();
dmazzoni948fbc72015-05-17 07:57:33171 PlatformExit();
[email protected]11a65b692012-03-30 11:29:16172}
173
[email protected]9e00e6352012-07-30 17:05:18174void Shell::SetShellCreatedCallback(
175 base::Callback<void(Shell*)> shell_created_callback) {
176 DCHECK(shell_created_callback_.is_null());
Tommy Nyquist4b749d02018-03-20 21:46:29177 shell_created_callback_ = std::move(shell_created_callback);
[email protected]9e00e6352012-07-30 17:05:18178}
179
[email protected]74830f02012-01-30 22:27:04180Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) {
181 for (size_t i = 0; i < windows_.size(); ++i) {
[email protected]0b659b32012-03-26 21:29:32182 if (windows_[i]->web_contents() &&
183 windows_[i]->web_contents()->GetRenderViewHost() == rvh) {
[email protected]74830f02012-01-30 22:27:04184 return windows_[i];
185 }
186 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28187 return nullptr;
[email protected]74830f02012-01-30 22:27:04188}
189
[email protected]6153b272013-01-25 22:29:23190// static
191void Shell::Initialize() {
pdrcab84ee2015-03-13 21:47:04192 PlatformInitialize(GetShellDefaultSize());
[email protected]6153b272013-01-25 22:29:23193}
194
[email protected]a2904092013-10-15 04:53:59195gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) {
196 if (!initial_size.IsEmpty())
197 return initial_size;
pdrcab84ee2015-03-13 21:47:04198 return GetShellDefaultSize();
[email protected]a2904092013-10-15 04:53:59199}
200
[email protected]bdcf9152012-07-19 17:43:21201Shell* Shell::CreateNewWindow(BrowserContext* browser_context,
[email protected]e99ca5112011-09-26 17:22:54202 const GURL& url,
lukasza04130152016-10-21 20:26:32203 const scoped_refptr<SiteInstance>& site_instance,
[email protected]cdb806722013-01-10 14:18:23204 const gfx::Size& initial_size) {
[email protected]54944cde2012-12-09 09:24:59205 WebContents::CreateParams create_params(browser_context, site_instance);
mark a. foltzef394fce2017-10-21 09:11:02206 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
207 switches::kForcePresentationReceiverForTesting)) {
208 create_params.starting_sandbox_flags =
209 blink::kPresentationReceiverSandboxFlags;
210 }
[email protected]a2904092013-10-15 04:53:59211 create_params.initial_size = AdjustWindowSize(initial_size);
erikchenbee5c9622018-04-27 19:30:25212 std::unique_ptr<WebContents> web_contents =
Erik Chenbb8e738e2018-04-28 14:10:43213 WebContents::Create(create_params);
erikchenbee5c9622018-04-27 19:30:25214 Shell* shell =
215 CreateShell(std::move(web_contents), create_params.initial_size);
[email protected]e99ca5112011-09-26 17:22:54216 if (!url.is_empty())
217 shell->LoadURL(url);
[email protected]9fbd3f862011-09-20 23:31:34218 return shell;
219}
220
221void Shell::LoadURL(const GURL& url) {
Alex Moshchuk7e26eca2018-03-03 01:34:29222 LoadURLForFrame(
223 url, std::string(),
224 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED |
225 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR));
[email protected]d2494ff2013-02-20 08:22:37226}
227
Alex Moshchuk7e26eca2018-03-03 01:34:29228void Shell::LoadURLForFrame(const GURL& url,
229 const std::string& frame_name,
230 ui::PageTransition transition_type) {
[email protected]d2494ff2013-02-20 08:22:37231 NavigationController::LoadURLParams params(url);
[email protected]d2494ff2013-02-20 08:22:37232 params.frame_name = frame_name;
Alex Moshchuk7e26eca2018-03-03 01:34:29233 params.transition_type = transition_type;
[email protected]d2494ff2013-02-20 08:22:37234 web_contents_->GetController().LoadURLWithParams(params);
[email protected]fc2b46b2014-05-03 16:33:45235 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34236}
237
[email protected]76bdecb2014-04-16 17:58:08238void Shell::LoadDataWithBaseURL(const GURL& url, const std::string& data,
239 const GURL& base_url) {
boliuec93ea92016-02-17 22:23:07240 bool load_as_string = false;
241 LoadDataWithBaseURLInternal(url, data, base_url, load_as_string);
242}
243
244#if defined(OS_ANDROID)
245void Shell::LoadDataAsStringWithBaseURL(const GURL& url,
246 const std::string& data,
247 const GURL& base_url) {
248 bool load_as_string = true;
249 LoadDataWithBaseURLInternal(url, data, base_url, load_as_string);
250}
251#endif
252
253void Shell::LoadDataWithBaseURLInternal(const GURL& url,
254 const std::string& data,
255 const GURL& base_url,
256 bool load_as_string) {
257#if !defined(OS_ANDROID)
258 DCHECK(!load_as_string); // Only supported on Android.
259#endif
260
261 NavigationController::LoadURLParams params(GURL::EmptyGURL());
262 const std::string data_url_header = "data:text/html;charset=utf-8,";
263 if (load_as_string) {
264 params.url = GURL(data_url_header);
265 std::string data_url_as_string = data_url_header + data;
266#if defined(OS_ANDROID)
267 params.data_url_as_string =
268 base::RefCountedString::TakeString(&data_url_as_string);
269#endif
270 } else {
271 params.url = GURL(data_url_header + data);
272 }
273
[email protected]76bdecb2014-04-16 17:58:08274 params.load_type = NavigationController::LOAD_TYPE_DATA;
275 params.base_url_for_data_url = base_url;
276 params.virtual_url_for_data_url = url;
277 params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE;
278 web_contents_->GetController().LoadURLWithParams(params);
[email protected]fc2b46b2014-05-03 16:33:45279 web_contents_->Focus();
[email protected]76bdecb2014-04-16 17:58:08280}
281
[email protected]a2904092013-10-15 04:53:59282void Shell::AddNewContents(WebContents* source,
erikchenbee5c9622018-04-27 19:30:25283 std::unique_ptr<WebContents> new_contents,
[email protected]a2904092013-10-15 04:53:59284 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:39285 const gfx::Rect& initial_rect,
[email protected]a2904092013-10-15 04:53:59286 bool user_gesture,
287 bool* was_blocked) {
erikchenbee5c9622018-04-27 19:30:25288 WebContents* raw_new_contents = new_contents.get();
289 CreateShell(std::move(new_contents), AdjustWindowSize(initial_rect.size()));
lukasza381b0492016-03-10 16:48:43290 if (switches::IsRunLayoutTestSwitchPresent())
erikchenbee5c9622018-04-27 19:30:25291 SecondaryTestWindowObserver::CreateForWebContents(raw_new_contents);
[email protected]a2904092013-10-15 04:53:59292}
293
[email protected]9fbd3f862011-09-20 23:31:34294void Shell::GoBackOrForward(int offset) {
[email protected]0b659b32012-03-26 21:29:32295 web_contents_->GetController().GoToOffset(offset);
[email protected]fc2b46b2014-05-03 16:33:45296 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34297}
298
299void Shell::Reload() {
toyoshim6142d96f2016-12-19 09:07:25300 web_contents_->GetController().Reload(ReloadType::NORMAL, false);
[email protected]fc2b46b2014-05-03 16:33:45301 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34302}
303
toyoshime5aaf6a2016-05-18 08:07:48304void Shell::ReloadBypassingCache() {
toyoshim6142d96f2016-12-19 09:07:25305 web_contents_->GetController().Reload(ReloadType::BYPASSING_CACHE, false);
toyoshime5aaf6a2016-05-18 08:07:48306 web_contents_->Focus();
307}
308
[email protected]9fbd3f862011-09-20 23:31:34309void Shell::Stop() {
[email protected]0b659b32012-03-26 21:29:32310 web_contents_->Stop();
[email protected]fc2b46b2014-05-03 16:33:45311 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34312}
313
[email protected]e3b10d12014-03-28 16:06:09314void Shell::UpdateNavigationControls(bool to_different_document) {
[email protected]0b659b32012-03-26 21:29:32315 int current_index = web_contents_->GetController().GetCurrentEntryIndex();
316 int max_index = web_contents_->GetController().GetEntryCount() - 1;
[email protected]9fbd3f862011-09-20 23:31:34317
318 PlatformEnableUIControl(BACK_BUTTON, current_index > 0);
319 PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index);
[email protected]e3b10d12014-03-28 16:06:09320 PlatformEnableUIControl(STOP_BUTTON,
321 to_different_document && web_contents_->IsLoading());
[email protected]9fbd3f862011-09-20 23:31:34322}
323
[email protected]7c17b6992012-08-09 16:16:30324void Shell::ShowDevTools() {
mohsen6eb57fb2016-07-22 03:14:08325 if (!devtools_frontend_) {
326 devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents());
327 devtools_observer_.reset(new DevToolsWebContentsObserver(
328 this, devtools_frontend_->frontend_shell()->web_contents()));
329 }
[email protected]3142e5d2014-02-07 00:54:46330
mohsen6eb57fb2016-07-22 03:14:08331 devtools_frontend_->Activate();
332 devtools_frontend_->Focus();
[email protected]7c17b6992012-08-09 16:16:30333}
334
[email protected]001841c92012-12-11 17:00:13335void Shell::CloseDevTools() {
[email protected]0773e0c2013-01-25 15:57:57336 if (!devtools_frontend_)
[email protected]001841c92012-12-11 17:00:13337 return;
[email protected]7fff43e2013-05-21 20:21:10338 devtools_observer_.reset();
[email protected]0773e0c2013-01-25 15:57:57339 devtools_frontend_->Close();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28340 devtools_frontend_ = nullptr;
[email protected]001841c92012-12-11 17:00:13341}
342
[email protected]9fbd3f862011-09-20 23:31:34343gfx::NativeView Shell::GetContentView() {
[email protected]59383c782013-04-17 16:43:27344 if (!web_contents_)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28345 return nullptr;
[email protected]fc2b46b2014-05-03 16:33:45346 return web_contents_->GetNativeView();
[email protected]9fbd3f862011-09-20 23:31:34347}
348
alexmos5a98a052016-01-06 00:15:02349WebContents* Shell::OpenURLFromTab(WebContents* source,
350 const OpenURLParams& params) {
lukasza04130152016-10-21 20:26:32351 WebContents* target = nullptr;
352 switch (params.disposition) {
353 case WindowOpenDisposition::CURRENT_TAB:
354 target = source;
355 break;
356
357 // Normally, the difference between NEW_POPUP and NEW_WINDOW is that a popup
358 // should have no toolbar, no status bar, no menu bar, no scrollbars and be
359 // not resizable. For simplicity and to enable new testing scenarios in
360 // content shell and layout tests, popups don't get special treatment below
361 // (i.e. they will have a toolbar and other things described here).
362 case WindowOpenDisposition::NEW_POPUP:
lukaszabe2f0da2017-04-25 00:43:00363 case WindowOpenDisposition::NEW_WINDOW:
364 // content_shell doesn't really support tabs, but some layout tests use
365 // middle click (which translates into kNavigationPolicyNewBackgroundTab),
366 // so we treat the cases below just like a NEW_WINDOW disposition.
367 case WindowOpenDisposition::NEW_BACKGROUND_TAB:
368 case WindowOpenDisposition::NEW_FOREGROUND_TAB: {
lukasza04130152016-10-21 20:26:32369 Shell* new_window =
370 Shell::CreateNewWindow(source->GetBrowserContext(),
371 GURL(), // Don't load anything just yet.
372 params.source_site_instance,
373 gfx::Size()); // Use default size.
374 target = new_window->web_contents();
375 if (switches::IsRunLayoutTestSwitchPresent())
376 SecondaryTestWindowObserver::CreateForWebContents(target);
377 break;
378 }
379
380 // No tabs in content_shell:
381 case WindowOpenDisposition::SINGLETON_TAB:
lukasza04130152016-10-21 20:26:32382 // No incognito mode in content_shell:
383 case WindowOpenDisposition::OFF_THE_RECORD:
384 // TODO(lukasza): Investigate if some layout tests might need support for
385 // SAVE_TO_DISK disposition. This would probably require that
386 // BlinkTestController always sets up and cleans up a temporary directory
387 // as the default downloads destinations for the duration of a test.
388 case WindowOpenDisposition::SAVE_TO_DISK:
389 // Ignoring requests with disposition == IGNORE_ACTION...
390 case WindowOpenDisposition::IGNORE_ACTION:
391 default:
392 return nullptr;
393 }
alexmos5a98a052016-01-06 00:15:02394
395 NavigationController::LoadURLParams load_url_params(params.url);
396 load_url_params.source_site_instance = params.source_site_instance;
397 load_url_params.transition_type = params.transition;
398 load_url_params.frame_tree_node_id = params.frame_tree_node_id;
399 load_url_params.referrer = params.referrer;
400 load_url_params.redirect_chain = params.redirect_chain;
401 load_url_params.extra_headers = params.extra_headers;
402 load_url_params.is_renderer_initiated = params.is_renderer_initiated;
alexmos5a98a052016-01-06 00:15:02403 load_url_params.should_replace_current_entry =
404 params.should_replace_current_entry;
Jochen Eisinger9f9789e92018-03-07 16:44:01405 load_url_params.suggested_filename = params.suggested_filename;
alexmos5a98a052016-01-06 00:15:02406
lukasza477a5a22016-06-16 18:28:43407 if (params.uses_post) {
408 load_url_params.load_type = NavigationController::LOAD_TYPE_HTTP_POST;
409 load_url_params.post_data = params.post_data;
alexmos5a98a052016-01-06 00:15:02410 }
411
lukasza04130152016-10-21 20:26:32412 target->GetController().LoadURLWithParams(load_url_params);
413 return target;
alexmos5a98a052016-01-06 00:15:02414}
415
[email protected]e3b10d12014-03-28 16:06:09416void Shell::LoadingStateChanged(WebContents* source,
417 bool to_different_document) {
418 UpdateNavigationControls(to_different_document);
[email protected]15aea412012-01-19 03:18:50419 PlatformSetIsLoading(source->IsLoading());
[email protected]e99ca5112011-09-26 17:22:54420}
421
Dave Tapuska3ed44192018-05-01 18:53:30422void Shell::EnterFullscreenModeForTab(
423 WebContents* web_contents,
424 const GURL& origin,
425 const blink::WebFullscreenOptions& options) {
mlamouri7a78d6fd2015-01-17 13:23:53426 ToggleFullscreenModeForTab(web_contents, true);
427}
428
429void Shell::ExitFullscreenModeForTab(WebContents* web_contents) {
430 ToggleFullscreenModeForTab(web_contents, false);
431}
432
[email protected]99c014c2012-11-27 12:03:42433void Shell::ToggleFullscreenModeForTab(WebContents* web_contents,
434 bool enter_fullscreen) {
435#if defined(OS_ANDROID)
436 PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen);
437#endif
lukasza381b0492016-03-10 16:48:43438 if (!switches::IsRunLayoutTestSwitchPresent())
[email protected]99c014c2012-11-27 12:03:42439 return;
440 if (is_fullscreen_ != enter_fullscreen) {
441 is_fullscreen_ = enter_fullscreen;
Fady Samuel0b911822018-04-25 13:22:16442 web_contents->GetRenderViewHost()
443 ->GetWidget()
444 ->SynchronizeVisualProperties();
[email protected]99c014c2012-11-27 12:03:42445 }
446}
447
448bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const {
449#if defined(OS_ANDROID)
450 return PlatformIsFullscreenForTabOrPending(web_contents);
451#else
452 return is_fullscreen_;
453#endif
454}
455
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12456blink::WebDisplayMode Shell::GetDisplayMode(
457 const WebContents* web_contents) const {
458 // TODO : should return blink::WebDisplayModeFullscreen wherever user puts
459 // a browser window into fullscreen (not only in case of renderer-initiated
460 // fullscreen mode): crbug.com/476874.
Blink Reformat1c4d759e2017-04-09 16:34:54461 return IsFullscreenForTabOrPending(web_contents)
462 ? blink::kWebDisplayModeFullscreen
463 : blink::kWebDisplayModeBrowser;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12464}
465
[email protected]f78439002012-11-28 14:45:59466void Shell::RequestToLockMouse(WebContents* web_contents,
467 bool user_gesture,
468 bool last_unlocked_by_target) {
469 web_contents->GotResponseToLockMouseRequest(true);
470}
471
[email protected]9e00e6352012-07-30 17:05:18472void Shell::CloseContents(WebContents* source) {
473 Close();
474}
475
[email protected]067310262012-11-22 14:30:41476bool Shell::CanOverscrollContent() const {
477#if defined(USE_AURA)
478 return true;
479#else
480 return false;
481#endif
482}
483
[email protected]3bbacc5b2012-04-17 17:46:15484void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) {
[email protected]4e3c7522013-08-13 11:53:18485 PlatformSetAddressBarURL(web_contents->GetLastCommittedURL());
[email protected]e99ca5112011-09-26 17:22:54486}
487
mathiash72a5e462014-11-19 08:18:50488JavaScriptDialogManager* Shell::GetJavaScriptDialogManager(
489 WebContents* source) {
mkwst6efe7f2e62014-10-08 15:09:01490 if (!dialog_manager_) {
lukasza381b0492016-03-10 16:48:43491 dialog_manager_.reset(switches::IsRunLayoutTestSwitchPresent()
492 ? new LayoutTestJavaScriptDialogManager
493 : new ShellJavaScriptDialogManager);
mkwst6efe7f2e62014-10-08 15:09:01494 }
[email protected]71a88bb2013-02-01 22:05:15495 return dialog_manager_.get();
[email protected]f2210022012-03-29 00:36:08496}
497
dcheng6003e0b2016-04-09 18:42:34498std::unique_ptr<BluetoothChooser> Shell::RunBluetoothChooser(
jyasskin93649a52016-02-17 19:57:02499 RenderFrameHost* frame,
500 const BluetoothChooser::EventHandler& event_handler) {
Lukasz Anforowiczf227b4912017-12-22 23:08:59501 BlinkTestController* blink_test_controller = BlinkTestController::Get();
502 if (blink_test_controller && switches::IsRunLayoutTestSwitchPresent())
503 return blink_test_controller->RunBluetoothChooser(frame, event_handler);
jyasskin8057c002015-09-10 19:09:53504 return nullptr;
505}
506
avia90ae4e2016-11-11 20:49:33507bool Shell::DidAddMessageToConsole(WebContents* source,
508 int32_t level,
509 const base::string16& message,
510 int32_t line_no,
511 const base::string16& source_id) {
lukasza381b0492016-03-10 16:48:43512 return switches::IsRunLayoutTestSwitchPresent();
[email protected]efb5f572012-01-29 10:57:33513}
514
Avi Drissman8920def2018-01-31 19:53:36515void Shell::RendererUnresponsive(WebContents* source,
Avi Drissman1572e8c3c2018-02-02 19:06:36516 RenderWidgetHost* render_widget_host) {
Lukasz Anforowiczf227b4912017-12-22 23:08:59517 BlinkTestController* blink_test_controller = BlinkTestController::Get();
518 if (blink_test_controller && switches::IsRunLayoutTestSwitchPresent())
519 blink_test_controller->RendererUnresponsive();
[email protected]5bf68f22012-08-31 07:38:10520}
521
[email protected]233567d2013-02-27 20:22:02522void Shell::ActivateContents(WebContents* contents) {
avif9ab5d942015-10-15 14:05:44523 contents->GetRenderViewHost()->GetWidget()->Focus();
[email protected]233567d2013-02-27 20:22:02524}
525
carloskd9d97942017-02-16 08:58:09526bool Shell::ShouldAllowRunningInsecureContent(
527 content::WebContents* web_contents,
528 bool allowed_per_prefs,
529 const url::Origin& origin,
530 const GURL& resource_url) {
531 bool allowed_by_test = false;
Lukasz Anforowiczf227b4912017-12-22 23:08:59532 BlinkTestController* blink_test_controller = BlinkTestController::Get();
533 if (blink_test_controller &&
534 base::CommandLine::ForCurrentProcess()->HasSwitch(
carloskd9d97942017-02-16 08:58:09535 switches::kRunLayoutTest)) {
536 const base::DictionaryValue& test_flags =
Lukasz Anforowiczf227b4912017-12-22 23:08:59537 blink_test_controller->accumulated_layout_test_runtime_flags_changes();
carloskd9d97942017-02-16 08:58:09538 test_flags.GetBoolean("running_insecure_content_allowed", &allowed_by_test);
539 }
540
541 return allowed_per_prefs || allowed_by_test;
542}
543
pdrcab84ee2015-03-13 21:47:04544gfx::Size Shell::GetShellDefaultSize() {
545 static gfx::Size default_shell_size;
546 if (!default_shell_size.IsEmpty())
547 return default_shell_size;
548 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
549 if (command_line->HasSwitch(switches::kContentShellHostWindowSize)) {
550 const std::string size_str = command_line->GetSwitchValueASCII(
551 switches::kContentShellHostWindowSize);
552 int width, height;
553 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height));
554 default_shell_size = gfx::Size(width, height);
555 } else {
556 default_shell_size = gfx::Size(
557 kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip);
558 }
559 return default_shell_size;
560}
561
Avi Drissman93002212017-09-27 03:20:52562void Shell::TitleWasSet(NavigationEntry* entry) {
[email protected]1ef02d242013-10-07 16:18:53563 if (entry)
564 PlatformSetTitle(entry->GetTitle());
[email protected]aecc085b2012-06-01 18:15:53565}
566
[email protected]7fff43e2013-05-21 20:21:10567void Shell::OnDevToolsWebContentsDestroyed() {
568 devtools_observer_.reset();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28569 devtools_frontend_ = nullptr;
[email protected]7fff43e2013-05-21 20:21:10570}
571
[email protected]9fbd3f862011-09-20 23:31:34572} // namespace content