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

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

Issue 10119003: Pull shell window stuff out of ExtensionHost and put in ShellWindow (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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) 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_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 153
154 ExtensionHost::~ExtensionHost() { 154 ExtensionHost::~ExtensionHost() {
155 content::NotificationService::current()->Notify( 155 content::NotificationService::current()->Notify(
156 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 156 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
157 content::Source<Profile>(profile_), 157 content::Source<Profile>(profile_),
158 content::Details<ExtensionHost>(this)); 158 content::Details<ExtensionHost>(this));
159 ProcessCreationQueue::GetInstance()->Remove(this); 159 ProcessCreationQueue::GetInstance()->Remove(this);
160 } 160 }
161 161
162 void ExtensionHost::CreateView(Browser* browser) {
163 #if defined(TOOLKIT_VIEWS)
164 view_.reset(new ExtensionView(this, browser));
165 // We own |view_|, so don't auto delete when it's removed from the view
166 // hierarchy.
167 view_->set_parent_owned(false);
168 #elif defined(OS_MACOSX)
169 view_.reset(new ExtensionViewMac(this, browser));
170 view_->Init();
171 #elif defined(TOOLKIT_GTK)
172 view_.reset(new ExtensionViewGtk(this, browser));
173 view_->Init();
174 #else
175 // TODO(port)
176 NOTREACHED();
177 #endif
178 }
179
180 void ExtensionHost::CreateViewWithoutBrowser() {
181 CreateView(NULL);
182 }
183
184 WebContents* ExtensionHost::GetAssociatedWebContents() const { 162 WebContents* ExtensionHost::GetAssociatedWebContents() const {
185 return associated_web_contents_; 163 return associated_web_contents_;
186 } 164 }
187 165
188 void ExtensionHost::SetAssociatedWebContents( 166 void ExtensionHost::SetAssociatedWebContents(
189 content::WebContents* web_contents) { 167 content::WebContents* web_contents) {
190 associated_web_contents_ = web_contents; 168 associated_web_contents_ = web_contents;
191 if (web_contents) { 169 if (web_contents) {
192 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 170 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
193 content::Source<WebContents>(associated_web_contents_)); 171 content::Source<WebContents>(associated_web_contents_));
194 } 172 }
195 } 173 }
196 174
175 content::WebContents* ExtensionHost::host_contents() const {
176 return host_contents_.get();
177 }
197 178
198 content::RenderProcessHost* ExtensionHost::render_process_host() const { 179 content::RenderProcessHost* ExtensionHost::render_process_host() const {
199 return render_view_host()->GetProcess(); 180 return render_view_host()->GetProcess();
200 } 181 }
201 182
202 RenderViewHost* ExtensionHost::render_view_host() const { 183 RenderViewHost* ExtensionHost::render_view_host() const {
203 // TODO(mpcomplete): This can be NULL. How do we handle that? 184 // TODO(mpcomplete): This can be NULL. How do we handle that?
204 return render_view_host_; 185 return render_view_host_;
205 } 186 }
206 187
(...skipping 21 matching lines...) Expand all
228 } 209 }
229 210
230 const Browser* ExtensionHost::GetBrowser() const { 211 const Browser* ExtensionHost::GetBrowser() const {
231 return view() ? view()->browser() : NULL; 212 return view() ? view()->browser() : NULL;
232 } 213 }
233 214
234 Browser* ExtensionHost::GetBrowser() { 215 Browser* ExtensionHost::GetBrowser() {
235 return view() ? view()->browser() : NULL; 216 return view() ? view()->browser() : NULL;
236 } 217 }
237 218
219 content::ViewType ExtensionHost::extension_host_type() const {
220 return extension_host_type_;
221 }
222
238 const GURL& ExtensionHost::GetURL() const { 223 const GURL& ExtensionHost::GetURL() const {
239 return host_contents()->GetURL(); 224 return host_contents()->GetURL();
240 } 225 }
241 226
242 void ExtensionHost::LoadInitialURL() { 227 void ExtensionHost::LoadInitialURL() {
243 if (!is_background_page() && 228 if (!is_background_page() &&
244 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) { 229 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) {
245 // Make sure the background page loads before any others. 230 // Make sure the background page loads before any others.
246 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, 231 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
247 content::Source<Extension>(extension_)); 232 content::Source<Extension>(extension_));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 271 }
287 break; 272 break;
288 default: 273 default:
289 NOTREACHED() << "Unexpected notification sent."; 274 NOTREACHED() << "Unexpected notification sent.";
290 break; 275 break;
291 } 276 }
292 } 277 }
293 278
294 void ExtensionHost::ResizeDueToAutoResize(WebContents* source, 279 void ExtensionHost::ResizeDueToAutoResize(WebContents* source,
295 const gfx::Size& new_size) { 280 const gfx::Size& new_size) {
296 if (view_.get()) 281 if (view())
297 view_->ResizeDueToAutoResize(new_size); 282 view()->ResizeDueToAutoResize(new_size);
298 } 283 }
299 284
300 void ExtensionHost::RenderViewGone(base::TerminationStatus status) { 285 void ExtensionHost::RenderViewGone(base::TerminationStatus status) {
301 // During browser shutdown, we may use sudden termination on an extension 286 // During browser shutdown, we may use sudden termination on an extension
302 // process, so it is expected to lose our connection to the render view. 287 // process, so it is expected to lose our connection to the render view.
303 // Do nothing. 288 // Do nothing.
304 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) 289 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID)
305 return; 290 return;
306 291
307 // In certain cases, multiple ExtensionHost objects may have pointed to 292 // In certain cases, multiple ExtensionHost objects may have pointed to
(...skipping 23 matching lines...) Expand all
331 316
332 render_view_host()->InsertCSS(string16(), css.as_string()); 317 render_view_host()->InsertCSS(string16(), css.as_string());
333 } 318 }
334 319
335 void ExtensionHost::DidStopLoading() { 320 void ExtensionHost::DidStopLoading() {
336 bool notify = !did_stop_loading_; 321 bool notify = !did_stop_loading_;
337 did_stop_loading_ = true; 322 did_stop_loading_ = true;
338 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || 323 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP ||
339 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || 324 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG ||
340 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR || 325 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR ||
341 extension_host_type_ == chrome::VIEW_TYPE_APP_SHELL ||
342 extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 326 extension_host_type_ == chrome::VIEW_TYPE_PANEL) {
343 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) 327 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)
344 if (view_.get()) 328 if (view())
345 view_->DidStopLoading(); 329 view()->DidStopLoading();
346 #endif 330 #endif
347 } 331 }
348 if (notify) { 332 if (notify) {
349 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 333 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
350 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime", 334 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime",
351 since_created_.Elapsed()); 335 since_created_.Elapsed());
352 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG) { 336 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG) {
353 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime", 337 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime",
354 since_created_.Elapsed()); 338 since_created_.Elapsed());
355 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) { 339 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) {
356 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime", 340 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime",
357 since_created_.Elapsed()); 341 since_created_.Elapsed());
358 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { 342 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) {
359 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime", 343 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime",
360 since_created_.Elapsed()); 344 since_created_.Elapsed());
361 } else if (extension_host_type_ == chrome::VIEW_TYPE_APP_SHELL) {
362 UMA_HISTOGRAM_TIMES("Extensions.ShellLoadTime", since_created_.Elapsed());
363 } else if (extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 345 } else if (extension_host_type_ == chrome::VIEW_TYPE_PANEL) {
364 UMA_HISTOGRAM_TIMES("Extensions.PanelLoadTime", since_created_.Elapsed()); 346 UMA_HISTOGRAM_TIMES("Extensions.PanelLoadTime", since_created_.Elapsed());
365 } 347 }
366 348
367 // Send the notification last, because it might result in this being 349 // Send the notification last, because it might result in this being
368 // deleted. 350 // deleted.
369 content::NotificationService::current()->Notify( 351 content::NotificationService::current()->Notify(
370 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, 352 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
371 content::Source<Profile>(profile_), 353 content::Source<Profile>(profile_),
372 content::Details<ExtensionHost>(this)); 354 content::Details<ExtensionHost>(this));
(...skipping 26 matching lines...) Expand all
399 content::Source<Profile>(profile_), 381 content::Source<Profile>(profile_),
400 content::Details<ExtensionHost>(this)); 382 content::Details<ExtensionHost>(this));
401 } 383 }
402 384
403 void ExtensionHost::CloseContents(WebContents* contents) { 385 void ExtensionHost::CloseContents(WebContents* contents) {
404 // TODO(mpcomplete): is this check really necessary? 386 // TODO(mpcomplete): is this check really necessary?
405 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || 387 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP ||
406 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || 388 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG ||
407 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE || 389 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE ||
408 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR || 390 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR ||
409 extension_host_type_ == chrome::VIEW_TYPE_APP_SHELL ||
410 extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 391 extension_host_type_ == chrome::VIEW_TYPE_PANEL) {
411 Close(); 392 Close();
412 } 393 }
413 } 394 }
414 395
415 bool ExtensionHost::ShouldSuppressDialogs() {
416 return extension_->is_platform_app();
417 }
418
419 void ExtensionHost::WillRunJavaScriptDialog() { 396 void ExtensionHost::WillRunJavaScriptDialog() {
420 ExtensionProcessManager* pm = 397 ExtensionProcessManager* pm =
421 ExtensionSystem::Get(profile_)->process_manager(); 398 ExtensionSystem::Get(profile_)->process_manager();
422 if (pm) 399 if (pm)
423 pm->IncrementLazyKeepaliveCount(extension()); 400 pm->IncrementLazyKeepaliveCount(extension());
424 } 401 }
425 402
426 void ExtensionHost::DidCloseJavaScriptDialog() { 403 void ExtensionHost::DidCloseJavaScriptDialog() {
427 ExtensionProcessManager* pm = 404 ExtensionProcessManager* pm =
428 ExtensionSystem::Get(profile_)->process_manager(); 405 ExtensionSystem::Get(profile_)->process_manager();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 return handled; 459 return handled;
483 } 460 }
484 461
485 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { 462 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) {
486 extension_function_dispatcher_.Dispatch(params, render_view_host()); 463 extension_function_dispatcher_.Dispatch(params, render_view_host());
487 } 464 }
488 465
489 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { 466 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) {
490 render_view_host_ = render_view_host; 467 render_view_host_ = render_view_host;
491 468
492 if (view_.get()) 469 if (view())
493 view_->RenderViewCreated(); 470 view()->RenderViewCreated();
494 471
495 // If the host is bound to a browser, then extract its window id. 472 // If the host is bound to a browser, then extract its window id.
496 // Extensions hosted in ExternalTabContainer objects may not have 473 // Extensions hosted in ExternalTabContainer objects may not have
497 // an associated browser. 474 // an associated browser.
498 const Browser* browser = GetBrowser(); 475 const Browser* browser = GetBrowser();
499 if (browser) { 476 if (browser) {
500 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId( 477 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId(
501 render_view_host->GetRoutingID(), 478 render_view_host->GetRoutingID(),
502 ExtensionTabUtil::GetWindowId(browser))); 479 ExtensionTabUtil::GetWindowId(browser)));
503 } 480 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 params.user_gesture = user_gesture; 549 params.user_gesture = user_gesture;
573 browser::Navigate(&params); 550 browser::Navigate(&params);
574 } 551 }
575 552
576 void ExtensionHost::RenderViewReady() { 553 void ExtensionHost::RenderViewReady() {
577 content::NotificationService::current()->Notify( 554 content::NotificationService::current()->Notify(
578 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, 555 chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
579 content::Source<Profile>(profile_), 556 content::Source<Profile>(profile_),
580 content::Details<ExtensionHost>(this)); 557 content::Details<ExtensionHost>(this));
581 } 558 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698