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_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 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 FilePath path; | 628 FilePath path; |
629 const Extension* current_extension = GetExtensionById(extension_id, false); | 629 const Extension* current_extension = GetExtensionById(extension_id, false); |
630 | 630 |
631 // Disable the extension if it's loaded. It might not be loaded if it crashed. | 631 // Disable the extension if it's loaded. It might not be loaded if it crashed. |
632 if (current_extension) { | 632 if (current_extension) { |
633 // If the extension has an inspector open for its background page, detach | 633 // If the extension has an inspector open for its background page, detach |
634 // the inspector and hang onto a cookie for it, so that we can reattach | 634 // the inspector and hang onto a cookie for it, so that we can reattach |
635 // later. | 635 // later. |
636 // TODO(yoz): this is not incognito-safe! | 636 // TODO(yoz): this is not incognito-safe! |
637 ExtensionProcessManager* manager = system_->process_manager(); | 637 ExtensionProcessManager* manager = system_->process_manager(); |
638 ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); | 638 extensions::ExtensionHost* host = |
| 639 manager->GetBackgroundHostForExtension(extension_id); |
639 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( | 640 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( |
640 host->render_view_host())) { | 641 host->render_view_host())) { |
641 // Look for an open inspector for the background page. | 642 // Look for an open inspector for the background page. |
642 DevToolsAgentHost* agent = | 643 DevToolsAgentHost* agent = |
643 DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 644 DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
644 host->render_view_host()); | 645 host->render_view_host()); |
645 int devtools_cookie = | 646 int devtools_cookie = |
646 content::DevToolsManager::GetInstance()->DetachClientHost(agent); | 647 content::DevToolsManager::GetInstance()->DetachClientHost(agent); |
647 if (devtools_cookie >= 0) | 648 if (devtools_cookie >= 0) |
648 orphaned_dev_tools_[extension_id] = devtools_cookie; | 649 orphaned_dev_tools_[extension_id] = devtools_cookie; |
(...skipping 1657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2306 content::Details<const std::string>(&error)); | 2307 content::Details<const std::string>(&error)); |
2307 | 2308 |
2308 std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName()); | 2309 std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName()); |
2309 string16 message = UTF8ToUTF16(base::StringPrintf( | 2310 string16 message = UTF8ToUTF16(base::StringPrintf( |
2310 "Could not load extension from '%s'. %s", | 2311 "Could not load extension from '%s'. %s", |
2311 path_str.c_str(), error.c_str())); | 2312 path_str.c_str(), error.c_str())); |
2312 ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy); | 2313 ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy); |
2313 } | 2314 } |
2314 | 2315 |
2315 void ExtensionService::DidCreateRenderViewForBackgroundPage( | 2316 void ExtensionService::DidCreateRenderViewForBackgroundPage( |
2316 ExtensionHost* host) { | 2317 extensions::ExtensionHost* host) { |
2317 OrphanedDevTools::iterator iter = | 2318 OrphanedDevTools::iterator iter = |
2318 orphaned_dev_tools_.find(host->extension_id()); | 2319 orphaned_dev_tools_.find(host->extension_id()); |
2319 if (iter == orphaned_dev_tools_.end()) | 2320 if (iter == orphaned_dev_tools_.end()) |
2320 return; | 2321 return; |
2321 | 2322 |
2322 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 2323 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
2323 host->render_view_host()); | 2324 host->render_view_host()); |
2324 content::DevToolsManager::GetInstance()->AttachClientHost(iter->second, | 2325 content::DevToolsManager::GetInstance()->AttachClientHost(iter->second, |
2325 agent); | 2326 agent); |
2326 orphaned_dev_tools_.erase(iter); | 2327 orphaned_dev_tools_.erase(iter); |
2327 } | 2328 } |
2328 | 2329 |
2329 void ExtensionService::Observe(int type, | 2330 void ExtensionService::Observe(int type, |
2330 const content::NotificationSource& source, | 2331 const content::NotificationSource& source, |
2331 const content::NotificationDetails& details) { | 2332 const content::NotificationDetails& details) { |
2332 switch (type) { | 2333 switch (type) { |
2333 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { | 2334 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
2334 if (profile_ != | 2335 if (profile_ != |
2335 content::Source<Profile>(source).ptr()->GetOriginalProfile()) { | 2336 content::Source<Profile>(source).ptr()->GetOriginalProfile()) { |
2336 break; | 2337 break; |
2337 } | 2338 } |
2338 | 2339 |
2339 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 2340 extensions::ExtensionHost* host = |
| 2341 content::Details<extensions::ExtensionHost>(details).ptr(); |
2340 | 2342 |
2341 // Mark the extension as terminated and Unload it. We want it to | 2343 // Mark the extension as terminated and Unload it. We want it to |
2342 // be in a consistent state: either fully working or not loaded | 2344 // be in a consistent state: either fully working or not loaded |
2343 // at all, but never half-crashed. We do it in a PostTask so | 2345 // at all, but never half-crashed. We do it in a PostTask so |
2344 // that other handlers of this notification will still have | 2346 // that other handlers of this notification will still have |
2345 // access to the Extension and ExtensionHost. | 2347 // access to the Extension and ExtensionHost. |
2346 MessageLoop::current()->PostTask( | 2348 MessageLoop::current()->PostTask( |
2347 FROM_HERE, | 2349 FROM_HERE, |
2348 base::Bind( | 2350 base::Bind( |
2349 &ExtensionService::TrackTerminatedExtension, | 2351 &ExtensionService::TrackTerminatedExtension, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2540 | 2542 |
2541 ExtensionService::NaClModuleInfoList::iterator | 2543 ExtensionService::NaClModuleInfoList::iterator |
2542 ExtensionService::FindNaClModule(const GURL& url) { | 2544 ExtensionService::FindNaClModule(const GURL& url) { |
2543 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2545 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
2544 iter != nacl_module_list_.end(); ++iter) { | 2546 iter != nacl_module_list_.end(); ++iter) { |
2545 if (iter->url == url) | 2547 if (iter->url == url) |
2546 return iter; | 2548 return iter; |
2547 } | 2549 } |
2548 return nacl_module_list_.end(); | 2550 return nacl_module_list_.end(); |
2549 } | 2551 } |
OLD | NEW |