| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/shell.h" | 5 #include "content/shell/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.h" | 9 #include "base/message_loop.h" | 
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" | 
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" | 
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" | 
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" | 
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" | 
| 15 #include "content/public/browser/devtools_manager.h" | 15 #include "content/public/browser/devtools_manager.h" | 
| 16 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" | 
| 17 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" | 
| 18 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" | 
| 19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" | 
| 20 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" | 
| 21 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" | 
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" | 
|  | 23 #include "content/public/browser/web_contents_observer.h" | 
| 23 #include "content/public/browser/web_contents_view.h" | 24 #include "content/public/browser/web_contents_view.h" | 
| 24 #include "content/public/common/renderer_preferences.h" | 25 #include "content/public/common/renderer_preferences.h" | 
| 25 #include "content/shell/common/shell_messages.h" | 26 #include "content/shell/common/shell_messages.h" | 
| 26 #include "content/shell/common/shell_switches.h" | 27 #include "content/shell/common/shell_switches.h" | 
| 27 #include "content/shell/notify_done_forwarder.h" | 28 #include "content/shell/notify_done_forwarder.h" | 
| 28 #include "content/shell/shell_browser_main_parts.h" | 29 #include "content/shell/shell_browser_main_parts.h" | 
| 29 #include "content/shell/shell_content_browser_client.h" | 30 #include "content/shell/shell_content_browser_client.h" | 
| 30 #include "content/shell/shell_devtools_frontend.h" | 31 #include "content/shell/shell_devtools_frontend.h" | 
| 31 #include "content/shell/shell_javascript_dialog_manager.h" | 32 #include "content/shell/shell_javascript_dialog_manager.h" | 
| 32 #include "content/shell/webkit_test_controller.h" | 33 #include "content/shell/webkit_test_controller.h" | 
| 33 | 34 | 
| 34 // Content area size for newly created windows. | 35 // Content area size for newly created windows. | 
| 35 static const int kTestWindowWidth = 800; | 36 static const int kTestWindowWidth = 800; | 
| 36 static const int kTestWindowHeight = 600; | 37 static const int kTestWindowHeight = 600; | 
| 37 | 38 | 
| 38 namespace content { | 39 namespace content { | 
| 39 | 40 | 
| 40 std::vector<Shell*> Shell::windows_; | 41 std::vector<Shell*> Shell::windows_; | 
| 41 base::Callback<void(Shell*)> Shell::shell_created_callback_; | 42 base::Callback<void(Shell*)> Shell::shell_created_callback_; | 
| 42 | 43 | 
| 43 bool Shell::quit_message_loop_ = true; | 44 bool Shell::quit_message_loop_ = true; | 
| 44 | 45 | 
|  | 46 class Shell::DevToolsWebContentsObserver : public WebContentsObserver { | 
|  | 47  public: | 
|  | 48   DevToolsWebContentsObserver(Shell* shell, WebContents* web_contents) | 
|  | 49       : WebContentsObserver(web_contents), | 
|  | 50         shell_(shell) { | 
|  | 51   } | 
|  | 52 | 
|  | 53   // WebContentsObserver | 
|  | 54   virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE { | 
|  | 55     shell_->OnDevToolsWebContentsDestroyed(); | 
|  | 56   } | 
|  | 57 | 
|  | 58  private: | 
|  | 59   Shell* shell_; | 
|  | 60 | 
|  | 61   DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver); | 
|  | 62 }; | 
|  | 63 | 
| 45 Shell::Shell(WebContents* web_contents) | 64 Shell::Shell(WebContents* web_contents) | 
| 46     : devtools_frontend_(NULL), | 65     : devtools_frontend_(NULL), | 
| 47       is_fullscreen_(false), | 66       is_fullscreen_(false), | 
| 48       window_(NULL), | 67       window_(NULL), | 
| 49       url_edit_view_(NULL), | 68       url_edit_view_(NULL), | 
| 50 #if defined(OS_WIN) && !defined(USE_AURA) | 69 #if defined(OS_WIN) && !defined(USE_AURA) | 
| 51       default_edit_wnd_proc_(0), | 70       default_edit_wnd_proc_(0), | 
| 52 #endif | 71 #endif | 
| 53       headless_(false) { | 72       headless_(false) { | 
| 54   const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 73   const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 185   PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index); | 204   PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index); | 
| 186   PlatformEnableUIControl(STOP_BUTTON, web_contents_->IsLoading()); | 205   PlatformEnableUIControl(STOP_BUTTON, web_contents_->IsLoading()); | 
| 187 } | 206 } | 
| 188 | 207 | 
| 189 void Shell::ShowDevTools() { | 208 void Shell::ShowDevTools() { | 
| 190   if (devtools_frontend_) { | 209   if (devtools_frontend_) { | 
| 191     devtools_frontend_->Focus(); | 210     devtools_frontend_->Focus(); | 
| 192     return; | 211     return; | 
| 193   } | 212   } | 
| 194   devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents()); | 213   devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents()); | 
| 195   registrar_.Add(this, | 214   devtools_observer_.reset(new DevToolsWebContentsObserver( | 
| 196                  NOTIFICATION_WEB_CONTENTS_DESTROYED, | 215       this, devtools_frontend_->frontend_shell()->web_contents())); | 
| 197                  Source<WebContents>( |  | 
| 198                      devtools_frontend_->frontend_shell()->web_contents())); |  | 
| 199 } | 216 } | 
| 200 | 217 | 
| 201 void Shell::CloseDevTools() { | 218 void Shell::CloseDevTools() { | 
| 202   if (!devtools_frontend_) | 219   if (!devtools_frontend_) | 
| 203     return; | 220     return; | 
| 204   registrar_.Remove(this, | 221   devtools_observer_.reset(); | 
| 205                     NOTIFICATION_WEB_CONTENTS_DESTROYED, |  | 
| 206                     Source<WebContents>( |  | 
| 207                         devtools_frontend_->frontend_shell()->web_contents())); |  | 
| 208   devtools_frontend_->Close(); | 222   devtools_frontend_->Close(); | 
| 209   devtools_frontend_ = NULL; | 223   devtools_frontend_ = NULL; | 
| 210 } | 224 } | 
| 211 | 225 | 
| 212 gfx::NativeView Shell::GetContentView() { | 226 gfx::NativeView Shell::GetContentView() { | 
| 213   if (!web_contents_) | 227   if (!web_contents_) | 
| 214     return NULL; | 228     return NULL; | 
| 215   return web_contents_->GetView()->GetNativeView(); | 229   return web_contents_->GetView()->GetNativeView(); | 
| 216 } | 230 } | 
| 217 | 231 | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 314                     const NotificationSource& source, | 328                     const NotificationSource& source, | 
| 315                     const NotificationDetails& details) { | 329                     const NotificationDetails& details) { | 
| 316   if (type == NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) { | 330   if (type == NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) { | 
| 317     std::pair<NavigationEntry*, bool>* title = | 331     std::pair<NavigationEntry*, bool>* title = | 
| 318         Details<std::pair<NavigationEntry*, bool> >(details).ptr(); | 332         Details<std::pair<NavigationEntry*, bool> >(details).ptr(); | 
| 319 | 333 | 
| 320     if (title->first) { | 334     if (title->first) { | 
| 321       string16 text = title->first->GetTitle(); | 335       string16 text = title->first->GetTitle(); | 
| 322       PlatformSetTitle(text); | 336       PlatformSetTitle(text); | 
| 323     } | 337     } | 
| 324   } else if (type == NOTIFICATION_WEB_CONTENTS_DESTROYED) { |  | 
| 325     devtools_frontend_ = NULL; |  | 
| 326     registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, source); |  | 
| 327   } else { | 338   } else { | 
| 328     NOTREACHED(); | 339     NOTREACHED(); | 
| 329   } | 340   } | 
| 330 } | 341 } | 
| 331 | 342 | 
|  | 343 void Shell::OnDevToolsWebContentsDestroyed() { | 
|  | 344   devtools_observer_.reset(); | 
|  | 345   devtools_frontend_ = NULL; | 
|  | 346 } | 
|  | 347 | 
| 332 }  // namespace content | 348 }  // namespace content | 
| OLD | NEW | 
|---|