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 #include "chrome/browser/extensions/extension_toolbar_model.h" | 5 #include "chrome/browser/extensions/extension_toolbar_model.h" |
6 | 6 |
| 7 #include "chrome/browser/extensions/extension_browser_event_router.h" |
7 #include "chrome/browser/extensions/extension_prefs.h" | 8 #include "chrome/browser/extensions/extension_prefs.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_tab_util.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
12 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
13 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
15 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
16 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/browser/web_contents.h" |
17 | 21 |
18 using extensions::Extension; | 22 using extensions::Extension; |
19 using extensions::ExtensionList; | 23 using extensions::ExtensionList; |
20 | 24 |
21 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) | 25 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) |
22 : service_(service), | 26 : service_(service), |
23 prefs_(service->profile()->GetPrefs()), | 27 prefs_(service->profile()->GetPrefs()), |
24 extensions_initialized_(false) { | 28 extensions_initialized_(false) { |
25 DCHECK(service_); | 29 DCHECK(service_); |
26 | 30 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 index = toolitems_.size(); | 76 index = toolitems_.size(); |
73 | 77 |
74 toolitems_.push_back(make_scoped_refptr(extension)); | 78 toolitems_.push_back(make_scoped_refptr(extension)); |
75 } | 79 } |
76 | 80 |
77 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); | 81 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); |
78 | 82 |
79 UpdatePrefs(); | 83 UpdatePrefs(); |
80 } | 84 } |
81 | 85 |
82 void ExtensionToolbarModel::ExecuteBrowserAction( | 86 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( |
83 const std::string& extension_id, Browser* browser) { | 87 const Extension* extension, |
84 FOR_EACH_OBSERVER(Observer, observers_, | 88 Browser* browser, |
85 BrowserActionExecuted(extension_id, browser)); | 89 GURL* popup_url_out) { |
| 90 TabContentsWrapper* tab_contents = browser->GetSelectedTabContentsWrapper(); |
| 91 if (!tab_contents) |
| 92 return ACTION_NONE; |
| 93 |
| 94 int tab_id = ExtensionTabUtil::GetTabId(tab_contents->web_contents()); |
| 95 if (tab_id < 0) |
| 96 return ACTION_NONE; |
| 97 |
| 98 ExtensionAction* browser_action = extension->browser_action(); |
| 99 if (browser_action->HasPopup(tab_id)) { |
| 100 if (popup_url_out) |
| 101 *popup_url_out = browser_action->GetPopupUrl(tab_id); |
| 102 return ACTION_SHOW_POPUP; |
| 103 } |
| 104 |
| 105 service_->browser_event_router()->BrowserActionExecuted( |
| 106 extension->id(), browser); |
| 107 return ACTION_NONE; |
86 } | 108 } |
87 | 109 |
88 void ExtensionToolbarModel::SetVisibleIconCount(int count) { | 110 void ExtensionToolbarModel::SetVisibleIconCount(int count) { |
89 visible_icon_count_ = count == static_cast<int>(size()) ? -1 : count; | 111 visible_icon_count_ = count == static_cast<int>(size()) ? -1 : count; |
90 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); | 112 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); |
91 } | 113 } |
92 | 114 |
93 void ExtensionToolbarModel::Observe( | 115 void ExtensionToolbarModel::Observe( |
94 int type, | 116 int type, |
95 const content::NotificationSource& source, | 117 const content::NotificationSource& source, |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 int incognito_index = 0, i = 0; | 284 int incognito_index = 0, i = 0; |
263 for (ExtensionList::iterator iter = begin(); iter != end(); | 285 for (ExtensionList::iterator iter = begin(); iter != end(); |
264 ++iter, ++i) { | 286 ++iter, ++i) { |
265 if (original_index == i) | 287 if (original_index == i) |
266 break; | 288 break; |
267 if (service_->IsIncognitoEnabled((*iter)->id())) | 289 if (service_->IsIncognitoEnabled((*iter)->id())) |
268 ++incognito_index; | 290 ++incognito_index; |
269 } | 291 } |
270 return incognito_index; | 292 return incognito_index; |
271 } | 293 } |
OLD | NEW |