[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 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 7 | #include "base/auto_reset.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | aaf6889 | 2013-07-18 00:11:30 | [diff] [blame] | 9 | #include "base/message_loop/message_loop.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 10 | #include "base/strings/string_number_conversions.h" |
| 11 | #include "base/strings/string_util.h" |
| 12 | #include "base/strings/stringprintf.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 13 | #include "base/strings/utf_string_conversions.h" |
[email protected] | b50452f | 2014-08-18 12:31:44 | [diff] [blame] | 14 | #include "content/public/browser/devtools_agent_host.h" |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 15 | #include "content/public/browser/navigation_controller.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 16 | #include "content/public/browser/navigation_entry.h" |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 17 | #include "content/public/browser/render_view_host.h" |
| 18 | #include "content/public/browser/web_contents.h" |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 19 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 20 | #include "content/public/common/renderer_preferences.h" |
mkwst | 30d20d5 | 2014-10-09 13:33:14 | [diff] [blame] | 21 | #include "content/shell/browser/layout_test/layout_test_devtools_frontend.h" |
mkwst | 6efe7f2e6 | 2014-10-08 15:09:01 | [diff] [blame] | 22 | #include "content/shell/browser/layout_test/layout_test_javascript_dialog_manager.h" |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 23 | #include "content/shell/browser/notify_done_forwarder.h" |
| 24 | #include "content/shell/browser/shell_browser_main_parts.h" |
| 25 | #include "content/shell/browser/shell_content_browser_client.h" |
| 26 | #include "content/shell/browser/shell_devtools_frontend.h" |
| 27 | #include "content/shell/browser/shell_javascript_dialog_manager.h" |
| 28 | #include "content/shell/browser/webkit_test_controller.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 29 | #include "content/shell/common/shell_messages.h" |
| 30 | #include "content/shell/common/shell_switches.h" |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 31 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 32 | namespace content { |
| 33 | |
[email protected] | 1e57cab | 2013-05-28 04:26:11 | [diff] [blame] | 34 | const int Shell::kDefaultTestWindowWidthDip = 800; |
| 35 | const int Shell::kDefaultTestWindowHeightDip = 600; |
| 36 | |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 37 | std::vector<Shell*> Shell::windows_; |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 38 | base::Callback<void(Shell*)> Shell::shell_created_callback_; |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 39 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 40 | bool Shell::quit_message_loop_ = true; |
| 41 | |
arurajku | 168b0ac | 2014-12-15 19:36:28 | [diff] [blame] | 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 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 62 | class Shell::DevToolsWebContentsObserver : public WebContentsObserver { |
| 63 | public: |
| 64 | DevToolsWebContentsObserver(Shell* shell, WebContents* web_contents) |
| 65 | : WebContentsObserver(web_contents), |
| 66 | shell_(shell) { |
| 67 | } |
| 68 | |
| 69 | // WebContentsObserver |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 70 | void WebContentsDestroyed() override { |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 71 | shell_->OnDevToolsWebContentsDestroyed(); |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | Shell* shell_; |
| 76 | |
| 77 | DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver); |
| 78 | }; |
| 79 | |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 80 | Shell::Shell(WebContents* web_contents) |
[email protected] | 1ef02d24 | 2013-10-07 16:18:53 | [diff] [blame] | 81 | : WebContentsObserver(web_contents), |
| 82 | devtools_frontend_(NULL), |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 83 | is_fullscreen_(false), |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 84 | window_(NULL), |
[email protected] | 86b36e67 | 2012-12-21 00:09:51 | [diff] [blame] | 85 | url_edit_view_(NULL), |
[email protected] | 86b36e67 | 2012-12-21 00:09:51 | [diff] [blame] | 86 | headless_(false) { |
| 87 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 28cc78e | 2013-06-13 09:05:46 | [diff] [blame] | 88 | if (command_line.HasSwitch(switches::kDumpRenderTree)) |
[email protected] | 86b36e67 | 2012-12-21 00:09:51 | [diff] [blame] | 89 | headless_ = true; |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 90 | windows_.push_back(this); |
| 91 | |
| 92 | if (!shell_created_callback_.is_null()) { |
| 93 | shell_created_callback_.Run(this); |
| 94 | shell_created_callback_.Reset(); |
| 95 | } |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | Shell::~Shell() { |
| 99 | PlatformCleanUp(); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 100 | |
| 101 | for (size_t i = 0; i < windows_.size(); ++i) { |
| 102 | if (windows_[i] == this) { |
| 103 | windows_.erase(windows_.begin() + i); |
| 104 | break; |
| 105 | } |
| 106 | } |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 107 | |
[email protected] | b53adf45 | 2014-02-07 12:55:08 | [diff] [blame] | 108 | if (windows_.empty() && quit_message_loop_) { |
| 109 | if (headless_) |
| 110 | PlatformExit(); |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 111 | base::MessageLoop::current()->PostTask(FROM_HERE, |
| 112 | base::MessageLoop::QuitClosure()); |
[email protected] | b53adf45 | 2014-02-07 12:55:08 | [diff] [blame] | 113 | } |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 114 | } |
| 115 | |
[email protected] | c0d036d | 2013-05-07 12:50:50 | [diff] [blame] | 116 | Shell* Shell::CreateShell(WebContents* web_contents, |
| 117 | const gfx::Size& initial_size) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 118 | Shell* shell = new Shell(web_contents); |
[email protected] | c0d036d | 2013-05-07 12:50:50 | [diff] [blame] | 119 | shell->PlatformCreateWindow(initial_size.width(), initial_size.height()); |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 120 | |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 121 | shell->web_contents_.reset(web_contents); |
| 122 | web_contents->SetDelegate(shell); |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 123 | |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 124 | shell->PlatformSetContents(); |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 125 | |
| 126 | shell->PlatformResizeSubViews(); |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 127 | |
| 128 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { |
| 129 | web_contents->GetMutableRendererPrefs()->use_custom_colors = false; |
| 130 | web_contents->GetRenderViewHost()->SyncRendererPrefs(); |
| 131 | } |
| 132 | |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 133 | return shell; |
| 134 | } |
| 135 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 136 | void Shell::CloseAllWindows() { |
[email protected] | 997ec9f | 2012-11-21 04:44:14 | [diff] [blame] | 137 | base::AutoReset<bool> auto_reset(&quit_message_loop_, false); |
[email protected] | b50452f | 2014-08-18 12:31:44 | [diff] [blame] | 138 | DevToolsAgentHost::DetachAllClients(); |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 139 | std::vector<Shell*> open_windows(windows_); |
| 140 | for (size_t i = 0; i < open_windows.size(); ++i) |
| 141 | open_windows[i]->Close(); |
[email protected] | 4249a42 | 2013-11-27 19:04:04 | [diff] [blame] | 142 | PlatformExit(); |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 143 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 144 | } |
| 145 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 146 | void Shell::SetShellCreatedCallback( |
| 147 | base::Callback<void(Shell*)> shell_created_callback) { |
| 148 | DCHECK(shell_created_callback_.is_null()); |
| 149 | shell_created_callback_ = shell_created_callback; |
| 150 | } |
| 151 | |
[email protected] | 74830f0 | 2012-01-30 22:27:04 | [diff] [blame] | 152 | Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) { |
| 153 | for (size_t i = 0; i < windows_.size(); ++i) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 154 | if (windows_[i]->web_contents() && |
| 155 | windows_[i]->web_contents()->GetRenderViewHost() == rvh) { |
[email protected] | 74830f0 | 2012-01-30 22:27:04 | [diff] [blame] | 156 | return windows_[i]; |
| 157 | } |
| 158 | } |
| 159 | return NULL; |
| 160 | } |
| 161 | |
[email protected] | 6153b27 | 2013-01-25 22:29:23 | [diff] [blame] | 162 | // static |
| 163 | void Shell::Initialize() { |
arurajku | 168b0ac | 2014-12-15 19:36:28 | [diff] [blame] | 164 | PlatformInitialize(ShellDefaultSize()); |
[email protected] | 6153b27 | 2013-01-25 22:29:23 | [diff] [blame] | 165 | } |
| 166 | |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 167 | gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) { |
| 168 | if (!initial_size.IsEmpty()) |
| 169 | return initial_size; |
arurajku | 168b0ac | 2014-12-15 19:36:28 | [diff] [blame] | 170 | return ShellDefaultSize(); |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 171 | } |
| 172 | |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame] | 173 | Shell* Shell::CreateNewWindow(BrowserContext* browser_context, |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 174 | const GURL& url, |
| 175 | SiteInstance* site_instance, |
[email protected] | cdb80672 | 2013-01-10 14:18:23 | [diff] [blame] | 176 | const gfx::Size& initial_size) { |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 177 | WebContents::CreateParams create_params(browser_context, site_instance); |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 178 | create_params.initial_size = AdjustWindowSize(initial_size); |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 179 | WebContents* web_contents = WebContents::Create(create_params); |
[email protected] | c0d036d | 2013-05-07 12:50:50 | [diff] [blame] | 180 | Shell* shell = CreateShell(web_contents, create_params.initial_size); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 181 | if (!url.is_empty()) |
| 182 | shell->LoadURL(url); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 183 | return shell; |
| 184 | } |
| 185 | |
| 186 | void Shell::LoadURL(const GURL& url) { |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 187 | LoadURLForFrame(url, std::string()); |
| 188 | } |
| 189 | |
| 190 | void Shell::LoadURLForFrame(const GURL& url, const std::string& frame_name) { |
| 191 | NavigationController::LoadURLParams params(url); |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 192 | params.transition_type = ui::PageTransitionFromInt( |
| 193 | ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 194 | params.frame_name = frame_name; |
| 195 | web_contents_->GetController().LoadURLWithParams(params); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 196 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | 76bdecb | 2014-04-16 17:58:08 | [diff] [blame] | 199 | void Shell::LoadDataWithBaseURL(const GURL& url, const std::string& data, |
| 200 | const GURL& base_url) { |
| 201 | const GURL data_url = GURL("data:text/html;charset=utf-8," + data); |
| 202 | NavigationController::LoadURLParams params(data_url); |
| 203 | params.load_type = NavigationController::LOAD_TYPE_DATA; |
| 204 | params.base_url_for_data_url = base_url; |
| 205 | params.virtual_url_for_data_url = url; |
| 206 | params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE; |
| 207 | web_contents_->GetController().LoadURLWithParams(params); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 208 | web_contents_->Focus(); |
[email protected] | 76bdecb | 2014-04-16 17:58:08 | [diff] [blame] | 209 | } |
| 210 | |
[email protected] | a290409 | 2013-10-15 04:53:59 | [diff] [blame] | 211 | void Shell::AddNewContents(WebContents* source, |
| 212 | WebContents* new_contents, |
| 213 | WindowOpenDisposition disposition, |
| 214 | const gfx::Rect& initial_pos, |
| 215 | bool user_gesture, |
| 216 | bool* was_blocked) { |
| 217 | CreateShell(new_contents, AdjustWindowSize(initial_pos.size())); |
| 218 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
| 219 | NotifyDoneForwarder::CreateForWebContents(new_contents); |
| 220 | } |
| 221 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 222 | void Shell::GoBackOrForward(int offset) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 223 | web_contents_->GetController().GoToOffset(offset); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 224 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void Shell::Reload() { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 228 | web_contents_->GetController().Reload(false); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 229 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | void Shell::Stop() { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 233 | web_contents_->Stop(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 234 | web_contents_->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 235 | } |
| 236 | |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 237 | void Shell::UpdateNavigationControls(bool to_different_document) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 238 | int current_index = web_contents_->GetController().GetCurrentEntryIndex(); |
| 239 | int max_index = web_contents_->GetController().GetEntryCount() - 1; |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 240 | |
| 241 | PlatformEnableUIControl(BACK_BUTTON, current_index > 0); |
| 242 | PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index); |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 243 | PlatformEnableUIControl(STOP_BUTTON, |
| 244 | to_different_document && web_contents_->IsLoading()); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 245 | } |
| 246 | |
[email protected] | 7c17b699 | 2012-08-09 16:16:30 | [diff] [blame] | 247 | void Shell::ShowDevTools() { |
[email protected] | 06c25301 | 2014-04-16 18:35:33 | [diff] [blame] | 248 | InnerShowDevTools("", ""); |
[email protected] | 3142e5d | 2014-02-07 00:54:46 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void Shell::ShowDevToolsForElementAt(int x, int y) { |
[email protected] | 06c25301 | 2014-04-16 18:35:33 | [diff] [blame] | 252 | InnerShowDevTools("", ""); |
[email protected] | 2317fcd | 2014-02-10 14:36:48 | [diff] [blame] | 253 | devtools_frontend_->InspectElementAt(x, y); |
[email protected] | 7c17b699 | 2012-08-09 16:16:30 | [diff] [blame] | 254 | } |
| 255 | |
[email protected] | 06c25301 | 2014-04-16 18:35:33 | [diff] [blame] | 256 | void Shell::ShowDevToolsForTest(const std::string& settings, |
| 257 | const std::string& frontend_url) { |
| 258 | InnerShowDevTools(settings, frontend_url); |
[email protected] | fee9eca0 | 2014-02-14 19:24:40 | [diff] [blame] | 259 | } |
| 260 | |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 261 | void Shell::CloseDevTools() { |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 262 | if (!devtools_frontend_) |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 263 | return; |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 264 | devtools_observer_.reset(); |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 265 | devtools_frontend_->Close(); |
| 266 | devtools_frontend_ = NULL; |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 267 | } |
| 268 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 269 | gfx::NativeView Shell::GetContentView() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 270 | if (!web_contents_) |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 271 | return NULL; |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 272 | return web_contents_->GetNativeView(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 273 | } |
| 274 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 275 | WebContents* Shell::OpenURLFromTab(WebContents* source, |
| 276 | const OpenURLParams& params) { |
[email protected] | 7cf3830 | 2013-08-29 12:23:46 | [diff] [blame] | 277 | // CURRENT_TAB is the only one we implement for now. |
| 278 | if (params.disposition != CURRENT_TAB) |
| 279 | return NULL; |
[email protected] | fbaccee | 2013-08-12 23:24:02 | [diff] [blame] | 280 | NavigationController::LoadURLParams load_url_params(params.url); |
lfg | 9ef7d2d | 2014-12-15 22:32:30 | [diff] [blame^] | 281 | load_url_params.source_site_instance = params.source_site_instance; |
[email protected] | fbaccee | 2013-08-12 23:24:02 | [diff] [blame] | 282 | load_url_params.referrer = params.referrer; |
[email protected] | c8029778 | 2013-11-21 07:10:16 | [diff] [blame] | 283 | load_url_params.frame_tree_node_id = params.frame_tree_node_id; |
[email protected] | fbaccee | 2013-08-12 23:24:02 | [diff] [blame] | 284 | load_url_params.transition_type = params.transition; |
| 285 | load_url_params.extra_headers = params.extra_headers; |
| 286 | load_url_params.should_replace_current_entry = |
| 287 | params.should_replace_current_entry; |
| 288 | |
| 289 | if (params.transferred_global_request_id != GlobalRequestID()) { |
| 290 | load_url_params.is_renderer_initiated = params.is_renderer_initiated; |
| 291 | load_url_params.transferred_global_request_id = |
| 292 | params.transferred_global_request_id; |
| 293 | } else if (params.is_renderer_initiated) { |
| 294 | load_url_params.is_renderer_initiated = true; |
| 295 | } |
| 296 | |
| 297 | source->GetController().LoadURLWithParams(load_url_params); |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 298 | return source; |
| 299 | } |
| 300 | |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 301 | void Shell::LoadingStateChanged(WebContents* source, |
| 302 | bool to_different_document) { |
| 303 | UpdateNavigationControls(to_different_document); |
[email protected] | 15aea41 | 2012-01-19 03:18:50 | [diff] [blame] | 304 | PlatformSetIsLoading(source->IsLoading()); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 305 | } |
| 306 | |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 307 | void Shell::ToggleFullscreenModeForTab(WebContents* web_contents, |
| 308 | bool enter_fullscreen) { |
| 309 | #if defined(OS_ANDROID) |
| 310 | PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen); |
| 311 | #endif |
| 312 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
| 313 | return; |
| 314 | if (is_fullscreen_ != enter_fullscreen) { |
| 315 | is_fullscreen_ = enter_fullscreen; |
| 316 | web_contents->GetRenderViewHost()->WasResized(); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const { |
| 321 | #if defined(OS_ANDROID) |
| 322 | return PlatformIsFullscreenForTabOrPending(web_contents); |
| 323 | #else |
| 324 | return is_fullscreen_; |
| 325 | #endif |
| 326 | } |
| 327 | |
[email protected] | f7843900 | 2012-11-28 14:45:59 | [diff] [blame] | 328 | void Shell::RequestToLockMouse(WebContents* web_contents, |
| 329 | bool user_gesture, |
| 330 | bool last_unlocked_by_target) { |
| 331 | web_contents->GotResponseToLockMouseRequest(true); |
| 332 | } |
| 333 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 334 | void Shell::CloseContents(WebContents* source) { |
| 335 | Close(); |
| 336 | } |
| 337 | |
[email protected] | 06731026 | 2012-11-22 14:30:41 | [diff] [blame] | 338 | bool Shell::CanOverscrollContent() const { |
| 339 | #if defined(USE_AURA) |
| 340 | return true; |
| 341 | #else |
| 342 | return false; |
| 343 | #endif |
| 344 | } |
| 345 | |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 346 | void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
[email protected] | 4e3c752 | 2013-08-13 11:53:18 | [diff] [blame] | 347 | PlatformSetAddressBarURL(web_contents->GetLastCommittedURL()); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 348 | } |
| 349 | |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 350 | JavaScriptDialogManager* Shell::GetJavaScriptDialogManager( |
| 351 | WebContents* source) { |
mkwst | 6efe7f2e6 | 2014-10-08 15:09:01 | [diff] [blame] | 352 | if (!dialog_manager_) { |
| 353 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 354 | dialog_manager_.reset(command_line.HasSwitch(switches::kDumpRenderTree) |
| 355 | ? new LayoutTestJavaScriptDialogManager |
| 356 | : new ShellJavaScriptDialogManager); |
| 357 | } |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 358 | return dialog_manager_.get(); |
[email protected] | f221002 | 2012-03-29 00:36:08 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | c272c5b | 2012-06-06 09:01:06 | [diff] [blame] | 361 | bool Shell::AddMessageToConsole(WebContents* source, |
| 362 | int32 level, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 363 | const base::string16& message, |
[email protected] | c272c5b | 2012-06-06 09:01:06 | [diff] [blame] | 364 | int32 line_no, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 365 | const base::string16& source_id) { |
[email protected] | 55a5cd1 | 2013-01-28 15:24:23 | [diff] [blame] | 366 | return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 367 | } |
| 368 | |
[email protected] | 5bf68f2 | 2012-08-31 07:38:10 | [diff] [blame] | 369 | void Shell::RendererUnresponsive(WebContents* source) { |
| 370 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
| 371 | return; |
| 372 | WebKitTestController::Get()->RendererUnresponsive(); |
| 373 | } |
| 374 | |
[email protected] | 233567d | 2013-02-27 20:22:02 | [diff] [blame] | 375 | void Shell::ActivateContents(WebContents* contents) { |
| 376 | contents->GetRenderViewHost()->Focus(); |
| 377 | } |
| 378 | |
| 379 | void Shell::DeactivateContents(WebContents* contents) { |
| 380 | contents->GetRenderViewHost()->Blur(); |
| 381 | } |
| 382 | |
[email protected] | 3eeacfa6 | 2013-07-23 09:23:15 | [diff] [blame] | 383 | void Shell::WorkerCrashed(WebContents* source) { |
| 384 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
| 385 | return; |
| 386 | WebKitTestController::Get()->WorkerCrashed(); |
| 387 | } |
| 388 | |
[email protected] | 3142e5d | 2014-02-07 00:54:46 | [diff] [blame] | 389 | bool Shell::HandleContextMenu(const content::ContextMenuParams& params) { |
| 390 | return PlatformHandleContextMenu(params); |
| 391 | } |
| 392 | |
[email protected] | d0bb995 | 2014-02-10 20:58:26 | [diff] [blame] | 393 | void Shell::WebContentsFocused(WebContents* contents) { |
| 394 | #if defined(TOOLKIT_VIEWS) |
| 395 | PlatformWebContentsFocused(contents); |
| 396 | #endif |
| 397 | } |
| 398 | |
[email protected] | 1ef02d24 | 2013-10-07 16:18:53 | [diff] [blame] | 399 | void Shell::TitleWasSet(NavigationEntry* entry, bool explicit_set) { |
| 400 | if (entry) |
| 401 | PlatformSetTitle(entry->GetTitle()); |
[email protected] | aecc085b | 2012-06-01 18:15:53 | [diff] [blame] | 402 | } |
| 403 | |
[email protected] | 06c25301 | 2014-04-16 18:35:33 | [diff] [blame] | 404 | void Shell::InnerShowDevTools(const std::string& settings, |
| 405 | const std::string& frontend_url) { |
[email protected] | fee9eca0 | 2014-02-14 19:24:40 | [diff] [blame] | 406 | if (!devtools_frontend_) { |
mkwst | 30d20d5 | 2014-10-09 13:33:14 | [diff] [blame] | 407 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 408 | switches::kDumpRenderTree)) { |
| 409 | devtools_frontend_ = LayoutTestDevToolsFrontend::Show( |
| 410 | web_contents(), settings, frontend_url); |
| 411 | } else { |
| 412 | devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents()); |
| 413 | } |
[email protected] | fee9eca0 | 2014-02-14 19:24:40 | [diff] [blame] | 414 | devtools_observer_.reset(new DevToolsWebContentsObserver( |
| 415 | this, devtools_frontend_->frontend_shell()->web_contents())); |
| 416 | } |
| 417 | |
| 418 | devtools_frontend_->Activate(); |
| 419 | devtools_frontend_->Focus(); |
| 420 | } |
| 421 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 422 | void Shell::OnDevToolsWebContentsDestroyed() { |
| 423 | devtools_observer_.reset(); |
| 424 | devtools_frontend_ = NULL; |
| 425 | } |
| 426 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 427 | } // namespace content |