| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/plugin_finder.h" | 5 #include "chrome/browser/plugin_finder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/plugin_installer.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 14 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 15 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 16 #include "grit/browser_resources.h" | 18 #include "grit/browser_resources.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 18 | 20 |
| 19 PluginFinder* PluginFinder::GetInstance() { | 21 PluginFinder* PluginFinder::GetInstance() { |
| 20 return Singleton<PluginFinder>::get(); | 22 return Singleton<PluginFinder>::get(); |
| 21 } | 23 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 40 dict->GetList("plugins", &list); | 42 dict->GetList("plugins", &list); |
| 41 plugin_list_.reset(list->DeepCopy()); | 43 plugin_list_.reset(list->DeepCopy()); |
| 42 } | 44 } |
| 43 DCHECK(plugin_list_.get()); | 45 DCHECK(plugin_list_.get()); |
| 44 #endif | 46 #endif |
| 45 if (!plugin_list_.get()) | 47 if (!plugin_list_.get()) |
| 46 plugin_list_.reset(new base::ListValue()); | 48 plugin_list_.reset(new base::ListValue()); |
| 47 } | 49 } |
| 48 | 50 |
| 49 PluginFinder::~PluginFinder() { | 51 PluginFinder::~PluginFinder() { |
| 52 STLDeleteValues(&installers_); |
| 50 } | 53 } |
| 51 | 54 |
| 52 void PluginFinder::FindPlugin( | 55 void PluginFinder::FindPlugin( |
| 53 const std::string& mime_type, | 56 const std::string& mime_type, |
| 54 const std::string& language, | 57 const std::string& language, |
| 55 const FindPluginCallback& found_callback, | 58 const FindPluginCallback& found_callback, |
| 56 const base::Closure& not_found_callback) { | 59 const base::Closure& not_found_callback) { |
| 57 if (g_browser_process->local_state()->GetBoolean( | 60 if (g_browser_process->local_state()->GetBoolean( |
| 58 prefs::kDisablePluginFinder)) { | 61 prefs::kDisablePluginFinder)) { |
| 59 MessageLoop::current()->PostTask(FROM_HERE, not_found_callback); | 62 MessageLoop::current()->PostTask(FROM_HERE, not_found_callback); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 74 continue; | 77 continue; |
| 75 ListValue* mime_types = NULL; | 78 ListValue* mime_types = NULL; |
| 76 success = plugin->GetList("mime_types", &mime_types); | 79 success = plugin->GetList("mime_types", &mime_types); |
| 77 DCHECK(success); | 80 DCHECK(success); |
| 78 for (ListValue::const_iterator mime_type_it = mime_types->begin(); | 81 for (ListValue::const_iterator mime_type_it = mime_types->begin(); |
| 79 mime_type_it != mime_types->end(); ++mime_type_it) { | 82 mime_type_it != mime_types->end(); ++mime_type_it) { |
| 80 std::string mime_type_str; | 83 std::string mime_type_str; |
| 81 success = (*mime_type_it)->GetAsString(&mime_type_str); | 84 success = (*mime_type_it)->GetAsString(&mime_type_str); |
| 82 DCHECK(success); | 85 DCHECK(success); |
| 83 if (mime_type_str == mime_type) { | 86 if (mime_type_str == mime_type) { |
| 84 std::string url; | 87 std::string identifier; |
| 85 success = plugin->GetString("url", &url); | 88 success = plugin->GetString("identifier", &identifier); |
| 86 DCHECK(success); | 89 DCHECK(success); |
| 87 string16 name; | 90 PluginInstaller* installer = installers_[identifier]; |
| 88 success = plugin->GetString("name", &name); | 91 if (!installer) { |
| 89 DCHECK(success); | 92 std::string url; |
| 90 bool display_url = false; | 93 success = plugin->GetString("url", &url); |
| 91 plugin->GetBoolean("displayurl", &display_url); | 94 DCHECK(success); |
| 95 std::string help_url; |
| 96 plugin->GetString("help_url", &help_url); |
| 97 string16 name; |
| 98 success = plugin->GetString("name", &name); |
| 99 DCHECK(success); |
| 100 bool display_url = false; |
| 101 plugin->GetBoolean("displayurl", &display_url); |
| 102 installer = new PluginInstaller(identifier, |
| 103 GURL(url), GURL(help_url), name, |
| 104 display_url); |
| 105 installers_[identifier] = installer; |
| 106 } |
| 92 MessageLoop::current()->PostTask( | 107 MessageLoop::current()->PostTask( |
| 93 FROM_HERE, | 108 FROM_HERE, |
| 94 base::Bind(found_callback, GURL(url), name, display_url)); | 109 base::Bind(found_callback, installer)); |
| 95 return; | 110 return; |
| 96 } | 111 } |
| 97 } | 112 } |
| 98 } | 113 } |
| 99 MessageLoop::current()->PostTask(FROM_HERE, not_found_callback); | 114 MessageLoop::current()->PostTask(FROM_HERE, not_found_callback); |
| 100 } | 115 } |
| 101 | 116 |
| OLD | NEW |