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

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

Issue 3056029: Move the number conversions from string_util to a new file.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_tabs_module.h" 5 #include "chrome/browser/extensions/extension_tabs_module.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/string_number_conversions.h"
8 #include "base/string_util.h" 9 #include "base/string_util.h"
9 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_list.h" 11 #include "chrome/browser/browser_list.h"
11 #include "chrome/browser/browser_window.h" 12 #include "chrome/browser/browser_window.h"
12 #include "chrome/browser/extensions/extension_function_dispatcher.h" 13 #include "chrome/browser/extensions/extension_function_dispatcher.h"
13 #include "chrome/browser/extensions/extension_host.h" 14 #include "chrome/browser/extensions/extension_host.h"
14 #include "chrome/browser/extensions/extension_infobar_delegate.h" 15 #include "chrome/browser/extensions/extension_infobar_delegate.h"
15 #include "chrome/browser/extensions/extension_tabs_module_constants.h" 16 #include "chrome/browser/extensions/extension_tabs_module_constants.h"
16 #include "chrome/browser/extensions/extensions_service.h" 17 #include "chrome/browser/extensions/extensions_service.h"
17 #include "chrome/browser/profile.h" 18 #include "chrome/browser/profile.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // Windows --------------------------------------------------------------------- 217 // Windows ---------------------------------------------------------------------
217 218
218 bool GetWindowFunction::RunImpl() { 219 bool GetWindowFunction::RunImpl() {
219 int window_id; 220 int window_id;
220 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 221 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
221 222
222 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, 223 Browser* browser = GetBrowserInProfileWithId(profile(), window_id,
223 include_incognito(), &error_); 224 include_incognito(), &error_);
224 if (!browser || !browser->window()) { 225 if (!browser || !browser->window()) {
225 error_ = ExtensionErrorUtils::FormatErrorMessage( 226 error_ = ExtensionErrorUtils::FormatErrorMessage(
226 keys::kWindowNotFoundError, IntToString(window_id)); 227 keys::kWindowNotFoundError, base::IntToString(window_id));
227 return false; 228 return false;
228 } 229 }
229 230
230 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); 231 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false));
231 return true; 232 return true;
232 } 233 }
233 234
234 bool GetCurrentWindowFunction::RunImpl() { 235 bool GetCurrentWindowFunction::RunImpl() {
235 Browser* browser = GetCurrentBrowser(); 236 Browser* browser = GetCurrentBrowser();
236 if (!browser || !browser->window()) { 237 if (!browser || !browser->window()) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 bool UpdateWindowFunction::RunImpl() { 390 bool UpdateWindowFunction::RunImpl() {
390 int window_id; 391 int window_id;
391 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 392 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
392 DictionaryValue* update_props; 393 DictionaryValue* update_props;
393 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); 394 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
394 395
395 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, 396 Browser* browser = GetBrowserInProfileWithId(profile(), window_id,
396 include_incognito(), &error_); 397 include_incognito(), &error_);
397 if (!browser || !browser->window()) { 398 if (!browser || !browser->window()) {
398 error_ = ExtensionErrorUtils::FormatErrorMessage( 399 error_ = ExtensionErrorUtils::FormatErrorMessage(
399 keys::kWindowNotFoundError, IntToString(window_id)); 400 keys::kWindowNotFoundError, base::IntToString(window_id));
400 return false; 401 return false;
401 } 402 }
402 403
403 gfx::Rect bounds = browser->window()->GetRestoredBounds(); 404 gfx::Rect bounds = browser->window()->GetRestoredBounds();
404 // Any part of the bounds can optionally be set by the caller. 405 // Any part of the bounds can optionally be set by the caller.
405 int bounds_val; 406 int bounds_val;
406 if (update_props->HasKey(keys::kLeftKey)) { 407 if (update_props->HasKey(keys::kLeftKey)) {
407 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 408 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
408 keys::kLeftKey, 409 keys::kLeftKey,
409 &bounds_val)); 410 &bounds_val));
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 return false; 740 return false;
740 } 741 }
741 742
742 // If windowId is different from the current window, move between windows. 743 // If windowId is different from the current window, move between windows.
743 if (ExtensionTabUtil::GetWindowId(target_browser) != 744 if (ExtensionTabUtil::GetWindowId(target_browser) !=
744 ExtensionTabUtil::GetWindowId(source_browser)) { 745 ExtensionTabUtil::GetWindowId(source_browser)) {
745 TabStripModel* target_tab_strip = target_browser->tabstrip_model(); 746 TabStripModel* target_tab_strip = target_browser->tabstrip_model();
746 contents = source_tab_strip->DetachTabContentsAt(tab_index); 747 contents = source_tab_strip->DetachTabContentsAt(tab_index);
747 if (!contents) { 748 if (!contents) {
748 error_ = ExtensionErrorUtils::FormatErrorMessage( 749 error_ = ExtensionErrorUtils::FormatErrorMessage(
749 keys::kTabNotFoundError, IntToString(tab_id)); 750 keys::kTabNotFoundError, base::IntToString(tab_id));
750 return false; 751 return false;
751 } 752 }
752 753
753 // Clamp move location to the last position. 754 // Clamp move location to the last position.
754 // This is ">" because it can append to a new index position. 755 // This is ">" because it can append to a new index position.
755 if (new_index > target_tab_strip->count()) 756 if (new_index > target_tab_strip->count())
756 new_index = target_tab_strip->count(); 757 new_index = target_tab_strip->count();
757 758
758 target_tab_strip->InsertTabContentsAt(new_index, contents, 759 target_tab_strip->InsertTabContentsAt(new_index, contents,
759 TabStripModel::ADD_NONE); 760 TabStripModel::ADD_NONE);
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 for (BrowserList::const_iterator browser = BrowserList::begin(); 1054 for (BrowserList::const_iterator browser = BrowserList::begin();
1054 browser != BrowserList::end(); ++browser) { 1055 browser != BrowserList::end(); ++browser) {
1055 if (((*browser)->profile() == profile || 1056 if (((*browser)->profile() == profile ||
1056 (*browser)->profile() == incognito_profile) && 1057 (*browser)->profile() == incognito_profile) &&
1057 ExtensionTabUtil::GetWindowId(*browser) == window_id) 1058 ExtensionTabUtil::GetWindowId(*browser) == window_id)
1058 return *browser; 1059 return *browser;
1059 } 1060 }
1060 1061
1061 if (error_message) 1062 if (error_message)
1062 *error_message = ExtensionErrorUtils::FormatErrorMessage( 1063 *error_message = ExtensionErrorUtils::FormatErrorMessage(
1063 keys::kWindowNotFoundError, IntToString(window_id)); 1064 keys::kWindowNotFoundError, base::IntToString(window_id));
1064 1065
1065 return NULL; 1066 return NULL;
1066 } 1067 }
1067 1068
1068 static bool GetTabById(int tab_id, Profile* profile, 1069 static bool GetTabById(int tab_id, Profile* profile,
1069 bool include_incognito, 1070 bool include_incognito,
1070 Browser** browser, 1071 Browser** browser,
1071 TabStripModel** tab_strip, 1072 TabStripModel** tab_strip,
1072 TabContents** contents, 1073 TabContents** contents,
1073 int* tab_index, 1074 int* tab_index,
1074 std::string* error_message) { 1075 std::string* error_message) {
1075 if (ExtensionTabUtil::GetTabById(tab_id, profile, include_incognito, 1076 if (ExtensionTabUtil::GetTabById(tab_id, profile, include_incognito,
1076 browser, tab_strip, contents, tab_index)) 1077 browser, tab_strip, contents, tab_index))
1077 return true; 1078 return true;
1078 1079
1079 if (error_message) 1080 if (error_message)
1080 *error_message = ExtensionErrorUtils::FormatErrorMessage( 1081 *error_message = ExtensionErrorUtils::FormatErrorMessage(
1081 keys::kTabNotFoundError, IntToString(tab_id)); 1082 keys::kTabNotFoundError, base::IntToString(tab_id));
1082 1083
1083 return false; 1084 return false;
1084 } 1085 }
1085 1086
1086 static std::string GetWindowTypeText(Browser::Type type) { 1087 static std::string GetWindowTypeText(Browser::Type type) {
1087 // Note: for app popups, we report "app". 1088 // Note: for app popups, we report "app".
1088 if ((type & Browser::TYPE_APP) != 0 || type == Browser::TYPE_EXTENSION_APP) 1089 if ((type & Browser::TYPE_APP) != 0 || type == Browser::TYPE_EXTENSION_APP)
1089 return keys::kWindowTypeValueApp; 1090 return keys::kWindowTypeValueApp;
1090 if ((type & Browser::TYPE_POPUP) != 0) 1091 if ((type & Browser::TYPE_POPUP) != 0)
1091 return keys::kWindowTypeValuePopup; 1092 return keys::kWindowTypeValuePopup;
1092 1093
1093 DCHECK(type == Browser::TYPE_NORMAL); 1094 DCHECK(type == Browser::TYPE_NORMAL);
1094 return keys::kWindowTypeValueNormal; 1095 return keys::kWindowTypeValueNormal;
1095 } 1096 }
1096 1097
1097 static GURL ResolvePossiblyRelativeURL(std::string url_string, 1098 static GURL ResolvePossiblyRelativeURL(std::string url_string,
1098 Extension* extension) { 1099 Extension* extension) {
1099 GURL url = GURL(url_string); 1100 GURL url = GURL(url_string);
1100 if (!url.is_valid()) 1101 if (!url.is_valid())
1101 url = extension->GetResourceURL(url_string); 1102 url = extension->GetResourceURL(url_string);
1102 1103
1103 return url; 1104 return url;
1104 } 1105 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs_unittest.cc ('k') | chrome/browser/extensions/extension_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698