OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 27 matching lines...) Expand all Loading... |
38 #include "content/browser/browsing_instance.h" | 38 #include "content/browser/browsing_instance.h" |
39 #include "content/browser/renderer_host/browser_render_process_host.h" | 39 #include "content/browser/renderer_host/browser_render_process_host.h" |
40 #include "content/browser/renderer_host/render_process_host.h" | 40 #include "content/browser/renderer_host/render_process_host.h" |
41 #include "content/browser/renderer_host/render_view_host.h" | 41 #include "content/browser/renderer_host/render_view_host.h" |
42 #include "content/browser/renderer_host/render_widget_host.h" | 42 #include "content/browser/renderer_host/render_widget_host.h" |
43 #include "content/browser/renderer_host/render_widget_host_view.h" | 43 #include "content/browser/renderer_host/render_widget_host_view.h" |
44 #include "content/browser/site_instance.h" | 44 #include "content/browser/site_instance.h" |
45 #include "content/browser/tab_contents/popup_menu_helper_mac.h" | 45 #include "content/browser/tab_contents/popup_menu_helper_mac.h" |
46 #include "content/browser/tab_contents/tab_contents.h" | 46 #include "content/browser/tab_contents/tab_contents.h" |
47 #include "content/browser/tab_contents/tab_contents_view.h" | 47 #include "content/browser/tab_contents/tab_contents_view.h" |
48 #include "content/common/notification_service.h" | 48 #include "content/public/browser/notification_service.h" |
49 #include "content/common/view_messages.h" | 49 #include "content/common/view_messages.h" |
50 #include "content/public/browser/content_browser_client.h" | 50 #include "content/public/browser/content_browser_client.h" |
51 #include "content/public/browser/native_web_keyboard_event.h" | 51 #include "content/public/browser/native_web_keyboard_event.h" |
52 #include "content/public/common/bindings_policy.h" | 52 #include "content/public/common/bindings_policy.h" |
53 #include "grit/browser_resources.h" | 53 #include "grit/browser_resources.h" |
54 #include "grit/chromium_strings.h" | 54 #include "grit/chromium_strings.h" |
55 #include "grit/generated_resources.h" | 55 #include "grit/generated_resources.h" |
56 #include "ui/base/keycodes/keyboard_codes.h" | 56 #include "ui/base/keycodes/keyboard_codes.h" |
57 #include "ui/base/l10n/l10n_util.h" | 57 #include "ui/base/l10n/l10n_util.h" |
58 #include "ui/base/resource/resource_bundle.h" | 58 #include "ui/base/resource/resource_bundle.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 did_stop_loading_(false), | 168 did_stop_loading_(false), |
169 document_element_available_(false), | 169 document_element_available_(false), |
170 url_(GURL()), | 170 url_(GURL()), |
171 ALLOW_THIS_IN_INITIALIZER_LIST( | 171 ALLOW_THIS_IN_INITIALIZER_LIST( |
172 extension_function_dispatcher_(profile_, this)), | 172 extension_function_dispatcher_(profile_, this)), |
173 extension_host_type_(host_type), | 173 extension_host_type_(host_type), |
174 associated_tab_contents_(NULL) { | 174 associated_tab_contents_(NULL) { |
175 } | 175 } |
176 | 176 |
177 ExtensionHost::~ExtensionHost() { | 177 ExtensionHost::~ExtensionHost() { |
178 NotificationService::current()->Notify( | 178 content::NotificationService::current()->Notify( |
179 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 179 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
180 content::Source<Profile>(profile_), | 180 content::Source<Profile>(profile_), |
181 content::Details<ExtensionHost>(this)); | 181 content::Details<ExtensionHost>(this)); |
182 ProcessCreationQueue::GetInstance()->Remove(this); | 182 ProcessCreationQueue::GetInstance()->Remove(this); |
183 GetJavaScriptDialogCreatorInstance()->ResetJavaScriptState(this); | 183 GetJavaScriptDialogCreatorInstance()->ResetJavaScriptState(this); |
184 // render_view_host_ may be NULL in unit tests. | 184 // render_view_host_ may be NULL in unit tests. |
185 if (render_view_host_) | 185 if (render_view_host_) |
186 render_view_host_->Shutdown(); // deletes render_view_host | 186 render_view_host_->Shutdown(); // deletes render_view_host |
187 } | 187 } |
188 | 188 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 void ExtensionHost::Observe(int type, | 291 void ExtensionHost::Observe(int type, |
292 const content::NotificationSource& source, | 292 const content::NotificationSource& source, |
293 const content::NotificationDetails& details) { | 293 const content::NotificationDetails& details) { |
294 switch (type) { | 294 switch (type) { |
295 case chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY: | 295 case chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY: |
296 DCHECK(profile_->GetExtensionService()-> | 296 DCHECK(profile_->GetExtensionService()-> |
297 IsBackgroundPageReady(extension_)); | 297 IsBackgroundPageReady(extension_)); |
298 NavigateToURL(url_); | 298 NavigateToURL(url_); |
299 break; | 299 break; |
300 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: | 300 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: |
301 NotificationService::current()->Notify( | 301 content::NotificationService::current()->Notify( |
302 chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, | 302 chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, |
303 content::Source<Profile>(profile_), | 303 content::Source<Profile>(profile_), |
304 content::Details<ExtensionHost>(this)); | 304 content::Details<ExtensionHost>(this)); |
305 break; | 305 break; |
306 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 306 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
307 // The extension object will be deleted after this notification has been | 307 // The extension object will be deleted after this notification has been |
308 // sent. NULL it out so that dirty pointer issues don't arise in cases | 308 // sent. NULL it out so that dirty pointer issues don't arise in cases |
309 // when multiple ExtensionHost objects pointing to the same Extension are | 309 // when multiple ExtensionHost objects pointing to the same Extension are |
310 // present. | 310 // present. |
311 if (extension_ == | 311 if (extension_ == |
(...skipping 27 matching lines...) Expand all Loading... |
339 // is unloaded, and any other host that pointed to that extension will have | 339 // is unloaded, and any other host that pointed to that extension will have |
340 // its pointer to it NULLed out so that any attempt to unload a dirty pointer | 340 // its pointer to it NULLed out so that any attempt to unload a dirty pointer |
341 // will be averted. | 341 // will be averted. |
342 if (!extension_) | 342 if (!extension_) |
343 return; | 343 return; |
344 | 344 |
345 // TODO(aa): This is suspicious. There can be multiple views in an extension, | 345 // TODO(aa): This is suspicious. There can be multiple views in an extension, |
346 // and they aren't all going to use ExtensionHost. This should be in someplace | 346 // and they aren't all going to use ExtensionHost. This should be in someplace |
347 // more central, like EPM maybe. | 347 // more central, like EPM maybe. |
348 DCHECK_EQ(render_view_host_, render_view_host); | 348 DCHECK_EQ(render_view_host_, render_view_host); |
349 NotificationService::current()->Notify( | 349 content::NotificationService::current()->Notify( |
350 chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 350 chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
351 content::Source<Profile>(profile_), | 351 content::Source<Profile>(profile_), |
352 content::Details<ExtensionHost>(this)); | 352 content::Details<ExtensionHost>(this)); |
353 } | 353 } |
354 | 354 |
355 void ExtensionHost::DidNavigate(RenderViewHost* render_view_host, | 355 void ExtensionHost::DidNavigate(RenderViewHost* render_view_host, |
356 const ViewHostMsg_FrameNavigate_Params& params) { | 356 const ViewHostMsg_FrameNavigate_Params& params) { |
357 // We only care when the outer frame changes. | 357 // We only care when the outer frame changes. |
358 if (!content::PageTransitionIsMainFrame(params.transition)) | 358 if (!content::PageTransitionIsMainFrame(params.transition)) |
359 return; | 359 return; |
(...skipping 21 matching lines...) Expand all Loading... |
381 did_stop_loading_ = true; | 381 did_stop_loading_ = true; |
382 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || | 382 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || |
383 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || | 383 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || |
384 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { | 384 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { |
385 #if defined(TOOLKIT_VIEWS) | 385 #if defined(TOOLKIT_VIEWS) |
386 if (view_.get()) | 386 if (view_.get()) |
387 view_->DidStopLoading(); | 387 view_->DidStopLoading(); |
388 #endif | 388 #endif |
389 } | 389 } |
390 if (notify) { | 390 if (notify) { |
391 NotificationService::current()->Notify( | 391 content::NotificationService::current()->Notify( |
392 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 392 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
393 content::Source<Profile>(profile_), | 393 content::Source<Profile>(profile_), |
394 content::Details<ExtensionHost>(this)); | 394 content::Details<ExtensionHost>(this)); |
395 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 395 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
396 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime", | 396 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime", |
397 since_created_.Elapsed()); | 397 since_created_.Elapsed()); |
398 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG) { | 398 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG) { |
399 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime", | 399 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime", |
400 since_created_.Elapsed()); | 400 since_created_.Elapsed()); |
401 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) { | 401 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) { |
(...skipping 22 matching lines...) Expand all Loading... |
424 break; | 424 break; |
425 default: | 425 default: |
426 break; // No style sheet for other types, at the moment. | 426 break; // No style sheet for other types, at the moment. |
427 } | 427 } |
428 } | 428 } |
429 } | 429 } |
430 | 430 |
431 void ExtensionHost::DocumentOnLoadCompletedInMainFrame(RenderViewHost* rvh, | 431 void ExtensionHost::DocumentOnLoadCompletedInMainFrame(RenderViewHost* rvh, |
432 int32 page_id) { | 432 int32 page_id) { |
433 if (chrome::VIEW_TYPE_EXTENSION_POPUP == GetRenderViewType()) { | 433 if (chrome::VIEW_TYPE_EXTENSION_POPUP == GetRenderViewType()) { |
434 NotificationService::current()->Notify( | 434 content::NotificationService::current()->Notify( |
435 chrome::NOTIFICATION_EXTENSION_POPUP_VIEW_READY, | 435 chrome::NOTIFICATION_EXTENSION_POPUP_VIEW_READY, |
436 content::Source<Profile>(profile_), | 436 content::Source<Profile>(profile_), |
437 content::Details<ExtensionHost>(this)); | 437 content::Details<ExtensionHost>(this)); |
438 } | 438 } |
439 } | 439 } |
440 | 440 |
441 void ExtensionHost::RunJavaScriptMessage(const RenderViewHost* rvh, | 441 void ExtensionHost::RunJavaScriptMessage(const RenderViewHost* rvh, |
442 const string16& message, | 442 const string16& message, |
443 const string16& default_prompt, | 443 const string16& default_prompt, |
444 const GURL& frame_url, | 444 const GURL& frame_url, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 render_view_host()->JavaScriptDialogClosed(reply_msg, | 496 render_view_host()->JavaScriptDialogClosed(reply_msg, |
497 success, | 497 success, |
498 user_input); | 498 user_input); |
499 } | 499 } |
500 | 500 |
501 void ExtensionHost::Close(RenderViewHost* render_view_host) { | 501 void ExtensionHost::Close(RenderViewHost* render_view_host) { |
502 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || | 502 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || |
503 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || | 503 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || |
504 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE || | 504 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE || |
505 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { | 505 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { |
506 NotificationService::current()->Notify( | 506 content::NotificationService::current()->Notify( |
507 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 507 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
508 content::Source<Profile>(profile_), | 508 content::Source<Profile>(profile_), |
509 content::Details<ExtensionHost>(this)); | 509 content::Details<ExtensionHost>(this)); |
510 } | 510 } |
511 } | 511 } |
512 | 512 |
513 RendererPreferences ExtensionHost::GetRendererPrefs( | 513 RendererPreferences ExtensionHost::GetRendererPrefs( |
514 content::BrowserContext* browser_context) const { | 514 content::BrowserContext* browser_context) const { |
515 Profile* profile = Profile::FromBrowserContext(browser_context); | 515 Profile* profile = Profile::FromBrowserContext(browser_context); |
516 RendererPreferences preferences; | 516 RendererPreferences preferences; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 DCHECK(is_keyboard_shortcut != NULL); | 565 DCHECK(is_keyboard_shortcut != NULL); |
566 *is_keyboard_shortcut = true; | 566 *is_keyboard_shortcut = true; |
567 } | 567 } |
568 return false; | 568 return false; |
569 } | 569 } |
570 | 570 |
571 void ExtensionHost::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 571 void ExtensionHost::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
572 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) { | 572 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) { |
573 if (event.type == NativeWebKeyboardEvent::RawKeyDown && | 573 if (event.type == NativeWebKeyboardEvent::RawKeyDown && |
574 event.windowsKeyCode == ui::VKEY_ESCAPE) { | 574 event.windowsKeyCode == ui::VKEY_ESCAPE) { |
575 NotificationService::current()->Notify( | 575 content::NotificationService::current()->Notify( |
576 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 576 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
577 content::Source<Profile>(profile_), | 577 content::Source<Profile>(profile_), |
578 content::Details<ExtensionHost>(this)); | 578 content::Details<ExtensionHost>(this)); |
579 return; | 579 return; |
580 } | 580 } |
581 } | 581 } |
582 UnhandledKeyboardEvent(event); | 582 UnhandledKeyboardEvent(event); |
583 } | 583 } |
584 | 584 |
585 void ExtensionHost::HandleMouseMove() { | 585 void ExtensionHost::HandleMouseMove() { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { | 815 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { |
816 if (view_.get()) | 816 if (view_.get()) |
817 view_->RenderViewCreated(); | 817 view_->RenderViewCreated(); |
818 | 818 |
819 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || | 819 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || |
820 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { | 820 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { |
821 render_view_host->EnablePreferredSizeMode( | 821 render_view_host->EnablePreferredSizeMode( |
822 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); | 822 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); |
823 } | 823 } |
824 } | 824 } |
OLD | NEW |