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