| 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 21 matching lines...) Expand all Loading... |
| 32 namespace content { | 32 namespace content { |
| 33 | 33 |
| 34 const int Shell::kDefaultTestWindowWidthDip = 800; | 34 const int Shell::kDefaultTestWindowWidthDip = 800; |
| 35 const int Shell::kDefaultTestWindowHeightDip = 600; | 35 const int Shell::kDefaultTestWindowHeightDip = 600; |
| 36 | 36 |
| 37 std::vector<Shell*> Shell::windows_; | 37 std::vector<Shell*> Shell::windows_; |
| 38 base::Callback<void(Shell*)> Shell::shell_created_callback_; | 38 base::Callback<void(Shell*)> Shell::shell_created_callback_; |
| 39 | 39 |
| 40 bool Shell::quit_message_loop_ = true; | 40 bool Shell::quit_message_loop_ = true; |
| 41 | 41 |
| 42 namespace { |
| 43 gfx::Size ShellDefaultSize() { |
| 44 static gfx::Size default_shell_size; |
| 45 if (!default_shell_size.IsEmpty()) |
| 46 return default_shell_size; |
| 47 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 48 if (command_line->HasSwitch(switches::kContentShellHostWindowSize)) { |
| 49 const std::string size_str = command_line->GetSwitchValueASCII( |
| 50 switches::kContentShellHostWindowSize); |
| 51 int width, height; |
| 52 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height)); |
| 53 default_shell_size = gfx::Size(width, height); |
| 54 } else { |
| 55 default_shell_size = gfx::Size( |
| 56 Shell::kDefaultTestWindowWidthDip, Shell::kDefaultTestWindowHeightDip); |
| 57 } |
| 58 return default_shell_size; |
| 59 } |
| 60 } // namespace |
| 61 |
| 42 class Shell::DevToolsWebContentsObserver : public WebContentsObserver { | 62 class Shell::DevToolsWebContentsObserver : public WebContentsObserver { |
| 43 public: | 63 public: |
| 44 DevToolsWebContentsObserver(Shell* shell, WebContents* web_contents) | 64 DevToolsWebContentsObserver(Shell* shell, WebContents* web_contents) |
| 45 : WebContentsObserver(web_contents), | 65 : WebContentsObserver(web_contents), |
| 46 shell_(shell) { | 66 shell_(shell) { |
| 47 } | 67 } |
| 48 | 68 |
| 49 // WebContentsObserver | 69 // WebContentsObserver |
| 50 void WebContentsDestroyed() override { | 70 void WebContentsDestroyed() override { |
| 51 shell_->OnDevToolsWebContentsDestroyed(); | 71 shell_->OnDevToolsWebContentsDestroyed(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 if (windows_[i]->web_contents() && | 154 if (windows_[i]->web_contents() && |
| 135 windows_[i]->web_contents()->GetRenderViewHost() == rvh) { | 155 windows_[i]->web_contents()->GetRenderViewHost() == rvh) { |
| 136 return windows_[i]; | 156 return windows_[i]; |
| 137 } | 157 } |
| 138 } | 158 } |
| 139 return NULL; | 159 return NULL; |
| 140 } | 160 } |
| 141 | 161 |
| 142 // static | 162 // static |
| 143 void Shell::Initialize() { | 163 void Shell::Initialize() { |
| 144 PlatformInitialize( | 164 PlatformInitialize(ShellDefaultSize()); |
| 145 gfx::Size(kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip)); | |
| 146 } | 165 } |
| 147 | 166 |
| 148 gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) { | 167 gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) { |
| 149 if (!initial_size.IsEmpty()) | 168 if (!initial_size.IsEmpty()) |
| 150 return initial_size; | 169 return initial_size; |
| 151 return gfx::Size(kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip); | 170 return ShellDefaultSize(); |
| 152 } | 171 } |
| 153 | 172 |
| 154 Shell* Shell::CreateNewWindow(BrowserContext* browser_context, | 173 Shell* Shell::CreateNewWindow(BrowserContext* browser_context, |
| 155 const GURL& url, | 174 const GURL& url, |
| 156 SiteInstance* site_instance, | 175 SiteInstance* site_instance, |
| 157 const gfx::Size& initial_size) { | 176 const gfx::Size& initial_size) { |
| 158 WebContents::CreateParams create_params(browser_context, site_instance); | 177 WebContents::CreateParams create_params(browser_context, site_instance); |
| 159 create_params.initial_size = AdjustWindowSize(initial_size); | 178 create_params.initial_size = AdjustWindowSize(initial_size); |
| 160 WebContents* web_contents = WebContents::Create(create_params); | 179 WebContents* web_contents = WebContents::Create(create_params); |
| 161 Shell* shell = CreateShell(web_contents, create_params.initial_size); | 180 Shell* shell = CreateShell(web_contents, create_params.initial_size); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 devtools_frontend_->Activate(); | 417 devtools_frontend_->Activate(); |
| 399 devtools_frontend_->Focus(); | 418 devtools_frontend_->Focus(); |
| 400 } | 419 } |
| 401 | 420 |
| 402 void Shell::OnDevToolsWebContentsDestroyed() { | 421 void Shell::OnDevToolsWebContentsDestroyed() { |
| 403 devtools_observer_.reset(); | 422 devtools_observer_.reset(); |
| 404 devtools_frontend_ = NULL; | 423 devtools_frontend_ = NULL; |
| 405 } | 424 } |
| 406 | 425 |
| 407 } // namespace content | 426 } // namespace content |
| OLD | NEW |