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

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

Issue 119117: make extension apis tolerate browser absence during start-up & shutdown (Closed)
Patch Set: CR changes Created 11 years, 6 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
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "chrome/browser/browser.h" 8 #include "chrome/browser/browser.h"
9 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 site_instance()->GetProcess()); 125 site_instance()->GetProcess());
126 } 126 }
127 127
128 void ExtensionHost::ShowCreatedWindow(int route_id, 128 void ExtensionHost::ShowCreatedWindow(int route_id,
129 WindowOpenDisposition disposition, 129 WindowOpenDisposition disposition,
130 const gfx::Rect& initial_pos, 130 const gfx::Rect& initial_pos,
131 bool user_gesture, 131 bool user_gesture,
132 const GURL& creator_url) { 132 const GURL& creator_url) {
133 TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id); 133 TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
134 if (contents) { 134 if (contents) {
135 Browser* browser = GetBrowser();
136 DCHECK(browser);
137 if (!browser)
138 return;
135 // TODO(erikkay) is it safe to pass in NULL as source? 139 // TODO(erikkay) is it safe to pass in NULL as source?
136 GetBrowser()->AddTabContents(contents, disposition, initial_pos, 140 browser->AddTabContents(contents, disposition, initial_pos,
137 user_gesture); 141 user_gesture);
138 } 142 }
139 } 143 }
140 144
141 void ExtensionHost::ShowCreatedWidget(int route_id, 145 void ExtensionHost::ShowCreatedWidget(int route_id,
142 const gfx::Rect& initial_pos) { 146 const gfx::Rect& initial_pos) {
143 RenderWidgetHostView* widget_host_view = 147 RenderWidgetHostView* widget_host_view =
144 delegate_view_helper_.GetCreatedWidget(route_id); 148 delegate_view_helper_.GetCreatedWidget(route_id);
145 GetBrowser()->BrowserRenderWidgetShowing(); 149 Browser *browser = GetBrowser();
150 DCHECK(browser);
151 if (!browser)
152 return;
153 browser->BrowserRenderWidgetShowing();
146 // TODO(erikkay): These two lines could be refactored with TabContentsView. 154 // TODO(erikkay): These two lines could be refactored with TabContentsView.
147 widget_host_view->InitAsPopup(render_view_host()->view(), initial_pos); 155 widget_host_view->InitAsPopup(render_view_host()->view(), initial_pos);
148 widget_host_view->GetRenderWidgetHost()->Init(); 156 widget_host_view->GetRenderWidgetHost()->Init();
149 } 157 }
150 158
151 void ExtensionHost::ShowContextMenu(const ContextMenuParams& params) { 159 void ExtensionHost::ShowContextMenu(const ContextMenuParams& params) {
152 // TODO(erikkay) - This is a temporary hack. Show a menu here instead. 160 // TODO(erikkay) - This is a temporary hack. Show a menu here instead.
153 g_browser_process->devtools_manager()->OpenDevToolsWindow(render_view_host()); 161 g_browser_process->devtools_manager()->OpenDevToolsWindow(render_view_host());
154 } 162 }
155 163
(...skipping 23 matching lines...) Expand all
179 #endif 187 #endif
180 } 188 }
181 189
182 Browser* ExtensionHost::GetBrowser() { 190 Browser* ExtensionHost::GetBrowser() {
183 #if defined(OS_WIN) 191 #if defined(OS_WIN)
184 if (view_) 192 if (view_)
185 return view_->browser(); 193 return view_->browser();
186 #endif 194 #endif
187 Browser* browser = BrowserList::GetLastActiveWithProfile( 195 Browser* browser = BrowserList::GetLastActiveWithProfile(
188 render_view_host()->process()->profile()); 196 render_view_host()->process()->profile());
189 // TODO(mpcomplete): what this verifies doesn't actually happen yet. 197 // NOTE(rafaelw): This can return NULL in some circumstances. In particular,
190 CHECK(browser) << "ExtensionHost running in Profile with no Browser active." 198 // a toolstrip or background_page onload chrome.tabs api call can make it
191 " It should have been deleted."; 199 // into here before the browser is sufficiently initialized to return here.
200 // A similar situation may arise during shutdown.
201 // TODO(rafaelw): Delay creation of background_page until the browser
202 // is available. http://code.google.com/p/chromium/issues/detail?id=13284
192 return browser; 203 return browser;
193 } 204 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_function_dispatcher.cc ('k') | chrome/browser/extensions/extension_tabs_module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698