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

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

Issue 391036: Forbid reloading the Inspector window (Closed)
Patch Set: Follow codereview Created 11 years 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/browser.h" 5 #include "chrome/browser/browser.h"
6 6
7 #include "app/animation.h" 7 #include "app/animation.h"
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/gfx/point.h" 11 #include "base/gfx/point.h"
12 #include "base/keyboard_codes.h" 12 #include "base/keyboard_codes.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/thread.h" 16 #include "base/thread.h"
17 #include "chrome/app/chrome_dll_resource.h" 17 #include "chrome/app/chrome_dll_resource.h"
18 #include "chrome/browser/bookmarks/bookmark_model.h" 18 #include "chrome/browser/bookmarks/bookmark_model.h"
19 #include "chrome/browser/bookmarks/bookmark_utils.h" 19 #include "chrome/browser/bookmarks/bookmark_utils.h"
20 #include "chrome/browser/browser_list.h" 20 #include "chrome/browser/browser_list.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/browser_shutdown.h" 22 #include "chrome/browser/browser_shutdown.h"
23 #include "chrome/browser/browser_window.h" 23 #include "chrome/browser/browser_window.h"
24 #include "chrome/browser/character_encoding.h" 24 #include "chrome/browser/character_encoding.h"
25 #include "chrome/browser/debugger/devtools_manager.h" 25 #include "chrome/browser/debugger/devtools_manager.h"
26 #include "chrome/browser/debugger/devtools_window.h"
26 #include "chrome/browser/download/download_item_model.h" 27 #include "chrome/browser/download/download_item_model.h"
27 #include "chrome/browser/download/download_manager.h" 28 #include "chrome/browser/download/download_manager.h"
28 #include "chrome/browser/download/download_shelf.h" 29 #include "chrome/browser/download/download_shelf.h"
29 #include "chrome/browser/download/download_started_animation.h" 30 #include "chrome/browser/download/download_started_animation.h"
30 #include "chrome/browser/extensions/crashed_extension_infobar.h" 31 #include "chrome/browser/extensions/crashed_extension_infobar.h"
31 #include "chrome/browser/extensions/extension_browser_event_router.h" 32 #include "chrome/browser/extensions/extension_browser_event_router.h"
32 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" 33 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h"
33 #include "chrome/browser/extensions/extension_shelf_model.h" 34 #include "chrome/browser/extensions/extension_shelf_model.h"
34 #include "chrome/browser/extensions/extension_tabs_module.h" 35 #include "chrome/browser/extensions/extension_tabs_module.h"
35 #include "chrome/browser/extensions/extensions_service.h" 36 #include "chrome/browser/extensions/extensions_service.h"
(...skipping 15 matching lines...) Expand all
51 #include "chrome/browser/status_bubble.h" 52 #include "chrome/browser/status_bubble.h"
52 #include "chrome/browser/sync/profile_sync_service.h" 53 #include "chrome/browser/sync/profile_sync_service.h"
53 #include "chrome/browser/sync/sync_ui_util.h" 54 #include "chrome/browser/sync/sync_ui_util.h"
54 #include "chrome/browser/tab_contents/interstitial_page.h" 55 #include "chrome/browser/tab_contents/interstitial_page.h"
55 #include "chrome/browser/tab_contents/navigation_controller.h" 56 #include "chrome/browser/tab_contents/navigation_controller.h"
56 #include "chrome/browser/tab_contents/navigation_entry.h" 57 #include "chrome/browser/tab_contents/navigation_entry.h"
57 #include "chrome/browser/tab_contents/tab_contents.h" 58 #include "chrome/browser/tab_contents/tab_contents.h"
58 #include "chrome/browser/tab_contents/tab_contents_view.h" 59 #include "chrome/browser/tab_contents/tab_contents_view.h"
59 #include "chrome/browser/web_applications/web_app.h" 60 #include "chrome/browser/web_applications/web_app.h"
60 #include "chrome/browser/window_sizer.h" 61 #include "chrome/browser/window_sizer.h"
61 #include "chrome/browser/web_applications/web_app.h"
62 #include "chrome/common/chrome_constants.h" 62 #include "chrome/common/chrome_constants.h"
63 #include "chrome/common/chrome_switches.h" 63 #include "chrome/common/chrome_switches.h"
64 #include "chrome/common/extensions/extension.h" 64 #include "chrome/common/extensions/extension.h"
65 #include "chrome/common/notification_service.h" 65 #include "chrome/common/notification_service.h"
66 #include "chrome/common/page_transition_types.h" 66 #include "chrome/common/page_transition_types.h"
67 #include "chrome/common/platform_util.h" 67 #include "chrome/common/platform_util.h"
68 #include "chrome/common/pref_names.h" 68 #include "chrome/common/pref_names.h"
69 #include "chrome/common/pref_service.h" 69 #include "chrome/common/pref_service.h"
70 #include "chrome/common/url_constants.h" 70 #include "chrome/common/url_constants.h"
71 #include "grit/chromium_strings.h" 71 #include "grit/chromium_strings.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 232
233 // static 233 // static
234 Browser* Browser::CreateForApp(const std::wstring& app_name, 234 Browser* Browser::CreateForApp(const std::wstring& app_name,
235 Profile* profile, bool is_popup) { 235 Profile* profile, bool is_popup) {
236 Browser* browser = new Browser(is_popup? TYPE_APP_POPUP : TYPE_APP, profile); 236 Browser* browser = new Browser(is_popup? TYPE_APP_POPUP : TYPE_APP, profile);
237 browser->app_name_ = app_name; 237 browser->app_name_ = app_name;
238 browser->CreateBrowserWindow(); 238 browser->CreateBrowserWindow();
239 return browser; 239 return browser;
240 } 240 }
241 241
242 // static
243 Browser* Browser::CreateForDevTools(Profile* profile) {
244 Browser* browser = new Browser(TYPE_DEVTOOLS, profile);
245 browser->app_name_ = DevToolsWindow::kDevToolsApp;
246 browser->CreateBrowserWindow();
247 return browser;
248 }
249
242 void Browser::CreateBrowserWindow() { 250 void Browser::CreateBrowserWindow() {
243 DCHECK(!window_); 251 DCHECK(!window_);
244 252
245 if (SupportsWindowFeature(FEATURE_EXTENSIONSHELF)) 253 if (SupportsWindowFeature(FEATURE_EXTENSIONSHELF))
246 extension_shelf_model_.reset(new ExtensionShelfModel(this)); 254 extension_shelf_model_.reset(new ExtensionShelfModel(this));
247 255
248 window_ = BrowserWindow::CreateBrowserWindow(this); 256 window_ = BrowserWindow::CreateBrowserWindow(this);
249 257
250 #if defined(OS_WIN) 258 #if defined(OS_WIN)
251 // Set the app user model id for this application to that of the application 259 // Set the app user model id for this application to that of the application
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 // If the page has unload listeners, then we tell the renderer to fire 1793 // If the page has unload listeners, then we tell the renderer to fire
1786 // them. Once they have fired, we'll get a message back saying whether 1794 // them. Once they have fired, we'll get a message back saying whether
1787 // to proceed closing the page or not, which sends us back to this method 1795 // to proceed closing the page or not, which sends us back to this method
1788 // with the HasUnloadListener bit cleared. 1796 // with the HasUnloadListener bit cleared.
1789 contents->render_view_host()->FirePageBeforeUnload(false); 1797 contents->render_view_host()->FirePageBeforeUnload(false);
1790 return true; 1798 return true;
1791 } 1799 }
1792 return false; 1800 return false;
1793 } 1801 }
1794 1802
1803 bool Browser::CanReloadContents(TabContents* source) const {
1804 return type() != TYPE_DEVTOOLS;
1805 }
1806
1795 bool Browser::CanCloseContentsAt(int index) { 1807 bool Browser::CanCloseContentsAt(int index) {
1796 if (tabstrip_model_.count() > 1) 1808 if (tabstrip_model_.count() > 1)
1797 return true; 1809 return true;
1798 // We are closing the last tab for this browser. Make sure to check for 1810 // We are closing the last tab for this browser. Make sure to check for
1799 // in-progress downloads. 1811 // in-progress downloads.
1800 // Note that the next call when it returns false will ask the user for 1812 // Note that the next call when it returns false will ask the user for
1801 // confirmation before closing the browser if the user decides so. 1813 // confirmation before closing the browser if the user decides so.
1802 return CanCloseWithInProgressDownloads(); 1814 return CanCloseWithInProgressDownloads();
1803 } 1815 }
1804 1816
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 void Browser::OnStartDownload(DownloadItem* download) { 2246 void Browser::OnStartDownload(DownloadItem* download) {
2235 if (!window()) 2247 if (!window())
2236 return; 2248 return;
2237 2249
2238 // GetDownloadShelf creates the download shelf if it was not yet created. 2250 // GetDownloadShelf creates the download shelf if it was not yet created.
2239 window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download)); 2251 window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download));
2240 2252
2241 // Don't show the animation for "Save file" downloads. 2253 // Don't show the animation for "Save file" downloads.
2242 if (download->total_bytes() <= 0) 2254 if (download->total_bytes() <= 0)
2243 return; 2255 return;
2244 2256
2245 // For non-theme extensions, we don't show the download animation. 2257 // For non-theme extensions, we don't show the download animation.
2246 if (DownloadManager::IsExtensionInstall(download) && 2258 if (DownloadManager::IsExtensionInstall(download) &&
2247 !ExtensionsService::IsDownloadFromMiniGallery(download->url())) 2259 !ExtensionsService::IsDownloadFromMiniGallery(download->url()))
2248 return; 2260 return;
2249 2261
2250 TabContents* current_tab = GetSelectedTabContents(); 2262 TabContents* current_tab = GetSelectedTabContents();
2251 // We make this check for the case of minimized windows, unit tests, etc. 2263 // We make this check for the case of minimized windows, unit tests, etc.
2252 if (platform_util::IsVisible(current_tab->GetNativeView()) && 2264 if (platform_util::IsVisible(current_tab->GetNativeView()) &&
2253 Animation::ShouldRenderRichAnimation()) 2265 Animation::ShouldRenderRichAnimation())
2254 DownloadStartedAnimation::Show(current_tab); 2266 DownloadStartedAnimation::Show(current_tab);
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
2622 // than the display one (returned by GetURL) which may be different (like 2634 // than the display one (returned by GetURL) which may be different (like
2623 // having "view-source:" on the front). 2635 // having "view-source:" on the front).
2624 GURL savable_url = (active_entry) ? active_entry->url() : GURL::EmptyGURL(); 2636 GURL savable_url = (active_entry) ? active_entry->url() : GURL::EmptyGURL();
2625 2637
2626 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, 2638 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE,
2627 SavePackage::IsSavableURL(savable_url)); 2639 SavePackage::IsSavableURL(savable_url));
2628 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, 2640 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU,
2629 SavePackage::IsSavableContents(current_tab->contents_mime_type()) && 2641 SavePackage::IsSavableContents(current_tab->contents_mime_type()) &&
2630 SavePackage::IsSavableURL(savable_url)); 2642 SavePackage::IsSavableURL(savable_url));
2631 2643
2644 // Disable certain items if running DevTools
2645 command_updater_.UpdateCommandEnabled(IDC_RELOAD,
2646 CanReloadContents(current_tab));
2647 bool enabled_for_non_devtools = type() != TYPE_DEVTOOLS;
2648 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled_for_non_devtools);
2649 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT,
2650 enabled_for_non_devtools);
2651 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS,
2652 enabled_for_non_devtools);
2653 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
2654 enabled_for_non_devtools);
2655
2632 // Show various bits of UI 2656 // Show various bits of UI
2633 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, 2657 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS,
2634 web_app::IsValidUrl(current_tab->GetURL())); 2658 web_app::IsValidUrl(current_tab->GetURL()));
2635 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, 2659 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
2636 current_tab->ShouldDisplayURL() && current_tab->GetURL().is_valid()); 2660 current_tab->ShouldDisplayURL() && current_tab->GetURL().is_valid());
2637 } 2661 }
2638 2662
2639 void Browser::UpdateStopGoState(bool is_loading, bool force) { 2663 void Browser::UpdateStopGoState(bool is_loading, bool force) {
2640 window_->UpdateStopGoState(is_loading, force); 2664 window_->UpdateStopGoState(is_loading, force);
2641 command_updater_.UpdateCommandEnabled(IDC_GO, !is_loading); 2665 command_updater_.UpdateCommandEnabled(IDC_GO, !is_loading);
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
3153 /////////////////////////////////////////////////////////////////////////////// 3177 ///////////////////////////////////////////////////////////////////////////////
3154 // BrowserToolbarModel (private): 3178 // BrowserToolbarModel (private):
3155 3179
3156 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { 3180 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() {
3157 // This |current_tab| can be NULL during the initialization of the 3181 // This |current_tab| can be NULL during the initialization of the
3158 // toolbar during window creation (i.e. before any tabs have been added 3182 // toolbar during window creation (i.e. before any tabs have been added
3159 // to the window). 3183 // to the window).
3160 TabContents* current_tab = browser_->GetSelectedTabContents(); 3184 TabContents* current_tab = browser_->GetSelectedTabContents();
3161 return current_tab ? &current_tab->controller() : NULL; 3185 return current_tab ? &current_tab->controller() : NULL;
3162 } 3186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698