| 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/ui/app_list/extension_app_model_builder.h" | 5 #include "chrome/browser/ui/app_list/extension_app_model_builder.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/prefs/pref_service.h" | |
| 14 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/extensions/extension_ui_util.h" |
| 15 #include "chrome/browser/extensions/install_tracker.h" | 15 #include "chrome/browser/extensions/install_tracker.h" |
| 16 #include "chrome/browser/extensions/install_tracker_factory.h" | 16 #include "chrome/browser/extensions/install_tracker_factory.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 18 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 19 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 19 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 20 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 20 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
| 21 #include "chrome/browser/ui/app_list/extension_app_item.h" | 21 #include "chrome/browser/ui/app_list/extension_app_item.h" |
| 22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | |
| 24 #include "chrome/common/pref_names.h" | |
| 25 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 26 #include "extensions/browser/extension_prefs.h" | 24 #include "extensions/browser/extension_prefs.h" |
| 27 #include "extensions/browser/extension_system.h" | 25 #include "extensions/browser/extension_system.h" |
| 28 #include "extensions/browser/extensions_browser_client.h" | 26 #include "extensions/browser/extensions_browser_client.h" |
| 29 #include "extensions/browser/pref_names.h" | 27 #include "extensions/browser/pref_names.h" |
| 30 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
| 31 #include "extensions/common/extension_set.h" | 29 #include "extensions/common/extension_set.h" |
| 32 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
| 33 | 31 |
| 34 using extensions::Extension; | 32 using extensions::Extension; |
| 35 | 33 |
| 36 namespace { | |
| 37 | |
| 38 bool ShouldDisplayInAppLauncher(Profile* profile, | |
| 39 scoped_refptr<const Extension> app) { | |
| 40 // If it's the web store, check the policy. | |
| 41 bool blocked_by_policy = | |
| 42 (app->id() == extension_misc::kWebStoreAppId || | |
| 43 app->id() == extension_misc::kEnterpriseWebStoreAppId) && | |
| 44 profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon); | |
| 45 return app->ShouldDisplayInAppLauncher() && !blocked_by_policy; | |
| 46 } | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 ExtensionAppModelBuilder::ExtensionAppModelBuilder( | 34 ExtensionAppModelBuilder::ExtensionAppModelBuilder( |
| 51 AppListControllerDelegate* controller) | 35 AppListControllerDelegate* controller) |
| 52 : service_(NULL), | 36 : service_(NULL), |
| 53 profile_(NULL), | 37 profile_(NULL), |
| 54 controller_(controller), | 38 controller_(controller), |
| 55 model_(NULL), | 39 model_(NULL), |
| 56 highlighted_app_pending_(false), | 40 highlighted_app_pending_(false), |
| 57 tracker_(NULL) { | 41 tracker_(NULL) { |
| 58 } | 42 } |
| 59 | 43 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 return; | 118 return; |
| 135 item->SetPercentDownloaded(percent_downloaded); | 119 item->SetPercentDownloaded(percent_downloaded); |
| 136 } | 120 } |
| 137 | 121 |
| 138 void ExtensionAppModelBuilder::OnInstallFailure( | 122 void ExtensionAppModelBuilder::OnInstallFailure( |
| 139 const std::string& extension_id) { | 123 const std::string& extension_id) { |
| 140 model_->DeleteItem(extension_id); | 124 model_->DeleteItem(extension_id); |
| 141 } | 125 } |
| 142 | 126 |
| 143 void ExtensionAppModelBuilder::OnExtensionLoaded(const Extension* extension) { | 127 void ExtensionAppModelBuilder::OnExtensionLoaded(const Extension* extension) { |
| 144 if (!extension->ShouldDisplayInAppLauncher()) | 128 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) |
| 145 return; | 129 return; |
| 146 | 130 |
| 147 DVLOG(2) << service_ << ": OnExtensionLoaded: " | 131 DVLOG(2) << service_ << ": OnExtensionLoaded: " |
| 148 << extension->id().substr(0, 8); | 132 << extension->id().substr(0, 8); |
| 149 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); | 133 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); |
| 150 if (existing_item) { | 134 if (existing_item) { |
| 151 existing_item->Reload(); | 135 existing_item->Reload(); |
| 152 if (service_) | 136 if (service_) |
| 153 service_->UpdateItem(existing_item); | 137 service_->UpdateItem(existing_item); |
| 154 return; | 138 return; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 174 DVLOG(2) << service_ << ": OnExtensionUninstalled: " | 158 DVLOG(2) << service_ << ": OnExtensionUninstalled: " |
| 175 << extension->id().substr(0, 8); | 159 << extension->id().substr(0, 8); |
| 176 service_->RemoveItem(extension->id()); | 160 service_->RemoveItem(extension->id()); |
| 177 return; | 161 return; |
| 178 } | 162 } |
| 179 model_->DeleteItem(extension->id()); | 163 model_->DeleteItem(extension->id()); |
| 180 } | 164 } |
| 181 | 165 |
| 182 void ExtensionAppModelBuilder::OnDisabledExtensionUpdated( | 166 void ExtensionAppModelBuilder::OnDisabledExtensionUpdated( |
| 183 const Extension* extension) { | 167 const Extension* extension) { |
| 184 if (!extension->ShouldDisplayInAppLauncher()) | 168 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) |
| 185 return; | 169 return; |
| 186 | 170 |
| 187 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); | 171 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); |
| 188 if (existing_item) | 172 if (existing_item) |
| 189 existing_item->Reload(); | 173 existing_item->Reload(); |
| 190 } | 174 } |
| 191 | 175 |
| 192 void ExtensionAppModelBuilder::OnAppInstalledToAppList( | 176 void ExtensionAppModelBuilder::OnAppInstalledToAppList( |
| 193 const std::string& extension_id) { | 177 const std::string& extension_id) { |
| 194 SetHighlightedApp(extension_id); | 178 SetHighlightedApp(extension_id); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 if (tracker_) | 211 if (tracker_) |
| 228 tracker_->AddObserver(this); | 212 tracker_->AddObserver(this); |
| 229 } | 213 } |
| 230 | 214 |
| 231 void ExtensionAppModelBuilder::PopulateApps() { | 215 void ExtensionAppModelBuilder::PopulateApps() { |
| 232 extensions::ExtensionSet extensions; | 216 extensions::ExtensionSet extensions; |
| 233 controller_->GetApps(profile_, &extensions); | 217 controller_->GetApps(profile_, &extensions); |
| 234 | 218 |
| 235 for (extensions::ExtensionSet::const_iterator app = extensions.begin(); | 219 for (extensions::ExtensionSet::const_iterator app = extensions.begin(); |
| 236 app != extensions.end(); ++app) { | 220 app != extensions.end(); ++app) { |
| 237 if (!ShouldDisplayInAppLauncher(profile_, *app)) | 221 if (!extensions::ui_util::ShouldDisplayInAppLauncher(*app, profile_)) |
| 238 continue; | 222 continue; |
| 239 InsertApp(CreateAppItem((*app)->id(), | 223 InsertApp(CreateAppItem((*app)->id(), |
| 240 "", | 224 "", |
| 241 gfx::ImageSkia(), | 225 gfx::ImageSkia(), |
| 242 (*app)->is_platform_app())); | 226 (*app)->is_platform_app())); |
| 243 } | 227 } |
| 244 } | 228 } |
| 245 | 229 |
| 246 void ExtensionAppModelBuilder::InsertApp(scoped_ptr<ExtensionAppItem> app) { | 230 void ExtensionAppModelBuilder::InsertApp(scoped_ptr<ExtensionAppItem> app) { |
| 247 if (service_) { | 231 if (service_) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 app_list::AppListItem* item = item_list->item_at(idx + 1); | 294 app_list::AppListItem* item = item_list->item_at(idx + 1); |
| 311 if (item->GetItemType() == ExtensionAppItem::kItemType) { | 295 if (item->GetItemType() == ExtensionAppItem::kItemType) { |
| 312 next = static_cast<ExtensionAppItem*>(item); | 296 next = static_cast<ExtensionAppItem*>(item); |
| 313 break; | 297 break; |
| 314 } | 298 } |
| 315 } | 299 } |
| 316 // item->Move will call set_position, overriding the item's position. | 300 // item->Move will call set_position, overriding the item's position. |
| 317 if (prev || next) | 301 if (prev || next) |
| 318 static_cast<ExtensionAppItem*>(item)->Move(prev, next); | 302 static_cast<ExtensionAppItem*>(item)->Move(prev, next); |
| 319 } | 303 } |
| OLD | NEW |