blob: 9d561d70ab1a8f50d47f1ee16941716c7c9767d7 [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"
[email protected]9fbd3f862011-09-20 23:31:3445
[email protected]9fbd3f862011-09-20 23:31:3446namespace content {
47
pdrcab84ee2015-03-13 21:47:0448const int kDefaultTestWindowWidthDip = 800;
49const int kDefaultTestWindowHeightDip = 600;
[email protected]1e57cab2013-05-28 04:26:1150
[email protected]e99ca5112011-09-26 17:22:5451std::vector<Shell*> Shell::windows_;
[email protected]9e00e6352012-07-30 17:05:1852base::Callback<void(Shell*)> Shell::shell_created_callback_;
[email protected]9fbd3f862011-09-20 23:31:3453
[email protected]11a65b692012-03-30 11:29:1654bool Shell::quit_message_loop_ = true;
55
[email protected]7fff43e2013-05-21 20:21:1056class Shell::DevToolsWebContentsObserver : public WebContentsObserver {
57 public:
58 DevToolsWebContentsObserver(Shell* shell, WebContents* web_contents)
59 : WebContentsObserver(web_contents),
60 shell_(shell) {
61 }
62
63 // WebContentsObserver
dchenge933b3e2014-10-21 11:44:0964 void WebContentsDestroyed() override {
[email protected]7fff43e2013-05-21 20:21:1065 shell_->OnDevToolsWebContentsDestroyed();
66 }
67
68 private:
69 Shell* shell_;
70
71 DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver);
72};
73
[email protected]0b659b32012-03-26 21:29:3274Shell::Shell(WebContents* web_contents)
[email protected]1ef02d242013-10-07 16:18:5375 : WebContentsObserver(web_contents),
76 devtools_frontend_(NULL),
[email protected]001841c92012-12-11 17:00:1377 is_fullscreen_(false),
[email protected]99c014c2012-11-27 12:03:4278 window_(NULL),
sadrul8b11d262015-11-12 18:41:3379#if defined(OS_MACOSX)
[email protected]86b36e672012-12-21 00:09:5180 url_edit_view_(NULL),
sadrul8b11d262015-11-12 18:41:3381#endif
[email protected]86b36e672012-12-21 00:09:5182 headless_(false) {
lukasza381b0492016-03-10 16:48:4383 if (switches::IsRunLayoutTestSwitchPresent())
[email protected]86b36e672012-12-21 00:09:5184 headless_ = true;
[email protected]9e00e6352012-07-30 17:05:1885 windows_.push_back(this);
86
87 if (!shell_created_callback_.is_null()) {
88 shell_created_callback_.Run(this);
89 shell_created_callback_.Reset();
90 }
[email protected]9fbd3f862011-09-20 23:31:3491}
92
93Shell::~Shell() {
94 PlatformCleanUp();
[email protected]e99ca5112011-09-26 17:22:5495
96 for (size_t i = 0; i < windows_.size(); ++i) {
97 if (windows_[i] == this) {
98 windows_.erase(windows_.begin() + i);
99 break;
100 }
101 }
[email protected]11a65b692012-03-30 11:29:16102
[email protected]b53adf452014-02-07 12:55:08103 if (windows_.empty() && quit_message_loop_) {
104 if (headless_)
105 PlatformExit();
skyostil95082a62015-06-05 19:53:07106 base::ThreadTaskRunnerHandle::Get()->PostTask(
ki.stfu800779242015-10-12 22:46:26107 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
[email protected]b53adf452014-02-07 12:55:08108 }
[email protected]9fbd3f862011-09-20 23:31:34109}
110
[email protected]c0d036d2013-05-07 12:50:50111Shell* Shell::CreateShell(WebContents* web_contents,
112 const gfx::Size& initial_size) {
[email protected]0b659b32012-03-26 21:29:32113 Shell* shell = new Shell(web_contents);
[email protected]c0d036d2013-05-07 12:50:50114 shell->PlatformCreateWindow(initial_size.width(), initial_size.height());
[email protected]3fd84032012-01-12 18:20:17115
[email protected]0b659b32012-03-26 21:29:32116 shell->web_contents_.reset(web_contents);
117 web_contents->SetDelegate(shell);
[email protected]3fd84032012-01-12 18:20:17118
[email protected]5cba3bf2012-01-14 02:40:35119 shell->PlatformSetContents();
[email protected]3fd84032012-01-12 18:20:17120
121 shell->PlatformResizeSubViews();
[email protected]1596efb2013-01-17 22:13:01122
creisb6561df2016-02-11 20:20:54123 // Note: Do not make RenderFrameHost or RenderViewHost specific state changes
124 // here, because they will be forgotten after a cross-process navigation. Use
125 // RenderFrameCreated or RenderViewCreated instead.
lukasza381b0492016-03-10 16:48:43126 if (switches::IsRunLayoutTestSwitchPresent()) {
[email protected]1596efb2013-01-17 22:13:01127 web_contents->GetMutableRendererPrefs()->use_custom_colors = false;
128 web_contents->GetRenderViewHost()->SyncRendererPrefs();
129 }
130
Brett Wilson0748bf412016-11-22 17:55:46131#if BUILDFLAG(ENABLE_WEBRTC)
lukasza381b0492016-03-10 16:48:43132 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
guoweis4ee48592015-12-02 06:37:07133 if (command_line->HasSwitch(switches::kForceWebRtcIPHandlingPolicy)) {
guoweisc537ba22015-11-06 21:20:31134 web_contents->GetMutableRendererPrefs()->webrtc_ip_handling_policy =
guoweis4ee48592015-12-02 06:37:07135 command_line->GetSwitchValueASCII(
136 switches::kForceWebRtcIPHandlingPolicy);
guoweis8efb6d892015-10-12 18:26:17137 }
138#endif
139
[email protected]3fd84032012-01-12 18:20:17140 return shell;
141}
142
[email protected]11a65b692012-03-30 11:29:16143void Shell::CloseAllWindows() {
[email protected]997ec9f2012-11-21 04:44:14144 base::AutoReset<bool> auto_reset(&quit_message_loop_, false);
[email protected]b50452f2014-08-18 12:31:44145 DevToolsAgentHost::DetachAllClients();
[email protected]11a65b692012-03-30 11:29:16146 std::vector<Shell*> open_windows(windows_);
147 for (size_t i = 0; i < open_windows.size(); ++i)
148 open_windows[i]->Close();
fdoray896bea12016-06-10 15:52:01149 base::RunLoop().RunUntilIdle();
dmazzoni948fbc72015-05-17 07:57:33150 PlatformExit();
[email protected]11a65b692012-03-30 11:29:16151}
152
[email protected]9e00e6352012-07-30 17:05:18153void Shell::SetShellCreatedCallback(
154 base::Callback<void(Shell*)> shell_created_callback) {
155 DCHECK(shell_created_callback_.is_null());
156 shell_created_callback_ = shell_created_callback;
157}
158
[email protected]74830f02012-01-30 22:27:04159Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) {
160 for (size_t i = 0; i < windows_.size(); ++i) {
[email protected]0b659b32012-03-26 21:29:32161 if (windows_[i]->web_contents() &&
162 windows_[i]->web_contents()->GetRenderViewHost() == rvh) {
[email protected]74830f02012-01-30 22:27:04163 return windows_[i];
164 }
165 }
166 return NULL;
167}
168
[email protected]6153b272013-01-25 22:29:23169// static
170void Shell::Initialize() {
pdrcab84ee2015-03-13 21:47:04171 PlatformInitialize(GetShellDefaultSize());
[email protected]6153b272013-01-25 22:29:23172}
173
[email protected]a2904092013-10-15 04:53:59174gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) {
175 if (!initial_size.IsEmpty())
176 return initial_size;
pdrcab84ee2015-03-13 21:47:04177 return GetShellDefaultSize();
[email protected]a2904092013-10-15 04:53:59178}
179
[email protected]bdcf9152012-07-19 17:43:21180Shell* Shell::CreateNewWindow(BrowserContext* browser_context,
[email protected]e99ca5112011-09-26 17:22:54181 const GURL& url,
lukasza04130152016-10-21 20:26:32182 const scoped_refptr<SiteInstance>& site_instance,
[email protected]cdb806722013-01-10 14:18:23183 const gfx::Size& initial_size) {
[email protected]54944cde2012-12-09 09:24:59184 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]a2904092013-10-15 04:53:59185 create_params.initial_size = AdjustWindowSize(initial_size);
[email protected]54944cde2012-12-09 09:24:59186 WebContents* web_contents = WebContents::Create(create_params);
[email protected]c0d036d2013-05-07 12:50:50187 Shell* shell = CreateShell(web_contents, create_params.initial_size);
[email protected]e99ca5112011-09-26 17:22:54188 if (!url.is_empty())
189 shell->LoadURL(url);
[email protected]9fbd3f862011-09-20 23:31:34190 return shell;
191}
192
193void Shell::LoadURL(const GURL& url) {
[email protected]d2494ff2013-02-20 08:22:37194 LoadURLForFrame(url, std::string());
195}
196
197void Shell::LoadURLForFrame(const GURL& url, const std::string& frame_name) {
198 NavigationController::LoadURLParams params(url);
Sylvain Defresnec6ccc77d2014-09-19 10:19:35199 params.transition_type = ui::PageTransitionFromInt(
200 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
[email protected]d2494ff2013-02-20 08:22:37201 params.frame_name = frame_name;
202 web_contents_->GetController().LoadURLWithParams(params);
[email protected]fc2b46b2014-05-03 16:33:45203 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34204}
205
[email protected]76bdecb2014-04-16 17:58:08206void Shell::LoadDataWithBaseURL(const GURL& url, const std::string& data,
207 const GURL& base_url) {
boliuec93ea92016-02-17 22:23:07208 bool load_as_string = false;
209 LoadDataWithBaseURLInternal(url, data, base_url, load_as_string);
210}
211
212#if defined(OS_ANDROID)
213void Shell::LoadDataAsStringWithBaseURL(const GURL& url,
214 const std::string& data,
215 const GURL& base_url) {
216 bool load_as_string = true;
217 LoadDataWithBaseURLInternal(url, data, base_url, load_as_string);
218}
219#endif
220
221void Shell::LoadDataWithBaseURLInternal(const GURL& url,
222 const std::string& data,
223 const GURL& base_url,
224 bool load_as_string) {
225#if !defined(OS_ANDROID)
226 DCHECK(!load_as_string); // Only supported on Android.
227#endif
228
229 NavigationController::LoadURLParams params(GURL::EmptyGURL());
230 const std::string data_url_header = "data:text/html;charset=utf-8,";
231 if (load_as_string) {
232 params.url = GURL(data_url_header);
233 std::string data_url_as_string = data_url_header + data;
234#if defined(OS_ANDROID)
235 params.data_url_as_string =
236 base::RefCountedString::TakeString(&data_url_as_string);
237#endif
238 } else {
239 params.url = GURL(data_url_header + data);
240 }
241
[email protected]76bdecb2014-04-16 17:58:08242 params.load_type = NavigationController::LOAD_TYPE_DATA;
243 params.base_url_for_data_url = base_url;
244 params.virtual_url_for_data_url = url;
245 params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE;
246 web_contents_->GetController().LoadURLWithParams(params);
[email protected]fc2b46b2014-05-03 16:33:45247 web_contents_->Focus();
[email protected]76bdecb2014-04-16 17:58:08248}
249
[email protected]a2904092013-10-15 04:53:59250void Shell::AddNewContents(WebContents* source,
251 WebContents* new_contents,
252 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:39253 const gfx::Rect& initial_rect,
[email protected]a2904092013-10-15 04:53:59254 bool user_gesture,
255 bool* was_blocked) {
bokan107a47f2015-02-03 23:23:39256 CreateShell(new_contents, AdjustWindowSize(initial_rect.size()));
lukasza381b0492016-03-10 16:48:43257 if (switches::IsRunLayoutTestSwitchPresent())
lukasza8e550a02016-04-18 18:34:17258 SecondaryTestWindowObserver::CreateForWebContents(new_contents);
[email protected]a2904092013-10-15 04:53:59259}
260
[email protected]9fbd3f862011-09-20 23:31:34261void Shell::GoBackOrForward(int offset) {
[email protected]0b659b32012-03-26 21:29:32262 web_contents_->GetController().GoToOffset(offset);
[email protected]fc2b46b2014-05-03 16:33:45263 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34264}
265
266void Shell::Reload() {
toyoshim6142d96f2016-12-19 09:07:25267 web_contents_->GetController().Reload(ReloadType::NORMAL, false);
[email protected]fc2b46b2014-05-03 16:33:45268 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34269}
270
toyoshime5aaf6a2016-05-18 08:07:48271void Shell::ReloadBypassingCache() {
toyoshim6142d96f2016-12-19 09:07:25272 web_contents_->GetController().Reload(ReloadType::BYPASSING_CACHE, false);
toyoshime5aaf6a2016-05-18 08:07:48273 web_contents_->Focus();
274}
275
[email protected]9fbd3f862011-09-20 23:31:34276void Shell::Stop() {
[email protected]0b659b32012-03-26 21:29:32277 web_contents_->Stop();
[email protected]fc2b46b2014-05-03 16:33:45278 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34279}
280
[email protected]e3b10d12014-03-28 16:06:09281void Shell::UpdateNavigationControls(bool to_different_document) {
[email protected]0b659b32012-03-26 21:29:32282 int current_index = web_contents_->GetController().GetCurrentEntryIndex();
283 int max_index = web_contents_->GetController().GetEntryCount() - 1;
[email protected]9fbd3f862011-09-20 23:31:34284
285 PlatformEnableUIControl(BACK_BUTTON, current_index > 0);
286 PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index);
[email protected]e3b10d12014-03-28 16:06:09287 PlatformEnableUIControl(STOP_BUTTON,
288 to_different_document && web_contents_->IsLoading());
[email protected]9fbd3f862011-09-20 23:31:34289}
290
[email protected]7c17b6992012-08-09 16:16:30291void Shell::ShowDevTools() {
mohsen6eb57fb2016-07-22 03:14:08292 if (!devtools_frontend_) {
293 devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents());
294 devtools_observer_.reset(new DevToolsWebContentsObserver(
295 this, devtools_frontend_->frontend_shell()->web_contents()));
296 }
[email protected]3142e5d2014-02-07 00:54:46297
mohsen6eb57fb2016-07-22 03:14:08298 devtools_frontend_->Activate();
299 devtools_frontend_->Focus();
[email protected]7c17b6992012-08-09 16:16:30300}
301
[email protected]001841c92012-12-11 17:00:13302void Shell::CloseDevTools() {
[email protected]0773e0c2013-01-25 15:57:57303 if (!devtools_frontend_)
[email protected]001841c92012-12-11 17:00:13304 return;
[email protected]7fff43e2013-05-21 20:21:10305 devtools_observer_.reset();
[email protected]0773e0c2013-01-25 15:57:57306 devtools_frontend_->Close();
307 devtools_frontend_ = NULL;
[email protected]001841c92012-12-11 17:00:13308}
309
[email protected]9fbd3f862011-09-20 23:31:34310gfx::NativeView Shell::GetContentView() {
[email protected]59383c782013-04-17 16:43:27311 if (!web_contents_)
[email protected]9fbd3f862011-09-20 23:31:34312 return NULL;
[email protected]fc2b46b2014-05-03 16:33:45313 return web_contents_->GetNativeView();
[email protected]9fbd3f862011-09-20 23:31:34314}
315
alexmos5a98a052016-01-06 00:15:02316WebContents* Shell::OpenURLFromTab(WebContents* source,
317 const OpenURLParams& params) {
lukasza04130152016-10-21 20:26:32318 WebContents* target = nullptr;
319 switch (params.disposition) {
320 case WindowOpenDisposition::CURRENT_TAB:
321 target = source;
322 break;
323
324 // Normally, the difference between NEW_POPUP and NEW_WINDOW is that a popup
325 // should have no toolbar, no status bar, no menu bar, no scrollbars and be
326 // not resizable. For simplicity and to enable new testing scenarios in
327 // content shell and layout tests, popups don't get special treatment below
328 // (i.e. they will have a toolbar and other things described here).
329 case WindowOpenDisposition::NEW_POPUP:
lukaszabe2f0da2017-04-25 00:43:00330 case WindowOpenDisposition::NEW_WINDOW:
331 // content_shell doesn't really support tabs, but some layout tests use
332 // middle click (which translates into kNavigationPolicyNewBackgroundTab),
333 // so we treat the cases below just like a NEW_WINDOW disposition.
334 case WindowOpenDisposition::NEW_BACKGROUND_TAB:
335 case WindowOpenDisposition::NEW_FOREGROUND_TAB: {
lukasza04130152016-10-21 20:26:32336 Shell* new_window =
337 Shell::CreateNewWindow(source->GetBrowserContext(),
338 GURL(), // Don't load anything just yet.
339 params.source_site_instance,
340 gfx::Size()); // Use default size.
341 target = new_window->web_contents();
342 if (switches::IsRunLayoutTestSwitchPresent())
343 SecondaryTestWindowObserver::CreateForWebContents(target);
344 break;
345 }
346
347 // No tabs in content_shell:
348 case WindowOpenDisposition::SINGLETON_TAB:
lukasza04130152016-10-21 20:26:32349 // No incognito mode in content_shell:
350 case WindowOpenDisposition::OFF_THE_RECORD:
351 // TODO(lukasza): Investigate if some layout tests might need support for
352 // SAVE_TO_DISK disposition. This would probably require that
353 // BlinkTestController always sets up and cleans up a temporary directory
354 // as the default downloads destinations for the duration of a test.
355 case WindowOpenDisposition::SAVE_TO_DISK:
356 // Ignoring requests with disposition == IGNORE_ACTION...
357 case WindowOpenDisposition::IGNORE_ACTION:
358 default:
359 return nullptr;
360 }
alexmos5a98a052016-01-06 00:15:02361
362 NavigationController::LoadURLParams load_url_params(params.url);
363 load_url_params.source_site_instance = params.source_site_instance;
364 load_url_params.transition_type = params.transition;
365 load_url_params.frame_tree_node_id = params.frame_tree_node_id;
366 load_url_params.referrer = params.referrer;
367 load_url_params.redirect_chain = params.redirect_chain;
368 load_url_params.extra_headers = params.extra_headers;
369 load_url_params.is_renderer_initiated = params.is_renderer_initiated;
alexmos5a98a052016-01-06 00:15:02370 load_url_params.should_replace_current_entry =
371 params.should_replace_current_entry;
372
lukasza477a5a22016-06-16 18:28:43373 if (params.uses_post) {
374 load_url_params.load_type = NavigationController::LOAD_TYPE_HTTP_POST;
375 load_url_params.post_data = params.post_data;
alexmos5a98a052016-01-06 00:15:02376 }
377
lukasza04130152016-10-21 20:26:32378 target->GetController().LoadURLWithParams(load_url_params);
379 return target;
alexmos5a98a052016-01-06 00:15:02380}
381
[email protected]e3b10d12014-03-28 16:06:09382void Shell::LoadingStateChanged(WebContents* source,
383 bool to_different_document) {
384 UpdateNavigationControls(to_different_document);
[email protected]15aea412012-01-19 03:18:50385 PlatformSetIsLoading(source->IsLoading());
[email protected]e99ca5112011-09-26 17:22:54386}
387
mlamouri7a78d6fd2015-01-17 13:23:53388void Shell::EnterFullscreenModeForTab(WebContents* web_contents,
389 const GURL& origin) {
390 ToggleFullscreenModeForTab(web_contents, true);
391}
392
393void Shell::ExitFullscreenModeForTab(WebContents* web_contents) {
394 ToggleFullscreenModeForTab(web_contents, false);
395}
396
[email protected]99c014c2012-11-27 12:03:42397void Shell::ToggleFullscreenModeForTab(WebContents* web_contents,
398 bool enter_fullscreen) {
399#if defined(OS_ANDROID)
400 PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen);
401#endif
lukasza381b0492016-03-10 16:48:43402 if (!switches::IsRunLayoutTestSwitchPresent())
[email protected]99c014c2012-11-27 12:03:42403 return;
404 if (is_fullscreen_ != enter_fullscreen) {
405 is_fullscreen_ = enter_fullscreen;
avif9ab5d942015-10-15 14:05:44406 web_contents->GetRenderViewHost()->GetWidget()->WasResized();
[email protected]99c014c2012-11-27 12:03:42407 }
408}
409
410bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const {
411#if defined(OS_ANDROID)
412 return PlatformIsFullscreenForTabOrPending(web_contents);
413#else
414 return is_fullscreen_;
415#endif
416}
417
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12418blink::WebDisplayMode Shell::GetDisplayMode(
419 const WebContents* web_contents) const {
420 // TODO : should return blink::WebDisplayModeFullscreen wherever user puts
421 // a browser window into fullscreen (not only in case of renderer-initiated
422 // fullscreen mode): crbug.com/476874.
Blink Reformat1c4d759e2017-04-09 16:34:54423 return IsFullscreenForTabOrPending(web_contents)
424 ? blink::kWebDisplayModeFullscreen
425 : blink::kWebDisplayModeBrowser;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12426}
427
[email protected]f78439002012-11-28 14:45:59428void Shell::RequestToLockMouse(WebContents* web_contents,
429 bool user_gesture,
430 bool last_unlocked_by_target) {
431 web_contents->GotResponseToLockMouseRequest(true);
432}
433
[email protected]9e00e6352012-07-30 17:05:18434void Shell::CloseContents(WebContents* source) {
435 Close();
436}
437
[email protected]067310262012-11-22 14:30:41438bool Shell::CanOverscrollContent() const {
439#if defined(USE_AURA)
440 return true;
441#else
442 return false;
443#endif
444}
445
[email protected]3bbacc5b2012-04-17 17:46:15446void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) {
[email protected]4e3c7522013-08-13 11:53:18447 PlatformSetAddressBarURL(web_contents->GetLastCommittedURL());
[email protected]e99ca5112011-09-26 17:22:54448}
449
mathiash72a5e462014-11-19 08:18:50450JavaScriptDialogManager* Shell::GetJavaScriptDialogManager(
451 WebContents* source) {
mkwst6efe7f2e62014-10-08 15:09:01452 if (!dialog_manager_) {
lukasza381b0492016-03-10 16:48:43453 dialog_manager_.reset(switches::IsRunLayoutTestSwitchPresent()
454 ? new LayoutTestJavaScriptDialogManager
455 : new ShellJavaScriptDialogManager);
mkwst6efe7f2e62014-10-08 15:09:01456 }
[email protected]71a88bb2013-02-01 22:05:15457 return dialog_manager_.get();
[email protected]f2210022012-03-29 00:36:08458}
459
dcheng6003e0b2016-04-09 18:42:34460std::unique_ptr<BluetoothChooser> Shell::RunBluetoothChooser(
jyasskin93649a52016-02-17 19:57:02461 RenderFrameHost* frame,
462 const BluetoothChooser::EventHandler& event_handler) {
lukasza381b0492016-03-10 16:48:43463 if (switches::IsRunLayoutTestSwitchPresent()) {
jyasskin93649a52016-02-17 19:57:02464 return BlinkTestController::Get()->RunBluetoothChooser(frame,
465 event_handler);
jyasskin8057c002015-09-10 19:09:53466 }
467 return nullptr;
468}
469
avia90ae4e2016-11-11 20:49:33470bool Shell::DidAddMessageToConsole(WebContents* source,
471 int32_t level,
472 const base::string16& message,
473 int32_t line_no,
474 const base::string16& source_id) {
lukasza381b0492016-03-10 16:48:43475 return switches::IsRunLayoutTestSwitchPresent();
[email protected]efb5f572012-01-29 10:57:33476}
477
dtapuskae99ec6e52016-10-18 00:15:42478void Shell::RendererUnresponsive(
479 WebContents* source,
480 const WebContentsUnresponsiveState& unresponsive_state) {
lukasza381b0492016-03-10 16:48:43481 if (switches::IsRunLayoutTestSwitchPresent())
482 BlinkTestController::Get()->RendererUnresponsive();
[email protected]5bf68f22012-08-31 07:38:10483}
484
[email protected]233567d2013-02-27 20:22:02485void Shell::ActivateContents(WebContents* contents) {
avif9ab5d942015-10-15 14:05:44486 contents->GetRenderViewHost()->GetWidget()->Focus();
[email protected]233567d2013-02-27 20:22:02487}
488
carloskd9d97942017-02-16 08:58:09489bool Shell::ShouldAllowRunningInsecureContent(
490 content::WebContents* web_contents,
491 bool allowed_per_prefs,
492 const url::Origin& origin,
493 const GURL& resource_url) {
494 bool allowed_by_test = false;
495 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
496 switches::kRunLayoutTest)) {
497 const base::DictionaryValue& test_flags =
498 BlinkTestController::Get()
499 ->accumulated_layout_test_runtime_flags_changes();
500 test_flags.GetBoolean("running_insecure_content_allowed", &allowed_by_test);
501 }
502
503 return allowed_per_prefs || allowed_by_test;
504}
505
pdrcab84ee2015-03-13 21:47:04506gfx::Size Shell::GetShellDefaultSize() {
507 static gfx::Size default_shell_size;
508 if (!default_shell_size.IsEmpty())
509 return default_shell_size;
510 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
511 if (command_line->HasSwitch(switches::kContentShellHostWindowSize)) {
512 const std::string size_str = command_line->GetSwitchValueASCII(
513 switches::kContentShellHostWindowSize);
514 int width, height;
515 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height));
516 default_shell_size = gfx::Size(width, height);
517 } else {
518 default_shell_size = gfx::Size(
519 kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip);
520 }
521 return default_shell_size;
522}
523
[email protected]1ef02d242013-10-07 16:18:53524void Shell::TitleWasSet(NavigationEntry* entry, bool explicit_set) {
525 if (entry)
526 PlatformSetTitle(entry->GetTitle());
[email protected]aecc085b2012-06-01 18:15:53527}
528
[email protected]7fff43e2013-05-21 20:21:10529void Shell::OnDevToolsWebContentsDestroyed() {
530 devtools_observer_.reset();
531 devtools_frontend_ = NULL;
532}
533
[email protected]9fbd3f862011-09-20 23:31:34534} // namespace content