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

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: Moved logic to BrowserTabStripController 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 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 from an thread that allows IO.
asanka 2013/11/25 22:35:05 Nit: s/from an/on a/
michaelpg 2013/11/25 23:02:35 Done.
90 std::string FindURLMimeType(GURL url) {
91 base::FilePath full_path;
92 net::FileURLToFilePath(url, &full_path);
93
94 // Get the MIME type based on the filename.
95 std::string mime_type;
96 net::GetMimeTypeFromFile(full_path, &mime_type);
97
98 return mime_type;
99 }
100
82 } // namespace 101 } // namespace
83 102
84 class BrowserTabStripController::TabContextMenuContents 103 class BrowserTabStripController::TabContextMenuContents
85 : public ui::SimpleMenuModel::Delegate { 104 : public ui::SimpleMenuModel::Delegate {
86 public: 105 public:
87 TabContextMenuContents(Tab* tab, 106 TabContextMenuContents(Tab* tab,
88 BrowserTabStripController* controller) 107 BrowserTabStripController* controller)
89 : tab_(tab), 108 : tab_(tab),
90 controller_(controller), 109 controller_(controller),
91 last_command_(TabStripModel::CommandFirst) { 110 last_command_(TabStripModel::CommandFirst) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 }; 189 };
171 190
172 //////////////////////////////////////////////////////////////////////////////// 191 ////////////////////////////////////////////////////////////////////////////////
173 // BrowserTabStripController, public: 192 // BrowserTabStripController, public:
174 193
175 BrowserTabStripController::BrowserTabStripController(Browser* browser, 194 BrowserTabStripController::BrowserTabStripController(Browser* browser,
176 TabStripModel* model) 195 TabStripModel* model)
177 : model_(model), 196 : model_(model),
178 tabstrip_(NULL), 197 tabstrip_(NULL),
179 browser_(browser), 198 browser_(browser),
180 hover_tab_selector_(model) { 199 hover_tab_selector_(model),
200 weak_ptr_factory_(this) {
181 model_->AddObserver(this); 201 model_->AddObserver(this);
182 202
183 local_pref_registrar_.Init(g_browser_process->local_state()); 203 local_pref_registrar_.Init(g_browser_process->local_state());
184 local_pref_registrar_.Add( 204 local_pref_registrar_.Add(
185 prefs::kTabStripLayoutType, 205 prefs::kTabStripLayoutType,
186 base::Bind(&BrowserTabStripController::UpdateLayoutType, 206 base::Bind(&BrowserTabStripController::UpdateLayoutType,
187 base::Unretained(this))); 207 base::Unretained(this)));
188 } 208 }
189 209
190 BrowserTabStripController::~BrowserTabStripController() { 210 BrowserTabStripController::~BrowserTabStripController() {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 immersive_reveal_lock_.reset( 414 immersive_reveal_lock_.reset(
395 browser_view->immersive_mode_controller()->GetRevealedLock( 415 browser_view->immersive_mode_controller()->GetRevealedLock(
396 ImmersiveModeController::ANIMATE_REVEAL_NO)); 416 ImmersiveModeController::ANIMATE_REVEAL_NO));
397 } 417 }
398 } 418 }
399 419
400 void BrowserTabStripController::OnStoppedDraggingTabs() { 420 void BrowserTabStripController::OnStoppedDraggingTabs() {
401 immersive_reveal_lock_.reset(); 421 immersive_reveal_lock_.reset();
402 } 422 }
403 423
424 void BrowserTabStripController::CheckFileSupported(GURL url) {
425 base::PostTaskAndReplyWithResult(
426 content::BrowserThread::GetBlockingPool(),
427 FROM_HERE,
428 base::Bind(&FindURLMimeType, url),
429 base::Bind(&BrowserTabStripController::OnFindURLMimeTypeCompleted,
430 weak_ptr_factory_.GetWeakPtr(),
431 url));
432 }
433
404 //////////////////////////////////////////////////////////////////////////////// 434 ////////////////////////////////////////////////////////////////////////////////
405 // BrowserTabStripController, TabStripModelObserver implementation: 435 // BrowserTabStripController, TabStripModelObserver implementation:
406 436
407 void BrowserTabStripController::TabInsertedAt(WebContents* contents, 437 void BrowserTabStripController::TabInsertedAt(WebContents* contents,
408 int model_index, 438 int model_index,
409 bool is_active) { 439 bool is_active) {
410 DCHECK(contents); 440 DCHECK(contents);
411 DCHECK(model_->ContainsIndex(model_index)); 441 DCHECK(model_->ContainsIndex(model_index));
412 AddTab(contents, model_index, is_active); 442 AddTab(contents, model_index, is_active);
413 } 443 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 tabstrip_->AddTabAt(index, data, is_active); 569 tabstrip_->AddTabAt(index, data, is_active);
540 } 570 }
541 571
542 void BrowserTabStripController::UpdateLayoutType() { 572 void BrowserTabStripController::UpdateLayoutType() {
543 bool adjust_layout = false; 573 bool adjust_layout = false;
544 TabStripLayoutType layout_type = 574 TabStripLayoutType layout_type =
545 DetermineTabStripLayout(g_browser_process->local_state(), 575 DetermineTabStripLayout(g_browser_process->local_state(),
546 browser_->host_desktop_type(), &adjust_layout); 576 browser_->host_desktop_type(), &adjust_layout);
547 tabstrip_->SetLayoutType(layout_type, adjust_layout); 577 tabstrip_->SetLayoutType(layout_type, adjust_layout);
548 } 578 }
579
580 void BrowserTabStripController::OnFindURLMimeTypeCompleted(
581 GURL url,
582 const std::string& mime_type) {
583 // Check whether the mime type, if given, is known to be supported or whether
584 // there is a plugin that supports the mime type (e.g. PDF).
585 // TODO(bauerb): This possibly uses stale information, but it's guaranteed not
586 // to do disk access.
587 content::WebPluginInfo plugin;
588 tabstrip_->FileSupported(
589 url,
590 mime_type.empty() ||
591 net::IsSupportedMimeType(mime_type) ||
592 content::PluginService::GetInstance()->GetPluginInfo(
asanka 2013/11/25 22:35:05 Is it safe to make this call on the UI thread?
michaelpg 2013/11/25 23:02:35 Yes. PluginService::GetPluginInfoArray says "This
593 -1, // process ID
594 MSG_ROUTING_NONE, // routing ID
595 model_->profile()->GetResourceContext(),
596 url, GURL(), mime_type, false,
597 NULL, &plugin, NULL));
598 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698