blob: 24d14f19000359c034c6a760d5dc8cbce4a31dc2 [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"
[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"
Brett Wilson0748bf412016-11-22 17:55:4644#include "media/media_features.h"
mark a. foltzef394fce2017-10-21 09:11:0245#include "third_party/WebKit/public/web/WebPresentationReceiverFlags.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
[email protected]0b659b32012-03-26 21:29:3275Shell::Shell(WebContents* web_contents)
[email protected]1ef02d242013-10-07 16:18:5376 : WebContentsObserver(web_contents),
arthursonzognifdd49912017-08-31 08:55:2677 web_contents_(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
lukasza381b0492016-03-10 16:48:4388 if (switches::IsRunLayoutTestSwitchPresent())
[email protected]86b36e672012-12-21 00:09:5189 headless_ = true;
Pavel Feldmanc7cd063c2017-10-06 20:04:2890
91 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
92 switches::kContentShellHideToolbar))
93 hide_toolbar_ = true;
94
[email protected]9e00e6352012-07-30 17:05:1895 windows_.push_back(this);
96
97 if (!shell_created_callback_.is_null()) {
98 shell_created_callback_.Run(this);
99 shell_created_callback_.Reset();
100 }
[email protected]9fbd3f862011-09-20 23:31:34101}
102
103Shell::~Shell() {
104 PlatformCleanUp();
[email protected]e99ca5112011-09-26 17:22:54105
106 for (size_t i = 0; i < windows_.size(); ++i) {
107 if (windows_[i] == this) {
108 windows_.erase(windows_.begin() + i);
109 break;
110 }
111 }
[email protected]11a65b692012-03-30 11:29:16112
[email protected]b53adf452014-02-07 12:55:08113 if (windows_.empty() && quit_message_loop_) {
114 if (headless_)
115 PlatformExit();
skyostil95082a62015-06-05 19:53:07116 base::ThreadTaskRunnerHandle::Get()->PostTask(
ki.stfu800779242015-10-12 22:46:26117 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
[email protected]b53adf452014-02-07 12:55:08118 }
arthursonzognifdd49912017-08-31 08:55:26119
120 web_contents_->SetDelegate(nullptr);
[email protected]9fbd3f862011-09-20 23:31:34121}
122
[email protected]c0d036d2013-05-07 12:50:50123Shell* Shell::CreateShell(WebContents* web_contents,
124 const gfx::Size& initial_size) {
[email protected]0b659b32012-03-26 21:29:32125 Shell* shell = new Shell(web_contents);
[email protected]c0d036d2013-05-07 12:50:50126 shell->PlatformCreateWindow(initial_size.width(), initial_size.height());
[email protected]3fd84032012-01-12 18:20:17127
[email protected]5cba3bf2012-01-14 02:40:35128 shell->PlatformSetContents();
[email protected]3fd84032012-01-12 18:20:17129
130 shell->PlatformResizeSubViews();
[email protected]1596efb2013-01-17 22:13:01131
creisb6561df2016-02-11 20:20:54132 // Note: Do not make RenderFrameHost or RenderViewHost specific state changes
133 // here, because they will be forgotten after a cross-process navigation. Use
134 // RenderFrameCreated or RenderViewCreated instead.
lukasza381b0492016-03-10 16:48:43135 if (switches::IsRunLayoutTestSwitchPresent()) {
[email protected]1596efb2013-01-17 22:13:01136 web_contents->GetMutableRendererPrefs()->use_custom_colors = false;
137 web_contents->GetRenderViewHost()->SyncRendererPrefs();
138 }
139
Brett Wilson0748bf412016-11-22 17:55:46140#if BUILDFLAG(ENABLE_WEBRTC)
lukasza381b0492016-03-10 16:48:43141 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
guoweis4ee48592015-12-02 06:37:07142 if (command_line->HasSwitch(switches::kForceWebRtcIPHandlingPolicy)) {
guoweisc537ba22015-11-06 21:20:31143 web_contents->GetMutableRendererPrefs()->webrtc_ip_handling_policy =
guoweis4ee48592015-12-02 06:37:07144 command_line->GetSwitchValueASCII(
145 switches::kForceWebRtcIPHandlingPolicy);
guoweis8efb6d892015-10-12 18:26:17146 }
147#endif
148
[email protected]3fd84032012-01-12 18:20:17149 return shell;
150}
151
[email protected]11a65b692012-03-30 11:29:16152void Shell::CloseAllWindows() {
[email protected]997ec9f2012-11-21 04:44:14153 base::AutoReset<bool> auto_reset(&quit_message_loop_, false);
[email protected]b50452f2014-08-18 12:31:44154 DevToolsAgentHost::DetachAllClients();
[email protected]11a65b692012-03-30 11:29:16155 std::vector<Shell*> open_windows(windows_);
156 for (size_t i = 0; i < open_windows.size(); ++i)
157 open_windows[i]->Close();
fdoray896bea12016-06-10 15:52:01158 base::RunLoop().RunUntilIdle();
dmazzoni948fbc72015-05-17 07:57:33159 PlatformExit();
[email protected]11a65b692012-03-30 11:29:16160}
161
[email protected]9e00e6352012-07-30 17:05:18162void Shell::SetShellCreatedCallback(
163 base::Callback<void(Shell*)> shell_created_callback) {
164 DCHECK(shell_created_callback_.is_null());
165 shell_created_callback_ = shell_created_callback;
166}
167
[email protected]74830f02012-01-30 22:27:04168Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) {
169 for (size_t i = 0; i < windows_.size(); ++i) {
[email protected]0b659b32012-03-26 21:29:32170 if (windows_[i]->web_contents() &&
171 windows_[i]->web_contents()->GetRenderViewHost() == rvh) {
[email protected]74830f02012-01-30 22:27:04172 return windows_[i];
173 }
174 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28175 return nullptr;
[email protected]74830f02012-01-30 22:27:04176}
177
[email protected]6153b272013-01-25 22:29:23178// static
179void Shell::Initialize() {
pdrcab84ee2015-03-13 21:47:04180 PlatformInitialize(GetShellDefaultSize());
[email protected]6153b272013-01-25 22:29:23181}
182
[email protected]a2904092013-10-15 04:53:59183gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) {
184 if (!initial_size.IsEmpty())
185 return initial_size;
pdrcab84ee2015-03-13 21:47:04186 return GetShellDefaultSize();
[email protected]a2904092013-10-15 04:53:59187}
188
[email protected]bdcf9152012-07-19 17:43:21189Shell* Shell::CreateNewWindow(BrowserContext* browser_context,
[email protected]e99ca5112011-09-26 17:22:54190 const GURL& url,
lukasza04130152016-10-21 20:26:32191 const scoped_refptr<SiteInstance>& site_instance,
[email protected]cdb806722013-01-10 14:18:23192 const gfx::Size& initial_size) {
[email protected]54944cde2012-12-09 09:24:59193 WebContents::CreateParams create_params(browser_context, site_instance);
mark a. foltzef394fce2017-10-21 09:11:02194 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
195 switches::kForcePresentationReceiverForTesting)) {
196 create_params.starting_sandbox_flags =
197 blink::kPresentationReceiverSandboxFlags;
198 }
[email protected]a2904092013-10-15 04:53:59199 create_params.initial_size = AdjustWindowSize(initial_size);
[email protected]54944cde2012-12-09 09:24:59200 WebContents* web_contents = WebContents::Create(create_params);
[email protected]c0d036d2013-05-07 12:50:50201 Shell* shell = CreateShell(web_contents, create_params.initial_size);
[email protected]e99ca5112011-09-26 17:22:54202 if (!url.is_empty())
203 shell->LoadURL(url);
[email protected]9fbd3f862011-09-20 23:31:34204 return shell;
205}
206
207void Shell::LoadURL(const GURL& url) {
[email protected]d2494ff2013-02-20 08:22:37208 LoadURLForFrame(url, std::string());
209}
210
211void Shell::LoadURLForFrame(const GURL& url, const std::string& frame_name) {
212 NavigationController::LoadURLParams params(url);
Sylvain Defresnec6ccc77d2014-09-19 10:19:35213 params.transition_type = ui::PageTransitionFromInt(
214 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
[email protected]d2494ff2013-02-20 08:22:37215 params.frame_name = frame_name;
216 web_contents_->GetController().LoadURLWithParams(params);
[email protected]fc2b46b2014-05-03 16:33:45217 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34218}
219
[email protected]76bdecb2014-04-16 17:58:08220void Shell::LoadDataWithBaseURL(const GURL& url, const std::string& data,
221 const GURL& base_url) {
boliuec93ea92016-02-17 22:23:07222 bool load_as_string = false;
223 LoadDataWithBaseURLInternal(url, data, base_url, load_as_string);
224}
225
226#if defined(OS_ANDROID)
227void Shell::LoadDataAsStringWithBaseURL(const GURL& url,
228 const std::string& data,
229 const GURL& base_url) {
230 bool load_as_string = true;
231 LoadDataWithBaseURLInternal(url, data, base_url, load_as_string);
232}
233#endif
234
235void Shell::LoadDataWithBaseURLInternal(const GURL& url,
236 const std::string& data,
237 const GURL& base_url,
238 bool load_as_string) {
239#if !defined(OS_ANDROID)
240 DCHECK(!load_as_string); // Only supported on Android.
241#endif
242
243 NavigationController::LoadURLParams params(GURL::EmptyGURL());
244 const std::string data_url_header = "data:text/html;charset=utf-8,";
245 if (load_as_string) {
246 params.url = GURL(data_url_header);
247 std::string data_url_as_string = data_url_header + data;
248#if defined(OS_ANDROID)
249 params.data_url_as_string =
250 base::RefCountedString::TakeString(&data_url_as_string);
251#endif
252 } else {
253 params.url = GURL(data_url_header + data);
254 }
255
[email protected]76bdecb2014-04-16 17:58:08256 params.load_type = NavigationController::LOAD_TYPE_DATA;
257 params.base_url_for_data_url = base_url;
258 params.virtual_url_for_data_url = url;
259 params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE;
260 web_contents_->GetController().LoadURLWithParams(params);
[email protected]fc2b46b2014-05-03 16:33:45261 web_contents_->Focus();
[email protected]76bdecb2014-04-16 17:58:08262}
263
[email protected]a2904092013-10-15 04:53:59264void Shell::AddNewContents(WebContents* source,
265 WebContents* new_contents,
266 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:39267 const gfx::Rect& initial_rect,
[email protected]a2904092013-10-15 04:53:59268 bool user_gesture,
269 bool* was_blocked) {
bokan107a47f2015-02-03 23:23:39270 CreateShell(new_contents, AdjustWindowSize(initial_rect.size()));
lukasza381b0492016-03-10 16:48:43271 if (switches::IsRunLayoutTestSwitchPresent())
lukasza8e550a02016-04-18 18:34:17272 SecondaryTestWindowObserver::CreateForWebContents(new_contents);
[email protected]a2904092013-10-15 04:53:59273}
274
[email protected]9fbd3f862011-09-20 23:31:34275void Shell::GoBackOrForward(int offset) {
[email protected]0b659b32012-03-26 21:29:32276 web_contents_->GetController().GoToOffset(offset);
[email protected]fc2b46b2014-05-03 16:33:45277 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34278}
279
280void Shell::Reload() {
toyoshim6142d96f2016-12-19 09:07:25281 web_contents_->GetController().Reload(ReloadType::NORMAL, false);
[email protected]fc2b46b2014-05-03 16:33:45282 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34283}
284
toyoshime5aaf6a2016-05-18 08:07:48285void Shell::ReloadBypassingCache() {
toyoshim6142d96f2016-12-19 09:07:25286 web_contents_->GetController().Reload(ReloadType::BYPASSING_CACHE, false);
toyoshime5aaf6a2016-05-18 08:07:48287 web_contents_->Focus();
288}
289
[email protected]9fbd3f862011-09-20 23:31:34290void Shell::Stop() {
[email protected]0b659b32012-03-26 21:29:32291 web_contents_->Stop();
[email protected]fc2b46b2014-05-03 16:33:45292 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34293}
294
[email protected]e3b10d12014-03-28 16:06:09295void Shell::UpdateNavigationControls(bool to_different_document) {
[email protected]0b659b32012-03-26 21:29:32296 int current_index = web_contents_->GetController().GetCurrentEntryIndex();
297 int max_index = web_contents_->GetController().GetEntryCount() - 1;
[email protected]9fbd3f862011-09-20 23:31:34298
299 PlatformEnableUIControl(BACK_BUTTON, current_index > 0);
300 PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index);
[email protected]e3b10d12014-03-28 16:06:09301 PlatformEnableUIControl(STOP_BUTTON,
302 to_different_document && web_contents_->IsLoading());
[email protected]9fbd3f862011-09-20 23:31:34303}
304
[email protected]7c17b6992012-08-09 16:16:30305void Shell::ShowDevTools() {
mohsen6eb57fb2016-07-22 03:14:08306 if (!devtools_frontend_) {
307 devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents());
308 devtools_observer_.reset(new DevToolsWebContentsObserver(
309 this, devtools_frontend_->frontend_shell()->web_contents()));
310 }
[email protected]3142e5d2014-02-07 00:54:46311
mohsen6eb57fb2016-07-22 03:14:08312 devtools_frontend_->Activate();
313 devtools_frontend_->Focus();
[email protected]7c17b6992012-08-09 16:16:30314}
315
[email protected]001841c92012-12-11 17:00:13316void Shell::CloseDevTools() {
[email protected]0773e0c2013-01-25 15:57:57317 if (!devtools_frontend_)
[email protected]001841c92012-12-11 17:00:13318 return;
[email protected]7fff43e2013-05-21 20:21:10319 devtools_observer_.reset();
[email protected]0773e0c2013-01-25 15:57:57320 devtools_frontend_->Close();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28321 devtools_frontend_ = nullptr;
[email protected]001841c92012-12-11 17:00:13322}
323
[email protected]9fbd3f862011-09-20 23:31:34324gfx::NativeView Shell::GetContentView() {
[email protected]59383c782013-04-17 16:43:27325 if (!web_contents_)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28326 return nullptr;
[email protected]fc2b46b2014-05-03 16:33:45327 return web_contents_->GetNativeView();
[email protected]9fbd3f862011-09-20 23:31:34328}
329
alexmos5a98a052016-01-06 00:15:02330WebContents* Shell::OpenURLFromTab(WebContents* source,
331 const OpenURLParams& params) {
lukasza04130152016-10-21 20:26:32332 WebContents* target = nullptr;
333 switch (params.disposition) {
334 case WindowOpenDisposition::CURRENT_TAB:
335 target = source;
336 break;
337
338 // Normally, the difference between NEW_POPUP and NEW_WINDOW is that a popup
339 // should have no toolbar, no status bar, no menu bar, no scrollbars and be
340 // not resizable. For simplicity and to enable new testing scenarios in
341 // content shell and layout tests, popups don't get special treatment below
342 // (i.e. they will have a toolbar and other things described here).
343 case WindowOpenDisposition::NEW_POPUP:
lukaszabe2f0da2017-04-25 00:43:00344 case WindowOpenDisposition::NEW_WINDOW:
345 // content_shell doesn't really support tabs, but some layout tests use
346 // middle click (which translates into kNavigationPolicyNewBackgroundTab),
347 // so we treat the cases below just like a NEW_WINDOW disposition.
348 case WindowOpenDisposition::NEW_BACKGROUND_TAB:
349 case WindowOpenDisposition::NEW_FOREGROUND_TAB: {
lukasza04130152016-10-21 20:26:32350 Shell* new_window =
351 Shell::CreateNewWindow(source->GetBrowserContext(),
352 GURL(), // Don't load anything just yet.
353 params.source_site_instance,
354 gfx::Size()); // Use default size.
355 target = new_window->web_contents();
356 if (switches::IsRunLayoutTestSwitchPresent())
357 SecondaryTestWindowObserver::CreateForWebContents(target);
358 break;
359 }
360
361 // No tabs in content_shell:
362 case WindowOpenDisposition::SINGLETON_TAB:
lukasza04130152016-10-21 20:26:32363 // No incognito mode in content_shell:
364 case WindowOpenDisposition::OFF_THE_RECORD:
365 // TODO(lukasza): Investigate if some layout tests might need support for
366 // SAVE_TO_DISK disposition. This would probably require that
367 // BlinkTestController always sets up and cleans up a temporary directory
368 // as the default downloads destinations for the duration of a test.
369 case WindowOpenDisposition::SAVE_TO_DISK:
370 // Ignoring requests with disposition == IGNORE_ACTION...
371 case WindowOpenDisposition::IGNORE_ACTION:
372 default:
373 return nullptr;
374 }
alexmos5a98a052016-01-06 00:15:02375
376 NavigationController::LoadURLParams load_url_params(params.url);
377 load_url_params.source_site_instance = params.source_site_instance;
378 load_url_params.transition_type = params.transition;
379 load_url_params.frame_tree_node_id = params.frame_tree_node_id;
380 load_url_params.referrer = params.referrer;
381 load_url_params.redirect_chain = params.redirect_chain;
382 load_url_params.extra_headers = params.extra_headers;
383 load_url_params.is_renderer_initiated = params.is_renderer_initiated;
alexmos5a98a052016-01-06 00:15:02384 load_url_params.should_replace_current_entry =
385 params.should_replace_current_entry;
386
lukasza477a5a22016-06-16 18:28:43387 if (params.uses_post) {
388 load_url_params.load_type = NavigationController::LOAD_TYPE_HTTP_POST;
389 load_url_params.post_data = params.post_data;
alexmos5a98a052016-01-06 00:15:02390 }
391
lukasza04130152016-10-21 20:26:32392 target->GetController().LoadURLWithParams(load_url_params);
393 return target;
alexmos5a98a052016-01-06 00:15:02394}
395
[email protected]e3b10d12014-03-28 16:06:09396void Shell::LoadingStateChanged(WebContents* source,
397 bool to_different_document) {
398 UpdateNavigationControls(to_different_document);
[email protected]15aea412012-01-19 03:18:50399 PlatformSetIsLoading(source->IsLoading());
[email protected]e99ca5112011-09-26 17:22:54400}
401
mlamouri7a78d6fd2015-01-17 13:23:53402void Shell::EnterFullscreenModeForTab(WebContents* web_contents,
403 const GURL& origin) {
404 ToggleFullscreenModeForTab(web_contents, true);
405}
406
407void Shell::ExitFullscreenModeForTab(WebContents* web_contents) {
408 ToggleFullscreenModeForTab(web_contents, false);
409}
410
[email protected]99c014c2012-11-27 12:03:42411void Shell::ToggleFullscreenModeForTab(WebContents* web_contents,
412 bool enter_fullscreen) {
413#if defined(OS_ANDROID)
414 PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen);
415#endif
lukasza381b0492016-03-10 16:48:43416 if (!switches::IsRunLayoutTestSwitchPresent())
[email protected]99c014c2012-11-27 12:03:42417 return;
418 if (is_fullscreen_ != enter_fullscreen) {
419 is_fullscreen_ = enter_fullscreen;
avif9ab5d942015-10-15 14:05:44420 web_contents->GetRenderViewHost()->GetWidget()->WasResized();
[email protected]99c014c2012-11-27 12:03:42421 }
422}
423
424bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const {
425#if defined(OS_ANDROID)
426 return PlatformIsFullscreenForTabOrPending(web_contents);
427#else
428 return is_fullscreen_;
429#endif
430}
431
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12432blink::WebDisplayMode Shell::GetDisplayMode(
433 const WebContents* web_contents) const {
434 // TODO : should return blink::WebDisplayModeFullscreen wherever user puts
435 // a browser window into fullscreen (not only in case of renderer-initiated
436 // fullscreen mode): crbug.com/476874.
Blink Reformat1c4d759e2017-04-09 16:34:54437 return IsFullscreenForTabOrPending(web_contents)
438 ? blink::kWebDisplayModeFullscreen
439 : blink::kWebDisplayModeBrowser;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12440}
441
[email protected]f78439002012-11-28 14:45:59442void Shell::RequestToLockMouse(WebContents* web_contents,
443 bool user_gesture,
444 bool last_unlocked_by_target) {
445 web_contents->GotResponseToLockMouseRequest(true);
446}
447
[email protected]9e00e6352012-07-30 17:05:18448void Shell::CloseContents(WebContents* source) {
449 Close();
450}
451
[email protected]067310262012-11-22 14:30:41452bool Shell::CanOverscrollContent() const {
453#if defined(USE_AURA)
454 return true;
455#else
456 return false;
457#endif
458}
459
[email protected]3bbacc5b2012-04-17 17:46:15460void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) {
[email protected]4e3c7522013-08-13 11:53:18461 PlatformSetAddressBarURL(web_contents->GetLastCommittedURL());
[email protected]e99ca5112011-09-26 17:22:54462}
463
mathiash72a5e462014-11-19 08:18:50464JavaScriptDialogManager* Shell::GetJavaScriptDialogManager(
465 WebContents* source) {
mkwst6efe7f2e62014-10-08 15:09:01466 if (!dialog_manager_) {
lukasza381b0492016-03-10 16:48:43467 dialog_manager_.reset(switches::IsRunLayoutTestSwitchPresent()
468 ? new LayoutTestJavaScriptDialogManager
469 : new ShellJavaScriptDialogManager);
mkwst6efe7f2e62014-10-08 15:09:01470 }
[email protected]71a88bb2013-02-01 22:05:15471 return dialog_manager_.get();
[email protected]f2210022012-03-29 00:36:08472}
473
dcheng6003e0b2016-04-09 18:42:34474std::unique_ptr<BluetoothChooser> Shell::RunBluetoothChooser(
jyasskin93649a52016-02-17 19:57:02475 RenderFrameHost* frame,
476 const BluetoothChooser::EventHandler& event_handler) {
Lukasz Anforowiczf227b4912017-12-22 23:08:59477 BlinkTestController* blink_test_controller = BlinkTestController::Get();
478 if (blink_test_controller && switches::IsRunLayoutTestSwitchPresent())
479 return blink_test_controller->RunBluetoothChooser(frame, event_handler);
jyasskin8057c002015-09-10 19:09:53480 return nullptr;
481}
482
avia90ae4e2016-11-11 20:49:33483bool Shell::DidAddMessageToConsole(WebContents* source,
484 int32_t level,
485 const base::string16& message,
486 int32_t line_no,
487 const base::string16& source_id) {
lukasza381b0492016-03-10 16:48:43488 return switches::IsRunLayoutTestSwitchPresent();
[email protected]efb5f572012-01-29 10:57:33489}
490
Avi Drissman8920def2018-01-31 19:53:36491void Shell::RendererUnresponsive(WebContents* source,
Avi Drissman1572e8c3c2018-02-02 19:06:36492 RenderWidgetHost* render_widget_host) {
Lukasz Anforowiczf227b4912017-12-22 23:08:59493 BlinkTestController* blink_test_controller = BlinkTestController::Get();
494 if (blink_test_controller && switches::IsRunLayoutTestSwitchPresent())
495 blink_test_controller->RendererUnresponsive();
[email protected]5bf68f22012-08-31 07:38:10496}
497
[email protected]233567d2013-02-27 20:22:02498void Shell::ActivateContents(WebContents* contents) {
avif9ab5d942015-10-15 14:05:44499 contents->GetRenderViewHost()->GetWidget()->Focus();
[email protected]233567d2013-02-27 20:22:02500}
501
carloskd9d97942017-02-16 08:58:09502bool Shell::ShouldAllowRunningInsecureContent(
503 content::WebContents* web_contents,
504 bool allowed_per_prefs,
505 const url::Origin& origin,
506 const GURL& resource_url) {
507 bool allowed_by_test = false;
Lukasz Anforowiczf227b4912017-12-22 23:08:59508 BlinkTestController* blink_test_controller = BlinkTestController::Get();
509 if (blink_test_controller &&
510 base::CommandLine::ForCurrentProcess()->HasSwitch(
carloskd9d97942017-02-16 08:58:09511 switches::kRunLayoutTest)) {
512 const base::DictionaryValue& test_flags =
Lukasz Anforowiczf227b4912017-12-22 23:08:59513 blink_test_controller->accumulated_layout_test_runtime_flags_changes();
carloskd9d97942017-02-16 08:58:09514 test_flags.GetBoolean("running_insecure_content_allowed", &allowed_by_test);
515 }
516
517 return allowed_per_prefs || allowed_by_test;
518}
519
pdrcab84ee2015-03-13 21:47:04520gfx::Size Shell::GetShellDefaultSize() {
521 static gfx::Size default_shell_size;
522 if (!default_shell_size.IsEmpty())
523 return default_shell_size;
524 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
525 if (command_line->HasSwitch(switches::kContentShellHostWindowSize)) {
526 const std::string size_str = command_line->GetSwitchValueASCII(
527 switches::kContentShellHostWindowSize);
528 int width, height;
529 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height));
530 default_shell_size = gfx::Size(width, height);
531 } else {
532 default_shell_size = gfx::Size(
533 kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip);
534 }
535 return default_shell_size;
536}
537
Avi Drissman93002212017-09-27 03:20:52538void Shell::TitleWasSet(NavigationEntry* entry) {
[email protected]1ef02d242013-10-07 16:18:53539 if (entry)
540 PlatformSetTitle(entry->GetTitle());
[email protected]aecc085b2012-06-01 18:15:53541}
542
[email protected]7fff43e2013-05-21 20:21:10543void Shell::OnDevToolsWebContentsDestroyed() {
544 devtools_observer_.reset();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28545 devtools_frontend_ = nullptr;
[email protected]7fff43e2013-05-21 20:21:10546}
547
[email protected]9fbd3f862011-09-20 23:31:34548} // namespace content