blob: 409f0d414826329852b675afaa8a9fba3c1f9d81 [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"
skyostil95082a62015-06-05 19:53:0713#include "base/single_thread_task_runner.h"
[email protected]21aa99682013-06-11 07:17:0114#include "base/strings/string_number_conversions.h"
15#include "base/strings/string_util.h"
16#include "base/strings/stringprintf.h"
[email protected]74ebfb12013-06-07 20:48:0017#include "base/strings/utf_string_conversions.h"
skyostil95082a62015-06-05 19:53:0718#include "base/thread_task_runner_handle.h"
avi66a07722015-12-25 23:38:1219#include "build/build_config.h"
[email protected]b50452f2014-08-18 12:31:4420#include "content/public/browser/devtools_agent_host.h"
[email protected]0b659b32012-03-26 21:29:3221#include "content/public/browser/navigation_controller.h"
[email protected]b7c504c2013-05-07 14:42:1222#include "content/public/browser/navigation_entry.h"
[email protected]0b659b32012-03-26 21:29:3223#include "content/public/browser/render_view_host.h"
avif9ab5d942015-10-15 14:05:4424#include "content/public/browser/render_widget_host.h"
[email protected]0b659b32012-03-26 21:29:3225#include "content/public/browser/web_contents.h"
[email protected]7fff43e2013-05-21 20:21:1026#include "content/public/browser/web_contents_observer.h"
guoweis8efb6d892015-10-12 18:26:1727#include "content/public/common/content_switches.h"
[email protected]1596efb2013-01-17 22:13:0128#include "content/public/common/renderer_preferences.h"
guoweisc537ba22015-11-06 21:20:3129#include "content/public/common/webrtc_ip_handling_policy.h"
tfarinacde91252015-05-06 16:10:4930#include "content/shell/browser/blink_test_controller.h"
jyasskin8057c002015-09-10 19:09:5331#include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factory.h"
mkwst30d20d52014-10-09 13:33:1432#include "content/shell/browser/layout_test/layout_test_devtools_frontend.h"
mkwst6efe7f2e62014-10-08 15:09:0133#include "content/shell/browser/layout_test/layout_test_javascript_dialog_manager.h"
[email protected]de7d61ff2013-08-20 11:30:4134#include "content/shell/browser/notify_done_forwarder.h"
35#include "content/shell/browser/shell_browser_main_parts.h"
36#include "content/shell/browser/shell_content_browser_client.h"
37#include "content/shell/browser/shell_devtools_frontend.h"
38#include "content/shell/browser/shell_javascript_dialog_manager.h"
[email protected]b7c504c2013-05-07 14:42:1239#include "content/shell/common/shell_messages.h"
40#include "content/shell/common/shell_switches.h"
[email protected]9fbd3f862011-09-20 23:31:3441
[email protected]9fbd3f862011-09-20 23:31:3442namespace content {
43
pdrcab84ee2015-03-13 21:47:0444const int kDefaultTestWindowWidthDip = 800;
45const int kDefaultTestWindowHeightDip = 600;
[email protected]1e57cab2013-05-28 04:26:1146
[email protected]e99ca5112011-09-26 17:22:5447std::vector<Shell*> Shell::windows_;
[email protected]9e00e6352012-07-30 17:05:1848base::Callback<void(Shell*)> Shell::shell_created_callback_;
[email protected]9fbd3f862011-09-20 23:31:3449
[email protected]11a65b692012-03-30 11:29:1650bool Shell::quit_message_loop_ = true;
51
[email protected]7fff43e2013-05-21 20:21:1052class Shell::DevToolsWebContentsObserver : public WebContentsObserver {
53 public:
54 DevToolsWebContentsObserver(Shell* shell, WebContents* web_contents)
55 : WebContentsObserver(web_contents),
56 shell_(shell) {
57 }
58
59 // WebContentsObserver
dchenge933b3e2014-10-21 11:44:0960 void WebContentsDestroyed() override {
[email protected]7fff43e2013-05-21 20:21:1061 shell_->OnDevToolsWebContentsDestroyed();
62 }
63
64 private:
65 Shell* shell_;
66
67 DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver);
68};
69
[email protected]0b659b32012-03-26 21:29:3270Shell::Shell(WebContents* web_contents)
[email protected]1ef02d242013-10-07 16:18:5371 : WebContentsObserver(web_contents),
72 devtools_frontend_(NULL),
[email protected]001841c92012-12-11 17:00:1373 is_fullscreen_(false),
[email protected]99c014c2012-11-27 12:03:4274 window_(NULL),
sadrul8b11d262015-11-12 18:41:3375#if defined(OS_MACOSX)
[email protected]86b36e672012-12-21 00:09:5176 url_edit_view_(NULL),
sadrul8b11d262015-11-12 18:41:3377#endif
[email protected]86b36e672012-12-21 00:09:5178 headless_(false) {
avi83883c82014-12-23 00:08:4979 const base::CommandLine& command_line =
80 *base::CommandLine::ForCurrentProcess();
paulmeyerbcc6ad22015-02-11 21:51:5981 if (command_line.HasSwitch(switches::kRunLayoutTest))
[email protected]86b36e672012-12-21 00:09:5182 headless_ = true;
[email protected]9e00e6352012-07-30 17:05:1883 windows_.push_back(this);
84
85 if (!shell_created_callback_.is_null()) {
86 shell_created_callback_.Run(this);
87 shell_created_callback_.Reset();
88 }
[email protected]9fbd3f862011-09-20 23:31:3489}
90
91Shell::~Shell() {
92 PlatformCleanUp();
[email protected]e99ca5112011-09-26 17:22:5493
94 for (size_t i = 0; i < windows_.size(); ++i) {
95 if (windows_[i] == this) {
96 windows_.erase(windows_.begin() + i);
97 break;
98 }
99 }
[email protected]11a65b692012-03-30 11:29:16100
[email protected]b53adf452014-02-07 12:55:08101 if (windows_.empty() && quit_message_loop_) {
102 if (headless_)
103 PlatformExit();
skyostil95082a62015-06-05 19:53:07104 base::ThreadTaskRunnerHandle::Get()->PostTask(
ki.stfu800779242015-10-12 22:46:26105 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
[email protected]b53adf452014-02-07 12:55:08106 }
[email protected]9fbd3f862011-09-20 23:31:34107}
108
[email protected]c0d036d2013-05-07 12:50:50109Shell* Shell::CreateShell(WebContents* web_contents,
110 const gfx::Size& initial_size) {
[email protected]0b659b32012-03-26 21:29:32111 Shell* shell = new Shell(web_contents);
[email protected]c0d036d2013-05-07 12:50:50112 shell->PlatformCreateWindow(initial_size.width(), initial_size.height());
[email protected]3fd84032012-01-12 18:20:17113
[email protected]0b659b32012-03-26 21:29:32114 shell->web_contents_.reset(web_contents);
115 web_contents->SetDelegate(shell);
[email protected]3fd84032012-01-12 18:20:17116
[email protected]5cba3bf2012-01-14 02:40:35117 shell->PlatformSetContents();
[email protected]3fd84032012-01-12 18:20:17118
119 shell->PlatformResizeSubViews();
[email protected]1596efb2013-01-17 22:13:01120
guoweis4ee48592015-12-02 06:37:07121 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
122 if (command_line->HasSwitch(switches::kRunLayoutTest)) {
[email protected]1596efb2013-01-17 22:13:01123 web_contents->GetMutableRendererPrefs()->use_custom_colors = false;
124 web_contents->GetRenderViewHost()->SyncRendererPrefs();
125 }
126
guoweis8efb6d892015-10-12 18:26:17127#if defined(ENABLE_WEBRTC)
guoweis4ee48592015-12-02 06:37:07128 if (command_line->HasSwitch(switches::kForceWebRtcIPHandlingPolicy)) {
guoweisc537ba22015-11-06 21:20:31129 web_contents->GetMutableRendererPrefs()->webrtc_ip_handling_policy =
guoweis4ee48592015-12-02 06:37:07130 command_line->GetSwitchValueASCII(
131 switches::kForceWebRtcIPHandlingPolicy);
guoweis8efb6d892015-10-12 18:26:17132 }
133#endif
134
[email protected]3fd84032012-01-12 18:20:17135 return shell;
136}
137
[email protected]11a65b692012-03-30 11:29:16138void Shell::CloseAllWindows() {
[email protected]997ec9f2012-11-21 04:44:14139 base::AutoReset<bool> auto_reset(&quit_message_loop_, false);
[email protected]b50452f2014-08-18 12:31:44140 DevToolsAgentHost::DetachAllClients();
[email protected]11a65b692012-03-30 11:29:16141 std::vector<Shell*> open_windows(windows_);
142 for (size_t i = 0; i < open_windows.size(); ++i)
143 open_windows[i]->Close();
[email protected]dd32b1272013-05-04 14:17:11144 base::MessageLoop::current()->RunUntilIdle();
dmazzoni948fbc72015-05-17 07:57:33145 PlatformExit();
[email protected]11a65b692012-03-30 11:29:16146}
147
[email protected]9e00e6352012-07-30 17:05:18148void Shell::SetShellCreatedCallback(
149 base::Callback<void(Shell*)> shell_created_callback) {
150 DCHECK(shell_created_callback_.is_null());
151 shell_created_callback_ = shell_created_callback;
152}
153
[email protected]74830f02012-01-30 22:27:04154Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) {
155 for (size_t i = 0; i < windows_.size(); ++i) {
[email protected]0b659b32012-03-26 21:29:32156 if (windows_[i]->web_contents() &&
157 windows_[i]->web_contents()->GetRenderViewHost() == rvh) {
[email protected]74830f02012-01-30 22:27:04158 return windows_[i];
159 }
160 }
161 return NULL;
162}
163
[email protected]6153b272013-01-25 22:29:23164// static
165void Shell::Initialize() {
pdrcab84ee2015-03-13 21:47:04166 PlatformInitialize(GetShellDefaultSize());
[email protected]6153b272013-01-25 22:29:23167}
168
[email protected]a2904092013-10-15 04:53:59169gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) {
170 if (!initial_size.IsEmpty())
171 return initial_size;
pdrcab84ee2015-03-13 21:47:04172 return GetShellDefaultSize();
[email protected]a2904092013-10-15 04:53:59173}
174
[email protected]bdcf9152012-07-19 17:43:21175Shell* Shell::CreateNewWindow(BrowserContext* browser_context,
[email protected]e99ca5112011-09-26 17:22:54176 const GURL& url,
177 SiteInstance* site_instance,
[email protected]cdb806722013-01-10 14:18:23178 const gfx::Size& initial_size) {
[email protected]54944cde2012-12-09 09:24:59179 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]a2904092013-10-15 04:53:59180 create_params.initial_size = AdjustWindowSize(initial_size);
[email protected]54944cde2012-12-09 09:24:59181 WebContents* web_contents = WebContents::Create(create_params);
[email protected]c0d036d2013-05-07 12:50:50182 Shell* shell = CreateShell(web_contents, create_params.initial_size);
[email protected]e99ca5112011-09-26 17:22:54183 if (!url.is_empty())
184 shell->LoadURL(url);
[email protected]9fbd3f862011-09-20 23:31:34185 return shell;
186}
187
188void Shell::LoadURL(const GURL& url) {
[email protected]d2494ff2013-02-20 08:22:37189 LoadURLForFrame(url, std::string());
190}
191
192void Shell::LoadURLForFrame(const GURL& url, const std::string& frame_name) {
193 NavigationController::LoadURLParams params(url);
Sylvain Defresnec6ccc77d2014-09-19 10:19:35194 params.transition_type = ui::PageTransitionFromInt(
195 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
[email protected]d2494ff2013-02-20 08:22:37196 params.frame_name = frame_name;
197 web_contents_->GetController().LoadURLWithParams(params);
[email protected]fc2b46b2014-05-03 16:33:45198 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34199}
200
[email protected]76bdecb2014-04-16 17:58:08201void Shell::LoadDataWithBaseURL(const GURL& url, const std::string& data,
202 const GURL& base_url) {
203 const GURL data_url = GURL("data:text/html;charset=utf-8," + data);
204 NavigationController::LoadURLParams params(data_url);
205 params.load_type = NavigationController::LOAD_TYPE_DATA;
206 params.base_url_for_data_url = base_url;
207 params.virtual_url_for_data_url = url;
208 params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE;
209 web_contents_->GetController().LoadURLWithParams(params);
[email protected]fc2b46b2014-05-03 16:33:45210 web_contents_->Focus();
[email protected]76bdecb2014-04-16 17:58:08211}
212
[email protected]a2904092013-10-15 04:53:59213void Shell::AddNewContents(WebContents* source,
214 WebContents* new_contents,
215 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:39216 const gfx::Rect& initial_rect,
[email protected]a2904092013-10-15 04:53:59217 bool user_gesture,
218 bool* was_blocked) {
bokan107a47f2015-02-03 23:23:39219 CreateShell(new_contents, AdjustWindowSize(initial_rect.size()));
avi83883c82014-12-23 00:08:49220 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
paulmeyerbcc6ad22015-02-11 21:51:59221 switches::kRunLayoutTest))
[email protected]a2904092013-10-15 04:53:59222 NotifyDoneForwarder::CreateForWebContents(new_contents);
223}
224
[email protected]9fbd3f862011-09-20 23:31:34225void Shell::GoBackOrForward(int offset) {
[email protected]0b659b32012-03-26 21:29:32226 web_contents_->GetController().GoToOffset(offset);
[email protected]fc2b46b2014-05-03 16:33:45227 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34228}
229
230void Shell::Reload() {
[email protected]0b659b32012-03-26 21:29:32231 web_contents_->GetController().Reload(false);
[email protected]fc2b46b2014-05-03 16:33:45232 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34233}
234
235void Shell::Stop() {
[email protected]0b659b32012-03-26 21:29:32236 web_contents_->Stop();
[email protected]fc2b46b2014-05-03 16:33:45237 web_contents_->Focus();
[email protected]9fbd3f862011-09-20 23:31:34238}
239
[email protected]e3b10d12014-03-28 16:06:09240void Shell::UpdateNavigationControls(bool to_different_document) {
[email protected]0b659b32012-03-26 21:29:32241 int current_index = web_contents_->GetController().GetCurrentEntryIndex();
242 int max_index = web_contents_->GetController().GetEntryCount() - 1;
[email protected]9fbd3f862011-09-20 23:31:34243
244 PlatformEnableUIControl(BACK_BUTTON, current_index > 0);
245 PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index);
[email protected]e3b10d12014-03-28 16:06:09246 PlatformEnableUIControl(STOP_BUTTON,
247 to_different_document && web_contents_->IsLoading());
[email protected]9fbd3f862011-09-20 23:31:34248}
249
[email protected]7c17b6992012-08-09 16:16:30250void Shell::ShowDevTools() {
pfeldman552756452015-02-03 17:33:06251 InnerShowDevTools();
[email protected]3142e5d2014-02-07 00:54:46252}
253
254void Shell::ShowDevToolsForElementAt(int x, int y) {
pfeldman552756452015-02-03 17:33:06255 InnerShowDevTools();
[email protected]2317fcd2014-02-10 14:36:48256 devtools_frontend_->InspectElementAt(x, y);
[email protected]7c17b6992012-08-09 16:16:30257}
258
[email protected]001841c92012-12-11 17:00:13259void Shell::CloseDevTools() {
[email protected]0773e0c2013-01-25 15:57:57260 if (!devtools_frontend_)
[email protected]001841c92012-12-11 17:00:13261 return;
[email protected]7fff43e2013-05-21 20:21:10262 devtools_observer_.reset();
[email protected]0773e0c2013-01-25 15:57:57263 devtools_frontend_->Close();
264 devtools_frontend_ = NULL;
[email protected]001841c92012-12-11 17:00:13265}
266
[email protected]9fbd3f862011-09-20 23:31:34267gfx::NativeView Shell::GetContentView() {
[email protected]59383c782013-04-17 16:43:27268 if (!web_contents_)
[email protected]9fbd3f862011-09-20 23:31:34269 return NULL;
[email protected]fc2b46b2014-05-03 16:33:45270 return web_contents_->GetNativeView();
[email protected]9fbd3f862011-09-20 23:31:34271}
272
alexmos5a98a052016-01-06 00:15:02273WebContents* Shell::OpenURLFromTab(WebContents* source,
274 const OpenURLParams& params) {
275 // This implementation only handles CURRENT_TAB.
276 if (params.disposition != CURRENT_TAB)
277 return nullptr;
278
279 NavigationController::LoadURLParams load_url_params(params.url);
280 load_url_params.source_site_instance = params.source_site_instance;
281 load_url_params.transition_type = params.transition;
282 load_url_params.frame_tree_node_id = params.frame_tree_node_id;
283 load_url_params.referrer = params.referrer;
284 load_url_params.redirect_chain = params.redirect_chain;
285 load_url_params.extra_headers = params.extra_headers;
286 load_url_params.is_renderer_initiated = params.is_renderer_initiated;
287 load_url_params.transferred_global_request_id =
288 params.transferred_global_request_id;
289 load_url_params.should_replace_current_entry =
290 params.should_replace_current_entry;
291
292 // Only allows the browser-initiated navigation to use POST.
293 if (params.uses_post && !params.is_renderer_initiated) {
294 load_url_params.load_type =
295 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST;
296 load_url_params.browser_initiated_post_data =
297 params.browser_initiated_post_data;
298 }
299
300 source->GetController().LoadURLWithParams(load_url_params);
301 return source;
302}
303
[email protected]e3b10d12014-03-28 16:06:09304void Shell::LoadingStateChanged(WebContents* source,
305 bool to_different_document) {
306 UpdateNavigationControls(to_different_document);
[email protected]15aea412012-01-19 03:18:50307 PlatformSetIsLoading(source->IsLoading());
[email protected]e99ca5112011-09-26 17:22:54308}
309
mlamouri7a78d6fd2015-01-17 13:23:53310void Shell::EnterFullscreenModeForTab(WebContents* web_contents,
311 const GURL& origin) {
312 ToggleFullscreenModeForTab(web_contents, true);
313}
314
315void Shell::ExitFullscreenModeForTab(WebContents* web_contents) {
316 ToggleFullscreenModeForTab(web_contents, false);
317}
318
[email protected]99c014c2012-11-27 12:03:42319void Shell::ToggleFullscreenModeForTab(WebContents* web_contents,
320 bool enter_fullscreen) {
321#if defined(OS_ANDROID)
322 PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen);
323#endif
avi83883c82014-12-23 00:08:49324 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
paulmeyerbcc6ad22015-02-11 21:51:59325 switches::kRunLayoutTest))
[email protected]99c014c2012-11-27 12:03:42326 return;
327 if (is_fullscreen_ != enter_fullscreen) {
328 is_fullscreen_ = enter_fullscreen;
avif9ab5d942015-10-15 14:05:44329 web_contents->GetRenderViewHost()->GetWidget()->WasResized();
[email protected]99c014c2012-11-27 12:03:42330 }
331}
332
333bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const {
334#if defined(OS_ANDROID)
335 return PlatformIsFullscreenForTabOrPending(web_contents);
336#else
337 return is_fullscreen_;
338#endif
339}
340
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12341blink::WebDisplayMode Shell::GetDisplayMode(
342 const WebContents* web_contents) const {
343 // TODO : should return blink::WebDisplayModeFullscreen wherever user puts
344 // a browser window into fullscreen (not only in case of renderer-initiated
345 // fullscreen mode): crbug.com/476874.
346 return IsFullscreenForTabOrPending(web_contents) ?
347 blink::WebDisplayModeFullscreen : blink::WebDisplayModeBrowser;
348}
349
[email protected]f78439002012-11-28 14:45:59350void Shell::RequestToLockMouse(WebContents* web_contents,
351 bool user_gesture,
352 bool last_unlocked_by_target) {
353 web_contents->GotResponseToLockMouseRequest(true);
354}
355
[email protected]9e00e6352012-07-30 17:05:18356void Shell::CloseContents(WebContents* source) {
357 Close();
358}
359
[email protected]067310262012-11-22 14:30:41360bool Shell::CanOverscrollContent() const {
361#if defined(USE_AURA)
362 return true;
363#else
364 return false;
365#endif
366}
367
[email protected]3bbacc5b2012-04-17 17:46:15368void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) {
[email protected]4e3c7522013-08-13 11:53:18369 PlatformSetAddressBarURL(web_contents->GetLastCommittedURL());
[email protected]e99ca5112011-09-26 17:22:54370}
371
mathiash72a5e462014-11-19 08:18:50372JavaScriptDialogManager* Shell::GetJavaScriptDialogManager(
373 WebContents* source) {
mkwst6efe7f2e62014-10-08 15:09:01374 if (!dialog_manager_) {
avi83883c82014-12-23 00:08:49375 const base::CommandLine& command_line =
376 *base::CommandLine::ForCurrentProcess();
paulmeyerbcc6ad22015-02-11 21:51:59377 dialog_manager_.reset(command_line.HasSwitch(switches::kRunLayoutTest)
mkwst6efe7f2e62014-10-08 15:09:01378 ? new LayoutTestJavaScriptDialogManager
379 : new ShellJavaScriptDialogManager);
380 }
[email protected]71a88bb2013-02-01 22:05:15381 return dialog_manager_.get();
[email protected]f2210022012-03-29 00:36:08382}
383
jyasskin8057c002015-09-10 19:09:53384scoped_ptr<BluetoothChooser> Shell::RunBluetoothChooser(
385 WebContents* web_contents,
386 const BluetoothChooser::EventHandler& event_handler,
387 const GURL& origin) {
388 const base::CommandLine& command_line =
389 *base::CommandLine::ForCurrentProcess();
390 if (command_line.HasSwitch(switches::kRunLayoutTest)) {
391 return BlinkTestController::Get()->RunBluetoothChooser(
392 web_contents, event_handler, origin);
393 }
394 return nullptr;
395}
396
[email protected]c272c5b2012-06-06 09:01:06397bool Shell::AddMessageToConsole(WebContents* source,
avi66a07722015-12-25 23:38:12398 int32_t level,
[email protected]fcf75d42013-12-03 20:11:26399 const base::string16& message,
avi66a07722015-12-25 23:38:12400 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:26401 const base::string16& source_id) {
avi83883c82014-12-23 00:08:49402 return base::CommandLine::ForCurrentProcess()->HasSwitch(
paulmeyerbcc6ad22015-02-11 21:51:59403 switches::kRunLayoutTest);
[email protected]efb5f572012-01-29 10:57:33404}
405
[email protected]5bf68f22012-08-31 07:38:10406void Shell::RendererUnresponsive(WebContents* source) {
avi83883c82014-12-23 00:08:49407 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
paulmeyerbcc6ad22015-02-11 21:51:59408 switches::kRunLayoutTest))
[email protected]5bf68f22012-08-31 07:38:10409 return;
tfarinacde91252015-05-06 16:10:49410 BlinkTestController::Get()->RendererUnresponsive();
[email protected]5bf68f22012-08-31 07:38:10411}
412
[email protected]233567d2013-02-27 20:22:02413void Shell::ActivateContents(WebContents* contents) {
avif9ab5d942015-10-15 14:05:44414 contents->GetRenderViewHost()->GetWidget()->Focus();
[email protected]233567d2013-02-27 20:22:02415}
416
[email protected]3142e5d2014-02-07 00:54:46417bool Shell::HandleContextMenu(const content::ContextMenuParams& params) {
418 return PlatformHandleContextMenu(params);
419}
420
pdrcab84ee2015-03-13 21:47:04421gfx::Size Shell::GetShellDefaultSize() {
422 static gfx::Size default_shell_size;
423 if (!default_shell_size.IsEmpty())
424 return default_shell_size;
425 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
426 if (command_line->HasSwitch(switches::kContentShellHostWindowSize)) {
427 const std::string size_str = command_line->GetSwitchValueASCII(
428 switches::kContentShellHostWindowSize);
429 int width, height;
430 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height));
431 default_shell_size = gfx::Size(width, height);
432 } else {
433 default_shell_size = gfx::Size(
434 kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip);
435 }
436 return default_shell_size;
437}
438
[email protected]1ef02d242013-10-07 16:18:53439void Shell::TitleWasSet(NavigationEntry* entry, bool explicit_set) {
440 if (entry)
441 PlatformSetTitle(entry->GetTitle());
[email protected]aecc085b2012-06-01 18:15:53442}
443
pfeldman552756452015-02-03 17:33:06444void Shell::InnerShowDevTools() {
[email protected]fee9eca02014-02-14 19:24:40445 if (!devtools_frontend_) {
pfeldman552756452015-02-03 17:33:06446 devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents());
[email protected]fee9eca02014-02-14 19:24:40447 devtools_observer_.reset(new DevToolsWebContentsObserver(
448 this, devtools_frontend_->frontend_shell()->web_contents()));
449 }
450
451 devtools_frontend_->Activate();
452 devtools_frontend_->Focus();
453}
454
[email protected]7fff43e2013-05-21 20:21:10455void Shell::OnDevToolsWebContentsDestroyed() {
456 devtools_observer_.reset();
457 devtools_frontend_ = NULL;
458}
459
[email protected]9fbd3f862011-09-20 23:31:34460} // namespace content