| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "chrome/browser/debugger/devtools_toggle_action.h" | 42 #include "chrome/browser/debugger/devtools_toggle_action.h" |
| 43 #include "chrome/browser/debugger/devtools_window.h" | 43 #include "chrome/browser/debugger/devtools_window.h" |
| 44 #include "chrome/browser/download/download_crx_util.h" | 44 #include "chrome/browser/download/download_crx_util.h" |
| 45 #include "chrome/browser/download/download_item_model.h" | 45 #include "chrome/browser/download/download_item_model.h" |
| 46 #include "chrome/browser/download/download_service.h" | 46 #include "chrome/browser/download/download_service.h" |
| 47 #include "chrome/browser/download/download_service_factory.h" | 47 #include "chrome/browser/download/download_service_factory.h" |
| 48 #include "chrome/browser/download/download_shelf.h" | 48 #include "chrome/browser/download/download_shelf.h" |
| 49 #include "chrome/browser/download/download_started_animation.h" | 49 #include "chrome/browser/download/download_started_animation.h" |
| 50 #include "chrome/browser/download/download_util.h" | 50 #include "chrome/browser/download/download_util.h" |
| 51 #include "chrome/browser/extensions/browser_extension_window_controller.h" | 51 #include "chrome/browser/extensions/browser_extension_window_controller.h" |
| 52 #include "chrome/browser/extensions/crx_installer.h" | |
| 53 #include "chrome/browser/extensions/default_apps_trial.h" | 52 #include "chrome/browser/extensions/default_apps_trial.h" |
| 54 #include "chrome/browser/extensions/extension_prefs.h" | 53 #include "chrome/browser/extensions/extension_prefs.h" |
| 55 #include "chrome/browser/extensions/extension_service.h" | 54 #include "chrome/browser/extensions/extension_service.h" |
| 56 #include "chrome/browser/extensions/extension_tab_helper.h" | 55 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 57 #include "chrome/browser/favicon/favicon_tab_helper.h" | 56 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 58 #include "chrome/browser/file_select_helper.h" | 57 #include "chrome/browser/file_select_helper.h" |
| 59 #include "chrome/browser/first_run/first_run.h" | 58 #include "chrome/browser/first_run/first_run.h" |
| 60 #include "chrome/browser/google/google_url_tracker.h" | 59 #include "chrome/browser/google/google_url_tracker.h" |
| 61 #include "chrome/browser/infobars/infobar_tab_helper.h" | 60 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 62 #include "chrome/browser/instant/instant_controller.h" | 61 #include "chrome/browser/instant/instant_controller.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 window_(NULL), | 299 window_(NULL), |
| 301 ALLOW_THIS_IN_INITIALIZER_LIST( | 300 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 302 tab_strip_model_(new TabStripModel(this, profile))), | 301 tab_strip_model_(new TabStripModel(this, profile))), |
| 303 app_type_(APP_TYPE_HOST), | 302 app_type_(APP_TYPE_HOST), |
| 304 chrome_updater_factory_(this), | 303 chrome_updater_factory_(this), |
| 305 is_attempting_to_close_browser_(false), | 304 is_attempting_to_close_browser_(false), |
| 306 cancel_download_confirmation_state_(NOT_PROMPTED), | 305 cancel_download_confirmation_state_(NOT_PROMPTED), |
| 307 initial_show_state_(ui::SHOW_STATE_DEFAULT), | 306 initial_show_state_(ui::SHOW_STATE_DEFAULT), |
| 308 is_session_restore_(false), | 307 is_session_restore_(false), |
| 309 weak_factory_(this), | 308 weak_factory_(this), |
| 310 pending_web_app_action_(NONE), | |
| 311 ALLOW_THIS_IN_INITIALIZER_LIST( | 309 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 312 content_setting_bubble_model_delegate_( | 310 content_setting_bubble_model_delegate_( |
| 313 new BrowserContentSettingBubbleModelDelegate(this))), | 311 new BrowserContentSettingBubbleModelDelegate(this))), |
| 314 ALLOW_THIS_IN_INITIALIZER_LIST( | 312 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 315 toolbar_model_delegate_( | 313 toolbar_model_delegate_( |
| 316 new BrowserToolbarModelDelegate(this))), | 314 new BrowserToolbarModelDelegate(this))), |
| 317 ALLOW_THIS_IN_INITIALIZER_LIST( | 315 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 318 tab_restore_service_delegate_( | 316 tab_restore_service_delegate_( |
| 319 new BrowserTabRestoreServiceDelegate(this))), | 317 new BrowserTabRestoreServiceDelegate(this))), |
| 320 ALLOW_THIS_IN_INITIALIZER_LIST( | 318 ALLOW_THIS_IN_INITIALIZER_LIST( |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 | 807 |
| 810 // TODO(beng): figure out how to juggle this. | 808 // TODO(beng): figure out how to juggle this. |
| 811 gfx::NativeWindow parent_window = window_->GetNativeWindow(); | 809 gfx::NativeWindow parent_window = window_->GetNativeWindow(); |
| 812 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, | 810 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, |
| 813 string16(), directory, | 811 string16(), directory, |
| 814 NULL, 0, FILE_PATH_LITERAL(""), | 812 NULL, 0, FILE_PATH_LITERAL(""), |
| 815 chrome::GetActiveWebContents(this), | 813 chrome::GetActiveWebContents(this), |
| 816 parent_window, NULL); | 814 parent_window, NULL); |
| 817 } | 815 } |
| 818 | 816 |
| 819 void Browser::OpenCreateShortcutsDialog() { | |
| 820 content::RecordAction(UserMetricsAction("CreateShortcut")); | |
| 821 #if !defined(OS_MACOSX) | |
| 822 TabContents* current_tab = chrome::GetActiveTabContents(this); | |
| 823 DCHECK(current_tab && | |
| 824 web_app::IsValidUrl(current_tab->web_contents()->GetURL())) << | |
| 825 "Menu item should be disabled."; | |
| 826 | |
| 827 NavigationEntry* entry = | |
| 828 current_tab->web_contents()->GetController().GetLastCommittedEntry(); | |
| 829 if (!entry) | |
| 830 return; | |
| 831 | |
| 832 // RVH's GetApplicationInfo should not be called before it returns. | |
| 833 DCHECK(pending_web_app_action_ == NONE); | |
| 834 pending_web_app_action_ = CREATE_SHORTCUT; | |
| 835 | |
| 836 // Start fetching web app info for CreateApplicationShortcut dialog and show | |
| 837 // the dialog when the data is available in OnDidGetApplicationInfo. | |
| 838 current_tab->extension_tab_helper()->GetApplicationInfo(entry->GetPageID()); | |
| 839 #else | |
| 840 NOTIMPLEMENTED(); | |
| 841 #endif | |
| 842 } | |
| 843 | |
| 844 void Browser::UpdateDownloadShelfVisibility(bool visible) { | 817 void Browser::UpdateDownloadShelfVisibility(bool visible) { |
| 845 if (GetStatusBubble()) | 818 if (GetStatusBubble()) |
| 846 GetStatusBubble()->UpdateDownloadShelfVisibility(visible); | 819 GetStatusBubble()->UpdateDownloadShelfVisibility(visible); |
| 847 } | 820 } |
| 848 | 821 |
| 849 bool Browser::OpenInstant(WindowOpenDisposition disposition) { | 822 bool Browser::OpenInstant(WindowOpenDisposition disposition) { |
| 850 if (!instant() || !instant()->PrepareForCommit() || | 823 if (!instant() || !instant()->PrepareForCommit() || |
| 851 disposition == NEW_BACKGROUND_TAB) { | 824 disposition == NEW_BACKGROUND_TAB) { |
| 852 // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't | 825 // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't |
| 853 // attempt to use the instant preview. | 826 // attempt to use the instant preview. |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 | 1500 |
| 1528 WebContents* selected_contents = chrome::GetActiveWebContents(this); | 1501 WebContents* selected_contents = chrome::GetActiveWebContents(this); |
| 1529 if (source == selected_contents) { | 1502 if (source == selected_contents) { |
| 1530 bool is_loading = source->IsLoading(); | 1503 bool is_loading = source->IsLoading(); |
| 1531 command_controller_->LoadingStateChanged(is_loading, false); | 1504 command_controller_->LoadingStateChanged(is_loading, false); |
| 1532 if (GetStatusBubble()) { | 1505 if (GetStatusBubble()) { |
| 1533 GetStatusBubble()->SetStatus( | 1506 GetStatusBubble()->SetStatus( |
| 1534 chrome::GetActiveTabContents(this)->core_tab_helper()-> | 1507 chrome::GetActiveTabContents(this)->core_tab_helper()-> |
| 1535 GetStatusText()); | 1508 GetStatusText()); |
| 1536 } | 1509 } |
| 1537 | |
| 1538 if (!is_loading && pending_web_app_action_ == UPDATE_SHORTCUT) { | |
| 1539 // Schedule a shortcut update when web application info is available if | |
| 1540 // last committed entry is not NULL. Last committed entry could be NULL | |
| 1541 // when an interstitial page is injected (e.g. bad https certificate, | |
| 1542 // malware site etc). When this happens, we abort the shortcut update. | |
| 1543 NavigationEntry* entry = source->GetController().GetLastCommittedEntry(); | |
| 1544 if (entry) { | |
| 1545 TabContents::FromWebContents(source)-> | |
| 1546 extension_tab_helper()->GetApplicationInfo(entry->GetPageID()); | |
| 1547 } else { | |
| 1548 pending_web_app_action_ = NONE; | |
| 1549 } | |
| 1550 } | |
| 1551 } | 1510 } |
| 1552 } | 1511 } |
| 1553 | 1512 |
| 1554 void Browser::CloseContents(WebContents* source) { | 1513 void Browser::CloseContents(WebContents* source) { |
| 1555 if (is_attempting_to_close_browser_) { | 1514 if (is_attempting_to_close_browser_) { |
| 1556 // If we're trying to close the browser, just clear the state related to | 1515 // If we're trying to close the browser, just clear the state related to |
| 1557 // waiting for unload to fire. Don't actually try to close the tab as it | 1516 // waiting for unload to fire. Don't actually try to close the tab as it |
| 1558 // will go down the slow shutdown path instead of the fast path of killing | 1517 // will go down the slow shutdown path instead of the fast path of killing |
| 1559 // all the renderer processes. | 1518 // all the renderer processes. |
| 1560 ClearUnloadState(source, true); | 1519 ClearUnloadState(source, true); |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2049 if (source == chrome::GetActiveTabContents(this)) { | 2008 if (source == chrome::GetActiveTabContents(this)) { |
| 2050 window_->SetZoomIconTooltipPercent(zoom_percent); | 2009 window_->SetZoomIconTooltipPercent(zoom_percent); |
| 2051 | 2010 |
| 2052 // Only show the zoom bubble for zoom changes in the active window. | 2011 // Only show the zoom bubble for zoom changes in the active window. |
| 2053 if (can_show_bubble && window_->IsActive()) | 2012 if (can_show_bubble && window_->IsActive()) |
| 2054 window_->ShowZoomBubble(zoom_percent); | 2013 window_->ShowZoomBubble(zoom_percent); |
| 2055 } | 2014 } |
| 2056 } | 2015 } |
| 2057 | 2016 |
| 2058 /////////////////////////////////////////////////////////////////////////////// | 2017 /////////////////////////////////////////////////////////////////////////////// |
| 2059 // Browser, ExtensionTabHelperDelegate implementation: | |
| 2060 | |
| 2061 void Browser::OnDidGetApplicationInfo(TabContents* source, | |
| 2062 int32 page_id) { | |
| 2063 if (chrome::GetActiveTabContents(this) != source) | |
| 2064 return; | |
| 2065 | |
| 2066 NavigationEntry* entry = | |
| 2067 source->web_contents()->GetController().GetLastCommittedEntry(); | |
| 2068 if (!entry || (entry->GetPageID() != page_id)) | |
| 2069 return; | |
| 2070 | |
| 2071 switch (pending_web_app_action_) { | |
| 2072 case CREATE_SHORTCUT: { | |
| 2073 window()->ShowCreateWebAppShortcutsDialog(source); | |
| 2074 break; | |
| 2075 } | |
| 2076 case UPDATE_SHORTCUT: { | |
| 2077 web_app::UpdateShortcutForTabContents(source); | |
| 2078 break; | |
| 2079 } | |
| 2080 default: | |
| 2081 NOTREACHED(); | |
| 2082 break; | |
| 2083 } | |
| 2084 | |
| 2085 pending_web_app_action_ = NONE; | |
| 2086 } | |
| 2087 | |
| 2088 void Browser::OnInstallApplication(TabContents* source, | |
| 2089 const WebApplicationInfo& web_app) { | |
| 2090 ExtensionService* extension_service = profile()->GetExtensionService(); | |
| 2091 if (!extension_service) | |
| 2092 return; | |
| 2093 | |
| 2094 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create( | |
| 2095 extension_service, | |
| 2096 extension_service->show_extensions_prompts() ? | |
| 2097 new ExtensionInstallPrompt(this) : NULL)); | |
| 2098 installer->InstallWebApp(web_app); | |
| 2099 } | |
| 2100 | |
| 2101 /////////////////////////////////////////////////////////////////////////////// | |
| 2102 // Browser, SelectFileDialog::Listener implementation: | 2018 // Browser, SelectFileDialog::Listener implementation: |
| 2103 | 2019 |
| 2104 void Browser::FileSelected(const FilePath& path, int index, void* params) { | 2020 void Browser::FileSelected(const FilePath& path, int index, void* params) { |
| 2105 profile_->set_last_selected_directory(path.DirName()); | 2021 profile_->set_last_selected_directory(path.DirName()); |
| 2106 GURL file_url = net::FilePathToFileURL(path); | 2022 GURL file_url = net::FilePathToFileURL(path); |
| 2107 | 2023 |
| 2108 #if defined(OS_CHROMEOS) | 2024 #if defined(OS_CHROMEOS) |
| 2109 gdata::util::ModifyGDataFileResourceUrl(profile_, path, &file_url); | 2025 gdata::util::ModifyGDataFileResourceUrl(profile_, path, &file_url); |
| 2110 #endif | 2026 #endif |
| 2111 | 2027 |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2604 void Browser::SetAsDelegate(TabContents* tab, Browser* delegate) { | 2520 void Browser::SetAsDelegate(TabContents* tab, Browser* delegate) { |
| 2605 // WebContents... | 2521 // WebContents... |
| 2606 tab->web_contents()->SetDelegate(delegate); | 2522 tab->web_contents()->SetDelegate(delegate); |
| 2607 | 2523 |
| 2608 // ...and all the helpers. | 2524 // ...and all the helpers. |
| 2609 tab->blocked_content_tab_helper()->set_delegate(delegate); | 2525 tab->blocked_content_tab_helper()->set_delegate(delegate); |
| 2610 tab->bookmark_tab_helper()->set_delegate(delegate); | 2526 tab->bookmark_tab_helper()->set_delegate(delegate); |
| 2611 tab->zoom_controller()->set_observer(delegate); | 2527 tab->zoom_controller()->set_observer(delegate); |
| 2612 tab->constrained_window_tab_helper()->set_delegate(delegate); | 2528 tab->constrained_window_tab_helper()->set_delegate(delegate); |
| 2613 tab->core_tab_helper()->set_delegate(delegate); | 2529 tab->core_tab_helper()->set_delegate(delegate); |
| 2614 tab->extension_tab_helper()->set_delegate(delegate); | |
| 2615 tab->search_engine_tab_helper()->set_delegate(delegate); | 2530 tab->search_engine_tab_helper()->set_delegate(delegate); |
| 2616 } | 2531 } |
| 2617 | 2532 |
| 2618 void Browser::CloseFrame() { | 2533 void Browser::CloseFrame() { |
| 2619 window_->Close(); | 2534 window_->Close(); |
| 2620 } | 2535 } |
| 2621 | 2536 |
| 2622 void Browser::TabDetachedAtImpl(TabContents* contents, int index, | 2537 void Browser::TabDetachedAtImpl(TabContents* contents, int index, |
| 2623 DetachType type) { | 2538 DetachType type) { |
| 2624 if (type == DETACH_TYPE_DETACH) { | 2539 if (type == DETACH_TYPE_DETACH) { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2815 if (contents && !allow_js_access) { | 2730 if (contents && !allow_js_access) { |
| 2816 contents->web_contents()->GetController().LoadURL( | 2731 contents->web_contents()->GetController().LoadURL( |
| 2817 target_url, | 2732 target_url, |
| 2818 content::Referrer(), | 2733 content::Referrer(), |
| 2819 content::PAGE_TRANSITION_LINK, | 2734 content::PAGE_TRANSITION_LINK, |
| 2820 std::string()); // No extra headers. | 2735 std::string()); // No extra headers. |
| 2821 } | 2736 } |
| 2822 | 2737 |
| 2823 return contents != NULL; | 2738 return contents != NULL; |
| 2824 } | 2739 } |
| OLD | NEW |