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

Side by Side Diff: chrome/browser/extensions/extension_tab_util.cc

Issue 2298493003: [Extensions] Convert some ChromeSyncExtensionFunctions (Closed)
Patch Set: fix Created 4 years, 3 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
« no previous file with comments | « chrome/browser/extensions/extension_tab_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/extensions/extension_tab_util.h" 5 #include "chrome/browser/extensions/extension_tab_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 } 89 }
90 90
91 if (error_message) 91 if (error_message)
92 *error_message = ErrorUtils::FormatErrorMessage( 92 *error_message = ErrorUtils::FormatErrorMessage(
93 keys::kWindowNotFoundError, base::IntToString(window_id)); 93 keys::kWindowNotFoundError, base::IntToString(window_id));
94 94
95 return NULL; 95 return NULL;
96 } 96 }
97 97
98 Browser* CreateBrowser(ChromeUIThreadExtensionFunction* function, 98 Browser* CreateBrowser(Profile* profile, int window_id, std::string* error) {
99 int window_id, 99 Browser::CreateParams params(Browser::TYPE_TABBED, profile);
100 std::string* error) {
101 Browser::CreateParams params(Browser::TYPE_TABBED, function->GetProfile());
102 Browser* browser = new Browser(params); 100 Browser* browser = new Browser(params);
103 browser->window()->Show(); 101 browser->window()->Show();
104 return browser; 102 return browser;
105 } 103 }
106 104
107 // Use this function for reporting a tab id to an extension. It will 105 // Use this function for reporting a tab id to an extension. It will
108 // take care of setting the id to TAB_ID_NONE if necessary (for 106 // take care of setting the id to TAB_ID_NONE if necessary (for
109 // example with devtools). 107 // example with devtools).
110 int GetTabIdForExtensions(const WebContents* web_contents) { 108 int GetTabIdForExtensions(const WebContents* web_contents) {
111 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 109 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
112 if (browser && !ExtensionTabUtil::BrowserSupportsTabs(browser)) 110 if (browser && !ExtensionTabUtil::BrowserSupportsTabs(browser))
113 return -1; 111 return -1;
114 return SessionTabHelper::IdForTab(web_contents); 112 return SessionTabHelper::IdForTab(web_contents);
115 } 113 }
116 114
117 } // namespace 115 } // namespace
118 116
119 ExtensionTabUtil::OpenTabParams::OpenTabParams() 117 ExtensionTabUtil::OpenTabParams::OpenTabParams()
120 : create_browser_if_needed(false) { 118 : create_browser_if_needed(false) {
121 } 119 }
122 120
123 ExtensionTabUtil::OpenTabParams::~OpenTabParams() { 121 ExtensionTabUtil::OpenTabParams::~OpenTabParams() {
124 } 122 }
125 123
126 // Opens a new tab for a given extension. Returns NULL and sets |error| if an 124 // Opens a new tab for a given extension. Returns NULL and sets |error| if an
127 // error occurs. 125 // error occurs.
128 base::DictionaryValue* ExtensionTabUtil::OpenTab( 126 base::DictionaryValue* ExtensionTabUtil::OpenTab(
129 ChromeUIThreadExtensionFunction* function, 127 UIThreadExtensionFunction* function,
130 const OpenTabParams& params, 128 const OpenTabParams& params,
131 std::string* error) { 129 std::string* error) {
130 ChromeExtensionFunctionDetails chrome_details(function);
131 Profile* profile = chrome_details.GetProfile();
132 // windowId defaults to "current" window. 132 // windowId defaults to "current" window.
133 int window_id = extension_misc::kCurrentWindowId; 133 int window_id = extension_misc::kCurrentWindowId;
134 if (params.window_id.get()) 134 if (params.window_id.get())
135 window_id = *params.window_id; 135 window_id = *params.window_id;
136 136
137 Browser* browser = GetBrowserFromWindowID(function, window_id, error); 137 Browser* browser = GetBrowserFromWindowID(chrome_details, window_id, error);
138 if (!browser) { 138 if (!browser) {
139 if (!params.create_browser_if_needed) { 139 if (!params.create_browser_if_needed) {
140 return NULL; 140 return NULL;
141 } 141 }
142 browser = CreateBrowser(function, window_id, error); 142 browser = CreateBrowser(profile, window_id, error);
143 if (!browser) 143 if (!browser)
144 return NULL; 144 return NULL;
145 } 145 }
146 146
147 // Ensure the selected browser is tabbed. 147 // Ensure the selected browser is tabbed.
148 if (!browser->is_type_tabbed() && browser->IsAttemptingToCloseBrowser()) 148 if (!browser->is_type_tabbed() && browser->IsAttemptingToCloseBrowser())
149 browser = chrome::FindTabbedBrowser(function->GetProfile(), 149 browser = chrome::FindTabbedBrowser(profile, function->include_incognito());
150 function->include_incognito());
151 if (!browser || !browser->window()) { 150 if (!browser || !browser->window()) {
152 if (error) 151 if (error)
153 *error = keys::kNoCurrentWindowError; 152 *error = keys::kNoCurrentWindowError;
154 return NULL; 153 return NULL;
155 } 154 }
156 155
157 // TODO(jstritar): Add a constant, chrome.tabs.TAB_ID_ACTIVE, that 156 // TODO(jstritar): Add a constant, chrome.tabs.TAB_ID_ACTIVE, that
158 // represents the active tab. 157 // represents the active tab.
159 WebContents* opener = NULL; 158 WebContents* opener = NULL;
160 if (params.opener_tab_id.get()) { 159 if (params.opener_tab_id.get()) {
161 int opener_id = *params.opener_tab_id; 160 int opener_id = *params.opener_tab_id;
162 161
163 if (!ExtensionTabUtil::GetTabById(opener_id, 162 if (!ExtensionTabUtil::GetTabById(opener_id, profile,
164 function->GetProfile(), 163 function->include_incognito(), NULL, NULL,
165 function->include_incognito(), 164 &opener, NULL)) {
166 NULL,
167 NULL,
168 &opener,
169 NULL)) {
170 if (error) { 165 if (error) {
171 *error = ErrorUtils::FormatErrorMessage(keys::kTabNotFoundError, 166 *error = ErrorUtils::FormatErrorMessage(keys::kTabNotFoundError,
172 base::IntToString(opener_id)); 167 base::IntToString(opener_id));
173 } 168 }
174 return NULL; 169 return NULL;
175 } 170 }
176 } 171 }
177 172
178 // TODO(rafaelw): handle setting remaining tab properties: 173 // TODO(rafaelw): handle setting remaining tab properties:
179 // -title 174 // -title
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 chrome::ShowSingletonTabOverwritingNTP(browser, params); 666 chrome::ShowSingletonTabOverwritingNTP(browser, params);
672 return true; 667 return true;
673 } 668 }
674 669
675 // static 670 // static
676 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) { 671 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) {
677 return browser && browser->tab_strip_model() && !browser->is_devtools(); 672 return browser && browser->tab_strip_model() && !browser->is_devtools();
678 } 673 }
679 674
680 } // namespace extensions 675 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tab_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698