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