| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/extensions/extension_host.h" | 5 #include "chrome/browser/extensions/extension_host.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" |
| 9 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| 10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 11 #include "base/singleton.h" | 12 #include "base/singleton.h" |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "chrome/browser/browser.h" | 14 #include "chrome/browser/browser.h" |
| 14 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
| 15 #include "chrome/browser/browser_theme_provider.h" | 16 #include "chrome/browser/browser_theme_provider.h" |
| 16 #include "chrome/browser/browsing_instance.h" | 17 #include "chrome/browser/browsing_instance.h" |
| 17 #include "chrome/browser/debugger/devtools_manager.h" | 18 #include "chrome/browser/debugger/devtools_manager.h" |
| 18 #include "chrome/browser/dom_ui/dom_ui_factory.h" | 19 #include "chrome/browser/dom_ui/dom_ui_factory.h" |
| 19 #include "chrome/browser/extensions/extension_message_service.h" | 20 #include "chrome/browser/extensions/extension_message_service.h" |
| 20 #include "chrome/browser/extensions/extension_tabs_module.h" | 21 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 22 #include "chrome/browser/jsmessage_box_handler.h" |
| 21 #include "chrome/browser/extensions/extension_popup_api.h" | 23 #include "chrome/browser/extensions/extension_popup_api.h" |
| 22 #include "chrome/browser/profile.h" | 24 #include "chrome/browser/profile.h" |
| 23 #include "chrome/browser/renderer_host/render_view_host.h" | 25 #include "chrome/browser/renderer_host/render_view_host.h" |
| 24 #include "chrome/browser/renderer_host/render_process_host.h" | 26 #include "chrome/browser/renderer_host/render_process_host.h" |
| 25 #include "chrome/browser/renderer_host/render_widget_host.h" | 27 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 26 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 28 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 27 #include "chrome/browser/renderer_host/site_instance.h" | 29 #include "chrome/browser/renderer_host/site_instance.h" |
| 30 #include "chrome/browser/tab_contents/tab_contents.h" |
| 31 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 28 #include "chrome/common/bindings_policy.h" | 32 #include "chrome/common/bindings_policy.h" |
| 29 #include "chrome/common/extensions/extension.h" | 33 #include "chrome/common/extensions/extension.h" |
| 30 #include "chrome/common/notification_service.h" | 34 #include "chrome/common/notification_service.h" |
| 31 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/common/pref_service.h" | 36 #include "chrome/common/pref_service.h" |
| 33 #include "chrome/common/view_types.h" | 37 #include "chrome/common/view_types.h" |
| 34 #include "chrome/common/render_messages.h" | 38 #include "chrome/common/render_messages.h" |
| 35 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
| 36 #include "grit/browser_resources.h" | 40 #include "grit/browser_resources.h" |
| 41 #include "grit/generated_resources.h" |
| 37 #include "webkit/glue/context_menu.h" | 42 #include "webkit/glue/context_menu.h" |
| 38 | 43 |
| 39 #if defined(TOOLKIT_VIEWS) | 44 #if defined(TOOLKIT_VIEWS) |
| 40 #include "chrome/browser/views/extensions/extension_popup.h" | 45 #include "chrome/browser/views/extensions/extension_popup.h" |
| 41 #include "views/widget/widget.h" | 46 #include "views/widget/widget.h" |
| 42 #endif | 47 #endif |
| 43 | 48 |
| 44 using WebKit::WebDragOperation; | 49 using WebKit::WebDragOperation; |
| 45 using WebKit::WebDragOperationsMask; | 50 using WebKit::WebDragOperationsMask; |
| 46 | 51 |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 Details<ExtensionHost>(this)); | 395 Details<ExtensionHost>(this)); |
| 391 } | 396 } |
| 392 } | 397 } |
| 393 | 398 |
| 394 void ExtensionHost::RunJavaScriptMessage(const std::wstring& message, | 399 void ExtensionHost::RunJavaScriptMessage(const std::wstring& message, |
| 395 const std::wstring& default_prompt, | 400 const std::wstring& default_prompt, |
| 396 const GURL& frame_url, | 401 const GURL& frame_url, |
| 397 const int flags, | 402 const int flags, |
| 398 IPC::Message* reply_msg, | 403 IPC::Message* reply_msg, |
| 399 bool* did_suppress_message) { | 404 bool* did_suppress_message) { |
| 400 // Automatically cancel the javascript alert (otherwise the renderer hangs | 405 *did_suppress_message = false; |
| 401 // indefinitely). | 406 // Unlike for page alerts, navigations aren't a good signal for when to |
| 402 *did_suppress_message = true; | 407 // resume showing alerts, so we can't reasonably stop showing them even if |
| 403 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, L""); | 408 // the extension is spammy. |
| 409 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt, |
| 410 false, reply_msg); |
| 411 } |
| 412 |
| 413 std::wstring ExtensionHost::GetMessageBoxTitle(const GURL& frame_url, |
| 414 bool is_alert) { |
| 415 if (extension_->name().empty()) |
| 416 return l10n_util::GetString( |
| 417 is_alert ? IDS_EXTENSION_ALERT_DEFAULT_TITLE |
| 418 : IDS_EXTENSION_MESSAGEBOX_DEFAULT_TITLE); |
| 419 |
| 420 return l10n_util::GetStringF( |
| 421 is_alert ? IDS_EXTENSION_ALERT_TITLE : IDS_EXTENSION_MESSAGEBOX_TITLE, |
| 422 UTF8ToWide(extension_->name())); |
| 423 } |
| 424 |
| 425 gfx::NativeWindow ExtensionHost::GetMessageBoxRootWindow() { |
| 426 TabContents* active_tab = GetBrowser()->GetSelectedTabContents(); |
| 427 if (active_tab) |
| 428 return active_tab->view()->GetTopLevelNativeWindow(); |
| 429 return NULL; |
| 430 } |
| 431 |
| 432 void ExtensionHost::OnMessageBoxClosed(IPC::Message* reply_msg, |
| 433 bool success, |
| 434 const std::wstring& prompt) { |
| 435 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); |
| 404 } | 436 } |
| 405 | 437 |
| 406 void ExtensionHost::Close(RenderViewHost* render_view_host) { | 438 void ExtensionHost::Close(RenderViewHost* render_view_host) { |
| 407 if (extension_host_type_ == ViewType::EXTENSION_POPUP) { | 439 if (extension_host_type_ == ViewType::EXTENSION_POPUP) { |
| 408 NotificationService::current()->Notify( | 440 NotificationService::current()->Notify( |
| 409 NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 441 NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 410 Source<Profile>(profile_), | 442 Source<Profile>(profile_), |
| 411 Details<ExtensionHost>(this)); | 443 Details<ExtensionHost>(this)); |
| 412 } | 444 } |
| 413 } | 445 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 window_id = ExtensionTabUtil::GetWindowId( | 609 window_id = ExtensionTabUtil::GetWindowId( |
| 578 const_cast<ExtensionHost* >(this)->GetBrowser()); | 610 const_cast<ExtensionHost* >(this)->GetBrowser()); |
| 579 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { | 611 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { |
| 580 // Background page is not attached to any browser window, so pass -1. | 612 // Background page is not attached to any browser window, so pass -1. |
| 581 window_id = -1; | 613 window_id = -1; |
| 582 } else { | 614 } else { |
| 583 NOTREACHED(); | 615 NOTREACHED(); |
| 584 } | 616 } |
| 585 return window_id; | 617 return window_id; |
| 586 } | 618 } |
| OLD | NEW |