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

Unified Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 119117: make extension apis tolerate browser absence during start-up & shutdown (Closed)
Patch Set: CR changes Created 11 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_tabs_module.cc
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index a3868fa496ff9da8caff15d9cb7df8d78abbabc6..ea1d3bec032e65984563c3df30945471b4494c94 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -164,12 +164,20 @@ bool GetWindowFunction::RunImpl() {
bool GetCurrentWindowFunction::RunImpl() {
Browser* browser = dispatcher_->GetBrowser();
+ if (!browser) {
+ error_ = keys::kNoCurrentWindowError;
+ return false;
+ }
result_.reset(CreateWindowValue(browser, false));
return true;
}
bool GetLastFocusedWindowFunction::RunImpl() {
Browser* browser = BrowserList::GetLastActiveWithProfile(profile());
+ if (!browser) {
+ error_ = keys::kNoLastFocusedWindowError;
+ return false;
+ }
result_.reset(CreateWindowValue(browser, false));
return true;
}
@@ -218,7 +226,10 @@ bool CreateWindowFunction::RunImpl() {
gfx::Rect bounds;
bool maximized;
// The call offsets the bounds by kWindowTilePixels (defined in WindowSizer to
- // be 10).
+ // be 10)
+ //
+ // NOTE(rafaelw): It's ok if dispatcher_->GetBrowser() returns NULL here.
+ // GetBrowserWindowBounds will default to saved "default" values for the app.
WindowSizer::GetBrowserWindowBounds(std::wstring(), empty_bounds,
dispatcher_->GetBrowser(), &bounds,
&maximized);
@@ -309,9 +320,6 @@ bool UpdateWindowFunction::RunImpl() {
bounds.set_height(bounds_val);
}
- // TODO(rafaelw): This call to SetBounds() ends up resulting in the target
- // window being activated (pushed to the front). On win32, this appears to be
- // the result of HWND event handling.
browser->window()->SetBounds(bounds);
// TODO(rafaelw): Support |focused|.
result_.reset(CreateWindowValue(browser, false));
@@ -342,16 +350,21 @@ bool GetSelectedTabFunction::RunImpl() {
if (!args_->IsType(Value::TYPE_NULL)) {
EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&window_id));
browser = GetBrowserInProfileWithId(profile(), window_id, &error_);
- if (!browser)
- return false;
} else {
browser = dispatcher_->GetBrowser();
+ if (!browser)
+ error_ = keys::kNoCurrentWindowError;
}
+ if (!browser)
+ return false;
TabStripModel* tab_strip = browser->tabstrip_model();
- result_.reset(ExtensionTabUtil::CreateTabValue(
- tab_strip->GetSelectedTabContents(),
- tab_strip,
+ TabContents* contents = tab_strip->GetSelectedTabContents();
+ if (!contents) {
+ error_ = keys::kNoSelectedTabError;
+ return false;
+ }
+ result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip,
tab_strip->selected_index()));
return true;
}
@@ -363,11 +376,13 @@ bool GetAllTabsInWindowFunction::RunImpl() {
if (!args_->IsType(Value::TYPE_NULL)) {
EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&window_id));
browser = GetBrowserInProfileWithId(profile(), window_id, &error_);
- if (!browser)
- return false;
} else {
browser = dispatcher_->GetBrowser();
+ if (!browser)
+ error_ = keys::kNoCurrentWindowError;
}
+ if (!browser)
+ return false;
result_.reset(CreateTabList(browser));
@@ -385,11 +400,13 @@ bool CreateTabFunction::RunImpl() {
EXTENSION_FUNCTION_VALIDATE(args->GetInteger(
keys::kWindowIdKey, &window_id));
browser = GetBrowserInProfileWithId(profile(), window_id, &error_);
- if (!browser)
- return false;
} else {
- browser = dispatcher_->GetBrowser();
+ browser = dispatcher_->GetBrowser();
+ if (!browser)
+ error_ = keys::kNoCurrentWindowError;
}
+ if (!browser)
+ return false;
TabStripModel* tab_strip = browser->tabstrip_model();
« no previous file with comments | « chrome/browser/extensions/extension_host.cc ('k') | chrome/browser/extensions/extension_tabs_module_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698