summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorraymes <raymes@chromium.org>2015-07-16 16:38:58 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-16 23:39:33 +0000
commit83dbc5011d9c708003457b38cbfd33ae563b4ff5 (patch)
tree5ff28f5509d54de51851ea7ebfeb7b7f5b8a7b47
parentc13bdd545cd70260f86341c3d5a17ec756975f11 (diff)
downloadchromium_src-83dbc5011d9c708003457b38cbfd33ae563b4ff5.zip
chromium_src-83dbc5011d9c708003457b38cbfd33ae563b4ff5.tar.gz
chromium_src-83dbc5011d9c708003457b38cbfd33ae563b4ff5.tar.bz2
Factor out logic to determine whether a MimeTypesHandler has a plugin and its path
This CL adds functions to MimeTypesHandler which return: 1) HasPlugin(): Whether the handler has a plugin associated with it (that is, it's a mimeHandlerPrivate API handler). If not, it's a handler for the streamsPrivate API. 2) GetPluiginPath(): If it does have a plugin, this returns the path of the associated plugin. BUG=443466 Review URL: https://codereview.chromium.org/1219903003 Cr-Commit-Position: refs/heads/master@{#339168}
-rw-r--r--chrome/browser/extensions/api/streams_private/streams_private_api.cc2
-rw-r--r--chrome/browser/extensions/plugin_manager.cc9
-rw-r--r--extensions/common/manifest_handlers/mime_types_handler.cc12
-rw-r--r--extensions/common/manifest_handlers/mime_types_handler.h9
4 files changed, 26 insertions, 6 deletions
diff --git a/chrome/browser/extensions/api/streams_private/streams_private_api.cc b/chrome/browser/extensions/api/streams_private/streams_private_api.cc
index 277afb2..57ebe6d 100644
--- a/chrome/browser/extensions/api/streams_private/streams_private_api.cc
+++ b/chrome/browser/extensions/api/streams_private/streams_private_api.cc
@@ -79,7 +79,7 @@ void StreamsPrivateAPI::ExecuteMimeTypeHandler(
// If the mime handler uses MimeHandlerViewGuest, the MimeHandlerViewGuest
// will take ownership of the stream. Otherwise, store the stream handle in
// |streams_| and fire an event notifying the extension.
- if (!handler->handler_url().empty()) {
+ if (handler->HasPlugin()) {
GURL handler_url(Extension::GetBaseURLFromExtensionId(extension_id).spec() +
handler->handler_url());
auto tab_id = ExtensionTabUtil::GetTabId(web_contents);
diff --git a/chrome/browser/extensions/plugin_manager.cc b/chrome/browser/extensions/plugin_manager.cc
index 2384d71..e86fcb8 100644
--- a/chrome/browser/extensions/plugin_manager.cc
+++ b/chrome/browser/extensions/plugin_manager.cc
@@ -84,13 +84,13 @@ void PluginManager::OnExtensionLoaded(content::BrowserContext* browser_context,
#endif
const MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension);
- if (handler && !handler->handler_url().empty()) {
+ if (handler && handler->HasPlugin()) {
plugins_or_nacl_changed = true;
content::WebPluginInfo info;
info.type = content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN;
info.name = base::UTF8ToUTF16(extension->name());
- info.path = base::FilePath::FromUTF8Unsafe(extension->url().spec());
+ info.path = handler->GetPluginPath();
for (std::set<std::string>::const_iterator mime_type =
handler->mime_type_set().begin();
@@ -146,10 +146,9 @@ void PluginManager::OnExtensionUnloaded(
#endif
const MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension);
- if (handler && !handler->handler_url().empty()) {
+ if (handler && handler->HasPlugin()) {
plugins_or_nacl_changed = true;
- base::FilePath path =
- base::FilePath::FromUTF8Unsafe(extension->url().spec());
+ base::FilePath path = handler->GetPluginPath();
PluginService::GetInstance()->UnregisterInternalPlugin(path);
PluginService::GetInstance()->ForcePluginShutdown(path);
PluginService::GetInstance()->RefreshPlugins();
diff --git a/extensions/common/manifest_handlers/mime_types_handler.cc b/extensions/common/manifest_handlers/mime_types_handler.cc
index 7c4f034..61e1342 100644
--- a/extensions/common/manifest_handlers/mime_types_handler.cc
+++ b/extensions/common/manifest_handlers/mime_types_handler.cc
@@ -63,6 +63,18 @@ bool MimeTypesHandler::CanHandleMIMEType(const std::string& mime_type) const {
return mime_type_set_.find(mime_type) != mime_type_set_.end();
}
+bool MimeTypesHandler::HasPlugin() const {
+ return !handler_url_.empty();
+}
+
+base::FilePath MimeTypesHandler::GetPluginPath() const {
+ // TODO(raymes): Storing the extension URL in a base::FilePath is really
+ // nasty. We should probably just use the extension ID as the placeholder path
+ // instead.
+ return base::FilePath::FromUTF8Unsafe(
+ std::string(extensions::kExtensionScheme) + "://" + extension_id_ + "/");
+}
+
// static
MimeTypesHandler* MimeTypesHandler::GetHandler(
const extensions::Extension* extension) {
diff --git a/extensions/common/manifest_handlers/mime_types_handler.h b/extensions/common/manifest_handlers/mime_types_handler.h
index 887e379..30f46a4 100644
--- a/extensions/common/manifest_handlers/mime_types_handler.h
+++ b/extensions/common/manifest_handlers/mime_types_handler.h
@@ -43,6 +43,15 @@ class MimeTypesHandler {
const std::set<std::string>& mime_type_set() const { return mime_type_set_; }
+ // Returns true if this MimeTypesHandler has a plugin associated with it (for
+ // the mimeHandlerPrivate API). Returns false if the MimeTypesHandler is for
+ // the streamsPrivate API.
+ bool HasPlugin() const;
+
+ // If HasPlugin() returns true, this will return the plugin path for the
+ // plugin associated with this MimeTypesHandler.
+ base::FilePath GetPluginPath() const;
+
private:
// The id for the extension this action belongs to (as defined in the
// extension manifest).