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

Side by Side 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: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ui/views/tabs/browser_tab_strip_controller.h" 5 #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/task_runner_util.h"
10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 11 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 12 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
12 #include "chrome/browser/autocomplete/autocomplete_match.h" 13 #include "chrome/browser/autocomplete/autocomplete_match.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/extensions/tab_helper.h" 16 #include "chrome/browser/extensions/tab_helper.h"
16 #include "chrome/browser/favicon/favicon_tab_helper.h" 17 #include "chrome/browser/favicon/favicon_tab_helper.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search/search.h" 19 #include "chrome/browser/search/search.h"
19 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_tabstrip.h" 21 #include "chrome/browser/ui/browser_tabstrip.h"
21 #include "chrome/browser/ui/tabs/tab_menu_model.h" 22 #include "chrome/browser/ui/tabs/tab_menu_model.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
24 #include "chrome/browser/ui/tabs/tab_utils.h" 25 #include "chrome/browser/ui/tabs/tab_utils.h"
25 #include "chrome/browser/ui/views/frame/browser_view.h" 26 #include "chrome/browser/ui/views/frame/browser_view.h"
26 #include "chrome/browser/ui/views/tabs/tab.h" 27 #include "chrome/browser/ui/views/tabs/tab.h"
27 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" 28 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h"
28 #include "chrome/browser/ui/views/tabs/tab_strip.h" 29 #include "chrome/browser/ui/views/tabs/tab_strip.h"
29 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
33 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
35 #include "content/public/browser/plugin_service.h"
33 #include "content/public/browser/user_metrics.h" 36 #include "content/public/browser/user_metrics.h"
34 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
38 #include "content/public/common/webplugininfo.h"
39 #include "ipc/ipc_message.h"
40 #include "net/base/net_util.h"
35 #include "ui/base/layout.h" 41 #include "ui/base/layout.h"
36 #include "ui/base/models/list_selection_model.h" 42 #include "ui/base/models/list_selection_model.h"
37 #include "ui/gfx/image/image.h" 43 #include "ui/gfx/image/image.h"
38 #include "ui/views/controls/menu/menu_item_view.h" 44 #include "ui/views/controls/menu/menu_item_view.h"
39 #include "ui/views/controls/menu/menu_runner.h" 45 #include "ui/views/controls/menu/menu_runner.h"
40 #include "ui/views/widget/widget.h" 46 #include "ui/views/widget/widget.h"
41 47
42 using content::UserMetricsAction; 48 using content::UserMetricsAction;
43 using content::WebContents; 49 using content::WebContents;
44 50
(...skipping 27 matching lines...) Expand all
72 #endif 78 #endif
73 *adjust_layout = true; 79 *adjust_layout = true;
74 switch (prefs->GetInteger(prefs::kTabStripLayoutType)) { 80 switch (prefs->GetInteger(prefs::kTabStripLayoutType)) {
75 case TAB_STRIP_LAYOUT_STACKED: 81 case TAB_STRIP_LAYOUT_STACKED:
76 return TAB_STRIP_LAYOUT_STACKED; 82 return TAB_STRIP_LAYOUT_STACKED;
77 default: 83 default:
78 return TAB_STRIP_LAYOUT_SHRINK; 84 return TAB_STRIP_LAYOUT_SHRINK;
79 } 85 }
80 } 86 }
81 87
88 // Get the MIME type of the file pointed to by the url, based on the file's
89 // extension. Must be called on a thread that allows IO.
90 std::string FindURLMimeType(const GURL& url) {
91 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
92 base::FilePath full_path;
93 net::FileURLToFilePath(url, &full_path);
94
95 // Get the MIME type based on the filename.
96 std::string mime_type;
97 net::GetMimeTypeFromFile(full_path, &mime_type);
98
99 return mime_type;
100 }
101
82 } // namespace 102 } // namespace
83 103
84 class BrowserTabStripController::TabContextMenuContents 104 class BrowserTabStripController::TabContextMenuContents
85 : public ui::SimpleMenuModel::Delegate { 105 : public ui::SimpleMenuModel::Delegate {
86 public: 106 public:
87 TabContextMenuContents(Tab* tab, 107 TabContextMenuContents(Tab* tab,
88 BrowserTabStripController* controller) 108 BrowserTabStripController* controller)
89 : tab_(tab), 109 : tab_(tab),
90 controller_(controller), 110 controller_(controller),
91 last_command_(TabStripModel::CommandFirst) { 111 last_command_(TabStripModel::CommandFirst) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 }; 190 };
171 191
172 //////////////////////////////////////////////////////////////////////////////// 192 ////////////////////////////////////////////////////////////////////////////////
173 // BrowserTabStripController, public: 193 // BrowserTabStripController, public:
174 194
175 BrowserTabStripController::BrowserTabStripController(Browser* browser, 195 BrowserTabStripController::BrowserTabStripController(Browser* browser,
176 TabStripModel* model) 196 TabStripModel* model)
177 : model_(model), 197 : model_(model),
178 tabstrip_(NULL), 198 tabstrip_(NULL),
179 browser_(browser), 199 browser_(browser),
180 hover_tab_selector_(model) { 200 hover_tab_selector_(model),
201 weak_ptr_factory_(this) {
181 model_->AddObserver(this); 202 model_->AddObserver(this);
182 203
183 local_pref_registrar_.Init(g_browser_process->local_state()); 204 local_pref_registrar_.Init(g_browser_process->local_state());
184 local_pref_registrar_.Add( 205 local_pref_registrar_.Add(
185 prefs::kTabStripLayoutType, 206 prefs::kTabStripLayoutType,
186 base::Bind(&BrowserTabStripController::UpdateLayoutType, 207 base::Bind(&BrowserTabStripController::UpdateLayoutType,
187 base::Unretained(this))); 208 base::Unretained(this)));
188 } 209 }
189 210
190 BrowserTabStripController::~BrowserTabStripController() { 211 BrowserTabStripController::~BrowserTabStripController() {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 immersive_reveal_lock_.reset( 415 immersive_reveal_lock_.reset(
395 browser_view->immersive_mode_controller()->GetRevealedLock( 416 browser_view->immersive_mode_controller()->GetRevealedLock(
396 ImmersiveModeController::ANIMATE_REVEAL_NO)); 417 ImmersiveModeController::ANIMATE_REVEAL_NO));
397 } 418 }
398 } 419 }
399 420
400 void BrowserTabStripController::OnStoppedDraggingTabs() { 421 void BrowserTabStripController::OnStoppedDraggingTabs() {
401 immersive_reveal_lock_.reset(); 422 immersive_reveal_lock_.reset();
402 } 423 }
403 424
425 void BrowserTabStripController::CheckFileSupported(const GURL& url) {
426 base::PostTaskAndReplyWithResult(
427 content::BrowserThread::GetBlockingPool(),
michaelpg 2013/12/03 01:58:36 This is causing compile errors in the tree.
dcheng 2013/12/03 02:15:20 Wild guess: you need to include the header for Seq
michaelpg 2013/12/03 02:49:35 Doh, that's exactly it. I wonder why it didn't com
428 FROM_HERE,
429 base::Bind(&FindURLMimeType, url),
430 base::Bind(&BrowserTabStripController::OnFindURLMimeTypeCompleted,
431 weak_ptr_factory_.GetWeakPtr(),
432 url));
433 }
434
404 //////////////////////////////////////////////////////////////////////////////// 435 ////////////////////////////////////////////////////////////////////////////////
405 // BrowserTabStripController, TabStripModelObserver implementation: 436 // BrowserTabStripController, TabStripModelObserver implementation:
406 437
407 void BrowserTabStripController::TabInsertedAt(WebContents* contents, 438 void BrowserTabStripController::TabInsertedAt(WebContents* contents,
408 int model_index, 439 int model_index,
409 bool is_active) { 440 bool is_active) {
410 DCHECK(contents); 441 DCHECK(contents);
411 DCHECK(model_->ContainsIndex(model_index)); 442 DCHECK(model_->ContainsIndex(model_index));
412 AddTab(contents, model_index, is_active); 443 AddTab(contents, model_index, is_active);
413 } 444 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 tabstrip_->AddTabAt(index, data, is_active); 570 tabstrip_->AddTabAt(index, data, is_active);
540 } 571 }
541 572
542 void BrowserTabStripController::UpdateLayoutType() { 573 void BrowserTabStripController::UpdateLayoutType() {
543 bool adjust_layout = false; 574 bool adjust_layout = false;
544 TabStripLayoutType layout_type = 575 TabStripLayoutType layout_type =
545 DetermineTabStripLayout(g_browser_process->local_state(), 576 DetermineTabStripLayout(g_browser_process->local_state(),
546 browser_->host_desktop_type(), &adjust_layout); 577 browser_->host_desktop_type(), &adjust_layout);
547 tabstrip_->SetLayoutType(layout_type, adjust_layout); 578 tabstrip_->SetLayoutType(layout_type, adjust_layout);
548 } 579 }
580
581 void BrowserTabStripController::OnFindURLMimeTypeCompleted(
582 const GURL& url,
583 const std::string& mime_type) {
584 // Check whether the mime type, if given, is known to be supported or whether
585 // there is a plugin that supports the mime type (e.g. PDF).
586 // TODO(bauerb): This possibly uses stale information, but it's guaranteed not
587 // to do disk access.
588 content::WebPluginInfo plugin;
589 tabstrip_->FileSupported(
590 url,
591 mime_type.empty() ||
592 net::IsSupportedMimeType(mime_type) ||
593 content::PluginService::GetInstance()->GetPluginInfo(
594 -1, // process ID
595 MSG_ROUTING_NONE, // routing ID
596 model_->profile()->GetResourceContext(),
597 url, GURL(), mime_type, false,
598 NULL, &plugin, NULL));
599 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698