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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 base::CommandLine& command_line = | 87 const base::CommandLine& command_line = |
88 *base::CommandLine::ForCurrentProcess(); | 88 *base::CommandLine::ForCurrentProcess(); |
89 if (command_line.HasSwitch(switches::kDumpRenderTree)) | 89 if (command_line.HasSwitch(switches::kRunLayoutTest)) |
90 headless_ = true; | 90 headless_ = true; |
91 windows_.push_back(this); | 91 windows_.push_back(this); |
92 | 92 |
93 if (!shell_created_callback_.is_null()) { | 93 if (!shell_created_callback_.is_null()) { |
94 shell_created_callback_.Run(this); | 94 shell_created_callback_.Run(this); |
95 shell_created_callback_.Reset(); | 95 shell_created_callback_.Reset(); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 Shell::~Shell() { | 99 Shell::~Shell() { |
(...skipping 20 matching lines...) Expand all Loading... |
120 shell->PlatformCreateWindow(initial_size.width(), initial_size.height()); | 120 shell->PlatformCreateWindow(initial_size.width(), initial_size.height()); |
121 | 121 |
122 shell->web_contents_.reset(web_contents); | 122 shell->web_contents_.reset(web_contents); |
123 web_contents->SetDelegate(shell); | 123 web_contents->SetDelegate(shell); |
124 | 124 |
125 shell->PlatformSetContents(); | 125 shell->PlatformSetContents(); |
126 | 126 |
127 shell->PlatformResizeSubViews(); | 127 shell->PlatformResizeSubViews(); |
128 | 128 |
129 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 129 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
130 switches::kDumpRenderTree)) { | 130 switches::kRunLayoutTest)) { |
131 web_contents->GetMutableRendererPrefs()->use_custom_colors = false; | 131 web_contents->GetMutableRendererPrefs()->use_custom_colors = false; |
132 web_contents->GetRenderViewHost()->SyncRendererPrefs(); | 132 web_contents->GetRenderViewHost()->SyncRendererPrefs(); |
133 } | 133 } |
134 | 134 |
135 return shell; | 135 return shell; |
136 } | 136 } |
137 | 137 |
138 void Shell::CloseAllWindows() { | 138 void Shell::CloseAllWindows() { |
139 base::AutoReset<bool> auto_reset(&quit_message_loop_, false); | 139 base::AutoReset<bool> auto_reset(&quit_message_loop_, false); |
140 DevToolsAgentHost::DetachAllClients(); | 140 DevToolsAgentHost::DetachAllClients(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 211 } |
212 | 212 |
213 void Shell::AddNewContents(WebContents* source, | 213 void Shell::AddNewContents(WebContents* source, |
214 WebContents* new_contents, | 214 WebContents* new_contents, |
215 WindowOpenDisposition disposition, | 215 WindowOpenDisposition disposition, |
216 const gfx::Rect& initial_pos, | 216 const gfx::Rect& initial_pos, |
217 bool user_gesture, | 217 bool user_gesture, |
218 bool* was_blocked) { | 218 bool* was_blocked) { |
219 CreateShell(new_contents, AdjustWindowSize(initial_pos.size())); | 219 CreateShell(new_contents, AdjustWindowSize(initial_pos.size())); |
220 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 220 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
221 switches::kDumpRenderTree)) | 221 switches::kRunLayoutTest)) |
222 NotifyDoneForwarder::CreateForWebContents(new_contents); | 222 NotifyDoneForwarder::CreateForWebContents(new_contents); |
223 } | 223 } |
224 | 224 |
225 void Shell::GoBackOrForward(int offset) { | 225 void Shell::GoBackOrForward(int offset) { |
226 web_contents_->GetController().GoToOffset(offset); | 226 web_contents_->GetController().GoToOffset(offset); |
227 web_contents_->Focus(); | 227 web_contents_->Focus(); |
228 } | 228 } |
229 | 229 |
230 void Shell::Reload() { | 230 void Shell::Reload() { |
231 web_contents_->GetController().Reload(false); | 231 web_contents_->GetController().Reload(false); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 void Shell::ExitFullscreenModeForTab(WebContents* web_contents) { | 310 void Shell::ExitFullscreenModeForTab(WebContents* web_contents) { |
311 ToggleFullscreenModeForTab(web_contents, false); | 311 ToggleFullscreenModeForTab(web_contents, false); |
312 } | 312 } |
313 | 313 |
314 void Shell::ToggleFullscreenModeForTab(WebContents* web_contents, | 314 void Shell::ToggleFullscreenModeForTab(WebContents* web_contents, |
315 bool enter_fullscreen) { | 315 bool enter_fullscreen) { |
316 #if defined(OS_ANDROID) | 316 #if defined(OS_ANDROID) |
317 PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen); | 317 PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen); |
318 #endif | 318 #endif |
319 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 319 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
320 switches::kDumpRenderTree)) | 320 switches::kRunLayoutTest)) |
321 return; | 321 return; |
322 if (is_fullscreen_ != enter_fullscreen) { | 322 if (is_fullscreen_ != enter_fullscreen) { |
323 is_fullscreen_ = enter_fullscreen; | 323 is_fullscreen_ = enter_fullscreen; |
324 web_contents->GetRenderViewHost()->WasResized(); | 324 web_contents->GetRenderViewHost()->WasResized(); |
325 } | 325 } |
326 } | 326 } |
327 | 327 |
328 bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const { | 328 bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const { |
329 #if defined(OS_ANDROID) | 329 #if defined(OS_ANDROID) |
330 return PlatformIsFullscreenForTabOrPending(web_contents); | 330 return PlatformIsFullscreenForTabOrPending(web_contents); |
(...skipping 22 matching lines...) Expand all Loading... |
353 | 353 |
354 void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) { | 354 void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
355 PlatformSetAddressBarURL(web_contents->GetLastCommittedURL()); | 355 PlatformSetAddressBarURL(web_contents->GetLastCommittedURL()); |
356 } | 356 } |
357 | 357 |
358 JavaScriptDialogManager* Shell::GetJavaScriptDialogManager( | 358 JavaScriptDialogManager* Shell::GetJavaScriptDialogManager( |
359 WebContents* source) { | 359 WebContents* source) { |
360 if (!dialog_manager_) { | 360 if (!dialog_manager_) { |
361 const base::CommandLine& command_line = | 361 const base::CommandLine& command_line = |
362 *base::CommandLine::ForCurrentProcess(); | 362 *base::CommandLine::ForCurrentProcess(); |
363 dialog_manager_.reset(command_line.HasSwitch(switches::kDumpRenderTree) | 363 dialog_manager_.reset(command_line.HasSwitch(switches::kRunLayoutTest) |
364 ? new LayoutTestJavaScriptDialogManager | 364 ? new LayoutTestJavaScriptDialogManager |
365 : new ShellJavaScriptDialogManager); | 365 : new ShellJavaScriptDialogManager); |
366 } | 366 } |
367 return dialog_manager_.get(); | 367 return dialog_manager_.get(); |
368 } | 368 } |
369 | 369 |
370 bool Shell::AddMessageToConsole(WebContents* source, | 370 bool Shell::AddMessageToConsole(WebContents* source, |
371 int32 level, | 371 int32 level, |
372 const base::string16& message, | 372 const base::string16& message, |
373 int32 line_no, | 373 int32 line_no, |
374 const base::string16& source_id) { | 374 const base::string16& source_id) { |
375 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 375 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
376 switches::kDumpRenderTree); | 376 switches::kRunLayoutTest); |
377 } | 377 } |
378 | 378 |
379 void Shell::RendererUnresponsive(WebContents* source) { | 379 void Shell::RendererUnresponsive(WebContents* source) { |
380 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 380 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
381 switches::kDumpRenderTree)) | 381 switches::kRunLayoutTest)) |
382 return; | 382 return; |
383 WebKitTestController::Get()->RendererUnresponsive(); | 383 WebKitTestController::Get()->RendererUnresponsive(); |
384 } | 384 } |
385 | 385 |
386 void Shell::ActivateContents(WebContents* contents) { | 386 void Shell::ActivateContents(WebContents* contents) { |
387 contents->GetRenderViewHost()->Focus(); | 387 contents->GetRenderViewHost()->Focus(); |
388 } | 388 } |
389 | 389 |
390 void Shell::DeactivateContents(WebContents* contents) { | 390 void Shell::DeactivateContents(WebContents* contents) { |
391 contents->GetRenderViewHost()->Blur(); | 391 contents->GetRenderViewHost()->Blur(); |
392 } | 392 } |
393 | 393 |
394 void Shell::WorkerCrashed(WebContents* source) { | 394 void Shell::WorkerCrashed(WebContents* source) { |
395 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 395 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
396 switches::kDumpRenderTree)) | 396 switches::kRunLayoutTest)) |
397 return; | 397 return; |
398 WebKitTestController::Get()->WorkerCrashed(); | 398 WebKitTestController::Get()->WorkerCrashed(); |
399 } | 399 } |
400 | 400 |
401 bool Shell::HandleContextMenu(const content::ContextMenuParams& params) { | 401 bool Shell::HandleContextMenu(const content::ContextMenuParams& params) { |
402 return PlatformHandleContextMenu(params); | 402 return PlatformHandleContextMenu(params); |
403 } | 403 } |
404 | 404 |
405 void Shell::WebContentsFocused(WebContents* contents) { | 405 void Shell::WebContentsFocused(WebContents* contents) { |
406 #if defined(TOOLKIT_VIEWS) | 406 #if defined(TOOLKIT_VIEWS) |
(...skipping 16 matching lines...) Expand all Loading... |
423 devtools_frontend_->Activate(); | 423 devtools_frontend_->Activate(); |
424 devtools_frontend_->Focus(); | 424 devtools_frontend_->Focus(); |
425 } | 425 } |
426 | 426 |
427 void Shell::OnDevToolsWebContentsDestroyed() { | 427 void Shell::OnDevToolsWebContentsDestroyed() { |
428 devtools_observer_.reset(); | 428 devtools_observer_.reset(); |
429 devtools_frontend_ = NULL; | 429 devtools_frontend_ = NULL; |
430 } | 430 } |
431 | 431 |
432 } // namespace content | 432 } // namespace content |
OLD | NEW |