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

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

Issue 2821011: Removes phantom tabs. (Closed)
Patch Set: Created 10 years, 6 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_tabs_module.h" 5 #include "chrome/browser/extensions/extension_tabs_module.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 bool RemoveTabFunction::RunImpl() { 777 bool RemoveTabFunction::RunImpl() {
778 int tab_id; 778 int tab_id;
779 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); 779 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
780 780
781 Browser* browser = NULL; 781 Browser* browser = NULL;
782 TabContents* contents = NULL; 782 TabContents* contents = NULL;
783 if (!GetTabById(tab_id, profile(), include_incognito(), 783 if (!GetTabById(tab_id, profile(), include_incognito(),
784 &browser, NULL, &contents, NULL, &error_)) 784 &browser, NULL, &contents, NULL, &error_))
785 return false; 785 return false;
786 786
787 int tab_index = browser->GetIndexOfController(&contents->controller());
788 if (browser->tabstrip_model()->IsPhantomTab(tab_index)) {
789 // Don't allow closing phantom tabs.
790 error_ = keys::kCannotRemovePhantomTab;
791 return false;
792 }
793
794 // Close the tab in this convoluted way, since there's a chance that the tab 787 // Close the tab in this convoluted way, since there's a chance that the tab
795 // is being dragged, or we're in some other nested event loop. This code path 788 // is being dragged, or we're in some other nested event loop. This code path
796 // should ensure that the tab is safely closed under such circumstances, 789 // should ensure that the tab is safely closed under such circumstances,
797 // whereas |Browser::CloseTabContents()| does not. 790 // whereas |Browser::CloseTabContents()| does not.
798 RenderViewHost* render_view_host = contents->render_view_host(); 791 RenderViewHost* render_view_host = contents->render_view_host();
799 render_view_host->delegate()->Close(render_view_host); 792 render_view_host->delegate()->Close(render_view_host);
800 return true; 793 return true;
801 } 794 }
802 795
803 bool CaptureVisibleTabFunction::RunImpl() { 796 bool CaptureVisibleTabFunction::RunImpl() {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 } else { 971 } else {
979 browser = GetCurrentBrowser(); 972 browser = GetCurrentBrowser();
980 if (!browser) 973 if (!browser)
981 return false; 974 return false;
982 contents = browser->tabstrip_model()->GetSelectedTabContents(); 975 contents = browser->tabstrip_model()->GetSelectedTabContents();
983 if (!contents) 976 if (!contents)
984 return false; 977 return false;
985 } 978 }
986 979
987 if (contents->controller().needs_reload()) { 980 if (contents->controller().needs_reload()) {
988 // If the tab hasn't been loaded, such as happens with phantom tabs, don't 981 // If the tab hasn't been loaded don't wait for the tab to load, instead
989 // wait for the tab to load, instead return. 982 // return.
990 error_ = keys::kCannotDetermineLanguageOfUnloadedTab; 983 error_ = keys::kCannotDetermineLanguageOfUnloadedTab;
991 return false; 984 return false;
992 } 985 }
993 986
994 AddRef(); // Balanced in GotLanguage() 987 AddRef(); // Balanced in GotLanguage()
995 988
996 if (!contents->language_state().original_language().empty()) { 989 if (!contents->language_state().original_language().empty()) {
997 // Delay the callback invocation until after the current JS call has 990 // Delay the callback invocation until after the current JS call has
998 // returned. 991 // returned.
999 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 992 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 } 1079 }
1087 1080
1088 static GURL ResolvePossiblyRelativeURL(std::string url_string, 1081 static GURL ResolvePossiblyRelativeURL(std::string url_string,
1089 Extension* extension) { 1082 Extension* extension) {
1090 GURL url = GURL(url_string); 1083 GURL url = GURL(url_string);
1091 if (!url.is_valid()) 1084 if (!url.is_valid())
1092 url = extension->GetResourceURL(url_string); 1085 url = extension->GetResourceURL(url_string);
1093 1086
1094 return url; 1087 return url;
1095 } 1088 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_message_service.cc ('k') | chrome/browser/extensions/extension_tabs_module_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698