Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 10699057: Move application creation and extension install prompt showing off Browser and onto ExtensionTabHel… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/browser_command_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 window_(NULL), 300 window_(NULL),
302 ALLOW_THIS_IN_INITIALIZER_LIST( 301 ALLOW_THIS_IN_INITIALIZER_LIST(
303 tab_strip_model_(new TabStripModel(this, profile))), 302 tab_strip_model_(new TabStripModel(this, profile))),
304 app_type_(APP_TYPE_HOST), 303 app_type_(APP_TYPE_HOST),
305 chrome_updater_factory_(this), 304 chrome_updater_factory_(this),
306 is_attempting_to_close_browser_(false), 305 is_attempting_to_close_browser_(false),
307 cancel_download_confirmation_state_(NOT_PROMPTED), 306 cancel_download_confirmation_state_(NOT_PROMPTED),
308 initial_show_state_(ui::SHOW_STATE_DEFAULT), 307 initial_show_state_(ui::SHOW_STATE_DEFAULT),
309 is_session_restore_(false), 308 is_session_restore_(false),
310 weak_factory_(this), 309 weak_factory_(this),
311 pending_web_app_action_(NONE),
312 ALLOW_THIS_IN_INITIALIZER_LIST( 310 ALLOW_THIS_IN_INITIALIZER_LIST(
313 content_setting_bubble_model_delegate_( 311 content_setting_bubble_model_delegate_(
314 new BrowserContentSettingBubbleModelDelegate(this))), 312 new BrowserContentSettingBubbleModelDelegate(this))),
315 ALLOW_THIS_IN_INITIALIZER_LIST( 313 ALLOW_THIS_IN_INITIALIZER_LIST(
316 toolbar_model_delegate_( 314 toolbar_model_delegate_(
317 new BrowserToolbarModelDelegate(this))), 315 new BrowserToolbarModelDelegate(this))),
318 ALLOW_THIS_IN_INITIALIZER_LIST( 316 ALLOW_THIS_IN_INITIALIZER_LIST(
319 tab_restore_service_delegate_( 317 tab_restore_service_delegate_(
320 new BrowserTabRestoreServiceDelegate(this))), 318 new BrowserTabRestoreServiceDelegate(this))),
321 ALLOW_THIS_IN_INITIALIZER_LIST( 319 ALLOW_THIS_IN_INITIALIZER_LIST(
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 const FilePath directory = profile_->last_selected_directory(); 808 const FilePath directory = profile_->last_selected_directory();
811 809
812 // TODO(beng): figure out how to juggle this. 810 // TODO(beng): figure out how to juggle this.
813 gfx::NativeWindow parent_window = window_->GetNativeWindow(); 811 gfx::NativeWindow parent_window = window_->GetNativeWindow();
814 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, 812 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE,
815 string16(), directory, 813 string16(), directory,
816 NULL, 0, FILE_PATH_LITERAL(""), 814 NULL, 0, FILE_PATH_LITERAL(""),
817 parent_window, NULL); 815 parent_window, NULL);
818 } 816 }
819 817
820 void Browser::OpenCreateShortcutsDialog() {
821 content::RecordAction(UserMetricsAction("CreateShortcut"));
822 #if !defined(OS_MACOSX)
823 TabContents* current_tab = chrome::GetActiveTabContents(this);
824 DCHECK(current_tab &&
825 web_app::IsValidUrl(current_tab->web_contents()->GetURL())) <<
826 "Menu item should be disabled.";
827
828 NavigationEntry* entry =
829 current_tab->web_contents()->GetController().GetLastCommittedEntry();
830 if (!entry)
831 return;
832
833 // RVH's GetApplicationInfo should not be called before it returns.
834 DCHECK(pending_web_app_action_ == NONE);
835 pending_web_app_action_ = CREATE_SHORTCUT;
836
837 // Start fetching web app info for CreateApplicationShortcut dialog and show
838 // the dialog when the data is available in OnDidGetApplicationInfo.
839 current_tab->extension_tab_helper()->GetApplicationInfo(entry->GetPageID());
840 #else
841 NOTIMPLEMENTED();
842 #endif
843 }
844
845 void Browser::UpdateDownloadShelfVisibility(bool visible) { 818 void Browser::UpdateDownloadShelfVisibility(bool visible) {
846 if (GetStatusBubble()) 819 if (GetStatusBubble())
847 GetStatusBubble()->UpdateDownloadShelfVisibility(visible); 820 GetStatusBubble()->UpdateDownloadShelfVisibility(visible);
848 } 821 }
849 822
850 bool Browser::OpenInstant(WindowOpenDisposition disposition) { 823 bool Browser::OpenInstant(WindowOpenDisposition disposition) {
851 if (!instant() || !instant()->PrepareForCommit() || 824 if (!instant() || !instant()->PrepareForCommit() ||
852 disposition == NEW_BACKGROUND_TAB) { 825 disposition == NEW_BACKGROUND_TAB) {
853 // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't 826 // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't
854 // attempt to use the instant preview. 827 // attempt to use the instant preview.
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 1501
1529 WebContents* selected_contents = chrome::GetActiveWebContents(this); 1502 WebContents* selected_contents = chrome::GetActiveWebContents(this);
1530 if (source == selected_contents) { 1503 if (source == selected_contents) {
1531 bool is_loading = source->IsLoading(); 1504 bool is_loading = source->IsLoading();
1532 command_controller_->LoadingStateChanged(is_loading, false); 1505 command_controller_->LoadingStateChanged(is_loading, false);
1533 if (GetStatusBubble()) { 1506 if (GetStatusBubble()) {
1534 GetStatusBubble()->SetStatus( 1507 GetStatusBubble()->SetStatus(
1535 chrome::GetActiveTabContents(this)->core_tab_helper()-> 1508 chrome::GetActiveTabContents(this)->core_tab_helper()->
1536 GetStatusText()); 1509 GetStatusText());
1537 } 1510 }
1538
1539 if (!is_loading && pending_web_app_action_ == UPDATE_SHORTCUT) {
1540 // Schedule a shortcut update when web application info is available if
1541 // last committed entry is not NULL. Last committed entry could be NULL
1542 // when an interstitial page is injected (e.g. bad https certificate,
1543 // malware site etc). When this happens, we abort the shortcut update.
1544 NavigationEntry* entry = source->GetController().GetLastCommittedEntry();
1545 if (entry) {
1546 TabContents::FromWebContents(source)->
1547 extension_tab_helper()->GetApplicationInfo(entry->GetPageID());
1548 } else {
1549 pending_web_app_action_ = NONE;
1550 }
1551 }
1552 } 1511 }
1553 } 1512 }
1554 1513
1555 void Browser::CloseContents(WebContents* source) { 1514 void Browser::CloseContents(WebContents* source) {
1556 if (is_attempting_to_close_browser_) { 1515 if (is_attempting_to_close_browser_) {
1557 // If we're trying to close the browser, just clear the state related to 1516 // If we're trying to close the browser, just clear the state related to
1558 // waiting for unload to fire. Don't actually try to close the tab as it 1517 // waiting for unload to fire. Don't actually try to close the tab as it
1559 // will go down the slow shutdown path instead of the fast path of killing 1518 // will go down the slow shutdown path instead of the fast path of killing
1560 // all the renderer processes. 1519 // all the renderer processes.
1561 ClearUnloadState(source, true); 1520 ClearUnloadState(source, true);
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
2050 if (source == chrome::GetActiveTabContents(this)) { 2009 if (source == chrome::GetActiveTabContents(this)) {
2051 window_->SetZoomIconTooltipPercent(zoom_percent); 2010 window_->SetZoomIconTooltipPercent(zoom_percent);
2052 2011
2053 // Only show the zoom bubble for zoom changes in the active window. 2012 // Only show the zoom bubble for zoom changes in the active window.
2054 if (can_show_bubble && window_->IsActive()) 2013 if (can_show_bubble && window_->IsActive())
2055 window_->ShowZoomBubble(zoom_percent); 2014 window_->ShowZoomBubble(zoom_percent);
2056 } 2015 }
2057 } 2016 }
2058 2017
2059 /////////////////////////////////////////////////////////////////////////////// 2018 ///////////////////////////////////////////////////////////////////////////////
2060 // Browser, ExtensionTabHelperDelegate implementation:
2061
2062 void Browser::OnDidGetApplicationInfo(TabContents* source,
2063 int32 page_id) {
2064 if (chrome::GetActiveTabContents(this) != source)
2065 return;
2066
2067 NavigationEntry* entry =
2068 source->web_contents()->GetController().GetLastCommittedEntry();
2069 if (!entry || (entry->GetPageID() != page_id))
2070 return;
2071
2072 switch (pending_web_app_action_) {
2073 case CREATE_SHORTCUT: {
2074 window()->ShowCreateWebAppShortcutsDialog(source);
2075 break;
2076 }
2077 case UPDATE_SHORTCUT: {
2078 web_app::UpdateShortcutForTabContents(source);
2079 break;
2080 }
2081 default:
2082 NOTREACHED();
2083 break;
2084 }
2085
2086 pending_web_app_action_ = NONE;
2087 }
2088
2089 void Browser::OnInstallApplication(TabContents* source,
2090 const WebApplicationInfo& web_app) {
2091 ExtensionService* extension_service = profile()->GetExtensionService();
2092 if (!extension_service)
2093 return;
2094
2095 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(
2096 extension_service,
2097 extension_service->show_extensions_prompts() ?
2098 new ExtensionInstallPrompt(this) : NULL));
2099 installer->InstallWebApp(web_app);
2100 }
2101
2102 ///////////////////////////////////////////////////////////////////////////////
2103 // Browser, SelectFileDialog::Listener implementation: 2019 // Browser, SelectFileDialog::Listener implementation:
2104 2020
2105 void Browser::FileSelected(const FilePath& path, int index, void* params) { 2021 void Browser::FileSelected(const FilePath& path, int index, void* params) {
2106 profile_->set_last_selected_directory(path.DirName()); 2022 profile_->set_last_selected_directory(path.DirName());
2107 GURL file_url = net::FilePathToFileURL(path); 2023 GURL file_url = net::FilePathToFileURL(path);
2108 2024
2109 #if defined(OS_CHROMEOS) 2025 #if defined(OS_CHROMEOS)
2110 gdata::util::ModifyGDataFileResourceUrl(profile_, path, &file_url); 2026 gdata::util::ModifyGDataFileResourceUrl(profile_, path, &file_url);
2111 #endif 2027 #endif
2112 2028
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
2605 void Browser::SetAsDelegate(TabContents* tab, Browser* delegate) { 2521 void Browser::SetAsDelegate(TabContents* tab, Browser* delegate) {
2606 // WebContents... 2522 // WebContents...
2607 tab->web_contents()->SetDelegate(delegate); 2523 tab->web_contents()->SetDelegate(delegate);
2608 2524
2609 // ...and all the helpers. 2525 // ...and all the helpers.
2610 tab->blocked_content_tab_helper()->set_delegate(delegate); 2526 tab->blocked_content_tab_helper()->set_delegate(delegate);
2611 tab->bookmark_tab_helper()->set_delegate(delegate); 2527 tab->bookmark_tab_helper()->set_delegate(delegate);
2612 tab->zoom_controller()->set_observer(delegate); 2528 tab->zoom_controller()->set_observer(delegate);
2613 tab->constrained_window_tab_helper()->set_delegate(delegate); 2529 tab->constrained_window_tab_helper()->set_delegate(delegate);
2614 tab->core_tab_helper()->set_delegate(delegate); 2530 tab->core_tab_helper()->set_delegate(delegate);
2615 tab->extension_tab_helper()->set_delegate(delegate);
2616 tab->search_engine_tab_helper()->set_delegate(delegate); 2531 tab->search_engine_tab_helper()->set_delegate(delegate);
2617 } 2532 }
2618 2533
2619 void Browser::CloseFrame() { 2534 void Browser::CloseFrame() {
2620 window_->Close(); 2535 window_->Close();
2621 } 2536 }
2622 2537
2623 void Browser::TabDetachedAtImpl(TabContents* contents, int index, 2538 void Browser::TabDetachedAtImpl(TabContents* contents, int index,
2624 DetachType type) { 2539 DetachType type) {
2625 if (type == DETACH_TYPE_DETACH) { 2540 if (type == DETACH_TYPE_DETACH) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2816 if (contents && !allow_js_access) { 2731 if (contents && !allow_js_access) {
2817 contents->web_contents()->GetController().LoadURL( 2732 contents->web_contents()->GetController().LoadURL(
2818 target_url, 2733 target_url,
2819 content::Referrer(), 2734 content::Referrer(),
2820 content::PAGE_TRANSITION_LINK, 2735 content::PAGE_TRANSITION_LINK,
2821 std::string()); // No extra headers. 2736 std::string()); // No extra headers.
2822 } 2737 }
2823 2738
2824 return contents != NULL; 2739 return contents != NULL;
2825 } 2740 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/browser_command_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698