Set Browser::is_attempting_to_close_browser_ in Browser::TabStripEmpty()
Set Browser::is_attempting_to_close_browser_ in Browser::TabStripEmpty()

Here is the relevent Scratchpad .js snippit:

  chrome.tabs.remove(tabId,
    function() {
      chrome.windows.getAll(null, 
        function(windows) {
          # if there is a 'normal' window:
            chrome.tabs.create({ url : "html/view.html"});

Here is the order in which the relevent Chrome code gets called:

1. RemoveTabsFunction::RunImpl()  // triggered by chrome.tabs.remove, removes the only tab in the Scratchpad Panel
1b. Browser::TabStripEmpty()  // removing the last tab triggers this, calls PostTask(Browser::CloseFrame)

2. GetAllWindowsFunction::RunImpl()  // triggered by chrome.windows.getAll, returns Panel Browser and any existing Tabbed Browsers

3. CreateTabFunction::RunImpl()  // triggered by chrome.tabs.create; Panel Browser is not yet flagged as closing, so tab gets created in the (now empty) Panel window.

1c. Browser::CloseFrame()  // calls window_->Close(), which triggers...
1d. Browser::OnWindowClosing()
1e. Browser::ShouldCloseWindow()  // this sets is_attempting_to_close_browser_ = true, too late for (3)


The fix in the CL seems to be the simplest, but may have the possibility of unintended side effects.

Other possible fixes:
a) Delay completion callback from chrome.tabs.remove() until the Browser close completes. Not sure how complicated this might be, and it would also have potential side effects.
b) Track that the associated browser window is closing in the Extension. I started down this path, but the code got complicated quickly, because we use BrowserList::FindAnyBrowser(profile) to get the "current" Browser. We would have to replace that with code that excluded the closing Browser.

Notes:
* We can't prevent opening a tab in a Panel Browser, because that is how the initial content is set.
* I am guessing that we are only seeing this issue now because of timing differences with 1b -> 1e in Aura. If, for example, the Scratchpad Panel is focused when the .js is called, 1c - 1e get called befre 2. and the code works as expected.

BUG=117567
TEST=Run all browser tests, test that closing all tabs closes the window, that tab close actions work correctly, and closing a window triggers close operations, and cancelling a close works correctly.


Review URL: http://codereview.chromium.org/10009020

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@131433 0039d316-1c4b-4281-b951-d872f2087c98

hgl888/chromium-crosswalk-efl,fujunwei/chromium-crosswalk,Pluto-tv/chromium-crosswalk,jaruba/chromium.src,dednal/chromium.src,junmin-zhu/chromium-rivertrail,Just-D/chromium-1,M4sse/chromium.src,hgl888/chromium-crosswalk,dednal/chromium.src,axinging/chromium-crosswalk,crosswalk-project/chromium-crosswalk-efl,mohamed--abdel-maksoud/chromium.src,Pluto-tv/chromium-crosswalk,axinging/chromium-crosswalk,axinging/chromium-crosswalk,markYoungH/chromium.src,Jonekee/chromium.src,fujunwei/chromium-crosswalk,hujiajie/pa-chromium,M4sse/chromium.src,anirudhSK/chromium,mohamed--abdel-maksoud/chromium.src,ltilve/chromium,jaruba/chromium.src,Just-D/chromium-1,dednal/chromium.src,timopulkkinen/BubbleFish,nacl-webkit/chrome_deps,chuan9/chromium-crosswalk,krieger-od/nwjs_chromium.src,PeterWangIntel/chromium-crosswalk,TheTypoMaster/chromium-crosswalk,crosswalk-project/chromium-crosswalk-efl,hujiajie/pa-chromium,Fireblend/chromium-crosswalk,M4sse/chromium.src,ltilve/chromium,TheTypoMaster/chromium-crosswalk,Fireblend/chromium-crosswalk,dushu1203/chromium.src,hgl888/chromium-crosswalk-efl,hujiajie/pa-chromium,ondra-novak/chromium.src,fujunwei/chromium-crosswalk,pozdnyakov/chromium-crosswalk,jaruba/chromium.src,mohamed--abdel-maksoud/chromium.src,ondra-novak/chromium.src,TheTypoMaster/chromium-crosswalk,mohamed--abdel-maksoud/chromium.src,ltilve/chromium,markYoungH/chromium.src,hujiajie/pa-chromium,zcbenz/cefode-chromium,Pluto-tv/chromium-crosswalk,patrickm/chromium.src,robclark/chromium,hgl888/chromium-crosswalk-efl,mogoweb/chromium-crosswalk,nacl-webkit/chrome_deps,Jonekee/chromium.src,chuan9/chromium-crosswalk,chuan9/chromium-crosswalk,zcbenz/cefode-chromium,junmin-zhu/chromium-rivertrail,littlstar/chromium.src,keishi/chromium,axinging/chromium-crosswalk,Fireblend/chromium-crosswalk,keishi/chromium,ChromiumWebApps/chromium,markYoungH/chromium.src,dednal/chromium.src,dushu1203/chromium.src,robclark/chromium,zcbenz/cefode-chromium,dushu1203/chromium.src,bright-sparks/chromium-spacewalk,PeterWangIntel/chromium-crosswalk,bright-sparks/chromium-spacewalk,Jonekee/chromium.src,Just-D/chromium-1,ltilve/chromium,dushu1203/chromium.src,anirudhSK/chromium,nacl-webkit/chrome_deps,bright-sparks/chromium-spacewalk,dushu1203/chromium.src,keishi/chromium,anirudhSK/chromium,ChromiumWebApps/chromium,patrickm/chromium.src,Just-D/chromium-1,robclark/chromium,ltilve/chromium,anirudhSK/chromium,krieger-od/nwjs_chromium.src,krieger-od/nwjs_chromium.src,mogoweb/chromium-crosswalk,hgl888/chromium-crosswalk,axinging/chromium-crosswalk,chuan9/chromium-crosswalk,ondra-novak/chromium.src,junmin-zhu/chromium-rivertrail,fujunwei/chromium-crosswalk,Pluto-tv/chromium-crosswalk,Chilledheart/chromium,ChromiumWebApps/chromium,dushu1203/chromium.src,mogoweb/chromium-crosswalk,pozdnyakov/chromium-crosswalk,ChromiumWebApps/chromium,jaruba/chromium.src,littlstar/chromium.src,krieger-od/nwjs_chromium.src,timopulkkinen/BubbleFish,crosswalk-project/chromium-crosswalk-efl,nacl-webkit/chrome_deps,littlstar/chromium.src,mogoweb/chromium-crosswalk,Jonekee/chromium.src,nacl-webkit/chrome_deps,Chilledheart/chromium,hujiajie/pa-chromium,patrickm/chromium.src,Fireblend/chromium-crosswalk,robclark/chromium,anirudhSK/chromium,hgl888/chromium-crosswalk-efl,nacl-webkit/chrome_deps,ondra-novak/chromium.src,nacl-webkit/chrome_deps,junmin-zhu/chromium-rivertrail,Chilledheart/chromium,jaruba/chromium.src,robclark/chromium,Fireblend/chromium-crosswalk,M4sse/chromium.src,anirudhSK/chromium,ondra-novak/chromium.src,hgl888/chromium-crosswalk-efl,zcbenz/cefode-chromium,PeterWangIntel/chromium-crosswalk,krieger-od/nwjs_chromium.src,Fireblend/chromium-crosswalk,Pluto-tv/chromium-crosswalk,hgl888/chromium-crosswalk,dushu1203/chromium.src,mogoweb/chromium-crosswalk,bright-sparks/chromium-spacewalk,M4sse/chromium.src,hgl888/chromium-crosswalk-efl,keishi/chromium,fujunwei/chromium-crosswalk,bright-sparks/chromium-spacewalk,chuan9/chromium-crosswalk,TheTypoMaster/chromium-crosswalk,littlstar/chromium.src,pozdnyakov/chromium-crosswalk,chuan9/chromium-crosswalk,dednal/chromium.src,Just-D/chromium-1,hgl888/chromium-crosswalk-efl,axinging/chromium-crosswalk,axinging/chromium-crosswalk,Fireblend/chromium-crosswalk,zcbenz/cefode-chromium,fujunwei/chromium-crosswalk,chuan9/chromium-crosswalk,junmin-zhu/chromium-rivertrail,nacl-webkit/chrome_deps,timopulkkinen/BubbleFish,junmin-zhu/chromium-rivertrail,dednal/chromium.src,bright-sparks/chromium-spacewalk,mohamed--abdel-maksoud/chromium.src,markYoungH/chromium.src,junmin-zhu/chromium-rivertrail,mohamed--abdel-maksoud/chromium.src,ondra-novak/chromium.src,dednal/chromium.src,jaruba/chromium.src,Chilledheart/chromium,patrickm/chromium.src,keishi/chromium,Just-D/chromium-1,fujunwei/chromium-crosswalk,robclark/chromium,mohamed--abdel-maksoud/chromium.src,chuan9/chromium-crosswalk,M4sse/chromium.src,zcbenz/cefode-chromium,keishi/chromium,crosswalk-project/chromium-crosswalk-efl,zcbenz/cefode-chromium,timopulkkinen/BubbleFish,dednal/chromium.src,anirudhSK/chromium,littlstar/chromium.src,krieger-od/nwjs_chromium.src,patrickm/chromium.src,axinging/chromium-crosswalk,junmin-zhu/chromium-rivertrail,pozdnyakov/chromium-crosswalk,PeterWangIntel/chromium-crosswalk,PeterWangIntel/chromium-crosswalk,hgl888/chromium-crosswalk,ChromiumWebApps/chromium,TheTypoMaster/chromium-crosswalk,keishi/chromium,bright-sparks/chromium-spacewalk,ChromiumWebApps/chromium,M4sse/chromium.src,Chilledheart/chromium,ChromiumWebApps/chromium,ChromiumWebApps/chromium,anirudhSK/chromium,axinging/chromium-crosswalk,Fireblend/chromium-crosswalk,Chilledheart/chromium,patrickm/chromium.src,mogoweb/chromium-crosswalk,ltilve/chromium,timopulkkinen/BubbleFish,Just-D/chromium-1,timopulkkinen/BubbleFish,ondra-novak/chromium.src,crosswalk-project/chromium-crosswalk-efl,Just-D/chromium-1,markYoungH/chromium.src,robclark/chromium,timopulkkinen/BubbleFish,hgl888/chromium-crosswalk,hgl888/chromium-crosswalk,anirudhSK/chromium,nacl-webkit/chrome_deps,TheTypoMaster/chromium-crosswalk,hgl888/chromium-crosswalk-efl,TheTypoMaster/chromium-crosswalk,anirudhSK/chromium,hujiajie/pa-chromium,markYoungH/chromium.src,krieger-od/nwjs_chromium.src,Jonekee/chromium.src,ltilve/chromium,pozdnyakov/chromium-crosswalk,Jonekee/chromium.src,zcbenz/cefode-chromium,mogoweb/chromium-crosswalk,hgl888/chromium-crosswalk,Chilledheart/chromium,Chilledheart/chromium,dushu1203/chromium.src,crosswalk-project/chromium-crosswalk-efl,patrickm/chromium.src,mohamed--abdel-maksoud/chromium.src,M4sse/chromium.src,krieger-od/nwjs_chromium.src,crosswalk-project/chromium-crosswalk-efl,crosswalk-project/chromium-crosswalk-efl,Jonekee/chromium.src,fujunwei/chromium-crosswalk,keishi/chromium,krieger-od/nwjs_chromium.src,jaruba/chromium.src,junmin-zhu/chromium-rivertrail,M4sse/chromium.src,littlstar/chromium.src,Just-D/chromium-1,ltilve/chromium,mohamed--abdel-maksoud/chromium.src,jaruba/chromium.src,mogoweb/chromium-crosswalk,Pluto-tv/chromium-crosswalk,keishi/chromium,hgl888/chromium-crosswalk,timopulkkinen/BubbleFish,pozdnyakov/chromium-crosswalk,timopulkkinen/BubbleFish,mohamed--abdel-maksoud/chromium.src,krieger-od/nwjs_chromium.src,timopulkkinen/BubbleFish,zcbenz/cefode-chromium,M4sse/chromium.src,bright-sparks/chromium-spacewalk,robclark/chromium,zcbenz/cefode-chromium,pozdnyakov/chromium-crosswalk,hujiajie/pa-chromium,ondra-novak/chromium.src,ondra-novak/chromium.src,pozdnyakov/chromium-crosswalk,dushu1203/chromium.src,PeterWangIntel/chromium-crosswalk,axinging/chromium-crosswalk,zcbenz/cefode-chromium,mohamed--abdel-maksoud/chromium.src,markYoungH/chromium.src,hgl888/chromium-crosswalk,dushu1203/chromium.src,crosswalk-project/chromium-crosswalk-efl,Fireblend/chromium-crosswalk,dednal/chromium.src,jaruba/chromium.src,timopulkkinen/BubbleFish,pozdnyakov/chromium-crosswalk,robclark/chromium,keishi/chromium,junmin-zhu/chromium-rivertrail,anirudhSK/chromium,hgl888/chromium-crosswalk-efl,Jonekee/chromium.src,patrickm/chromium.src,hujiajie/pa-chromium,ltilve/chromium,hujiajie/pa-chromium,hujiajie/pa-chromium,dednal/chromium.src,littlstar/chromium.src,chuan9/chromium-crosswalk,Chilledheart/chromium,Jonekee/chromium.src,mogoweb/chromium-crosswalk,ChromiumWebApps/chromium,markYoungH/chromium.src,M4sse/chromium.src,robclark/chromium,dushu1203/chromium.src,krieger-od/nwjs_chromium.src,hujiajie/pa-chromium,pozdnyakov/chromium-crosswalk,markYoungH/chromium.src,pozdnyakov/chromium-crosswalk,littlstar/chromium.src,PeterWangIntel/chromium-crosswalk,Jonekee/chromium.src,fujunwei/chromium-crosswalk,jaruba/chromium.src,nacl-webkit/chrome_deps,markYoungH/chromium.src,Jonekee/chromium.src,TheTypoMaster/chromium-crosswalk,anirudhSK/chromium,patrickm/chromium.src,Pluto-tv/chromium-crosswalk,hgl888/chromium-crosswalk-efl,ChromiumWebApps/chromium,ChromiumWebApps/chromium,PeterWangIntel/chromium-crosswalk,axinging/chromium-crosswalk,Pluto-tv/chromium-crosswalk,markYoungH/chromium.src,jaruba/chromium.src,Pluto-tv/chromium-crosswalk,nacl-webkit/chrome_deps,keishi/chromium,TheTypoMaster/chromium-crosswalk,bright-sparks/chromium-spacewalk,PeterWangIntel/chromium-crosswalk,dednal/chromium.src,ChromiumWebApps/chromium,junmin-zhu/chromium-rivertrail,mogoweb/chromium-crosswalk