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

Unified Diff: chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc

Issue 68133020: Fix dragging supported files to tab strip. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
index 90083b08df11b2b4ae05783853c467d74283b99b..03689c3b15397c1970de17f0ad0b1d5bb7fc25ba 100644
--- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
+++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
@@ -7,6 +7,7 @@
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
+#include "base/task_runner_util.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
@@ -29,9 +30,14 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/browser/plugin_service.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/webplugininfo.h"
+#include "ipc/ipc_message.h"
+#include "net/base/net_util.h"
#include "ui/base/layout.h"
#include "ui/base/models/list_selection_model.h"
#include "ui/gfx/image/image.h"
@@ -79,6 +85,20 @@ TabStripLayoutType DetermineTabStripLayout(
}
}
+// Get the MIME type of the file pointed to by the url, based on the file's
+// extension. Must be called on a thread that allows IO.
+std::string FindURLMimeType(const GURL& url) {
+ DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ base::FilePath full_path;
+ net::FileURLToFilePath(url, &full_path);
+
+ // Get the MIME type based on the filename.
+ std::string mime_type;
+ net::GetMimeTypeFromFile(full_path, &mime_type);
+
+ return mime_type;
+}
+
} // namespace
class BrowserTabStripController::TabContextMenuContents
@@ -177,7 +197,8 @@ BrowserTabStripController::BrowserTabStripController(Browser* browser,
: model_(model),
tabstrip_(NULL),
browser_(browser),
- hover_tab_selector_(model) {
+ hover_tab_selector_(model),
+ weak_ptr_factory_(this) {
model_->AddObserver(this);
local_pref_registrar_.Init(g_browser_process->local_state());
@@ -401,6 +422,16 @@ void BrowserTabStripController::OnStoppedDraggingTabs() {
immersive_reveal_lock_.reset();
}
+void BrowserTabStripController::CheckFileSupported(const GURL& url) {
+ base::PostTaskAndReplyWithResult(
+ content::BrowserThread::GetBlockingPool(),
+ FROM_HERE,
+ base::Bind(&FindURLMimeType, url),
+ base::Bind(&BrowserTabStripController::OnFindURLMimeTypeCompleted,
+ weak_ptr_factory_.GetWeakPtr(),
+ url));
+}
+
////////////////////////////////////////////////////////////////////////////////
// BrowserTabStripController, TabStripModelObserver implementation:
@@ -546,3 +577,23 @@ void BrowserTabStripController::UpdateLayoutType() {
browser_->host_desktop_type(), &adjust_layout);
tabstrip_->SetLayoutType(layout_type, adjust_layout);
}
+
+void BrowserTabStripController::OnFindURLMimeTypeCompleted(
+ GURL url,
dcheng 2013/11/28 09:07:39 Pass by reference.
michaelpg 2013/12/02 19:51:07 Done.
+ const std::string& mime_type) {
+ // Check whether the mime type, if given, is known to be supported or whether
+ // there is a plugin that supports the mime type (e.g. PDF).
+ // TODO(bauerb): This possibly uses stale information, but it's guaranteed not
+ // to do disk access.
+ content::WebPluginInfo plugin;
+ tabstrip_->FileSupported(
+ url,
+ mime_type.empty() ||
+ net::IsSupportedMimeType(mime_type) ||
+ content::PluginService::GetInstance()->GetPluginInfo(
+ -1, // process ID
+ MSG_ROUTING_NONE, // routing ID
+ model_->profile()->GetResourceContext(),
+ url, GURL(), mime_type, false,
+ NULL, &plugin, NULL));
+}

Powered by Google App Engine
This is Rietveld 408576698