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

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views_win.cc

Issue 10692164: Remove browser::FindTabbedBrowser call in bookmark_utils.cc. All callers, with the exception of met… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 months 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/bookmarks/bookmark_context_menu_controller_vie ws_win.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_vie ws_win.h"
6 6
7 #include "base/win/metro.h" 7 #include "base/win/metro.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/bookmarks/bookmark_utils.h" 9 #include "chrome/browser/bookmarks/bookmark_utils.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/browser_window.h"
15 #include "content/public/browser/page_navigator.h"
11 #include "content/public/browser/user_metrics.h" 16 #include "content/public/browser/user_metrics.h"
17 #include "content/public/browser/web_contents.h"
12 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
13 #include "ui/views/widget/widget.h" 19 #include "ui/views/widget/widget.h"
14 20
21 using content::OpenURLParams;
15 using content::UserMetricsAction; 22 using content::UserMetricsAction;
23 using content::WebContents;
24
25 namespace {
26
27 // A PageNavigator implementation that creates a new Browser. This is used when
28 // opening a url and there is no Browser open. The Browser is created the first
29 // time the PageNavigator method is invoked.
30 class NewBrowserPageNavigator : public content::PageNavigator {
31 public:
32 explicit NewBrowserPageNavigator(Profile* profile)
33 : profile_(profile),
34 browser_(NULL) {}
35
36 virtual ~NewBrowserPageNavigator() {
37 if (browser_)
38 browser_->window()->Show();
39 }
40
41 Browser* browser() const { return browser_; }
42
43 virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE {
44 if (!browser_) {
45 Profile* profile = (params.disposition == OFF_THE_RECORD) ?
46 profile_->GetOffTheRecordProfile() : profile_;
47 browser_ = Browser::Create(profile);
48 }
49
50 OpenURLParams forward_params = params;
51 forward_params.disposition = NEW_FOREGROUND_TAB;
52 return browser_->OpenURL(forward_params);
53 }
54
55 private:
56 Profile* profile_;
57 Browser* browser_;
58
59 DISALLOW_COPY_AND_ASSIGN(NewBrowserPageNavigator);
60 };
61
62 } // namespace
16 63
17 // static 64 // static
18 BookmarkContextMenuControllerViews* BookmarkContextMenuControllerViews::Create( 65 BookmarkContextMenuControllerViews* BookmarkContextMenuControllerViews::Create(
19 views::Widget* parent_widget, 66 views::Widget* parent_widget,
20 BookmarkContextMenuControllerViewsDelegate* delegate, 67 BookmarkContextMenuControllerViewsDelegate* delegate,
21 Browser* browser, 68 Browser* browser,
22 Profile* profile, 69 Profile* profile,
23 content::PageNavigator* navigator, 70 content::PageNavigator* navigator,
24 const BookmarkNode* parent, 71 const BookmarkNode* parent,
25 const std::vector<const BookmarkNode*>& selection) { 72 const std::vector<const BookmarkNode*>& selection) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 108
62 content::RecordAction( 109 content::RecordAction(
63 UserMetricsAction("BookmarkBar_ContextMenu_OpenAllInNewWindow")); 110 UserMetricsAction("BookmarkBar_ContextMenu_OpenAllInNewWindow"));
64 } else { 111 } else {
65 if (!profile_to_use->IsOffTheRecord()) 112 if (!profile_to_use->IsOffTheRecord())
66 profile_to_use = profile_to_use->GetOffTheRecordProfile(); 113 profile_to_use = profile_to_use->GetOffTheRecordProfile();
67 114
68 content::RecordAction( 115 content::RecordAction(
69 UserMetricsAction("BookmarkBar_ContextMenu_OpenAllIncognito")); 116 UserMetricsAction("BookmarkBar_ContextMenu_OpenAllIncognito"));
70 } 117 }
71 // Passing in NULL for the PageNavigator ensures that we first look for 118
72 // an existing browser window to handle the request before trying to 119 NewBrowserPageNavigator navigator_impl(profile_to_use);
73 // create one. 120 Browser* browser = browser::FindTabbedBrowser(profile_to_use, false);
74 bookmark_utils::OpenAll(parent_widget()->GetNativeWindow(), 121 content::PageNavigator* navigator = NULL;
75 profile_to_use, NULL, selection(), 122 if (!browser || !chrome::GetActiveWebContents(browser)) {
76 NEW_FOREGROUND_TAB); 123 navigator = &navigator_impl;
124 } else {
125 browser->window()->Activate();
126 navigator = chrome::GetActiveWebContents(browser);
127 }
128
129 bookmark_utils::OpenAll(parent_widget()->GetNativeWindow(), navigator,
130 selection(), NEW_FOREGROUND_TAB);
77 bookmark_utils::RecordBookmarkLaunch( 131 bookmark_utils::RecordBookmarkLaunch(
78 bookmark_utils::LAUNCH_CONTEXT_MENU); 132 bookmark_utils::LAUNCH_CONTEXT_MENU);
79 return; 133 return;
80 } 134 }
81 135
82 default: 136 default:
83 break; 137 break;
84 } 138 }
85 } 139 }
86 BookmarkContextMenuControllerViews::ExecuteCommand(id); 140 BookmarkContextMenuControllerViews::ExecuteCommand(id);
87 } 141 }
88 142
89 bool BookmarkContextMenuControllerViewsWin::IsCommandEnabled(int id) const { 143 bool BookmarkContextMenuControllerViewsWin::IsCommandEnabled(int id) const {
90 // In Windows 8 metro mode no new window option on a regular chrome window 144 // In Windows 8 metro mode no new window option on a regular chrome window
91 // and no new incognito window option on an incognito chrome window. 145 // and no new incognito window option on an incognito chrome window.
92 if (base::win::IsMetroProcess()) { 146 if (base::win::IsMetroProcess()) {
93 if (id == IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW && 147 if (id == IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW &&
94 !profile()->IsOffTheRecord()) { 148 !profile()->IsOffTheRecord()) {
95 return false; 149 return false;
96 } else if (id == IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO && 150 } else if (id == IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO &&
97 profile()->IsOffTheRecord()) { 151 profile()->IsOffTheRecord()) {
98 return false; 152 return false;
99 } 153 }
100 } 154 }
101 return BookmarkContextMenuControllerViews::IsCommandEnabled(id); 155 return BookmarkContextMenuControllerViews::IsCommandEnabled(id);
102 } 156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698