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 <string> | |
8 | |
7 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 11 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
10 #include "chrome/browser/extensions/extension_action.h" | 12 #include "chrome/browser/extensions/extension_action.h" |
11 #include "chrome/browser/extensions/extension_action_manager.h" | 13 #include "chrome/browser/extensions/extension_action_manager.h" |
12 #include "chrome/browser/extensions/extension_prefs.h" | 14 #include "chrome/browser/extensions/extension_prefs.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
15 #include "chrome/browser/extensions/tab_helper.h" | 17 #include "chrome/browser/extensions/tab_helper.h" |
16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 if (popup_url_out) | 151 if (popup_url_out) |
150 *popup_url_out = browser_action->GetPopupUrl(tab_id); | 152 *popup_url_out = browser_action->GetPopupUrl(tab_id); |
151 return ACTION_SHOW_POPUP; | 153 return ACTION_SHOW_POPUP; |
152 } | 154 } |
153 | 155 |
154 extensions::ExtensionActionAPI::BrowserActionExecuted( | 156 extensions::ExtensionActionAPI::BrowserActionExecuted( |
155 service_->profile(), *browser_action, web_contents); | 157 service_->profile(), *browser_action, web_contents); |
156 return ACTION_NONE; | 158 return ACTION_NONE; |
157 } | 159 } |
158 | 160 |
161 GURL ExtensionToolbarModel::GetPopupUrl( | |
162 const Extension* extension, Browser* browser) { | |
163 content::WebContents* web_contents = NULL; | |
164 int tab_id = 0; | |
165 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) | |
166 return GURL(); | |
167 | |
168 ExtensionAction* browser_action = | |
169 extensions::ExtensionActionManager::Get(service_->profile())-> | |
170 GetBrowserAction(*extension); | |
171 return browser_action->GetPopupUrl(tab_id); | |
172 } | |
173 | |
159 void ExtensionToolbarModel::SetVisibleIconCount(int count) { | 174 void ExtensionToolbarModel::SetVisibleIconCount(int count) { |
160 visible_icon_count_ = | 175 visible_icon_count_ = |
161 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; | 176 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; |
162 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); | 177 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); |
163 } | 178 } |
164 | 179 |
165 void ExtensionToolbarModel::Observe( | 180 void ExtensionToolbarModel::Observe( |
166 int type, | 181 int type, |
167 const content::NotificationSource& source, | 182 const content::NotificationSource& source, |
168 const content::NotificationDetails& details) { | 183 const content::NotificationDetails& details) { |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 | 462 |
448 if (last_known_positions_.size() > pref_position_size) { | 463 if (last_known_positions_.size() > pref_position_size) { |
449 // Need to update pref because we have extra icons. But can't call | 464 // Need to update pref because we have extra icons. But can't call |
450 // UpdatePrefs() directly within observation closure. | 465 // UpdatePrefs() directly within observation closure. |
451 base::MessageLoop::current()->PostTask( | 466 base::MessageLoop::current()->PostTask( |
452 FROM_HERE, | 467 FROM_HERE, |
453 base::Bind(&ExtensionToolbarModel::UpdatePrefs, | 468 base::Bind(&ExtensionToolbarModel::UpdatePrefs, |
454 weak_ptr_factory_.GetWeakPtr())); | 469 weak_ptr_factory_.GetWeakPtr())); |
455 } | 470 } |
456 } | 471 } |
472 | |
473 void ExtensionToolbarModel::ShowBrowserActionPopup( | |
474 const extensions::Extension* extension) { | |
475 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionShowPopup(extension)); | |
Finnur
2013/10/15 10:44:21
So, if you have two windows, aren't both going to
justinlin
2013/10/16 07:06:48
Added comment clarifying that only the active wind
| |
476 } | |
OLD | NEW |