| 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 // Implements the Chrome Extensions Debugger API. | 5 // Implements the Chrome Extensions Debugger API. |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/debugger/debugger_api.h" | 7 #include "chrome/browser/extensions/api/debugger/debugger_api.h" |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/values.h" | 23 #include "base/values.h" |
| 24 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
| 25 #include "chrome/browser/devtools/devtools_target_impl.h" | 25 #include "chrome/browser/devtools/devtools_target_impl.h" |
| 26 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" | 26 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" |
| 27 #include "chrome/browser/extensions/extension_service.h" | 27 #include "chrome/browser/extensions/extension_service.h" |
| 28 #include "chrome/browser/extensions/extension_tab_util.h" | 28 #include "chrome/browser/extensions/extension_tab_util.h" |
| 29 #include "chrome/browser/infobars/infobar_service.h" | 29 #include "chrome/browser/infobars/infobar_service.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
| 32 #include "chrome/browser/ui/browser_list.h" | 32 #include "chrome/browser/ui/browser_tab_strip_tracker.h" |
| 33 #include "chrome/browser/ui/browser_list_observer.h" | |
| 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 35 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 34 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 36 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 35 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| 37 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/grit/generated_resources.h" | 37 #include "chrome/grit/generated_resources.h" |
| 39 #include "components/infobars/core/confirm_infobar_delegate.h" | 38 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 40 #include "components/infobars/core/infobar.h" | 39 #include "components/infobars/core/infobar.h" |
| 41 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/devtools_agent_host.h" | 41 #include "content/public/browser/devtools_agent_host.h" |
| 43 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // InfoBarDismissed() will have closed us already. | 169 // InfoBarDismissed() will have closed us already. |
| 171 return false; | 170 return false; |
| 172 } | 171 } |
| 173 | 172 |
| 174 // GlobalConfirmInfoBar ------------------------------------------------------- | 173 // GlobalConfirmInfoBar ------------------------------------------------------- |
| 175 | 174 |
| 176 // GlobalConfirmInfobar is shown for every tab in every browser until it | 175 // GlobalConfirmInfobar is shown for every tab in every browser until it |
| 177 // is dismissed or the object itself is destroyed. | 176 // is dismissed or the object itself is destroyed. |
| 178 // It listens to all tabs in all browsers and adds/removes confirm infobar | 177 // It listens to all tabs in all browsers and adds/removes confirm infobar |
| 179 // to each of the tabs. | 178 // to each of the tabs. |
| 180 class GlobalConfirmInfoBar : public chrome::BrowserListObserver, | 179 class GlobalConfirmInfoBar : public TabStripModelObserver, |
| 181 public TabStripModelObserver, | |
| 182 public infobars::InfoBarManager::Observer { | 180 public infobars::InfoBarManager::Observer { |
| 183 public: | 181 public: |
| 184 GlobalConfirmInfoBar(const base::Closure& dismissed_callback, | 182 GlobalConfirmInfoBar(const base::Closure& dismissed_callback, |
| 185 const std::string& client_name); | 183 const std::string& client_name); |
| 186 ~GlobalConfirmInfoBar() override; | 184 ~GlobalConfirmInfoBar() override; |
| 187 | 185 |
| 188 private: | 186 private: |
| 189 using InfoBarMap = std::map<InfoBarService*, infobars::InfoBar*>; | 187 using InfoBarMap = std::map<InfoBarService*, infobars::InfoBar*>; |
| 190 | 188 |
| 191 // chrome::BrowserListObserver: | |
| 192 void OnBrowserAdded(Browser* browser) override; | |
| 193 void OnBrowserRemoved(Browser* browser) override; | |
| 194 | |
| 195 // TabStripModelObserver: | 189 // TabStripModelObserver: |
| 196 void TabInsertedAt(content::WebContents* web_contents, | 190 void TabInsertedAt(content::WebContents* web_contents, |
| 197 int index, | 191 int index, |
| 198 bool foreground) override; | 192 bool foreground) override; |
| 199 | 193 |
| 200 // infobars::InfoBarManager::Observer: | 194 // infobars::InfoBarManager::Observer: |
| 201 void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override; | 195 void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override; |
| 202 void OnManagerShuttingDown(infobars::InfoBarManager* manager) override; | 196 void OnManagerShuttingDown(infobars::InfoBarManager* manager) override; |
| 203 // We don't override OnInfoBarReplaces, as extension debugger api infobar | 197 // We don't override OnInfoBarReplaces, as extension debugger api infobar |
| 204 // should not be involved in replacements. | 198 // should not be involved in replacements. |
| 205 | 199 |
| 206 base::Closure dismissed_callback_; | 200 base::Closure dismissed_callback_; |
| 207 std::string client_name_; | 201 std::string client_name_; |
| 208 InfoBarMap infobars_; | 202 InfoBarMap infobars_; |
| 203 BrowserTabStripTracker browser_tab_strip_tracker_; |
| 209 | 204 |
| 210 DISALLOW_COPY_AND_ASSIGN(GlobalConfirmInfoBar); | 205 DISALLOW_COPY_AND_ASSIGN(GlobalConfirmInfoBar); |
| 211 }; | 206 }; |
| 212 | 207 |
| 213 GlobalConfirmInfoBar::GlobalConfirmInfoBar( | 208 GlobalConfirmInfoBar::GlobalConfirmInfoBar( |
| 214 const base::Closure& dismissed_callback, | 209 const base::Closure& dismissed_callback, |
| 215 const std::string& client_name) | 210 const std::string& client_name) |
| 216 : dismissed_callback_(dismissed_callback), client_name_(client_name) { | 211 : dismissed_callback_(dismissed_callback), |
| 217 BrowserList::AddObserver(this); | 212 client_name_(client_name), |
| 218 for (Browser* browser : *BrowserList::GetInstance(chrome::GetActiveDesktop())) | 213 browser_tab_strip_tracker_(this, nullptr, nullptr) { |
| 219 OnBrowserAdded(browser); | 214 browser_tab_strip_tracker_.Init( |
| 215 BrowserTabStripTracker::InitWith::BROWSERS_IN_ACTIVE_DESKTOP); |
| 220 } | 216 } |
| 221 | 217 |
| 222 GlobalConfirmInfoBar::~GlobalConfirmInfoBar() { | 218 GlobalConfirmInfoBar::~GlobalConfirmInfoBar() { |
| 223 while (!infobars_.empty()) { | 219 while (!infobars_.empty()) { |
| 224 InfoBarMap::iterator it = infobars_.begin(); | 220 InfoBarMap::iterator it = infobars_.begin(); |
| 225 it->first->RemoveInfoBar(it->second); | 221 it->first->RemoveInfoBar(it->second); |
| 226 } | 222 } |
| 227 | |
| 228 for (Browser* browser : *BrowserList::GetInstance(chrome::GetActiveDesktop())) | |
| 229 OnBrowserRemoved(browser); | |
| 230 BrowserList::RemoveObserver(this); | |
| 231 } | |
| 232 | |
| 233 void GlobalConfirmInfoBar::OnBrowserAdded(Browser* browser) { | |
| 234 TabStripModel* tab_strip_model = browser->tab_strip_model(); | |
| 235 tab_strip_model->AddObserver(this); | |
| 236 | |
| 237 for (int index = 0; index < tab_strip_model->count(); ++index) | |
| 238 TabInsertedAt(tab_strip_model->GetWebContentsAt(index), index, false); | |
| 239 } | |
| 240 | |
| 241 void GlobalConfirmInfoBar::OnBrowserRemoved(Browser* browser) { | |
| 242 browser->tab_strip_model()->RemoveObserver(this); | |
| 243 } | 223 } |
| 244 | 224 |
| 245 void GlobalConfirmInfoBar::TabInsertedAt(content::WebContents* web_contents, | 225 void GlobalConfirmInfoBar::TabInsertedAt(content::WebContents* web_contents, |
| 246 int index, | 226 int index, |
| 247 bool foreground) { | 227 bool foreground) { |
| 248 InfoBarService* infobar_service = | 228 InfoBarService* infobar_service = |
| 249 InfoBarService::FromWebContents(web_contents); | 229 InfoBarService::FromWebContents(web_contents); |
| 250 // WebContents from the tab strip must have the infobar service. | 230 // WebContents from the tab strip must have the infobar service. |
| 251 DCHECK(infobar_service); | 231 DCHECK(infobar_service); |
| 252 | 232 |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 const std::vector<DevToolsTargetImpl*>& target_list) { | 747 const std::vector<DevToolsTargetImpl*>& target_list) { |
| 768 scoped_ptr<base::ListValue> result(new base::ListValue()); | 748 scoped_ptr<base::ListValue> result(new base::ListValue()); |
| 769 for (size_t i = 0; i < target_list.size(); ++i) | 749 for (size_t i = 0; i < target_list.size(); ++i) |
| 770 result->Append(SerializeTarget(*target_list[i])); | 750 result->Append(SerializeTarget(*target_list[i])); |
| 771 STLDeleteContainerPointers(target_list.begin(), target_list.end()); | 751 STLDeleteContainerPointers(target_list.begin(), target_list.end()); |
| 772 SetResult(result.release()); | 752 SetResult(result.release()); |
| 773 SendResponse(true); | 753 SendResponse(true); |
| 774 } | 754 } |
| 775 | 755 |
| 776 } // namespace extensions | 756 } // namespace extensions |
| OLD | NEW |