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