| 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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver); | 77 DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 Shell::Shell(WebContents* web_contents) | 80 Shell::Shell(WebContents* web_contents) |
| 81 : WebContentsObserver(web_contents), | 81 : WebContentsObserver(web_contents), |
| 82 devtools_frontend_(NULL), | 82 devtools_frontend_(NULL), |
| 83 is_fullscreen_(false), | 83 is_fullscreen_(false), |
| 84 window_(NULL), | 84 window_(NULL), |
| 85 url_edit_view_(NULL), | 85 url_edit_view_(NULL), |
| 86 headless_(false) { | 86 headless_(false) { |
| 87 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 87 const base::CommandLine& command_line = |
| 88 *base::CommandLine::ForCurrentProcess(); |
| 88 if (command_line.HasSwitch(switches::kDumpRenderTree)) | 89 if (command_line.HasSwitch(switches::kDumpRenderTree)) |
| 89 headless_ = true; | 90 headless_ = true; |
| 90 windows_.push_back(this); | 91 windows_.push_back(this); |
| 91 | 92 |
| 92 if (!shell_created_callback_.is_null()) { | 93 if (!shell_created_callback_.is_null()) { |
| 93 shell_created_callback_.Run(this); | 94 shell_created_callback_.Run(this); |
| 94 shell_created_callback_.Reset(); | 95 shell_created_callback_.Reset(); |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 | 98 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 118 Shell* shell = new Shell(web_contents); | 119 Shell* shell = new Shell(web_contents); |
| 119 shell->PlatformCreateWindow(initial_size.width(), initial_size.height()); | 120 shell->PlatformCreateWindow(initial_size.width(), initial_size.height()); |
| 120 | 121 |
| 121 shell->web_contents_.reset(web_contents); | 122 shell->web_contents_.reset(web_contents); |
| 122 web_contents->SetDelegate(shell); | 123 web_contents->SetDelegate(shell); |
| 123 | 124 |
| 124 shell->PlatformSetContents(); | 125 shell->PlatformSetContents(); |
| 125 | 126 |
| 126 shell->PlatformResizeSubViews(); | 127 shell->PlatformResizeSubViews(); |
| 127 | 128 |
| 128 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { | 129 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 130 switches::kDumpRenderTree)) { |
| 129 web_contents->GetMutableRendererPrefs()->use_custom_colors = false; | 131 web_contents->GetMutableRendererPrefs()->use_custom_colors = false; |
| 130 web_contents->GetRenderViewHost()->SyncRendererPrefs(); | 132 web_contents->GetRenderViewHost()->SyncRendererPrefs(); |
| 131 } | 133 } |
| 132 | 134 |
| 133 return shell; | 135 return shell; |
| 134 } | 136 } |
| 135 | 137 |
| 136 void Shell::CloseAllWindows() { | 138 void Shell::CloseAllWindows() { |
| 137 base::AutoReset<bool> auto_reset(&quit_message_loop_, false); | 139 base::AutoReset<bool> auto_reset(&quit_message_loop_, false); |
| 138 DevToolsAgentHost::DetachAllClients(); | 140 DevToolsAgentHost::DetachAllClients(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 web_contents_->Focus(); | 210 web_contents_->Focus(); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void Shell::AddNewContents(WebContents* source, | 213 void Shell::AddNewContents(WebContents* source, |
| 212 WebContents* new_contents, | 214 WebContents* new_contents, |
| 213 WindowOpenDisposition disposition, | 215 WindowOpenDisposition disposition, |
| 214 const gfx::Rect& initial_pos, | 216 const gfx::Rect& initial_pos, |
| 215 bool user_gesture, | 217 bool user_gesture, |
| 216 bool* was_blocked) { | 218 bool* was_blocked) { |
| 217 CreateShell(new_contents, AdjustWindowSize(initial_pos.size())); | 219 CreateShell(new_contents, AdjustWindowSize(initial_pos.size())); |
| 218 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | 220 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 221 switches::kDumpRenderTree)) |
| 219 NotifyDoneForwarder::CreateForWebContents(new_contents); | 222 NotifyDoneForwarder::CreateForWebContents(new_contents); |
| 220 } | 223 } |
| 221 | 224 |
| 222 void Shell::GoBackOrForward(int offset) { | 225 void Shell::GoBackOrForward(int offset) { |
| 223 web_contents_->GetController().GoToOffset(offset); | 226 web_contents_->GetController().GoToOffset(offset); |
| 224 web_contents_->Focus(); | 227 web_contents_->Focus(); |
| 225 } | 228 } |
| 226 | 229 |
| 227 void Shell::Reload() { | 230 void Shell::Reload() { |
| 228 web_contents_->GetController().Reload(false); | 231 web_contents_->GetController().Reload(false); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 bool to_different_document) { | 305 bool to_different_document) { |
| 303 UpdateNavigationControls(to_different_document); | 306 UpdateNavigationControls(to_different_document); |
| 304 PlatformSetIsLoading(source->IsLoading()); | 307 PlatformSetIsLoading(source->IsLoading()); |
| 305 } | 308 } |
| 306 | 309 |
| 307 void Shell::ToggleFullscreenModeForTab(WebContents* web_contents, | 310 void Shell::ToggleFullscreenModeForTab(WebContents* web_contents, |
| 308 bool enter_fullscreen) { | 311 bool enter_fullscreen) { |
| 309 #if defined(OS_ANDROID) | 312 #if defined(OS_ANDROID) |
| 310 PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen); | 313 PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen); |
| 311 #endif | 314 #endif |
| 312 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | 315 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 316 switches::kDumpRenderTree)) |
| 313 return; | 317 return; |
| 314 if (is_fullscreen_ != enter_fullscreen) { | 318 if (is_fullscreen_ != enter_fullscreen) { |
| 315 is_fullscreen_ = enter_fullscreen; | 319 is_fullscreen_ = enter_fullscreen; |
| 316 web_contents->GetRenderViewHost()->WasResized(); | 320 web_contents->GetRenderViewHost()->WasResized(); |
| 317 } | 321 } |
| 318 } | 322 } |
| 319 | 323 |
| 320 bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const { | 324 bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const { |
| 321 #if defined(OS_ANDROID) | 325 #if defined(OS_ANDROID) |
| 322 return PlatformIsFullscreenForTabOrPending(web_contents); | 326 return PlatformIsFullscreenForTabOrPending(web_contents); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 343 #endif | 347 #endif |
| 344 } | 348 } |
| 345 | 349 |
| 346 void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) { | 350 void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
| 347 PlatformSetAddressBarURL(web_contents->GetLastCommittedURL()); | 351 PlatformSetAddressBarURL(web_contents->GetLastCommittedURL()); |
| 348 } | 352 } |
| 349 | 353 |
| 350 JavaScriptDialogManager* Shell::GetJavaScriptDialogManager( | 354 JavaScriptDialogManager* Shell::GetJavaScriptDialogManager( |
| 351 WebContents* source) { | 355 WebContents* source) { |
| 352 if (!dialog_manager_) { | 356 if (!dialog_manager_) { |
| 353 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 357 const base::CommandLine& command_line = |
| 358 *base::CommandLine::ForCurrentProcess(); |
| 354 dialog_manager_.reset(command_line.HasSwitch(switches::kDumpRenderTree) | 359 dialog_manager_.reset(command_line.HasSwitch(switches::kDumpRenderTree) |
| 355 ? new LayoutTestJavaScriptDialogManager | 360 ? new LayoutTestJavaScriptDialogManager |
| 356 : new ShellJavaScriptDialogManager); | 361 : new ShellJavaScriptDialogManager); |
| 357 } | 362 } |
| 358 return dialog_manager_.get(); | 363 return dialog_manager_.get(); |
| 359 } | 364 } |
| 360 | 365 |
| 361 bool Shell::AddMessageToConsole(WebContents* source, | 366 bool Shell::AddMessageToConsole(WebContents* source, |
| 362 int32 level, | 367 int32 level, |
| 363 const base::string16& message, | 368 const base::string16& message, |
| 364 int32 line_no, | 369 int32 line_no, |
| 365 const base::string16& source_id) { | 370 const base::string16& source_id) { |
| 366 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); | 371 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 372 switches::kDumpRenderTree); |
| 367 } | 373 } |
| 368 | 374 |
| 369 void Shell::RendererUnresponsive(WebContents* source) { | 375 void Shell::RendererUnresponsive(WebContents* source) { |
| 370 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | 376 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 377 switches::kDumpRenderTree)) |
| 371 return; | 378 return; |
| 372 WebKitTestController::Get()->RendererUnresponsive(); | 379 WebKitTestController::Get()->RendererUnresponsive(); |
| 373 } | 380 } |
| 374 | 381 |
| 375 void Shell::ActivateContents(WebContents* contents) { | 382 void Shell::ActivateContents(WebContents* contents) { |
| 376 contents->GetRenderViewHost()->Focus(); | 383 contents->GetRenderViewHost()->Focus(); |
| 377 } | 384 } |
| 378 | 385 |
| 379 void Shell::DeactivateContents(WebContents* contents) { | 386 void Shell::DeactivateContents(WebContents* contents) { |
| 380 contents->GetRenderViewHost()->Blur(); | 387 contents->GetRenderViewHost()->Blur(); |
| 381 } | 388 } |
| 382 | 389 |
| 383 void Shell::WorkerCrashed(WebContents* source) { | 390 void Shell::WorkerCrashed(WebContents* source) { |
| 384 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | 391 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 392 switches::kDumpRenderTree)) |
| 385 return; | 393 return; |
| 386 WebKitTestController::Get()->WorkerCrashed(); | 394 WebKitTestController::Get()->WorkerCrashed(); |
| 387 } | 395 } |
| 388 | 396 |
| 389 bool Shell::HandleContextMenu(const content::ContextMenuParams& params) { | 397 bool Shell::HandleContextMenu(const content::ContextMenuParams& params) { |
| 390 return PlatformHandleContextMenu(params); | 398 return PlatformHandleContextMenu(params); |
| 391 } | 399 } |
| 392 | 400 |
| 393 void Shell::WebContentsFocused(WebContents* contents) { | 401 void Shell::WebContentsFocused(WebContents* contents) { |
| 394 #if defined(TOOLKIT_VIEWS) | 402 #if defined(TOOLKIT_VIEWS) |
| 395 PlatformWebContentsFocused(contents); | 403 PlatformWebContentsFocused(contents); |
| 396 #endif | 404 #endif |
| 397 } | 405 } |
| 398 | 406 |
| 399 void Shell::TitleWasSet(NavigationEntry* entry, bool explicit_set) { | 407 void Shell::TitleWasSet(NavigationEntry* entry, bool explicit_set) { |
| 400 if (entry) | 408 if (entry) |
| 401 PlatformSetTitle(entry->GetTitle()); | 409 PlatformSetTitle(entry->GetTitle()); |
| 402 } | 410 } |
| 403 | 411 |
| 404 void Shell::InnerShowDevTools(const std::string& settings, | 412 void Shell::InnerShowDevTools(const std::string& settings, |
| 405 const std::string& frontend_url) { | 413 const std::string& frontend_url) { |
| 406 if (!devtools_frontend_) { | 414 if (!devtools_frontend_) { |
| 407 if (CommandLine::ForCurrentProcess()->HasSwitch( | 415 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 408 switches::kDumpRenderTree)) { | 416 switches::kDumpRenderTree)) { |
| 409 devtools_frontend_ = LayoutTestDevToolsFrontend::Show( | 417 devtools_frontend_ = LayoutTestDevToolsFrontend::Show( |
| 410 web_contents(), settings, frontend_url); | 418 web_contents(), settings, frontend_url); |
| 411 } else { | 419 } else { |
| 412 devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents()); | 420 devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents()); |
| 413 } | 421 } |
| 414 devtools_observer_.reset(new DevToolsWebContentsObserver( | 422 devtools_observer_.reset(new DevToolsWebContentsObserver( |
| 415 this, devtools_frontend_->frontend_shell()->web_contents())); | 423 this, devtools_frontend_->frontend_shell()->web_contents())); |
| 416 } | 424 } |
| 417 | 425 |
| 418 devtools_frontend_->Activate(); | 426 devtools_frontend_->Activate(); |
| 419 devtools_frontend_->Focus(); | 427 devtools_frontend_->Focus(); |
| 420 } | 428 } |
| 421 | 429 |
| 422 void Shell::OnDevToolsWebContentsDestroyed() { | 430 void Shell::OnDevToolsWebContentsDestroyed() { |
| 423 devtools_observer_.reset(); | 431 devtools_observer_.reset(); |
| 424 devtools_frontend_ = NULL; | 432 devtools_frontend_ = NULL; |
| 425 } | 433 } |
| 426 | 434 |
| 427 } // namespace content | 435 } // namespace content |
| OLD | NEW |