OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/browser/shell.h" | 5 #include "content/shell/browser/shell.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 Shell::Shell(WebContents* web_contents) | 71 Shell::Shell(WebContents* web_contents) |
72 : WebContentsObserver(web_contents), | 72 : WebContentsObserver(web_contents), |
73 devtools_frontend_(NULL), | 73 devtools_frontend_(NULL), |
74 is_fullscreen_(false), | 74 is_fullscreen_(false), |
75 window_(NULL), | 75 window_(NULL), |
76 #if defined(OS_MACOSX) | 76 #if defined(OS_MACOSX) |
77 url_edit_view_(NULL), | 77 url_edit_view_(NULL), |
78 #endif | 78 #endif |
79 headless_(false) { | 79 headless_(false) { |
80 const base::CommandLine& command_line = | 80 if (switches::IsRunLayoutTestSwitchPresent()) |
81 *base::CommandLine::ForCurrentProcess(); | |
82 if (command_line.HasSwitch(switches::kRunLayoutTest)) | |
83 headless_ = true; | 81 headless_ = true; |
84 windows_.push_back(this); | 82 windows_.push_back(this); |
85 | 83 |
86 if (!shell_created_callback_.is_null()) { | 84 if (!shell_created_callback_.is_null()) { |
87 shell_created_callback_.Run(this); | 85 shell_created_callback_.Run(this); |
88 shell_created_callback_.Reset(); | 86 shell_created_callback_.Reset(); |
89 } | 87 } |
90 } | 88 } |
91 | 89 |
92 Shell::~Shell() { | 90 Shell::~Shell() { |
(...skipping 22 matching lines...) Expand all Loading... |
115 shell->web_contents_.reset(web_contents); | 113 shell->web_contents_.reset(web_contents); |
116 web_contents->SetDelegate(shell); | 114 web_contents->SetDelegate(shell); |
117 | 115 |
118 shell->PlatformSetContents(); | 116 shell->PlatformSetContents(); |
119 | 117 |
120 shell->PlatformResizeSubViews(); | 118 shell->PlatformResizeSubViews(); |
121 | 119 |
122 // Note: Do not make RenderFrameHost or RenderViewHost specific state changes | 120 // Note: Do not make RenderFrameHost or RenderViewHost specific state changes |
123 // here, because they will be forgotten after a cross-process navigation. Use | 121 // here, because they will be forgotten after a cross-process navigation. Use |
124 // RenderFrameCreated or RenderViewCreated instead. | 122 // RenderFrameCreated or RenderViewCreated instead. |
125 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 123 if (switches::IsRunLayoutTestSwitchPresent()) { |
126 if (command_line->HasSwitch(switches::kRunLayoutTest)) { | |
127 web_contents->GetMutableRendererPrefs()->use_custom_colors = false; | 124 web_contents->GetMutableRendererPrefs()->use_custom_colors = false; |
128 web_contents->GetRenderViewHost()->SyncRendererPrefs(); | 125 web_contents->GetRenderViewHost()->SyncRendererPrefs(); |
129 } | 126 } |
130 | 127 |
131 #if defined(ENABLE_WEBRTC) | 128 #if defined(ENABLE_WEBRTC) |
| 129 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
132 if (command_line->HasSwitch(switches::kForceWebRtcIPHandlingPolicy)) { | 130 if (command_line->HasSwitch(switches::kForceWebRtcIPHandlingPolicy)) { |
133 web_contents->GetMutableRendererPrefs()->webrtc_ip_handling_policy = | 131 web_contents->GetMutableRendererPrefs()->webrtc_ip_handling_policy = |
134 command_line->GetSwitchValueASCII( | 132 command_line->GetSwitchValueASCII( |
135 switches::kForceWebRtcIPHandlingPolicy); | 133 switches::kForceWebRtcIPHandlingPolicy); |
136 } | 134 } |
137 #endif | 135 #endif |
138 | 136 |
139 return shell; | 137 return shell; |
140 } | 138 } |
141 | 139 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 web_contents_->Focus(); | 244 web_contents_->Focus(); |
247 } | 245 } |
248 | 246 |
249 void Shell::AddNewContents(WebContents* source, | 247 void Shell::AddNewContents(WebContents* source, |
250 WebContents* new_contents, | 248 WebContents* new_contents, |
251 WindowOpenDisposition disposition, | 249 WindowOpenDisposition disposition, |
252 const gfx::Rect& initial_rect, | 250 const gfx::Rect& initial_rect, |
253 bool user_gesture, | 251 bool user_gesture, |
254 bool* was_blocked) { | 252 bool* was_blocked) { |
255 CreateShell(new_contents, AdjustWindowSize(initial_rect.size())); | 253 CreateShell(new_contents, AdjustWindowSize(initial_rect.size())); |
256 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 254 if (switches::IsRunLayoutTestSwitchPresent()) |
257 switches::kRunLayoutTest)) | |
258 NotifyDoneForwarder::CreateForWebContents(new_contents); | 255 NotifyDoneForwarder::CreateForWebContents(new_contents); |
259 } | 256 } |
260 | 257 |
261 void Shell::GoBackOrForward(int offset) { | 258 void Shell::GoBackOrForward(int offset) { |
262 web_contents_->GetController().GoToOffset(offset); | 259 web_contents_->GetController().GoToOffset(offset); |
263 web_contents_->Focus(); | 260 web_contents_->Focus(); |
264 } | 261 } |
265 | 262 |
266 void Shell::Reload() { | 263 void Shell::Reload() { |
267 web_contents_->GetController().Reload(false); | 264 web_contents_->GetController().Reload(false); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 345 |
349 void Shell::ExitFullscreenModeForTab(WebContents* web_contents) { | 346 void Shell::ExitFullscreenModeForTab(WebContents* web_contents) { |
350 ToggleFullscreenModeForTab(web_contents, false); | 347 ToggleFullscreenModeForTab(web_contents, false); |
351 } | 348 } |
352 | 349 |
353 void Shell::ToggleFullscreenModeForTab(WebContents* web_contents, | 350 void Shell::ToggleFullscreenModeForTab(WebContents* web_contents, |
354 bool enter_fullscreen) { | 351 bool enter_fullscreen) { |
355 #if defined(OS_ANDROID) | 352 #if defined(OS_ANDROID) |
356 PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen); | 353 PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen); |
357 #endif | 354 #endif |
358 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 355 if (!switches::IsRunLayoutTestSwitchPresent()) |
359 switches::kRunLayoutTest)) | |
360 return; | 356 return; |
361 if (is_fullscreen_ != enter_fullscreen) { | 357 if (is_fullscreen_ != enter_fullscreen) { |
362 is_fullscreen_ = enter_fullscreen; | 358 is_fullscreen_ = enter_fullscreen; |
363 web_contents->GetRenderViewHost()->GetWidget()->WasResized(); | 359 web_contents->GetRenderViewHost()->GetWidget()->WasResized(); |
364 } | 360 } |
365 } | 361 } |
366 | 362 |
367 bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const { | 363 bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const { |
368 #if defined(OS_ANDROID) | 364 #if defined(OS_ANDROID) |
369 return PlatformIsFullscreenForTabOrPending(web_contents); | 365 return PlatformIsFullscreenForTabOrPending(web_contents); |
(...skipping 29 matching lines...) Expand all Loading... |
399 #endif | 395 #endif |
400 } | 396 } |
401 | 397 |
402 void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) { | 398 void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
403 PlatformSetAddressBarURL(web_contents->GetLastCommittedURL()); | 399 PlatformSetAddressBarURL(web_contents->GetLastCommittedURL()); |
404 } | 400 } |
405 | 401 |
406 JavaScriptDialogManager* Shell::GetJavaScriptDialogManager( | 402 JavaScriptDialogManager* Shell::GetJavaScriptDialogManager( |
407 WebContents* source) { | 403 WebContents* source) { |
408 if (!dialog_manager_) { | 404 if (!dialog_manager_) { |
409 const base::CommandLine& command_line = | 405 dialog_manager_.reset(switches::IsRunLayoutTestSwitchPresent() |
410 *base::CommandLine::ForCurrentProcess(); | 406 ? new LayoutTestJavaScriptDialogManager |
411 dialog_manager_.reset(command_line.HasSwitch(switches::kRunLayoutTest) | 407 : new ShellJavaScriptDialogManager); |
412 ? new LayoutTestJavaScriptDialogManager | |
413 : new ShellJavaScriptDialogManager); | |
414 } | 408 } |
415 return dialog_manager_.get(); | 409 return dialog_manager_.get(); |
416 } | 410 } |
417 | 411 |
418 scoped_ptr<BluetoothChooser> Shell::RunBluetoothChooser( | 412 scoped_ptr<BluetoothChooser> Shell::RunBluetoothChooser( |
419 RenderFrameHost* frame, | 413 RenderFrameHost* frame, |
420 const BluetoothChooser::EventHandler& event_handler) { | 414 const BluetoothChooser::EventHandler& event_handler) { |
421 const base::CommandLine& command_line = | 415 if (switches::IsRunLayoutTestSwitchPresent()) { |
422 *base::CommandLine::ForCurrentProcess(); | |
423 if (command_line.HasSwitch(switches::kRunLayoutTest)) { | |
424 return BlinkTestController::Get()->RunBluetoothChooser(frame, | 416 return BlinkTestController::Get()->RunBluetoothChooser(frame, |
425 event_handler); | 417 event_handler); |
426 } | 418 } |
427 return nullptr; | 419 return nullptr; |
428 } | 420 } |
429 | 421 |
430 bool Shell::AddMessageToConsole(WebContents* source, | 422 bool Shell::AddMessageToConsole(WebContents* source, |
431 int32_t level, | 423 int32_t level, |
432 const base::string16& message, | 424 const base::string16& message, |
433 int32_t line_no, | 425 int32_t line_no, |
434 const base::string16& source_id) { | 426 const base::string16& source_id) { |
435 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 427 return switches::IsRunLayoutTestSwitchPresent(); |
436 switches::kRunLayoutTest); | |
437 } | 428 } |
438 | 429 |
439 void Shell::RendererUnresponsive(WebContents* source) { | 430 void Shell::RendererUnresponsive(WebContents* source) { |
440 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 431 if (switches::IsRunLayoutTestSwitchPresent()) |
441 switches::kRunLayoutTest)) | 432 BlinkTestController::Get()->RendererUnresponsive(); |
442 return; | |
443 BlinkTestController::Get()->RendererUnresponsive(); | |
444 } | 433 } |
445 | 434 |
446 void Shell::ActivateContents(WebContents* contents) { | 435 void Shell::ActivateContents(WebContents* contents) { |
447 contents->GetRenderViewHost()->GetWidget()->Focus(); | 436 contents->GetRenderViewHost()->GetWidget()->Focus(); |
448 } | 437 } |
449 | 438 |
450 bool Shell::HandleContextMenu(const content::ContextMenuParams& params) { | 439 bool Shell::HandleContextMenu(const content::ContextMenuParams& params) { |
451 return PlatformHandleContextMenu(params); | 440 return PlatformHandleContextMenu(params); |
452 } | 441 } |
453 | 442 |
(...skipping 10 matching lines...) Expand all Loading... |
464 default_shell_size = gfx::Size(width, height); | 453 default_shell_size = gfx::Size(width, height); |
465 } else { | 454 } else { |
466 default_shell_size = gfx::Size( | 455 default_shell_size = gfx::Size( |
467 kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip); | 456 kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip); |
468 } | 457 } |
469 return default_shell_size; | 458 return default_shell_size; |
470 } | 459 } |
471 | 460 |
472 void Shell::RenderViewCreated(RenderViewHost* render_view_host) { | 461 void Shell::RenderViewCreated(RenderViewHost* render_view_host) { |
473 // All RenderViewHosts in layout tests should get Mojo bindings. | 462 // All RenderViewHosts in layout tests should get Mojo bindings. |
474 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 463 if (switches::IsRunLayoutTestSwitchPresent()) |
475 if (command_line->HasSwitch(switches::kRunLayoutTest)) | |
476 render_view_host->AllowBindings(BINDINGS_POLICY_MOJO); | 464 render_view_host->AllowBindings(BINDINGS_POLICY_MOJO); |
477 } | 465 } |
478 | 466 |
479 void Shell::TitleWasSet(NavigationEntry* entry, bool explicit_set) { | 467 void Shell::TitleWasSet(NavigationEntry* entry, bool explicit_set) { |
480 if (entry) | 468 if (entry) |
481 PlatformSetTitle(entry->GetTitle()); | 469 PlatformSetTitle(entry->GetTitle()); |
482 } | 470 } |
483 | 471 |
484 void Shell::InnerShowDevTools() { | 472 void Shell::InnerShowDevTools() { |
485 if (!devtools_frontend_) { | 473 if (!devtools_frontend_) { |
486 devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents()); | 474 devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents()); |
487 devtools_observer_.reset(new DevToolsWebContentsObserver( | 475 devtools_observer_.reset(new DevToolsWebContentsObserver( |
488 this, devtools_frontend_->frontend_shell()->web_contents())); | 476 this, devtools_frontend_->frontend_shell()->web_contents())); |
489 } | 477 } |
490 | 478 |
491 devtools_frontend_->Activate(); | 479 devtools_frontend_->Activate(); |
492 devtools_frontend_->Focus(); | 480 devtools_frontend_->Focus(); |
493 } | 481 } |
494 | 482 |
495 void Shell::OnDevToolsWebContentsDestroyed() { | 483 void Shell::OnDevToolsWebContentsDestroyed() { |
496 devtools_observer_.reset(); | 484 devtools_observer_.reset(); |
497 devtools_frontend_ = NULL; | 485 devtools_frontend_ = NULL; |
498 } | 486 } |
499 | 487 |
500 } // namespace content | 488 } // namespace content |
OLD | NEW |