[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | |
| 5 | #include "content/shell/shell.h" |
| 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] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 10 | #include "base/path_service.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 11 | #include "base/strings/string_number_conversions.h" |
| 12 | #include "base/strings/string_util.h" |
| 13 | #include "base/strings/stringprintf.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 14 | #include "base/strings/utf_string_conversions.h" |
[email protected] | e641ea69 | 2013-01-28 10:39:23 | [diff] [blame] | 15 | #include "content/public/browser/devtools_manager.h" |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 16 | #include "content/public/browser/navigation_controller.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 17 | #include "content/public/browser/navigation_entry.h" |
[email protected] | aecc085b | 2012-06-01 18:15:53 | [diff] [blame] | 18 | #include "content/public/browser/notification_details.h" |
| 19 | #include "content/public/browser/notification_source.h" |
| 20 | #include "content/public/browser/notification_types.h" |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 21 | #include "content/public/browser/render_view_host.h" |
| 22 | #include "content/public/browser/web_contents.h" |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 23 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | ed245db | 2012-12-18 08:00:45 | [diff] [blame] | 24 | #include "content/public/browser/web_contents_view.h" |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 25 | #include "content/public/common/renderer_preferences.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 26 | #include "content/shell/common/shell_messages.h" |
| 27 | #include "content/shell/common/shell_switches.h" |
[email protected] | 1ca4fac | 2013-04-08 14:15:11 | [diff] [blame] | 28 | #include "content/shell/notify_done_forwarder.h" |
[email protected] | 7c17b699 | 2012-08-09 16:16:30 | [diff] [blame] | 29 | #include "content/shell/shell_browser_main_parts.h" |
| 30 | #include "content/shell/shell_content_browser_client.h" |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 31 | #include "content/shell/shell_devtools_frontend.h" |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 32 | #include "content/shell/shell_javascript_dialog_manager.h" |
[email protected] | 8dafad3 | 2012-12-10 14:11:45 | [diff] [blame] | 33 | #include "content/shell/webkit_test_controller.h" |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 34 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 35 | namespace content { |
| 36 | |
[email protected] | 1e57cab | 2013-05-28 04:26:11 | [diff] [blame] | 37 | const int Shell::kDefaultTestWindowWidthDip = 800; |
| 38 | const int Shell::kDefaultTestWindowHeightDip = 600; |
| 39 | |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 40 | std::vector<Shell*> Shell::windows_; |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 41 | base::Callback<void(Shell*)> Shell::shell_created_callback_; |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 42 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 43 | bool Shell::quit_message_loop_ = true; |
| 44 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 45 | class Shell::DevToolsWebContentsObserver : public WebContentsObserver { |
| 46 | public: |
| 47 | DevToolsWebContentsObserver(Shell* shell, WebContents* web_contents) |
| 48 | : WebContentsObserver(web_contents), |
| 49 | shell_(shell) { |
| 50 | } |
| 51 | |
| 52 | // WebContentsObserver |
| 53 | virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE { |
| 54 | shell_->OnDevToolsWebContentsDestroyed(); |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | Shell* shell_; |
| 59 | |
| 60 | DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver); |
| 61 | }; |
| 62 | |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 63 | Shell::Shell(WebContents* web_contents) |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 64 | : devtools_frontend_(NULL), |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 65 | is_fullscreen_(false), |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 66 | window_(NULL), |
[email protected] | 86b36e67 | 2012-12-21 00:09:51 | [diff] [blame] | 67 | url_edit_view_(NULL), |
[email protected] | fa4a4583 | 2012-04-12 21:32:48 | [diff] [blame] | 68 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | 86b36e67 | 2012-12-21 00:09:51 | [diff] [blame] | 69 | default_edit_wnd_proc_(0), |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 70 | #endif |
[email protected] | 86b36e67 | 2012-12-21 00:09:51 | [diff] [blame] | 71 | headless_(false) { |
| 72 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 28cc78e | 2013-06-13 09:05:46 | [diff] [blame] | 73 | if (command_line.HasSwitch(switches::kDumpRenderTree)) |
[email protected] | 86b36e67 | 2012-12-21 00:09:51 | [diff] [blame] | 74 | headless_ = true; |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 75 | registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
| 76 | Source<WebContents>(web_contents)); |
| 77 | windows_.push_back(this); |
| 78 | |
| 79 | if (!shell_created_callback_.is_null()) { |
| 80 | shell_created_callback_.Run(this); |
| 81 | shell_created_callback_.Reset(); |
| 82 | } |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | Shell::~Shell() { |
| 86 | PlatformCleanUp(); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 87 | |
| 88 | for (size_t i = 0; i < windows_.size(); ++i) { |
| 89 | if (windows_[i] == this) { |
| 90 | windows_.erase(windows_.begin() + i); |
| 91 | break; |
| 92 | } |
| 93 | } |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 94 | |
| 95 | if (windows_.empty() && quit_message_loop_) |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 96 | base::MessageLoop::current()->PostTask(FROM_HERE, |
| 97 | base::MessageLoop::QuitClosure()); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 98 | } |
| 99 | |
[email protected] | c0d036d | 2013-05-07 12:50:50 | [diff] [blame] | 100 | Shell* Shell::CreateShell(WebContents* web_contents, |
| 101 | const gfx::Size& initial_size) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 102 | Shell* shell = new Shell(web_contents); |
[email protected] | c0d036d | 2013-05-07 12:50:50 | [diff] [blame] | 103 | shell->PlatformCreateWindow(initial_size.width(), initial_size.height()); |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 104 | |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 105 | shell->web_contents_.reset(web_contents); |
| 106 | web_contents->SetDelegate(shell); |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 107 | |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 108 | shell->PlatformSetContents(); |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 109 | |
| 110 | shell->PlatformResizeSubViews(); |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 111 | |
| 112 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { |
| 113 | web_contents->GetMutableRendererPrefs()->use_custom_colors = false; |
| 114 | web_contents->GetRenderViewHost()->SyncRendererPrefs(); |
| 115 | } |
| 116 | |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 117 | return shell; |
| 118 | } |
| 119 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 120 | void Shell::CloseAllWindows() { |
[email protected] | 997ec9f | 2012-11-21 04:44:14 | [diff] [blame] | 121 | base::AutoReset<bool> auto_reset(&quit_message_loop_, false); |
[email protected] | e641ea69 | 2013-01-28 10:39:23 | [diff] [blame] | 122 | DevToolsManager::GetInstance()->CloseAllClientHosts(); |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 123 | std::vector<Shell*> open_windows(windows_); |
| 124 | for (size_t i = 0; i < open_windows.size(); ++i) |
| 125 | open_windows[i]->Close(); |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 126 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 127 | } |
| 128 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 129 | void Shell::SetShellCreatedCallback( |
| 130 | base::Callback<void(Shell*)> shell_created_callback) { |
| 131 | DCHECK(shell_created_callback_.is_null()); |
| 132 | shell_created_callback_ = shell_created_callback; |
| 133 | } |
| 134 | |
[email protected] | 74830f0 | 2012-01-30 22:27:04 | [diff] [blame] | 135 | Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) { |
| 136 | for (size_t i = 0; i < windows_.size(); ++i) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 137 | if (windows_[i]->web_contents() && |
| 138 | windows_[i]->web_contents()->GetRenderViewHost() == rvh) { |
[email protected] | 74830f0 | 2012-01-30 22:27:04 | [diff] [blame] | 139 | return windows_[i]; |
| 140 | } |
| 141 | } |
| 142 | return NULL; |
| 143 | } |
| 144 | |
[email protected] | 6153b27 | 2013-01-25 22:29:23 | [diff] [blame] | 145 | // static |
| 146 | void Shell::Initialize() { |
[email protected] | 1e57cab | 2013-05-28 04:26:11 | [diff] [blame] | 147 | PlatformInitialize( |
| 148 | gfx::Size(kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip)); |
[email protected] | 6153b27 | 2013-01-25 22:29:23 | [diff] [blame] | 149 | } |
| 150 | |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame] | 151 | Shell* Shell::CreateNewWindow(BrowserContext* browser_context, |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 152 | const GURL& url, |
| 153 | SiteInstance* site_instance, |
| 154 | int routing_id, |
[email protected] | cdb80672 | 2013-01-10 14:18:23 | [diff] [blame] | 155 | const gfx::Size& initial_size) { |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 156 | WebContents::CreateParams create_params(browser_context, site_instance); |
| 157 | create_params.routing_id = routing_id; |
[email protected] | cdb80672 | 2013-01-10 14:18:23 | [diff] [blame] | 158 | if (!initial_size.IsEmpty()) |
| 159 | create_params.initial_size = initial_size; |
| 160 | else |
[email protected] | 1e57cab | 2013-05-28 04:26:11 | [diff] [blame] | 161 | create_params.initial_size = |
| 162 | gfx::Size(kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip); |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 163 | WebContents* web_contents = WebContents::Create(create_params); |
[email protected] | c0d036d | 2013-05-07 12:50:50 | [diff] [blame] | 164 | Shell* shell = CreateShell(web_contents, create_params.initial_size); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 165 | if (!url.is_empty()) |
| 166 | shell->LoadURL(url); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 167 | return shell; |
| 168 | } |
| 169 | |
| 170 | void Shell::LoadURL(const GURL& url) { |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 171 | LoadURLForFrame(url, std::string()); |
| 172 | } |
| 173 | |
| 174 | void Shell::LoadURLForFrame(const GURL& url, const std::string& frame_name) { |
| 175 | NavigationController::LoadURLParams params(url); |
| 176 | params.transition_type = PageTransitionFromInt( |
| 177 | PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR); |
| 178 | params.frame_name = frame_name; |
| 179 | web_contents_->GetController().LoadURLWithParams(params); |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 180 | web_contents_->GetView()->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void Shell::GoBackOrForward(int offset) { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 184 | web_contents_->GetController().GoToOffset(offset); |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 185 | web_contents_->GetView()->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | void Shell::Reload() { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 189 | web_contents_->GetController().Reload(false); |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 190 | web_contents_->GetView()->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void Shell::Stop() { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 194 | web_contents_->Stop(); |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 195 | web_contents_->GetView()->Focus(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | void Shell::UpdateNavigationControls() { |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 199 | int current_index = web_contents_->GetController().GetCurrentEntryIndex(); |
| 200 | int max_index = web_contents_->GetController().GetEntryCount() - 1; |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 201 | |
| 202 | PlatformEnableUIControl(BACK_BUTTON, current_index > 0); |
| 203 | PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index); |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 204 | PlatformEnableUIControl(STOP_BUTTON, web_contents_->IsLoading()); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 205 | } |
| 206 | |
[email protected] | 7c17b699 | 2012-08-09 16:16:30 | [diff] [blame] | 207 | void Shell::ShowDevTools() { |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 208 | if (devtools_frontend_) { |
| 209 | devtools_frontend_->Focus(); |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 210 | return; |
| 211 | } |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 212 | devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents()); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 213 | devtools_observer_.reset(new DevToolsWebContentsObserver( |
| 214 | this, devtools_frontend_->frontend_shell()->web_contents())); |
[email protected] | 7c17b699 | 2012-08-09 16:16:30 | [diff] [blame] | 215 | } |
| 216 | |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 217 | void Shell::CloseDevTools() { |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 218 | if (!devtools_frontend_) |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 219 | return; |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 220 | devtools_observer_.reset(); |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 221 | devtools_frontend_->Close(); |
| 222 | devtools_frontend_ = NULL; |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 223 | } |
| 224 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 225 | gfx::NativeView Shell::GetContentView() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 226 | if (!web_contents_) |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 227 | return NULL; |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 228 | return web_contents_->GetView()->GetNativeView(); |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 229 | } |
| 230 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 231 | WebContents* Shell::OpenURLFromTab(WebContents* source, |
| 232 | const OpenURLParams& params) { |
| 233 | // The only one we implement for now. |
| 234 | DCHECK(params.disposition == CURRENT_TAB); |
| 235 | source->GetController().LoadURL( |
| 236 | params.url, params.referrer, params.transition, std::string()); |
| 237 | return source; |
| 238 | } |
| 239 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 240 | void Shell::LoadingStateChanged(WebContents* source) { |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 241 | UpdateNavigationControls(); |
[email protected] | 15aea41 | 2012-01-19 03:18:50 | [diff] [blame] | 242 | PlatformSetIsLoading(source->IsLoading()); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 243 | } |
| 244 | |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 245 | void Shell::ToggleFullscreenModeForTab(WebContents* web_contents, |
| 246 | bool enter_fullscreen) { |
| 247 | #if defined(OS_ANDROID) |
| 248 | PlatformToggleFullscreenModeForTab(web_contents, enter_fullscreen); |
| 249 | #endif |
| 250 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
| 251 | return; |
| 252 | if (is_fullscreen_ != enter_fullscreen) { |
| 253 | is_fullscreen_ = enter_fullscreen; |
| 254 | web_contents->GetRenderViewHost()->WasResized(); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) const { |
| 259 | #if defined(OS_ANDROID) |
| 260 | return PlatformIsFullscreenForTabOrPending(web_contents); |
| 261 | #else |
| 262 | return is_fullscreen_; |
| 263 | #endif |
| 264 | } |
| 265 | |
[email protected] | f7843900 | 2012-11-28 14:45:59 | [diff] [blame] | 266 | void Shell::RequestToLockMouse(WebContents* web_contents, |
| 267 | bool user_gesture, |
| 268 | bool last_unlocked_by_target) { |
| 269 | web_contents->GotResponseToLockMouseRequest(true); |
| 270 | } |
| 271 | |
[email protected] | 9e00e635 | 2012-07-30 17:05:18 | [diff] [blame] | 272 | void Shell::CloseContents(WebContents* source) { |
| 273 | Close(); |
| 274 | } |
| 275 | |
[email protected] | 06731026 | 2012-11-22 14:30:41 | [diff] [blame] | 276 | bool Shell::CanOverscrollContent() const { |
| 277 | #if defined(USE_AURA) |
| 278 | return true; |
| 279 | #else |
| 280 | return false; |
| 281 | #endif |
| 282 | } |
| 283 | |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 284 | void Shell::WebContentsCreated(WebContents* source_contents, |
| 285 | int64 source_frame_id, |
[email protected] | 50de322 | 2013-03-20 15:36:13 | [diff] [blame] | 286 | const string16& frame_name, |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 287 | const GURL& target_url, |
| 288 | WebContents* new_contents) { |
[email protected] | c0d036d | 2013-05-07 12:50:50 | [diff] [blame] | 289 | CreateShell(new_contents, source_contents->GetView()->GetContainerSize()); |
[email protected] | 1ca4fac | 2013-04-08 14:15:11 | [diff] [blame] | 290 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
| 291 | NotifyDoneForwarder::CreateForWebContents(new_contents); |
[email protected] | 3fd8403 | 2012-01-12 18:20:17 | [diff] [blame] | 292 | } |
| 293 | |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 294 | void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
| 295 | PlatformSetAddressBarURL(web_contents->GetURL()); |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 296 | } |
| 297 | |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 298 | JavaScriptDialogManager* Shell::GetJavaScriptDialogManager() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 299 | if (!dialog_manager_) |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 300 | dialog_manager_.reset(new ShellJavaScriptDialogManager()); |
| 301 | return dialog_manager_.get(); |
[email protected] | f221002 | 2012-03-29 00:36:08 | [diff] [blame] | 302 | } |
| 303 | |
[email protected] | c272c5b | 2012-06-06 09:01:06 | [diff] [blame] | 304 | bool Shell::AddMessageToConsole(WebContents* source, |
| 305 | int32 level, |
| 306 | const string16& message, |
| 307 | int32 line_no, |
| 308 | const string16& source_id) { |
[email protected] | 55a5cd1 | 2013-01-28 15:24:23 | [diff] [blame] | 309 | return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 310 | } |
| 311 | |
[email protected] | 5bf68f2 | 2012-08-31 07:38:10 | [diff] [blame] | 312 | void Shell::RendererUnresponsive(WebContents* source) { |
| 313 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
| 314 | return; |
| 315 | WebKitTestController::Get()->RendererUnresponsive(); |
| 316 | } |
| 317 | |
[email protected] | 233567d | 2013-02-27 20:22:02 | [diff] [blame] | 318 | void Shell::ActivateContents(WebContents* contents) { |
| 319 | contents->GetRenderViewHost()->Focus(); |
| 320 | } |
| 321 | |
| 322 | void Shell::DeactivateContents(WebContents* contents) { |
| 323 | contents->GetRenderViewHost()->Blur(); |
| 324 | } |
| 325 | |
[email protected] | 3eeacfa6 | 2013-07-23 09:23:15 | [diff] [blame^] | 326 | void Shell::WorkerCrashed(WebContents* source) { |
| 327 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
| 328 | return; |
| 329 | WebKitTestController::Get()->WorkerCrashed(); |
| 330 | } |
| 331 | |
[email protected] | aecc085b | 2012-06-01 18:15:53 | [diff] [blame] | 332 | void Shell::Observe(int type, |
| 333 | const NotificationSource& source, |
| 334 | const NotificationDetails& details) { |
| 335 | if (type == NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) { |
| 336 | std::pair<NavigationEntry*, bool>* title = |
| 337 | Details<std::pair<NavigationEntry*, bool> >(details).ptr(); |
| 338 | |
| 339 | if (title->first) { |
| 340 | string16 text = title->first->GetTitle(); |
| 341 | PlatformSetTitle(text); |
| 342 | } |
[email protected] | d212efd | 2013-04-15 13:03:06 | [diff] [blame] | 343 | } else { |
| 344 | NOTREACHED(); |
[email protected] | aecc085b | 2012-06-01 18:15:53 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 348 | void Shell::OnDevToolsWebContentsDestroyed() { |
| 349 | devtools_observer_.reset(); |
| 350 | devtools_frontend_ = NULL; |
| 351 | } |
| 352 | |
[email protected] | 9fbd3f86 | 2011-09-20 23:31:34 | [diff] [blame] | 353 | } // namespace content |