OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chrome_content_browser_client.h" | 5 #include "chrome/browser/chrome_content_browser_client.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/app/breakpad_mac.h" | 8 #include "chrome/app/breakpad_mac.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/character_encoding.h" | 10 #include "chrome/browser/character_encoding.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/platform_util.h" | 21 #include "chrome/browser/platform_util.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/printing/printing_message_filter.h" | 23 #include "chrome/browser/printing/printing_message_filter.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/profiles/profile_io_data.h" | 25 #include "chrome/browser/profiles/profile_io_data.h" |
26 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 26 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
27 #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" | 27 #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" |
28 #include "chrome/browser/renderer_host/text_input_client_message_filter.h" | 28 #include "chrome/browser/renderer_host/text_input_client_message_filter.h" |
29 #include "chrome/browser/search_engines/search_provider_install_state_message_fi
lter.h" | 29 #include "chrome/browser/search_engines/search_provider_install_state_message_fi
lter.h" |
30 #include "chrome/browser/spellcheck_message_filter.h" | 30 #include "chrome/browser/spellcheck_message_filter.h" |
| 31 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" |
| 32 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
| 33 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 34 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.
h" |
| 35 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
31 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" | 36 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
32 #include "chrome/common/child_process_logging.h" | 37 #include "chrome/common/child_process_logging.h" |
| 38 #include "chrome/common/chrome_constants.h" |
33 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
34 #include "chrome/common/extensions/extension_messages.h" | 40 #include "chrome/common/extensions/extension_messages.h" |
35 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
36 #include "chrome/common/render_messages.h" | 42 #include "chrome/common/render_messages.h" |
37 #include "chrome/common/url_constants.h" | 43 #include "chrome/common/url_constants.h" |
38 #include "content/browser/browsing_instance.h" | 44 #include "content/browser/browsing_instance.h" |
39 #include "content/browser/child_process_security_policy.h" | 45 #include "content/browser/child_process_security_policy.h" |
40 #include "content/browser/plugin_process_host.h" | 46 #include "content/browser/plugin_process_host.h" |
41 #include "content/browser/renderer_host/browser_render_process_host.h" | 47 #include "content/browser/renderer_host/browser_render_process_host.h" |
42 #include "content/browser/renderer_host/render_view_host.h" | 48 #include "content/browser/renderer_host/render_view_host.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 extension->location() == Extension::COMPONENT)) { | 114 extension->location() == Extension::COMPONENT)) { |
109 render_view_host->Send(new ExtensionMsg_ActivateExtension(extension->id())); | 115 render_view_host->Send(new ExtensionMsg_ActivateExtension(extension->id())); |
110 render_view_host->AllowBindings(BindingsPolicy::EXTENSION); | 116 render_view_host->AllowBindings(BindingsPolicy::EXTENSION); |
111 } | 117 } |
112 } | 118 } |
113 | 119 |
114 } | 120 } |
115 | 121 |
116 namespace chrome { | 122 namespace chrome { |
117 | 123 |
| 124 class ChromeContentBrowserClient::JavaScriptDialogDelegateProxy |
| 125 : ChromeJavaScriptDialogDelegate { |
| 126 public: |
| 127 explicit JavaScriptDialogDelegateProxy( |
| 128 content::JavaScriptDialogDelegate* original); |
| 129 |
| 130 virtual void OnDialogClosed(IPC::Message* reply_msg, |
| 131 bool success, |
| 132 const string16& user_input) OVERRIDE; |
| 133 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE; |
| 134 virtual TabContents* AsTabContents() OVERRIDE; |
| 135 virtual void SetSuppressDialogs(bool suppress_dialogs) OVERRIDE; |
| 136 virtual ExtensionHost* AsExtensionHost() OVERRIDE; |
| 137 |
| 138 private: |
| 139 friend class ChromeContentBrowserClient; |
| 140 |
| 141 // The JavaScriptDialogDelegate this object is proxying. |
| 142 content::JavaScriptDialogDelegate* original_; |
| 143 |
| 144 // The time that the last JavaScript dialog was dismissed. |
| 145 base::TimeTicks last_javascript_message_dismissal_; |
| 146 |
| 147 // True if the user has decided to block future JavaScript dialogs. |
| 148 bool suppress_javascript_messages_; |
| 149 }; |
| 150 |
| 151 ChromeContentBrowserClient::JavaScriptDialogDelegateProxy:: |
| 152 JavaScriptDialogDelegateProxy(content::JavaScriptDialogDelegate* original) |
| 153 : original_(original), |
| 154 last_javascript_message_dismissal_(base::TimeTicks()), |
| 155 suppress_javascript_messages_(false) { |
| 156 } |
| 157 |
| 158 gfx::NativeWindow |
| 159 ChromeContentBrowserClient::JavaScriptDialogDelegateProxy::GetDialogRootWindow( |
| 160 ) { |
| 161 return original_->GetDialogRootWindow(); |
| 162 } |
| 163 |
| 164 void ChromeContentBrowserClient::JavaScriptDialogDelegateProxy::OnDialogClosed( |
| 165 IPC::Message* reply_msg, |
| 166 bool success, |
| 167 const string16& user_input) { |
| 168 last_javascript_message_dismissal_ = base::TimeTicks::Now(); |
| 169 original_->OnDialogClosed(reply_msg, success, user_input); |
| 170 } |
| 171 |
| 172 TabContents* |
| 173 ChromeContentBrowserClient::JavaScriptDialogDelegateProxy::AsTabContents() { |
| 174 return original_->AsTabContents(); |
| 175 } |
| 176 |
| 177 ExtensionHost* |
| 178 ChromeContentBrowserClient::JavaScriptDialogDelegateProxy::AsExtensionHost() { |
| 179 return original_->AsExtensionHost(); |
| 180 } |
| 181 |
| 182 void |
| 183 ChromeContentBrowserClient::JavaScriptDialogDelegateProxy::SetSuppressDialogs( |
| 184 bool suppress_dialogs) { |
| 185 suppress_javascript_messages_ = suppress_dialogs; |
| 186 } |
| 187 |
| 188 ChromeContentBrowserClient::ChromeContentBrowserClient() { |
| 189 } |
| 190 |
| 191 ChromeContentBrowserClient::~ChromeContentBrowserClient() { |
| 192 STLDeleteValues(&javascript_dialog_proxies_); |
| 193 } |
| 194 |
118 void ChromeContentBrowserClient::RenderViewHostCreated( | 195 void ChromeContentBrowserClient::RenderViewHostCreated( |
119 RenderViewHost* render_view_host) { | 196 RenderViewHost* render_view_host) { |
120 new ChromeRenderViewHostObserver(render_view_host); | 197 new ChromeRenderViewHostObserver(render_view_host); |
121 new DesktopNotificationHandler(render_view_host); | 198 new DesktopNotificationHandler(render_view_host); |
122 new DevToolsHandler(render_view_host); | 199 new DevToolsHandler(render_view_host); |
123 new ExtensionMessageHandler(render_view_host); | 200 new ExtensionMessageHandler(render_view_host); |
124 | 201 |
125 InitRenderViewHostForExtensions(render_view_host); | 202 InitRenderViewHostForExtensions(render_view_host); |
126 } | 203 } |
127 | 204 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 // do it on the FILE thread so we don't slow down UI. | 393 // do it on the FILE thread so we don't slow down UI. |
317 #if defined(OS_MACOSX) | 394 #if defined(OS_MACOSX) |
318 platform_util::OpenItem(path); | 395 platform_util::OpenItem(path); |
319 #else | 396 #else |
320 BrowserThread::PostTask( | 397 BrowserThread::PostTask( |
321 BrowserThread::FILE, FROM_HERE, | 398 BrowserThread::FILE, FROM_HERE, |
322 NewRunnableFunction(&platform_util::OpenItem, path)); | 399 NewRunnableFunction(&platform_util::OpenItem, path)); |
323 #endif | 400 #endif |
324 } | 401 } |
325 | 402 |
| 403 void ChromeContentBrowserClient::RunJavaScriptDialog( |
| 404 content::JavaScriptDialogDelegate* delegate, |
| 405 const GURL& frame_url, |
| 406 int dialog_flags, |
| 407 const string16& message_text, |
| 408 const string16& default_prompt_text, |
| 409 IPC::Message* reply_message, |
| 410 bool* did_suppress_message, |
| 411 Profile* profile) { |
| 412 *did_suppress_message = false; |
| 413 |
| 414 // Suppress JavaScript dialogs when inside a constrained popup window (because |
| 415 // that activates them and breaks them out of the constrained window jail). |
| 416 if (delegate->AsTabContents()) { |
| 417 TabContentsWrapper* wrapper = |
| 418 TabContentsWrapper::GetCurrentWrapperForContents( |
| 419 delegate->AsTabContents()); |
| 420 TabContentsWrapper* constraining_contents = wrapper; |
| 421 if (wrapper && wrapper->blocked_content_tab_helper()->delegate()) |
| 422 constraining_contents = wrapper->blocked_content_tab_helper()-> |
| 423 delegate()->GetConstrainingContentsWrapper(wrapper); |
| 424 if (constraining_contents != wrapper) { |
| 425 *did_suppress_message = true; |
| 426 return; |
| 427 } |
| 428 } |
| 429 |
| 430 JavaScriptDialogDelegateProxy* proxy = ProxyForDelegate(delegate); |
| 431 |
| 432 if (proxy->suppress_javascript_messages_) { |
| 433 *did_suppress_message = true; |
| 434 return; |
| 435 } |
| 436 |
| 437 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - |
| 438 proxy->last_javascript_message_dismissal_; |
| 439 bool display_suppress_checkbox = false; |
| 440 // Show a checkbox offering to suppress further messages if this message is |
| 441 // being displayed within kJavascriptMessageExpectedDelay of the last one. |
| 442 if (time_since_last_message < |
| 443 base::TimeDelta::FromMilliseconds( |
| 444 chrome::kJavascriptMessageExpectedDelay)) { |
| 445 display_suppress_checkbox = true; |
| 446 } |
| 447 |
| 448 RunJavascriptDialogImpl(profile, |
| 449 proxy, |
| 450 frame_url, |
| 451 dialog_flags, |
| 452 message_text, |
| 453 default_prompt_text, |
| 454 display_suppress_checkbox, |
| 455 reply_message); |
| 456 } |
| 457 |
| 458 void ChromeContentBrowserClient::RunBeforeUnloadDialog( |
| 459 content::JavaScriptDialogDelegate* delegate, |
| 460 const string16& message_text, |
| 461 IPC::Message* reply_msg) { |
| 462 JavaScriptDialogDelegateProxy* proxy = ProxyForDelegate(delegate); |
| 463 RunBeforeUnloadDialogImpl(proxy, message_text, reply_msg); |
| 464 } |
| 465 |
| 466 void ChromeContentBrowserClient::ResetJavaScriptState( |
| 467 content::JavaScriptDialogDelegate* delegate) { |
| 468 JavaScriptDialogProxyMap::iterator proxy_iterator = |
| 469 javascript_dialog_proxies_.find(delegate); |
| 470 if (proxy_iterator != javascript_dialog_proxies_.end()) { |
| 471 delete proxy_iterator->second; |
| 472 javascript_dialog_proxies_.erase(proxy_iterator); |
| 473 } |
| 474 } |
| 475 |
| 476 ChromeContentBrowserClient::JavaScriptDialogDelegateProxy* |
| 477 ChromeContentBrowserClient::ProxyForDelegate( |
| 478 content::JavaScriptDialogDelegate* delegate) { |
| 479 JavaScriptDialogProxyMap::iterator proxy_iterator = |
| 480 javascript_dialog_proxies_.find(delegate); |
| 481 if (proxy_iterator == javascript_dialog_proxies_.end()) { |
| 482 JavaScriptDialogDelegateProxy* proxy = |
| 483 new JavaScriptDialogDelegateProxy(delegate); |
| 484 proxy_iterator = |
| 485 javascript_dialog_proxies_. |
| 486 insert(std::make_pair(delegate, proxy)).first; |
| 487 } |
| 488 |
| 489 return proxy_iterator->second; |
| 490 } |
| 491 |
326 #if defined(OS_LINUX) | 492 #if defined(OS_LINUX) |
327 int ChromeContentBrowserClient::GetCrashSignalFD( | 493 int ChromeContentBrowserClient::GetCrashSignalFD( |
328 const std::string& process_type) { | 494 const std::string& process_type) { |
329 if (process_type == switches::kRendererProcess) | 495 if (process_type == switches::kRendererProcess) |
330 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); | 496 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
331 | 497 |
332 if (process_type == switches::kPluginProcess) | 498 if (process_type == switches::kPluginProcess) |
333 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); | 499 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
334 | 500 |
335 if (process_type == switches::kPpapiPluginProcess) | 501 if (process_type == switches::kPpapiPluginProcess) |
336 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); | 502 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
337 | 503 |
338 if (process_type == switches::kGpuProcess) | 504 if (process_type == switches::kGpuProcess) |
339 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); | 505 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
340 | 506 |
341 return -1; | 507 return -1; |
342 } | 508 } |
343 #endif | 509 #endif |
344 | 510 |
345 } // namespace chrome | 511 } // namespace chrome |
OLD | NEW |