[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 5 | #include "content/shell/browser/shell.h" |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 6 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 9 | #include "base/auto_reset.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 10 | #include "base/command_line.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 11 | #include "base/location.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 12 | #include "base/macros.h" |
fdoray | 896bea1 | 2016-06-10 15:52:01 | [diff] [blame] | 13 | #include "base/run_loop.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 14 | #include "base/single_thread_task_runner.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 15 | #include "base/strings/string_number_conversions.h" |
| 16 | #include "base/strings/string_util.h" |
| 17 | #include "base/strings/stringprintf.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 18 | #include "base/strings/utf_string_conversions.h" |
gab | 30f26df | 2016-05-11 19:37:55 | [diff] [blame] | 19 | #include "base/threading/thread_task_runner_handle.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 20 | #include "build/build_config.h" |
[email protected] | b50452f | 2014-08-18 12:31:44 | [diff] [blame] | 21 | #include "content/public/browser/devtools_agent_host.h" |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 22 | #include "content/public/browser/navigation_controller.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 23 | #include "content/public/browser/navigation_entry.h" |
Yutaka Hirano | 2109e58 | 2018-02-14 07:24:46 | [diff] [blame] | 24 | #include "content/public/browser/render_process_host.h" |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 25 | #include "content/public/browser/render_view_host.h" |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 26 | #include "content/public/browser/render_widget_host.h" |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 27 | #include "content/public/browser/web_contents.h" |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 28 | #include "content/public/browser/web_contents_observer.h" |
guoweis | 8efb6d89 | 2015-10-12 18:26:17 | [diff] [blame] | 29 | #include "content/public/common/content_switches.h" |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 30 | #include "content/public/common/renderer_preferences.h" |
guoweis | c537ba2 | 2015-11-06 21:20:31 | [diff] [blame] | 31 | #include "content/public/common/webrtc_ip_handling_policy.h" |
jochen | 5ce1af9 | 2016-02-17 20:39:45 | [diff] [blame] | 32 | #include "content/shell/browser/layout_test/blink_test_controller.h" |
jyasskin | 8057c00 | 2015-09-10 19:09:53 | [diff] [blame] | 33 | #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factory.h" |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 34 | #include "content/shell/browser/layout_test/layout_test_devtools_bindings.h" |
mkwst | 6efe7f2e6 | 2014-10-08 15:09:01 | [diff] [blame] | 35 | #include "content/shell/browser/layout_test/layout_test_javascript_dialog_manager.h" |
lukasza | 8e550a0 | 2016-04-18 18:34:17 | [diff] [blame] | 36 | #include "content/shell/browser/layout_test/secondary_test_window_observer.h" |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 37 | #include "content/shell/browser/shell_browser_main_parts.h" |
| 38 | #include "content/shell/browser/shell_content_browser_client.h" |
| 39 | #include "content/shell/browser/shell_devtools_frontend.h" |
| 40 | #include "content/shell/browser/shell_javascript_dialog_manager.h" |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 41 | #include "content/shell/common/layout_test/layout_test_switches.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 42 | #include "content/shell/common/shell_messages.h" |
| 43 | #include "content/shell/common/shell_switches.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 44 | #include "media/media_buildflags.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 45 | #include "third_party/blink/public/web/web_presentation_receiver_flags.h" |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 46 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 47 | namespace content { |
| 48 | |
pdr | cab84ee | 2015-03-13 21:47:04 | [diff] [blame] | 49 | const int kDefaultTestWindowWidthDip = 800; |
| 50 | const int kDefaultTestWindowHeightDip = 600; |
[email protected] | 1e57cab | 2013-05-28 04:26:11 | [diff] [blame] | 51 | |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 52 | std::vector<Shell*> Shell::windows_; |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 53 | base::Callback<void(Shell*)> Shell::shell_created_callback_; |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 54 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 55 | bool Shell::quit_message_loop_ = true; |
| 56 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 57 | class Shell::DevToolsWebContentsObserver : public WebContentsObserver { |
| 58 | public: |
| 59 | DevToolsWebContentsObserver(Shell* shell, WebContents* web_contents) |
| 60 | : WebContentsObserver(web_contents), |
| 61 | shell_(shell) { |
| 62 | } |
| 63 | |
| 64 | // WebContentsObserver |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 65 | void WebContentsDestroyed() override { |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 66 | shell_->OnDevToolsWebContentsDestroyed(); |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | Shell* shell_; |
| 71 | |
| 72 | DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver); |
| 73 | }; |
| 74 | |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 75 | Shell::Shell(std::unique_ptr<WebContents> web_contents) |
| 76 | : WebContentsObserver(web_contents.get()), |
| 77 | web_contents_(std::move(web_contents)), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 78 | devtools_frontend_(nullptr), |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 79 | is_fullscreen_(false), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 80 | window_(nullptr), |
sadrul | 8b11d26 | 2015-11-12 18:41:33 | [diff] [blame] | 81 | #if defined(OS_MACOSX) |
[email protected] | 86b36e67 | 2012-12-21 00:09:51 | [diff] [blame] | 82 | url_edit_view_(NULL), |
sadrul | 8b11d26 | 2015-11-12 18:41:33 | [diff] [blame] | 83 | #endif |
Pavel Feldman | c7cd063c | 2017-10-06 20:04:28 | [diff] [blame] | 84 | headless_(false), |
| 85 | hide_toolbar_(false) { |
arthursonzogni | fdd4991 | 2017-08-31 08:55:26 | [diff] [blame] | 86 | web_contents_->SetDelegate(this); |
| 87 | |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 88 | if (switches::IsRunWebTestsSwitchPresent()) { |
[email protected] | 86b36e67 | 2012-12-21 00:09:51 | [diff] [blame] | 89 | headless_ = true; |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 90 | // In a headless shell, disable occlusion tracking. Otherwise, WebContents |
| 91 | // would always behave as if they were occluded, i.e. would not render |
| 92 | // frames and would not receive input events. |
| 93 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 94 | switches::kDisableBackgroundingOccludedWindowsForTesting); |
| 95 | } |
Pavel Feldman | c7cd063c | 2017-10-06 20:04:28 | [diff] [blame] | 96 | |
| 97 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 98 | switches::kContentShellHideToolbar)) |
| 99 | hide_toolbar_ = true; |
| 100 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 101 | windows_.push_back(this); |
| 102 | |
| 103 | if (!shell_created_callback_.is_null()) { |
| 104 | shell_created_callback_.Run(this); |
| 105 | shell_created_callback_.Reset(); |
| 106 | } |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | Shell::~Shell() { |
| 110 | PlatformCleanUp(); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 111 | |
| 112 | for (size_t i = 0; i < windows_.size(); ++i) { |
| 113 | if (windows_[i] == this) { |
| 114 | windows_.erase(windows_.begin() + i); |
| 115 | break; |
| 116 | } |
| 117 | } |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 118 | |
[email protected] | b53adf45 | 2014-02-07 12:55:08 | [diff] [blame] | 119 | if (windows_.empty() && quit_message_loop_) { |
| 120 | if (headless_) |
| 121 | PlatformExit(); |
Yutaka Hirano | 2109e58 | 2018-02-14 07:24:46 | [diff] [blame] | 122 | for (auto it = RenderProcessHost::AllHostsIterator(); !it.IsAtEnd(); |
| 123 | it.Advance()) { |
| 124 | it.GetCurrentValue()->DisableKeepAliveRefCount(); |
| 125 | } |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 126 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
Gabriel Charette | ea91801 | 2018-05-16 11:53:44 | [diff] [blame] | 127 | FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated()); |
[email protected] | b53adf45 | 2014-02-07 12:55:08 | [diff] [blame] | 128 | } |
arthursonzogni | fdd4991 | 2017-08-31 08:55:26 | [diff] [blame] | 129 | |
| 130 | web_contents_->SetDelegate(nullptr); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 131 | } |
| 132 | |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 133 | Shell* Shell::CreateShell(std::unique_ptr<WebContents> web_contents, |
[email protected] | c0d036d | 2013-05-07 12:50:50 | [diff] [blame] | 134 | const gfx::Size& initial_size) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 135 | WebContents* raw_web_contents = web_contents.get(); |
| 136 | Shell* shell = new Shell(std::move(web_contents)); |
[email protected] | c0d036d | 2013-05-07 12:50:50 | [diff] [blame] | 137 | shell->PlatformCreateWindow(initial_size.width(), initial_size.height()); |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 138 | |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 139 | shell->PlatformSetContents(); |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 140 | |
| 141 | shell->PlatformResizeSubViews(); |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 142 | |
creis | b6561df | 2016-02-11 20:20:54 | [diff] [blame] | 143 | // Note: Do not make RenderFrameHost or RenderViewHost specific state changes |
| 144 | // here, because they will be forgotten after a cross-process navigation. Use |
| 145 | // RenderFrameCreated or RenderViewCreated instead. |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 146 | if (switches::IsRunWebTestsSwitchPresent()) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 147 | raw_web_contents->GetMutableRendererPrefs()->use_custom_colors = false; |
| 148 | raw_web_contents->GetRenderViewHost()->SyncRendererPrefs(); |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 149 | } |
| 150 | |
lukasza | 381b049 | 2016-03-10 16:48:43 | [diff] [blame] | 151 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
guoweis | 4ee4859 | 2015-12-02 06:37:07 | [diff] [blame] | 152 | if (command_line->HasSwitch(switches::kForceWebRtcIPHandlingPolicy)) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 153 | raw_web_contents->GetMutableRendererPrefs()->webrtc_ip_handling_policy = |
guoweis | 4ee4859 | 2015-12-02 06:37:07 | [diff] [blame] | 154 | command_line->GetSwitchValueASCII( |
| 155 | switches::kForceWebRtcIPHandlingPolicy); |
guoweis | 8efb6d89 | 2015-10-12 18:26:17 | [diff] [blame] | 156 | } |
guoweis | 8efb6d89 | 2015-10-12 18:26:17 | [diff] [blame] | 157 | |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 158 | return shell; |
| 159 | } |
| 160 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 161 | void Shell::CloseAllWindows() { |
[email protected] | 997ec9f | 2012-11-21 04:44:14 | [diff] [blame] | 162 | base::AutoReset<bool> auto_reset(&quit_message_loop_, false); |
[email protected] | b50452f | 2014-08-18 12:31:44 | [diff] [blame] | 163 | DevToolsAgentHost::DetachAllClients(); |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 164 | std::vector<Shell*> open_windows(windows_); |
| 165 | for (size_t i = 0; i < open_windows.size(); ++i) |
| 166 | open_windows[i]->Close(); |
fdoray | 896bea1 | 2016-06-10 15:52:01 | [diff] [blame] | 167 | base::RunLoop().RunUntilIdle(); |
dmazzoni | 948fbc7 | 2015-05-17 07:57:33 | [diff] [blame] | 168 | PlatformExit(); |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 169 | } |
| 170 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 171 | void Shell::SetShellCreatedCallback( |
| 172 | base::Callback<void(Shell*)> shell_created_callback) { |
| 173 | DCHECK(shell_created_callback_.is_null()); |
Tommy Nyquist | 4b749d0 | 2018-03-20 21:46:29 | [diff] [blame] | 174 | shell_created_callback_ = std::move(shell_created_callback); |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 175 | } |
| 176 | |
[email protected] | 74830f0 | 2012-01-30 22:27:04 | [diff] [blame] | 177 | Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) { |
| 178 | for (size_t i = 0; i < windows_.size(); ++i) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 179 | if (windows_[i]->web_contents() && |
| 180 | windows_[i]->web_contents()->GetRenderViewHost() == rvh) { |
[email protected] | 74830f0 | 2012-01-30 22:27:04 | [diff] [blame] | 181 | return windows_[i]; |
| 182 | } |
| 183 | } |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 184 | return nullptr; |
[email protected] | 74830f0 | 2012-01-30 22:27:04 | [diff] [blame] | 185 | } |
| 186 | |
[email protected] | 6153b27 | 2013-01-25 22:29:23 | [diff] [blame] | 187 | // static |
| 188 | void Shell::Initialize() { |
pdr | cab84ee | 2015-03-13 21:47:04 | [diff] [blame] | 189 | PlatformInitialize(GetShellDefaultSize()); |
[email protected] | 6153b27 | 2013-01-25 22:29:23 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 192 | gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) { |
| 193 | if (!initial_size.IsEmpty()) |
| 194 | return initial_size; |
pdr | cab84ee | 2015-03-13 21:47:04 | [diff] [blame] | 195 | return GetShellDefaultSize(); |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 196 | } |
| 197 | |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame] | 198 | Shell* Shell::CreateNewWindow(BrowserContext* browser_context, |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 199 | const GURL& url, |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 200 | const scoped_refptr<SiteInstance>& site_instance, |
[email protected] | cdb80672 | 2013-01-10 14:18:23 | [diff] [blame] | 201 | const gfx::Size& initial_size) { |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 202 | WebContents::CreateParams create_params(browser_context, site_instance); |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 203 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 204 | switches::kForcePresentationReceiverForTesting)) { |
| 205 | create_params.starting_sandbox_flags = |
| 206 | blink::kPresentationReceiverSandboxFlags; |
| 207 | } |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 208 | create_params.initial_size = AdjustWindowSize(initial_size); |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 209 | std::unique_ptr<WebContents> web_contents = |
Erik Chen | bb8e738e | 2018-04-28 14:10:43 | [diff] [blame] | 210 | WebContents::Create(create_params); |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 211 | Shell* shell = |
| 212 | CreateShell(std::move(web_contents), create_params.initial_size); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 213 | if (!url.is_empty()) |
| 214 | shell->LoadURL(url); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 215 | return shell; |
| 216 | } |
| 217 | |
| 218 | void Shell::LoadURL(const GURL& url) { |
Alex Moshchuk | 7e26eca | 2018-03-03 01:34:29 | [diff] [blame] | 219 | LoadURLForFrame( |
| 220 | url, std::string(), |
| 221 | ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 222 | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)); |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 223 | } |
| 224 | |
Alex Moshchuk | 7e26eca | 2018-03-03 01:34:29 | [diff] [blame] | 225 | void Shell::LoadURLForFrame(const GURL& url, |
| 226 | const std::string& frame_name, |
| 227 | ui::PageTransition transition_type) { |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 228 | NavigationController::LoadURLParams params(url); |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 229 | params.frame_name = frame_name; |
Alex Moshchuk | 7e26eca | 2018-03-03 01:34:29 | [diff] [blame] | 230 | params.transition_type = transition_type; |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 231 | web_contents_->GetController().LoadURLWithParams(params); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 232 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 233 | } |
| 234 | |
[email protected] | 76bdecb | 2014-04-16 17:58:08 | [diff] [blame] | 235 | void Shell::LoadDataWithBaseURL(const GURL& url, const std::string& data, |
| 236 | const GURL& base_url) { |
boliu | ec93ea9 | 2016-02-17 22:23:07 | [diff] [blame] | 237 | bool load_as_string = false; |
| 238 | LoadDataWithBaseURLInternal(url, data, base_url, load_as_string); |
| 239 | } |
| 240 | |
| 241 | #if defined(OS_ANDROID) |
| 242 | void Shell::LoadDataAsStringWithBaseURL(const GURL& url, |
| 243 | const std::string& data, |
| 244 | const GURL& base_url) { |
| 245 | bool load_as_string = true; |
| 246 | LoadDataWithBaseURLInternal(url, data, base_url, load_as_string); |
| 247 | } |
| 248 | #endif |
| 249 | |
| 250 | void Shell::LoadDataWithBaseURLInternal(const GURL& url, |
| 251 | const std::string& data, |
| 252 | const GURL& base_url, |
| 253 | bool load_as_string) { |
| 254 | #if !defined(OS_ANDROID) |
| 255 | DCHECK(!load_as_string); // Only supported on Android. |
| 256 | #endif |
| 257 | |
| 258 | NavigationController::LoadURLParams params(GURL::EmptyGURL()); |
| 259 | const std::string data_url_header = "data:text/html;charset=utf-8,"; |
| 260 | if (load_as_string) { |
| 261 | params.url = GURL(data_url_header); |
| 262 | std::string data_url_as_string = data_url_header + data; |
| 263 | #if defined(OS_ANDROID) |
| 264 | params.data_url_as_string = |
| 265 | base::RefCountedString::TakeString(&data_url_as_string); |
| 266 | #endif |
| 267 | } else { |
| 268 | params.url = GURL(data_url_header + data); |
| 269 | } |
| 270 | |
[email protected] | 76bdecb | 2014-04-16 17:58:08 | [diff] [blame] | 271 | params.load_type = NavigationController::LOAD_TYPE_DATA; |
| 272 | params.base_url_for_data_url = base_url; |
| 273 | params.virtual_url_for_data_url = url; |
| 274 | params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE; |
| 275 | web_contents_->GetController().LoadURLWithParams(params); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 276 | web_contents_->Focus(); |
[email protected] | 76bdecb | 2014-04-16 17:58:08 | [diff] [blame] | 277 | } |
| 278 | |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 279 | void Shell::AddNewContents(WebContents* source, |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 280 | std::unique_ptr<WebContents> new_contents, |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 281 | WindowOpenDisposition disposition, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 282 | const gfx::Rect& initial_rect, |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 283 | bool user_gesture, |
| 284 | bool* was_blocked) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 285 | WebContents* raw_new_contents = new_contents.get(); |
| 286 | CreateShell(std::move(new_contents), AdjustWindowSize(initial_rect.size())); |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 287 | if (switches::IsRunWebTestsSwitchPresent()) |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 288 | SecondaryTestWindowObserver::CreateForWebContents(raw_new_contents); |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 289 | } |
| 290 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 291 | void Shell::GoBackOrForward(int offset) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 292 | web_contents_->GetController().GoToOffset(offset); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 293 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void Shell::Reload() { |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 297 | web_contents_->GetController().Reload(ReloadType::NORMAL, false); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 298 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 299 | } |
| 300 | |
toyoshim | e5aaf6a | 2016-05-18 08:07:48 | [diff] [blame] | 301 | void Shell::ReloadBypassingCache() { |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 302 | web_contents_->GetController().Reload(ReloadType::BYPASSING_CACHE, false); |
toyoshim | e5aaf6a | 2016-05-18 08:07:48 | [diff] [blame] | 303 | web_contents_->Focus(); |
| 304 | } |
| 305 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 306 | void Shell::Stop() { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 307 | web_contents_->Stop(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 308 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 309 | } |
| 310 | |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 311 | void Shell::UpdateNavigationControls(bool to_different_document) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 312 | int current_index = web_contents_->GetController().GetCurrentEntryIndex(); |
| 313 | int max_index = web_contents_->GetController().GetEntryCount() - 1; |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 314 | |
| 315 | PlatformEnableUIControl(BACK_BUTTON, current_index > 0); |
| 316 | PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index); |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 317 | PlatformEnableUIControl(STOP_BUTTON, |
| 318 | to_different_document && web_contents_->IsLoading()); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 319 | } |
| 320 | |
[email protected] | 7c17b699 | 2012-08-09 16:16:30 | [diff] [blame] | 321 | void Shell::ShowDevTools() { |
mohsen | 6eb57fb | 2016-07-22 03:14:08 | [diff] [blame] | 322 | if (!devtools_frontend_) { |
| 323 | devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents()); |
| 324 | devtools_observer_.reset(new DevToolsWebContentsObserver( |
| 325 | this, devtools_frontend_->frontend_shell()->web_contents())); |
| 326 | } |
[email protected] | 3142e5d | 2014-02-07 00:54:46 | [diff] [blame] | 327 | |
mohsen | 6eb57fb | 2016-07-22 03:14:08 | [diff] [blame] | 328 | devtools_frontend_->Activate(); |
| 329 | devtools_frontend_->Focus(); |
[email protected] | 7c17b699 | 2012-08-09 16:16:30 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 332 | void Shell::CloseDevTools() { |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 333 | if (!devtools_frontend_) |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 334 | return; |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 335 | devtools_observer_.reset(); |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 336 | devtools_frontend_->Close(); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 337 | devtools_frontend_ = nullptr; |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 338 | } |
| 339 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 340 | gfx::NativeView Shell::GetContentView() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 341 | if (!web_contents_) |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 342 | return nullptr; |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 343 | return web_contents_->GetNativeView(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 344 | } |
| 345 | |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 346 | WebContents* Shell::OpenURLFromTab(WebContents* source, |
| 347 | const OpenURLParams& params) { |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 348 | WebContents* target = nullptr; |
| 349 | switch (params.disposition) { |
| 350 | case WindowOpenDisposition::CURRENT_TAB: |
| 351 | target = source; |
| 352 | break; |
| 353 | |
| 354 | // Normally, the difference between NEW_POPUP and NEW_WINDOW is that a popup |
| 355 | // should have no toolbar, no status bar, no menu bar, no scrollbars and be |
| 356 | // not resizable. For simplicity and to enable new testing scenarios in |
| 357 | // content shell and layout tests, popups don't get special treatment below |
| 358 | // (i.e. they will have a toolbar and other things described here). |
| 359 | case WindowOpenDisposition::NEW_POPUP: |
lukasza | be2f0da | 2017-04-25 00:43:00 | [diff] [blame] | 360 | case WindowOpenDisposition::NEW_WINDOW: |
| 361 | // content_shell doesn't really support tabs, but some layout tests use |
| 362 | // middle click (which translates into kNavigationPolicyNewBackgroundTab), |
| 363 | // so we treat the cases below just like a NEW_WINDOW disposition. |
| 364 | case WindowOpenDisposition::NEW_BACKGROUND_TAB: |
| 365 | case WindowOpenDisposition::NEW_FOREGROUND_TAB: { |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 366 | Shell* new_window = |
| 367 | Shell::CreateNewWindow(source->GetBrowserContext(), |
| 368 | GURL(), // Don't load anything just yet. |
| 369 | params.source_site_instance, |
| 370 | gfx::Size()); // Use default size. |
| 371 | target = new_window->web_contents(); |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 372 | if (switches::IsRunWebTestsSwitchPresent()) |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 373 | SecondaryTestWindowObserver::CreateForWebContents(target); |
| 374 | break; |
| 375 | } |
| 376 | |
| 377 | // No tabs in content_shell: |
| 378 | case WindowOpenDisposition::SINGLETON_TAB: |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 379 | // No incognito mode in content_shell: |
| 380 | case WindowOpenDisposition::OFF_THE_RECORD: |
| 381 | // TODO(lukasza): Investigate if some layout tests might need support for |
| 382 | // SAVE_TO_DISK disposition. This would probably require that |
| 383 | // BlinkTestController always sets up and cleans up a temporary directory |
| 384 | // as the default downloads destinations for the duration of a test. |
| 385 | case WindowOpenDisposition::SAVE_TO_DISK: |
| 386 | // Ignoring requests with disposition == IGNORE_ACTION... |
| 387 | case WindowOpenDisposition::IGNORE_ACTION: |
| 388 | default: |
| 389 | return nullptr; |
| 390 | } |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 391 | |
| 392 | NavigationController::LoadURLParams load_url_params(params.url); |
| 393 | load_url_params.source_site_instance = params.source_site_instance; |
| 394 | load_url_params.transition_type = params.transition; |
| 395 | load_url_params.frame_tree_node_id = params.frame_tree_node_id; |
| 396 | load_url_params.referrer = params.referrer; |
| 397 | load_url_params.redirect_chain = params.redirect_chain; |
| 398 | load_url_params.extra_headers = params.extra_headers; |
| 399 | load_url_params.is_renderer_initiated = params.is_renderer_initiated; |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 400 | load_url_params.should_replace_current_entry = |
| 401 | params.should_replace_current_entry; |
Marijn Kruisselbrink | 7a0d5e18 | 2018-05-24 22:55:09 | [diff] [blame^] | 402 | load_url_params.blob_url_loader_factory = params.blob_url_loader_factory; |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 403 | |
lukasza | 477a5a2 | 2016-06-16 18:28:43 | [diff] [blame] | 404 | if (params.uses_post) { |
| 405 | load_url_params.load_type = NavigationController::LOAD_TYPE_HTTP_POST; |
| 406 | load_url_params.post_data = params.post_data; |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 407 | } |
| 408 | |
lukasza | 0413015 | 2016-10-21 20:26:32 | [diff] [blame] | 409 | target->GetController().LoadURLWithParams(load_url_params); |
| 410 | return target; |
alexmos | 5a98a05 | 2016-01-06 00:15:02 | [diff] [blame] | 411 | } |
| 412 | |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 413 | void Shell::LoadingStateChanged(WebContents* source, |
| 414 | bool to_different_document) { |
| 415 | UpdateNavigationControls(to_different_document); |
[email protected] | 15aea41 | 2012-01-19 03:18:50 | [diff] [blame] | 416 | PlatformSetIsLoading(source->IsLoading()); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 417 | } |
| 418 | |
Dave Tapuska | 3ed4419 | 2018-05-01 18:53:30 | [diff] [blame] | 419 | void Shell::EnterFullscreenModeForTab( |
| 420 | WebContents* web_contents, |
| 421 | const GURL& origin, |
| 422 | const blink::WebFullscreenOptions& options) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 423 | ToggleFullscreenModeForTab(web_contents, true); |
| 424 | } |
| 425 | |
| 426 | void Shell::ExitFullscreenModeForTab(WebContents* web_contents) { |
| 427 | ToggleFullscreenModeForTab(web_contents, false); |
| 428 | } |
| 429 | |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 430 | void Shell::ToggleFullscreenModeForTab(WebContents* web_contents, |
| 431 | bool enter_fullscreen) { |
| 432 | #if defined(OS_ANDROID) |
| 433 | PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen); |
| 434 | #endif |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 435 | if (!switches::IsRunWebTestsSwitchPresent()) |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 436 | return; |
| 437 | if (is_fullscreen_ != enter_fullscreen) { |
| 438 | is_fullscreen_ = enter_fullscreen; |
Fady Samuel | 0b91182 | 2018-04-25 13:22:16 | [diff] [blame] | 439 | web_contents->GetRenderViewHost() |
| 440 | ->GetWidget() |
| 441 | ->SynchronizeVisualProperties(); |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
| 445 | bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const { |
| 446 | #if defined(OS_ANDROID) |
| 447 | return PlatformIsFullscreenForTabOrPending(web_contents); |
| 448 | #else |
| 449 | return is_fullscreen_; |
| 450 | #endif |
| 451 | } |
| 452 | |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 453 | blink::WebDisplayMode Shell::GetDisplayMode( |
| 454 | const WebContents* web_contents) const { |
| 455 | // TODO : should return blink::WebDisplayModeFullscreen wherever user puts |
| 456 | // a browser window into fullscreen (not only in case of renderer-initiated |
| 457 | // fullscreen mode): crbug.com/476874. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 458 | return IsFullscreenForTabOrPending(web_contents) |
| 459 | ? blink::kWebDisplayModeFullscreen |
| 460 | : blink::kWebDisplayModeBrowser; |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 461 | } |
| 462 | |
[email protected] | f7843900 | 2012-11-28 14:45:59 | [diff] [blame] | 463 | void Shell::RequestToLockMouse(WebContents* web_contents, |
| 464 | bool user_gesture, |
| 465 | bool last_unlocked_by_target) { |
| 466 | web_contents->GotResponseToLockMouseRequest(true); |
| 467 | } |
| 468 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 469 | void Shell::CloseContents(WebContents* source) { |
| 470 | Close(); |
| 471 | } |
| 472 | |
[email protected] | 06731026 | 2012-11-22 14:30:41 | [diff] [blame] | 473 | bool Shell::CanOverscrollContent() const { |
| 474 | #if defined(USE_AURA) |
| 475 | return true; |
| 476 | #else |
| 477 | return false; |
| 478 | #endif |
| 479 | } |
| 480 | |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 481 | void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
[email protected] | 4e3c752 | 2013-08-13 11:53:18 | [diff] [blame] | 482 | PlatformSetAddressBarURL(web_contents->GetLastCommittedURL()); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 483 | } |
| 484 | |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 485 | JavaScriptDialogManager* Shell::GetJavaScriptDialogManager( |
| 486 | WebContents* source) { |
mkwst | 6efe7f2e6 | 2014-10-08 15:09:01 | [diff] [blame] | 487 | if (!dialog_manager_) { |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 488 | dialog_manager_.reset(switches::IsRunWebTestsSwitchPresent() |
lukasza | 381b049 | 2016-03-10 16:48:43 | [diff] [blame] | 489 | ? new LayoutTestJavaScriptDialogManager |
| 490 | : new ShellJavaScriptDialogManager); |
mkwst | 6efe7f2e6 | 2014-10-08 15:09:01 | [diff] [blame] | 491 | } |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 492 | return dialog_manager_.get(); |
[email protected] | f221002 | 2012-03-29 00:36:08 | [diff] [blame] | 493 | } |
| 494 | |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 495 | std::unique_ptr<BluetoothChooser> Shell::RunBluetoothChooser( |
jyasskin | 93649a5 | 2016-02-17 19:57:02 | [diff] [blame] | 496 | RenderFrameHost* frame, |
| 497 | const BluetoothChooser::EventHandler& event_handler) { |
Lukasz Anforowicz | f227b491 | 2017-12-22 23:08:59 | [diff] [blame] | 498 | BlinkTestController* blink_test_controller = BlinkTestController::Get(); |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 499 | if (blink_test_controller && switches::IsRunWebTestsSwitchPresent()) |
Lukasz Anforowicz | f227b491 | 2017-12-22 23:08:59 | [diff] [blame] | 500 | return blink_test_controller->RunBluetoothChooser(frame, event_handler); |
jyasskin | 8057c00 | 2015-09-10 19:09:53 | [diff] [blame] | 501 | return nullptr; |
| 502 | } |
| 503 | |
avi | a90ae4e | 2016-11-11 20:49:33 | [diff] [blame] | 504 | bool Shell::DidAddMessageToConsole(WebContents* source, |
| 505 | int32_t level, |
| 506 | const base::string16& message, |
| 507 | int32_t line_no, |
| 508 | const base::string16& source_id) { |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 509 | return switches::IsRunWebTestsSwitchPresent(); |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 510 | } |
| 511 | |
Avi Drissman | 8920def | 2018-01-31 19:53:36 | [diff] [blame] | 512 | void Shell::RendererUnresponsive(WebContents* source, |
Avi Drissman | 1572e8c3c | 2018-02-02 19:06:36 | [diff] [blame] | 513 | RenderWidgetHost* render_widget_host) { |
Lukasz Anforowicz | f227b491 | 2017-12-22 23:08:59 | [diff] [blame] | 514 | BlinkTestController* blink_test_controller = BlinkTestController::Get(); |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 515 | if (blink_test_controller && switches::IsRunWebTestsSwitchPresent()) |
Lukasz Anforowicz | f227b491 | 2017-12-22 23:08:59 | [diff] [blame] | 516 | blink_test_controller->RendererUnresponsive(); |
[email protected] | 5bf68f2 | 2012-08-31 07:38:10 | [diff] [blame] | 517 | } |
| 518 | |
[email protected] | 233567d | 2013-02-27 20:22:02 | [diff] [blame] | 519 | void Shell::ActivateContents(WebContents* contents) { |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 520 | contents->GetRenderViewHost()->GetWidget()->Focus(); |
[email protected] | 233567d | 2013-02-27 20:22:02 | [diff] [blame] | 521 | } |
| 522 | |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 523 | bool Shell::ShouldAllowRunningInsecureContent( |
| 524 | content::WebContents* web_contents, |
| 525 | bool allowed_per_prefs, |
| 526 | const url::Origin& origin, |
| 527 | const GURL& resource_url) { |
| 528 | bool allowed_by_test = false; |
Lukasz Anforowicz | f227b491 | 2017-12-22 23:08:59 | [diff] [blame] | 529 | BlinkTestController* blink_test_controller = BlinkTestController::Get(); |
Kent Tamura | cd3ebc4 | 2018-05-16 06:44:22 | [diff] [blame] | 530 | if (blink_test_controller && switches::IsRunWebTestsSwitchPresent()) { |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 531 | const base::DictionaryValue& test_flags = |
Lukasz Anforowicz | f227b491 | 2017-12-22 23:08:59 | [diff] [blame] | 532 | blink_test_controller->accumulated_layout_test_runtime_flags_changes(); |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 533 | test_flags.GetBoolean("running_insecure_content_allowed", &allowed_by_test); |
| 534 | } |
| 535 | |
| 536 | return allowed_per_prefs || allowed_by_test; |
| 537 | } |
| 538 | |
Mounir Lamouri | 11e9ef43 | 2018-05-22 03:10:16 | [diff] [blame] | 539 | gfx::Size Shell::EnterPictureInPicture(const viz::SurfaceId& surface_id, |
| 540 | const gfx::Size& natural_size) { |
| 541 | // During tests, returning a fake window size to pretent the window was |
| 542 | // created and allow tests to run accordingly. |
| 543 | return switches::IsRunWebTestsSwitchPresent() ? gfx::Size(42, 42) |
| 544 | : gfx::Size(0, 0); |
| 545 | } |
| 546 | |
pdr | cab84ee | 2015-03-13 21:47:04 | [diff] [blame] | 547 | gfx::Size Shell::GetShellDefaultSize() { |
| 548 | static gfx::Size default_shell_size; |
| 549 | if (!default_shell_size.IsEmpty()) |
| 550 | return default_shell_size; |
| 551 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 552 | if (command_line->HasSwitch(switches::kContentShellHostWindowSize)) { |
| 553 | const std::string size_str = command_line->GetSwitchValueASCII( |
| 554 | switches::kContentShellHostWindowSize); |
| 555 | int width, height; |
| 556 | CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height)); |
| 557 | default_shell_size = gfx::Size(width, height); |
| 558 | } else { |
| 559 | default_shell_size = gfx::Size( |
| 560 | kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip); |
| 561 | } |
| 562 | return default_shell_size; |
| 563 | } |
| 564 | |
Avi Drissman | 9300221 | 2017-09-27 03:20:52 | [diff] [blame] | 565 | void Shell::TitleWasSet(NavigationEntry* entry) { |
[email protected] | 1ef02d24 | 2013-10-07 16:18:53 | [diff] [blame] | 566 | if (entry) |
| 567 | PlatformSetTitle(entry->GetTitle()); |
[email protected] | aecc085b | 2012-06-01 18:15:53 | [diff] [blame] | 568 | } |
| 569 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 570 | void Shell::OnDevToolsWebContentsDestroyed() { |
| 571 | devtools_observer_.reset(); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 572 | devtools_frontend_ = nullptr; |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 573 | } |
| 574 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 575 | } // namespace content |