Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 10911300: Move ExtensionAction from common/ to browser/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: proof of concept Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 343
344 // Figure out if extension installation should be enabled. 344 // Figure out if extension installation should be enabled.
345 if (command_line->HasSwitch(switches::kDisableExtensions)) { 345 if (command_line->HasSwitch(switches::kDisableExtensions)) {
346 extensions_enabled_ = false; 346 extensions_enabled_ = false;
347 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { 347 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) {
348 extensions_enabled_ = false; 348 extensions_enabled_ = false;
349 } 349 }
350 350
351 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 351 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
352 content::NotificationService::AllBrowserContextsAndSources()); 352 content::NotificationService::AllBrowserContextsAndSources());
353 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
354 content::NotificationService::AllBrowserContextsAndSources());
355 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
356 content::NotificationService::AllBrowserContextsAndSources());
353 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, 357 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
354 content::NotificationService::AllBrowserContextsAndSources()); 358 content::NotificationService::AllBrowserContextsAndSources());
355 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 359 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
356 content::NotificationService::AllBrowserContextsAndSources()); 360 content::NotificationService::AllBrowserContextsAndSources());
357 pref_change_registrar_.Init(profile->GetPrefs()); 361 pref_change_registrar_.Init(profile->GetPrefs());
358 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this); 362 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this);
359 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this); 363 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this);
360 364
361 // Set up the ExtensionUpdater 365 // Set up the ExtensionUpdater
362 if (autoupdate_enabled) { 366 if (autoupdate_enabled) {
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 1855
1852 void ExtensionService::UnloadAllExtensions() { 1856 void ExtensionService::UnloadAllExtensions() {
1853 profile_->GetExtensionSpecialStoragePolicy()-> 1857 profile_->GetExtensionSpecialStoragePolicy()->
1854 RevokeRightsForAllExtensions(); 1858 RevokeRightsForAllExtensions();
1855 1859
1856 extensions_.Clear(); 1860 extensions_.Clear();
1857 disabled_extensions_.Clear(); 1861 disabled_extensions_.Clear();
1858 terminated_extensions_.Clear(); 1862 terminated_extensions_.Clear();
1859 extension_runtime_data_.clear(); 1863 extension_runtime_data_.clear();
1860 1864
1865 STLDeleteValues(&page_actions_);
Jeffrey Yasskin 2012/09/14 19:18:33 Need to double-check if there are other places tha
1866 STLDeleteValues(&browser_actions_);
1867 STLDeleteValues(&script_badges_);
1868
1861 // TODO(erikkay) should there be a notification for this? We can't use 1869 // TODO(erikkay) should there be a notification for this? We can't use
1862 // EXTENSION_UNLOADED since that implies that the extension has been disabled 1870 // EXTENSION_UNLOADED since that implies that the extension has been disabled
1863 // or uninstalled, and UnloadAll is just part of shutdown. 1871 // or uninstalled, and UnloadAll is just part of shutdown.
1864 } 1872 }
1865 1873
1866 void ExtensionService::ReloadExtensions() { 1874 void ExtensionService::ReloadExtensions() {
1867 UnloadAllExtensions(); 1875 UnloadAllExtensions();
1868 component_loader_->LoadAll(); 1876 component_loader_->LoadAll();
1869 extensions::InstalledLoader(this).LoadAllExtensions(); 1877 extensions::InstalledLoader(this).LoadAllExtensions();
1870 } 1878 }
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 gfx::Image ExtensionService::GetOmniboxIcon( 2293 gfx::Image ExtensionService::GetOmniboxIcon(
2286 const std::string& extension_id) { 2294 const std::string& extension_id) {
2287 return gfx::Image(omnibox_icon_manager_.GetIcon(extension_id)); 2295 return gfx::Image(omnibox_icon_manager_.GetIcon(extension_id));
2288 } 2296 }
2289 2297
2290 gfx::Image ExtensionService::GetOmniboxPopupIcon( 2298 gfx::Image ExtensionService::GetOmniboxPopupIcon(
2291 const std::string& extension_id) { 2299 const std::string& extension_id) {
2292 return gfx::Image(omnibox_popup_icon_manager_.GetIcon(extension_id)); 2300 return gfx::Image(omnibox_popup_icon_manager_.GetIcon(extension_id));
2293 } 2301 }
2294 2302
2303 ExtensionAction* ExtensionService::GetPageAction(
2304 const Extension& extension) const {
2305 return ContainsKey(page_actions_, extension.id()) ?
2306 page_actions_.find(extension.id())->second : NULL;
2307 }
2308 ExtensionAction* ExtensionService::GetBrowserAction(
2309 const Extension& extension) const {
2310 return ContainsKey(browser_actions_, extension.id()) ?
2311 browser_actions_.find(extension.id())->second : NULL;
2312 }
2313 ExtensionAction* ExtensionService::GetScriptBadge(
2314 const Extension& extension) const {
2315 return ContainsKey(script_badges_, extension.id()) ?
2316 script_badges_.find(extension.id())->second : NULL;
2317 }
2318
2295 bool ExtensionService::OnExternalExtensionFileFound( 2319 bool ExtensionService::OnExternalExtensionFileFound(
2296 const std::string& id, 2320 const std::string& id,
2297 const Version* version, 2321 const Version* version,
2298 const FilePath& path, 2322 const FilePath& path,
2299 Extension::Location location, 2323 Extension::Location location,
2300 int creation_flags, 2324 int creation_flags,
2301 bool mark_acknowledged) { 2325 bool mark_acknowledged) {
2302 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2326 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2303 CHECK(Extension::IdIsValid(id)); 2327 CHECK(Extension::IdIsValid(id));
2304 if (extension_prefs_->IsExternalExtensionUninstalled(id)) 2328 if (extension_prefs_->IsExternalExtensionUninstalled(id))
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 host->render_view_host()); 2412 host->render_view_host());
2389 content::DevToolsManager::GetInstance()->AttachClientHost(iter->second, 2413 content::DevToolsManager::GetInstance()->AttachClientHost(iter->second,
2390 agent); 2414 agent);
2391 orphaned_dev_tools_.erase(iter); 2415 orphaned_dev_tools_.erase(iter);
2392 } 2416 }
2393 2417
2394 void ExtensionService::Observe(int type, 2418 void ExtensionService::Observe(int type,
2395 const content::NotificationSource& source, 2419 const content::NotificationSource& source,
2396 const content::NotificationDetails& details) { 2420 const content::NotificationDetails& details) {
2397 switch (type) { 2421 switch (type) {
2422 case chrome::NOTIFICATION_EXTENSION_LOADED: {
Aaron Boodman 2012/09/16 01:42:50 This is the kind of code I'm trying to keep out of
not at google - send to devlin 2012/09/27 00:46:10 Not that this solves the LOADED/UNLOADED problem,
2423 if (profile_ !=
2424 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
2425 break;
2426 }
2427
2428 const Extension* extension =
2429 content::Details<const Extension>(details).ptr();
2430 if (extension->page_action() &&
2431 !ContainsKey(page_actions_, extension->id())) {
2432 page_actions_[extension->id()] =
2433 new ExtensionAction(extension->id(), *extension->page_action());
2434 }
2435 if (extension->browser_action() &&
2436 !ContainsKey(browser_actions_, extension->id())) {
2437 browser_actions_[extension->id()] =
2438 new ExtensionAction(extension->id(), *extension->browser_action());
2439 }
2440 DCHECK(extension->script_badge());
2441 if (!ContainsKey(script_badges_, extension->id())) {
2442 script_badges_[extension->id()] =
2443 new ExtensionAction(extension->id(), *extension->script_badge());
2444 }
2445 break;
2446 }
2447 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
2448 if (profile_ !=
2449 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
2450 break;
2451 }
2452
2453 const Extension* extension =
2454 content::Details<UnloadedExtensionInfo>(details)->extension;
2455 if (ContainsKey(page_actions_, extension->id())) {
2456 delete page_actions_[extension->id()];
2457 page_actions_.erase(extension->id());
2458 }
2459 if (ContainsKey(browser_actions_, extension->id())) {
2460 delete browser_actions_[extension->id()];
2461 browser_actions_.erase(extension->id());
2462 }
2463 if (ContainsKey(script_badges_, extension->id())) {
2464 script_badges_.erase(extension->id());
2465 }
2466 break;
2467 }
2398 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { 2468 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
2399 if (profile_ != 2469 if (profile_ !=
2400 content::Source<Profile>(source).ptr()->GetOriginalProfile()) { 2470 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
2401 break; 2471 break;
2402 } 2472 }
2403 2473
2404 extensions::ExtensionHost* host = 2474 extensions::ExtensionHost* host =
2405 content::Details<extensions::ExtensionHost>(details).ptr(); 2475 content::Details<extensions::ExtensionHost>(details).ptr();
2406 2476
2407 // Mark the extension as terminated and Unload it. We want it to 2477 // Mark the extension as terminated and Unload it. We want it to
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2640 extensions::ExtensionHost* extension_host) { 2710 extensions::ExtensionHost* extension_host) {
2641 if (!extension_host) 2711 if (!extension_host)
2642 return; 2712 return;
2643 2713
2644 #if !defined(OS_ANDROID) 2714 #if !defined(OS_ANDROID)
2645 extensions::LaunchPlatformApp(extension_host->profile(), 2715 extensions::LaunchPlatformApp(extension_host->profile(),
2646 extension_host->extension(), 2716 extension_host->extension(),
2647 NULL, FilePath()); 2717 NULL, FilePath());
2648 #endif 2718 #endif
2649 } 2719 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698