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/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #endif // OS_WIN | 10 #endif // OS_WIN |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "base/time.h" | 24 #include "base/time.h" |
25 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
26 #include "chrome/app/chrome_command_ids.h" | 26 #include "chrome/app/chrome_command_ids.h" |
27 #include "chrome/browser/autofill/autofill_manager.h" | 27 #include "chrome/browser/autofill/autofill_manager.h" |
28 #include "chrome/browser/background/background_contents_service.h" | 28 #include "chrome/browser/background/background_contents_service.h" |
29 #include "chrome/browser/bookmarks/bookmark_model.h" | 29 #include "chrome/browser/bookmarks/bookmark_model.h" |
30 #include "chrome/browser/bookmarks/bookmark_utils.h" | 30 #include "chrome/browser/bookmarks/bookmark_utils.h" |
31 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
32 #include "chrome/browser/browser_shutdown.h" | 32 #include "chrome/browser/browser_shutdown.h" |
33 #include "chrome/browser/character_encoding.h" | 33 #include "chrome/browser/character_encoding.h" |
| 34 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 35 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" |
34 #include "chrome/browser/debugger/devtools_toggle_action.h" | 36 #include "chrome/browser/debugger/devtools_toggle_action.h" |
35 #include "chrome/browser/debugger/devtools_window.h" | 37 #include "chrome/browser/debugger/devtools_window.h" |
36 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 38 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
37 #include "chrome/browser/download/download_item_model.h" | 39 #include "chrome/browser/download/download_item_model.h" |
38 #include "chrome/browser/download/download_started_animation.h" | 40 #include "chrome/browser/download/download_started_animation.h" |
39 #include "chrome/browser/extensions/crx_installer.h" | 41 #include "chrome/browser/extensions/crx_installer.h" |
40 #include "chrome/browser/extensions/extension_browser_event_router.h" | 42 #include "chrome/browser/extensions/extension_browser_event_router.h" |
41 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" | 43 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
42 #include "chrome/browser/extensions/extension_host.h" | 44 #include "chrome/browser/extensions/extension_host.h" |
43 #include "chrome/browser/extensions/extension_prefs.h" | 45 #include "chrome/browser/extensions/extension_prefs.h" |
44 #include "chrome/browser/extensions/extension_service.h" | 46 #include "chrome/browser/extensions/extension_service.h" |
45 #include "chrome/browser/extensions/extension_tab_helper.h" | 47 #include "chrome/browser/extensions/extension_tab_helper.h" |
46 #include "chrome/browser/extensions/extension_tabs_module.h" | 48 #include "chrome/browser/extensions/extension_tabs_module.h" |
47 #include "chrome/browser/favicon/favicon_tab_helper.h" | 49 #include "chrome/browser/favicon/favicon_tab_helper.h" |
48 #include "chrome/browser/file_select_helper.h" | 50 #include "chrome/browser/file_select_helper.h" |
49 #include "chrome/browser/first_run/first_run.h" | 51 #include "chrome/browser/first_run/first_run.h" |
50 #include "chrome/browser/google/google_url_tracker.h" | 52 #include "chrome/browser/google/google_url_tracker.h" |
51 #include "chrome/browser/google/google_util.h" | 53 #include "chrome/browser/google/google_util.h" |
52 #include "chrome/browser/instant/instant_controller.h" | 54 #include "chrome/browser/instant/instant_controller.h" |
53 #include "chrome/browser/instant/instant_unload_handler.h" | 55 #include "chrome/browser/instant/instant_unload_handler.h" |
| 56 #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" |
54 #include "chrome/browser/net/browser_url_util.h" | 57 #include "chrome/browser/net/browser_url_util.h" |
55 #include "chrome/browser/net/url_fixer_upper.h" | 58 #include "chrome/browser/net/url_fixer_upper.h" |
56 #include "chrome/browser/notifications/notification_ui_manager.h" | 59 #include "chrome/browser/notifications/notification_ui_manager.h" |
57 #include "chrome/browser/platform_util.h" | 60 #include "chrome/browser/platform_util.h" |
58 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 61 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
59 #include "chrome/browser/prefs/pref_service.h" | 62 #include "chrome/browser/prefs/pref_service.h" |
60 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | 63 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
61 #include "chrome/browser/profiles/profile.h" | 64 #include "chrome/browser/profiles/profile.h" |
62 #include "chrome/browser/sessions/restore_tab_helper.h" | 65 #include "chrome/browser/sessions/restore_tab_helper.h" |
63 #include "chrome/browser/sessions/session_service.h" | 66 #include "chrome/browser/sessions/session_service.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 100 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
98 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 101 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
99 #include "chrome/browser/ui/webui/bug_report_ui.h" | 102 #include "chrome/browser/ui/webui/bug_report_ui.h" |
100 #include "chrome/browser/ui/webui/options/content_settings_handler.h" | 103 #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
101 #include "chrome/browser/ui/window_sizer.h" | 104 #include "chrome/browser/ui/window_sizer.h" |
102 #include "chrome/browser/upgrade_detector.h" | 105 #include "chrome/browser/upgrade_detector.h" |
103 #include "chrome/browser/web_applications/web_app.h" | 106 #include "chrome/browser/web_applications/web_app.h" |
104 #include "chrome/common/chrome_constants.h" | 107 #include "chrome/common/chrome_constants.h" |
105 #include "chrome/common/chrome_notification_types.h" | 108 #include "chrome/common/chrome_notification_types.h" |
106 #include "chrome/common/chrome_switches.h" | 109 #include "chrome/common/chrome_switches.h" |
| 110 #include "chrome/common/custom_handlers/protocol_handler.h" |
107 #include "chrome/common/extensions/extension.h" | 111 #include "chrome/common/extensions/extension.h" |
108 #include "chrome/common/extensions/extension_constants.h" | 112 #include "chrome/common/extensions/extension_constants.h" |
109 #include "chrome/common/pref_names.h" | 113 #include "chrome/common/pref_names.h" |
110 #include "chrome/common/profiling.h" | 114 #include "chrome/common/profiling.h" |
111 #include "chrome/common/url_constants.h" | 115 #include "chrome/common/url_constants.h" |
112 #include "chrome/common/web_apps.h" | 116 #include "chrome/common/web_apps.h" |
113 #include "content/browser/browser_url_handler.h" | 117 #include "content/browser/browser_url_handler.h" |
114 #include "content/browser/child_process_security_policy.h" | 118 #include "content/browser/child_process_security_policy.h" |
115 #include "content/browser/debugger/devtools_manager.h" | 119 #include "content/browser/debugger/devtools_manager.h" |
116 #include "content/browser/download/download_item.h" | 120 #include "content/browser/download/download_item.h" |
(...skipping 2288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2405 | 2409 |
2406 // This object is destroyed when the enumeration is performed or | 2410 // This object is destroyed when the enumeration is performed or |
2407 // cancelled. | 2411 // cancelled. |
2408 FileSelectHelper* file_select_helper = new FileSelectHelper(profile); | 2412 FileSelectHelper* file_select_helper = new FileSelectHelper(profile); |
2409 | 2413 |
2410 file_select_helper->EnumerateDirectory(request_id, | 2414 file_select_helper->EnumerateDirectory(request_id, |
2411 tab->render_view_host(), | 2415 tab->render_view_host(), |
2412 path); | 2416 path); |
2413 } | 2417 } |
2414 | 2418 |
| 2419 // static |
| 2420 void Browser::JSOutOfMemoryHelper(TabContents* tab) { |
| 2421 TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2422 tab); |
| 2423 if (tcw) { |
| 2424 tcw->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 2425 tab, NULL, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), |
| 2426 true)); |
| 2427 } |
| 2428 } |
| 2429 |
| 2430 // static |
| 2431 void Browser::RegisterProtocolHandlerHelper(TabContents* tab, |
| 2432 const std::string& protocol, |
| 2433 const GURL& url, |
| 2434 const string16& title) { |
| 2435 TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2436 tab); |
| 2437 if (!tcw || tcw->profile()->IsOffTheRecord()) |
| 2438 return; |
| 2439 |
| 2440 ChildProcessSecurityPolicy* policy = |
| 2441 ChildProcessSecurityPolicy::GetInstance(); |
| 2442 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol)) |
| 2443 return; |
| 2444 |
| 2445 ProtocolHandler handler = |
| 2446 ProtocolHandler::CreateProtocolHandler(protocol, url, title); |
| 2447 |
| 2448 ProtocolHandlerRegistry* registry = |
| 2449 tcw->profile()->GetProtocolHandlerRegistry(); |
| 2450 if (!registry->enabled() || registry->IsRegistered(handler) || |
| 2451 registry->IsIgnored(handler)) |
| 2452 return; |
| 2453 |
| 2454 if (!handler.IsEmpty() && |
| 2455 registry->CanSchemeBeOverridden(handler.protocol())) { |
| 2456 UserMetrics::RecordAction( |
| 2457 UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); |
| 2458 tcw->AddInfoBar(new RegisterProtocolHandlerInfoBarDelegate(tab, |
| 2459 registry, |
| 2460 handler)); |
| 2461 } |
| 2462 } |
| 2463 |
| 2464 // static |
| 2465 void Browser::RegisterIntentHandlerHelper(TabContents* tab, |
| 2466 const string16& action, |
| 2467 const string16& type, |
| 2468 const string16& href, |
| 2469 const string16& title) { |
| 2470 TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2471 tab); |
| 2472 if (!tcw || tcw->profile()->IsOffTheRecord()) |
| 2473 return; |
| 2474 |
| 2475 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) |
| 2476 return; |
| 2477 |
| 2478 GURL service_url(href); |
| 2479 if (!service_url.is_valid()) { |
| 2480 const GURL& url = tab->GetURL(); |
| 2481 service_url = url.Resolve(href); |
| 2482 } |
| 2483 |
| 2484 WebIntentData intent; |
| 2485 intent.service_url = service_url; |
| 2486 intent.action = action; |
| 2487 intent.type = type; |
| 2488 intent.title = title; |
| 2489 tcw->AddInfoBar(new RegisterIntentHandlerInfoBarDelegate(tab, intent)); |
| 2490 } |
| 2491 |
| 2492 // static |
| 2493 void Browser::WebIntentDispatchHelper(TabContents* tab, |
| 2494 int routing_id, |
| 2495 const string16& action, |
| 2496 const string16& type, |
| 2497 const string16& data, |
| 2498 int intent_id) { |
| 2499 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) |
| 2500 return; |
| 2501 |
| 2502 DLOG(INFO) << "Browser tab contents received intent:" |
| 2503 << "\naction=" << UTF16ToASCII(action) |
| 2504 << "\ntype=" << UTF16ToASCII(type) |
| 2505 << "\nrenderer_id=" << routing_id |
| 2506 << "\nid=" << intent_id; |
| 2507 } |
| 2508 |
2415 void Browser::ExecuteCommandWithDisposition( | 2509 void Browser::ExecuteCommandWithDisposition( |
2416 int id, WindowOpenDisposition disposition) { | 2510 int id, WindowOpenDisposition disposition) { |
2417 // No commands are enabled if there is not yet any selected tab. | 2511 // No commands are enabled if there is not yet any selected tab. |
2418 // TODO(pkasting): It seems like we should not need this, because either | 2512 // TODO(pkasting): It seems like we should not need this, because either |
2419 // most/all commands should not have been enabled yet anyway or the ones that | 2513 // most/all commands should not have been enabled yet anyway or the ones that |
2420 // are enabled should be global, or safe themselves against having no selected | 2514 // are enabled should be global, or safe themselves against having no selected |
2421 // tab. However, Ben says he tried removing this before and got lots of | 2515 // tab. However, Ben says he tried removing this before and got lots of |
2422 // crashes, e.g. from Windows sending WM_COMMANDs at random times during | 2516 // crashes, e.g. from Windows sending WM_COMMANDs at random times during |
2423 // window construction. This probably could use closer examination someday. | 2517 // window construction. This probably could use closer examination someday. |
2424 if (!GetSelectedTabContentsWrapper()) | 2518 if (!GetSelectedTabContentsWrapper()) |
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3630 if (tab != GetSelectedTabContents()) | 3724 if (tab != GetSelectedTabContents()) |
3631 return; | 3725 return; |
3632 fullscreened_tab_ = enter_fullscreen ? | 3726 fullscreened_tab_ = enter_fullscreen ? |
3633 TabContentsWrapper::GetCurrentWrapperForContents(tab) : NULL; | 3727 TabContentsWrapper::GetCurrentWrapperForContents(tab) : NULL; |
3634 if (enter_fullscreen && !window_->IsFullscreen()) | 3728 if (enter_fullscreen && !window_->IsFullscreen()) |
3635 tab_caused_fullscreen_ = true; | 3729 tab_caused_fullscreen_ = true; |
3636 if (tab_caused_fullscreen_) | 3730 if (tab_caused_fullscreen_) |
3637 ToggleFullscreenMode(); | 3731 ToggleFullscreenMode(); |
3638 } | 3732 } |
3639 | 3733 |
| 3734 void Browser::JSOutOfMemory(TabContents* tab) { |
| 3735 Browser::JSOutOfMemoryHelper(tab); |
| 3736 } |
| 3737 |
| 3738 void Browser::RegisterProtocolHandler(TabContents* tab, |
| 3739 const std::string& protocol, |
| 3740 const GURL& url, |
| 3741 const string16& title) { |
| 3742 Browser::RegisterProtocolHandlerHelper(tab, protocol, url, title); |
| 3743 } |
| 3744 |
| 3745 void Browser::RegisterIntentHandler(TabContents* tab, |
| 3746 const string16& action, |
| 3747 const string16& type, |
| 3748 const string16& href, |
| 3749 const string16& title) { |
| 3750 Browser::RegisterIntentHandlerHelper(tab, action, type, href, title); |
| 3751 } |
| 3752 |
| 3753 void Browser::WebIntentDispatch(TabContents* tab, |
| 3754 int routing_id, |
| 3755 const string16& action, |
| 3756 const string16& type, |
| 3757 const string16& data, |
| 3758 int intent_id) { |
| 3759 Browser::WebIntentDispatchHelper(tab, routing_id, action, type, data, |
| 3760 intent_id); |
| 3761 } |
| 3762 |
3640 void Browser::ExitTabbedFullscreenModeIfNecessary() { | 3763 void Browser::ExitTabbedFullscreenModeIfNecessary() { |
3641 if (tab_caused_fullscreen_) | 3764 if (tab_caused_fullscreen_) |
3642 ToggleFullscreenMode(); | 3765 ToggleFullscreenMode(); |
3643 else | 3766 else |
3644 NotifyTabOfFullscreenExitIfNecessary(); | 3767 NotifyTabOfFullscreenExitIfNecessary(); |
3645 } | 3768 } |
3646 | 3769 |
3647 /////////////////////////////////////////////////////////////////////////////// | 3770 /////////////////////////////////////////////////////////////////////////////// |
3648 // Browser, TabContentsWrapperDelegate implementation: | 3771 // Browser, TabContentsWrapperDelegate implementation: |
3649 | 3772 |
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4979 } | 5102 } |
4980 | 5103 |
4981 void Browser::ShowSyncSetup() { | 5104 void Browser::ShowSyncSetup() { |
4982 ProfileSyncService* service = | 5105 ProfileSyncService* service = |
4983 profile()->GetOriginalProfile()->GetProfileSyncService(); | 5106 profile()->GetOriginalProfile()->GetProfileSyncService(); |
4984 if (service->HasSyncSetupCompleted()) | 5107 if (service->HasSyncSetupCompleted()) |
4985 ShowOptionsTab(chrome::kSyncSetupSubPage); | 5108 ShowOptionsTab(chrome::kSyncSetupSubPage); |
4986 else | 5109 else |
4987 service->ShowLoginDialog(); | 5110 service->ShowLoginDialog(); |
4988 } | 5111 } |
OLD | NEW |